Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Locked thread
homercles
Feb 14, 2010

Azhais posted:

I'm too old to learn new syntax. Perl5 for life!

:corsair:

I'll learn Perl 6 when there are Perl 6 jobs out there. So, probably never.

Adbot
ADBOT LOVES YOU

Hughmoris
Apr 21, 2007
Let's go to the abyss!
Any recommend tutorials or starting points for learning Object Oriented programming in Perl 5? Im starting from scratch, no prior OO knowledge.

Just wanting to learn for hobby projects.

Mithaldu
Sep 25, 2007

Let's cuddle. :3:
This chapter explains bare-bones OO in Perl:

http://web.archive.org/web/20120717215030/http://ofps.oreilly.com/titles/9781118013847/object_oriented_perl.html

No need to really learn that, since much of it you won't be using anyhow. Good to know and skim though.

The next chapter explains OO how it is used in production, with wrappers creating very efficient DSLs around the basic OO bits of Perl:

http://web.archive.org/web/20120718083717/http://ofps.oreilly.com/titles/9781118013847/moose.html

Note however that 99% of the time, you won't actually want to use Moose (which comes with a heavy startup time penalty), and instead use Moo, which is 99% compatible from the outside (it doesn't have ->meta, and thus is MUCH lighter on the inside).

If you'd like something shorter, Modern Perl explains OO as well, and is reliable, though the notes from above apply as well:

http://modernperlbooks.com/books/modern_perl_2016/07-object-oriented-perl.html#T2JqZWN0cw

Additionally, you'll want to read the Moo docs as a sort of crash course to modern Perl OO:

https://metacpan.org/pod/Moo

And if you yearn for details, much of the Moose manual applies to Moo as well, but is a lot more verbose:

https://metacpan.org/pod/Moose#New-to-Moose

Edit, also, i forgot this excellent talk about Moo/se style OO which will help a lot in grasping the concepts behind it:

https://rjbs.manxome.org/talks/moose/Moose.pdf

Mithaldu fucked around with this message at 08:07 on Feb 5, 2016

Hughmoris
Apr 21, 2007
Let's go to the abyss!

Mithaldu posted:

This chapter explains bare-bones OO in Perl:

http://web.archive.org/web/20120717215030/http://ofps.oreilly.com/titles/9781118013847/object_oriented_perl.html

No need to really learn that, since much of it you won't be using anyhow. Good to know and skim though.

The next chapter explains OO how it is used in production, with wrappers creating very efficient DSLs around the basic OO bits of Perl:

http://web.archive.org/web/20120718083717/http://ofps.oreilly.com/titles/9781118013847/moose.html

Note however that 99% of the time, you won't actually want to use Moose (which comes with a heavy startup time penalty), and instead use Moo, which is 99% compatible from the outside (it doesn't have ->meta, and thus is MUCH lighter on the inside).

If you'd like something shorter, Modern Perl explains OO as well, and is reliable, though the notes from above apply as well:

http://modernperlbooks.com/books/modern_perl_2016/07-object-oriented-perl.html#T2JqZWN0cw

Additionally, you'll want to read the Moo docs as a sort of crash course to modern Perl OO:

https://metacpan.org/pod/Moo

And if you yearn for details, much of the Moose manual applies to Moo as well, but is a lot more verbose:

https://metacpan.org/pod/Moose#New-to-Moose

Thanks for this.

I asked this question in #perl IRC, and seemingly opened up a huge can of worms. Ended up being told to go learn OO in small talk or ruby.

Hughmoris fucked around with this message at 02:47 on Feb 5, 2016

Extortionist
Aug 31, 2001

Leave the gun. Take the cannoli.

Hughmoris posted:

Thanks for this.

I asked this question in #perl IRC, and seemingly opened up a huge can of worms. Ended up being told to go learn OO in small talk or ruby.
Really if your goal is learning OO programming, you might be better off with another language. OO support is pretty hacked in in perl (see the recommendations above requiring the use of non-core libraries) and might not translate well to general OO practices across other languages.

Those are good suggestions if you're married to perl for whatever reason, but you might look elsewhere if you're looking for more general learning.

Mithaldu
Sep 25, 2007

Let's cuddle. :3:

Hughmoris posted:

Thanks for this.

I asked this question in #perl IRC, and seemingly opened up a huge can of worms. Ended up being told to go learn OO in small talk or ruby.
I looked at the logs and you ran into Sushee and mauke. I'm sorry about that. They're good people, but also decidedly weird germans (like me) who have been around for too long and developed some weird prejudices about what constitutes correct and useful teaching, since they never interact with newbies a lot or in-depth. Unless you're showing some Perl code to be inspected for mistakes, it is entirely safe to disregard them (and even then i'd get a second opinion on anything Sushee says).

They're also both not very aware of the actual state of Perl tutorials and teaching resources about OO, or they would've told you to go read these following slides i forgot to link in my earlier post. (They will help a lot in grasping the concepts behind Moo/se style OO.)

https://rjbs.manxome.org/talks/moose/Moose.pdf


Extortionist posted:

Really if your goal is learning OO programming, you might be better off with another language. OO support is pretty hacked in in perl (see the recommendations above requiring the use of non-core libraries) and might not translate well to general OO practices across other languages.

Those are good suggestions if you're married to perl for whatever reason, but you might look elsewhere if you're looking for more general learning.
Entirely disagree. The only good reasons to go with another language to teach yourself OO are:

- for some insane reason you cannot use cpan;
- to either learn it in an decidedly un-C-like language (i.e. to widen horizons forcibly);
- to save yourself the frustration that's inevitable when you switch from Perl to another language and find that most other languages implement less OO features than Perl does (like a complete implementation of Roles or constructor/accessor DSL) (particular Ruby's OO is extremely barebones compared to Perl's)

There's also no reason to call it "hacked", since most other languages implement OO similar to how Moo/se does it, just inside the interpreter, not outside it. Seriously, go compare Python's implementation with Moose's. To complain about the level at which OO is implemented is roughly as pointless as drawing a hard line between "scripting" languages and "programming" languages. (If you're not sure why that is pointless, go google it please.)

jony neuemonic
Nov 13, 2009

You may also run into Mojolicious' classes if you do any web development, but they're a much thinner layer over top of the built-in OO than something like Moose (really just a base class with a few convenience methods and a nicer syntax for inheritance).

Extortionist
Aug 31, 2001

Leave the gun. Take the cannoli.

Mithaldu posted:

Entirely disagree.
Really my objections come from personal experience maintaining ostensibly OO-code written by people who learned OO coding exclusively with perl. You can surely learn it and learn it well with perl, but perl's ethos also lets you learn it poorly and think you're learning it well, regardless of whatever atrocities you're committing.

I really think someone new to OO programming would be better off learning its paradigms in a language where its paradigms are more commonly used and are more strictly enforced.

fuck the mods
Mar 30, 2015
You could learn classes in Perl 6... you would start with less preconception/habits you've developed in perl while still being trivial to jump back into p5 with Moose

Mithaldu
Sep 25, 2007

Let's cuddle. :3:

Extortionist posted:

Really my objections come from personal experience maintaining ostensibly OO-code written by people who learned OO coding exclusively with perl. You can surely learn it and learn it well with perl, but perl's ethos also lets you learn it poorly and think you're learning it well, regardless of whatever atrocities you're committing.

I really think someone new to OO programming would be better off learning its paradigms in a language where its paradigms are more commonly used and are more strictly enforced.

You're reflecting on the people involved, the learning resources they chose and your own lack of knowledge on quality OO Perl learning resources; not on anything inherent to Perl. In which case, yeah, i agree. If the person learning is generally lazy, and happy to start learning from the first google hit that presents to them, it's a good recommendation to go with a language that puts them in a straight-jacket. Otherwise Perl is fine to learn OO with, especially when sticking to the links i gave.

However note that your first post explained none of that, and made the false assertion of the OO support being "hacked" and OO practices not "translating well to other languages".

Mithaldu fucked around with this message at 16:37 on Feb 6, 2016

qntm
Jun 17, 2009
"OO support in Perl" is this, not Moose.

Mithaldu
Sep 25, 2007

Let's cuddle. :3:

qntm posted:

"OO support in Perl" is this, not Moose.

Even the perl core docs recommend Moo/se: http://perldoc.perl.org/perlootut.html

Unless you're trying to make a different kind of point, in which case you'll have to be more verbose.

Hughmoris
Apr 21, 2007
Let's go to the abyss!

gently caress the mods posted:

You could learn classes in Perl 6... you would start with less preconception/habits you've developed in perl while still being trivial to jump back into p5 with Moose

I've poked around Perl 6 but the small about of docs/tutorials are a little hard for me to catch on to. I learn better by seeing lots of examples, and since there is an abundance of Perl 5 OO tutorials out there, I figured I'd learn P5 and try and translate some of the knowledge to P6.

Extortionist
Aug 31, 2001

Leave the gun. Take the cannoli.

Mithaldu posted:

You're reflecting on the people involved, the learning resources they chose and your own lack of knowledge on quality OO Perl learning resources; not on anything inherent to Perl. In which case, yeah, i agree. If the person learning is generally lazy, and happy to start learning from the first google hit that presents to them, it's a good recommendation to go with a language that puts them in a straight-jacket. Otherwise Perl is fine to learn OO with, especially when sticking to the links i gave.

However note that your first post explained none of that, and made the false assertion of the OO support being "hacked" and OO practices not "translating well to other languages".
So, I was already familiar with all of the resources you linked and probably would have included some of them myself if it hadn't been redundant. You'll note that I said they were all good resources if someone's sticking to perl. Thanks for assuming I'm ignorant, though.

Perl's flexibility is a huge handicap against learning (yes, I am arguing that the issue here is something inherent to perl). I don't think it has much to do with the laziness you imply, so much as it has to do with the difficulty of learning various concepts and perl's willingness to let you put together something that entirely contradicts best practices but also solves the problem you're trying to solve (this is probably also one of perl's biggest strengths--just not so much when it comes to learning). I deal with the consequences of this too often in my daily work to assume that someone trying to learn something blindly in such a permissive language will magically fall into best practices. Surely someone can do it if they're smart and diligent enough--but probably they'd also have an easier time of it if the language didn't fool them about what they were doing.

I will stand by my assertion that perl's OO support is hacked. The core language plainly isn't designed to properly support OO, and you can easily blow apart any OO code in perl intentionally or accidentally.

Mithaldu
Sep 25, 2007

Let's cuddle. :3:

Extortionist posted:

Thanks for assuming I'm ignorant, though.
That, or prejudice. I assumed the nicer one.

Extortionist posted:

I deal with the consequences of this too often in my daily work
Meanwhile, using Ovid's Beginning Perl and Modern Perl, i've taught several Perl developers how to write good Perl, almost from scratch, each within less than a year; and when revisiting them later found they did an excellent job of maintaining the knowledge and passing it on in the way i did, by having others read the books and become good devs. It is a mark of pride for you that you stand by your coworkers, but the prejudice you maintain as a result isn't doing you any good.

Extortionist posted:

The core language plainly isn't designed to properly support OO, and you can easily blow apart any OO code in perl intentionally or accidentally.
You're misstating your thoughts. Your problem isn't that that the language isn't designed to properly support it (it does and contains all the minimum bits necessary to build OO on top of). Your problem is that you disagree with the level these structures are exposed at, despite them being the same structures as in any other language. Your problem is similar to people who declare C unsafe because people have to do memory management themselves instead of having it built into the language.

Ellie Crabcakes
Feb 1, 2008

Stop emailing my boyfriend Gay Crungus

Mithaldu posted:

(in particular Ruby's OO is extremely barebones compared to Perl's)
I have a few issues with ruby, but its OO being barebones isn't one of them.
code:
puts "lol".class.superclass.new.methods.inspect
puts "lol".class.superclass.methods.inspect
Now if that's possible in core perl, I'd like to know how.

Extortionist posted:

Perl's flexibility is a huge handicap against learning (yes, I am arguing that the issue here is something inherent to perl). I don't think it has much to do with the laziness you imply, so much as it has to do with the difficulty of learning various concepts and perl's willingness to let you put together something that entirely contradicts best practices but also solves the problem you're trying to solve (this is probably also one of perl's biggest strengths--just not so much when it comes to learning). I deal with the consequences of this too often in my daily work to assume that someone trying to learn something blindly in such a permissive language will magically fall into best practices. Surely someone can do it if they're smart and diligent enough--but probably they'd also have an easier time of it if the language didn't fool them about what they were doing.

I will stand by my assertion that perl's OO support is hacked. The core language plainly isn't designed to properly support OO, and you can easily blow apart any OO code in perl intentionally or accidentally.
Exactly. "There's more than one way to do it," in practice, often translates to "Here, have some more rope."

While I've coded in perl for about 17 years, it's not a good starter language.

[edit] Perl 6 :laffo:
[edit2] Mithaldu, are you that "true perler" guy from a few months back?

Ellie Crabcakes fucked around with this message at 08:17 on Feb 23, 2016

Mithaldu
Sep 25, 2007

Let's cuddle. :3:

John Big Booty posted:

I have a few issues with ruby, but its OO being barebones isn't one of them.
Particularly attribute and constructor declaration in Ruby are barely more detailed than those in core Perl.

Can you do this in Ruby at all?
code:
package RoleX {
    use Moo::Role;
    use Types::Standard "Int";
     
    has x => ( is => "rw", isa => Int, required => 0, default => sub { 5 } );
}

package Point {
    use Moo;
    with "RoleX";
    has "+x" => ( required => 1 );
}

my $o = Point->new( x => 4 );
And yeah, i don't care if you have to call in libraries or whatever, i just want to know if, in Ruby, you can have the syntax to declare attributes in a parametrized and compartmentalized manner, meaning:

- the constructor expects named arguments for the attributes
- setters/getters are created automatically, with the "is" arg ( ro/rw/rwp/lazy ) determining the exact set of them created
- type checks of some sort can be declared quickly and are baked into the constructor
- "required" status of attributes can be declared and are baked into the constructor
- "default" values can be provided in the attribute declaration and baked into the constructor
- the whole thing can be bundled up and re-used as one whole thing in many other classes
- the exact specification of an attribute pulled in from somewhere else can be modified in the target class

How many of these points can Ruby provide?

John Big Booty posted:

code:
puts "lol".class.superclass.new.methods.inspect
puts "lol".class.superclass.methods.inspect
Now if that's possible in core perl, I'd like to know how.
This needs clarification. What exactly is "that"?
a) The syntax? No, you need to implement at least some of that. (Although you could possibly hack that together by attaching things to UNIVERSAL.)
b) The functionality those methods do? Absolutely, i could hack you a quick example if you like.
c) The functionality applied on a string? No, strings are not objects in Perl (by default, but then we go back to b).

John Big Booty posted:

[edit2] Mithaldu, are you that "true perler" guy from a few months back?
John, are you the "reacts to a joke with direct insults" guy from a few months back?

Mithaldu fucked around with this message at 11:37 on Feb 23, 2016

Ellie Crabcakes
Feb 1, 2008

Stop emailing my boyfriend Gay Crungus

Mithaldu posted:

Particularly attribute and constructor declaration in Ruby are barely more detailed than those in core Perl.

Can you do this in Ruby at all?
code:
package RoleX {
    use Moo::Role;
    use Types::Standard "Int";
     
    has x => ( is => "rw", isa => Int, required => 0, default => sub { 5 } );
}

package Point {
    use Moo;
    with "RoleX";
    has "+x" => ( required => 1 );
}

my $o = Point->new( x => 4 );
And yeah, i don't care if you have to call in libraries or whatever, i just want to know if, in Ruby, you can have the syntax to declare attributes in a parametrized and compartmentalized manner, meaning:

- the constructor expects named arguments for the attributes
- setters/getters are created automatically, with the "is" arg ( ro/rw/rwp/lazy ) determining the exact set of them created
- type checks of some sort can be declared quickly and are baked into the constructor
- "required" status of attributes can be declared and are baked into the constructor
- "default" values can be provided in the attribute declaration and baked into the constructor
- the whole thing can be bundled up and re-used as one whole thing in many other classes
- the exact specification of an attribute pulled in from somewhere else can be modified in the target class

How many of these points can Ruby provide?
This needs clarification. What exactly is "that"?
a) The syntax? No, you need to implement at least some of that. (Although you could possibly hack that together by attaching things to UNIVERSAL.)
b) The functionality those methods do? Absolutely, i could hack you a quick example if you like.
c) The functionality applied on a string? No, strings are not objects in Perl (by default, but then we go back to b).
John, are you the "reacts to a joke with direct insults" guy from a few months back?
Perhaps I should have been more specific and said "without having to import a single class or module"

Because perl just can't do it off of a base install. If it could, Moo and Moose and Class::C3 and all of the other bolt-ons would be totally unnecessary.

Now if you're not actually a ridiculous perl bigot, I apologize, but you kinda come off as one. Especially when you say a from-the-ground-up OO language is barebones compared to perl.

Do you have any experience with any actual OO language?

Mithaldu
Sep 25, 2007

Let's cuddle. :3:

John Big Booty posted:

Now if you're not actually a ridiculous perl bigot, I apologize, but you kinda come off as one. Especially when you say a from-the-ground-up OO language is barebones compared to perl.
I'm sorry if i come across like that, but to be quite honest, i find it hard to do anything about it when things i thought i said explicitly are read as the opposite intended.

Mithaldu posted:

And yeah, i don't care if you have to call in libraries or whatever, i just want to know if, in Ruby, you can have the syntax to declare attributes in a parametrized and compartmentalized manner, meaning:
I'm not comparing perl + libs with ruby standalone. That would of course be a ridiculously unfair comparison. I'm comparing all Perl can offer with all Ruby can offer.

So, are you going to tell me which of the things i listed in the previous post Ruby can do?

John Big Booty posted:

Do you have any experience with any actual OO language?
Yeah, i've worked some with Java. I don't consider it particularly fondly. What exactly separates an "actual OO language" from a non-actual one for you though? I assume you mean "everything is an object" languages. I personally find that that detail is often inconsequential, and what matters for the day-to-day labor is how much syntax sugar is provided and/or can be bolted on.


Edit: I only just now realized what you meant with this:

John Big Booty posted:

Perhaps I should have been more specific and said "without having to import a single class or module"
The question is still vague though.

One way to interpret it is: "Can this be implemented without CPAN?" In which case, yes, I can, right now, implement all the functionality and syntax that code does*, without using anything off CPAN, in pure Perl.

Another way to interpret it would be "Are these methods available in the perl core distribution?" Then the answer is: No, perl core encourages using one via its documentation, but for various software engineering reasons does not include one yet.

Another way to interpret it would be "Are these methods available in the perl CORE namespace?" Then the answer is: No, that merely provides the minimum set of functions necessary for all of this.

In general however, even asking "can i do it without CPAN?" is a valid, but merely academic question, since in real world conditions almost nobody is restricted to *only* core perl, even if they have to copy in module files manually. (I have to do this with a client whose credit card security restrictions stipulate that any code used has to be vetted manually.)

* except for the "do it on a raw string" bit, since i don't know yet how pure perl autoboxing works, though i could read up on that

Mithaldu fucked around with this message at 18:31 on Feb 24, 2016

qntm
Jun 17, 2009
"Well, there's six or seven different ways to interpret your question, only one of which casts Perl in a positive light, so let's creatively assume that that's the interpretation you intended."

[beat]

"I'm sick of people misinterpreting me!"

Mithaldu
Sep 25, 2007

Let's cuddle. :3:
Except that i stated what was unclear about his question to me, and when it didn't become more clear, laid out the possible interpretations i saw, including the unfavourable ones, and answered those truthfully. Additionally his misunderstanding was about a question *i* asked and not related to his question at all.

Heck, the very first interpretation i had of his question was one i answered with "no".

Why are you making up poo poo?

Mithaldu
Sep 25, 2007

Let's cuddle. :3:
Got tired of checking manually for new posts on threads, so i automated that bit with a little script and cron: https://github.com/wchristian/SomethingAwful-FreshBookmarks/blob/master/bookmarks.pl

Hughmoris
Apr 21, 2007
Let's go to the abyss!

Mithaldu posted:

Got tired of checking manually for new posts on threads, so i automated that bit with a little script and cron: https://github.com/wchristian/SomethingAwful-FreshBookmarks/blob/master/bookmarks.pl

Pretty cool. You have a screenshot of what the typical output looks like?

Mithaldu
Sep 25, 2007

Let's cuddle. :3:

Hughmoris posted:

Pretty cool. You have a screenshot of what the typical output looks like?

For me it looks like this, since i use cron to send it via email.

BoyBlunder
Sep 17, 2008
I would like a perl script that does the following:

- Determines what version of docker server is running, and prints out 'DOCKERV#', depending on what version it is, e.g DOCKERV1 for v1.19, DOCKERV2, for v2.92, etc. The shell command for this prints the following:

$ docker version
Client:
Version: 1.10.3
API version: 1.22
Go version: go1.5.3
Git commit: 20f81dd
Built: Thu Mar 10 15:54:52 2016
OS/Arch: linux/amd64

Server:
Version: 1.10.3
API version: 1.22
Go version: go1.5.3
Git commit: 20f81dd
Built: Thu Mar 10 15:54:52 2016
OS/Arch: linux/amd64


Where do I begin?

Dawning Horror
Jun 18, 2009

BoyBlunder posted:

I would like a perl script that does the following:

- Determines what version of docker server is running, and prints out 'DOCKERV#', depending on what version it is, e.g DOCKERV1 for v1.19, DOCKERV2, for v2.92, etc. The shell command for this prints the following:

$ docker version
Client:
Version: 1.10.3
API version: 1.22
Go version: go1.5.3
Git commit: 20f81dd
Built: Thu Mar 10 15:54:52 2016
OS/Arch: linux/amd64

Server:
Version: 1.10.3
API version: 1.22
Go version: go1.5.3
Git commit: 20f81dd
Built: Thu Mar 10 15:54:52 2016
OS/Arch: linux/amd64


Where do I begin?

Well, you'd start by getting that output into your perl script, so you'd start with backticks. After that, you'd want a regex to grab the first digits after "Version: " and before the decimal:
code:
`docker version` =~ /Version:\s\d/;
But that would capture the Client version first instead, so let's make that more specific by making it match "Server:" on the line before as well:
code:
`docker version` =~ /Server:\nVersion:\s\d/
And since docker might live to see version 10 and upwards, let's add a + after the \d so it matches one or more digits. After that, we wrap \d+ in parentheses to store it in $1, which is a builtin variable used to store pattern matches. Then just do a print command and we're done.
code:
`docker version` =~ /Server:\nVersion:\s(\d+)/;
print "DOCKERV",$1,"\n";

Hughmoris
Apr 21, 2007
Let's go to the abyss!

Luke Johnson posted:

Well, you'd start by getting that output into your perl script, so you'd start with backticks. After that, you'd want a regex to grab the first digits after "Version: " and before the decimal:
code:
`docker version` =~ /Version:\s\d/;
But that would capture the Client version first instead, so let's make that more specific by making it match "Server:" on the line before as well:
code:
`docker version` =~ /Server:\nVersion:\s\d/
And since docker might live to see version 10 and upwards, let's add a + after the \d so it matches one or more digits. After that, we wrap \d+ in parentheses to store it in $1, which is a builtin variable used to store pattern matches. Then just do a print command and we're done.
code:
`docker version` =~ /Server:\nVersion:\s(\d+)/;
print "DOCKERV",$1,"\n";


I fiddle with Perl and dabble in Linux. Throwing backticks in front of DOCKER VERSION will essentially run that command in the shell (?) and return its output to the Perl script? Learn something new every day.

Dawning Horror
Jun 18, 2009

Hughmoris posted:

I fiddle with Perl and dabble in Linux. Throwing backticks in front of DOCKER VERSION will essentially run that command in the shell (?) and return its output to the Perl script? Learn something new every day.

Yeah, it's handy for simple things like this when you don't want to remember how open works with commands.

Hughmoris
Apr 21, 2007
Let's go to the abyss!
I'm trying to create my first tangible programming project outside of puzzles and text parsing for work. I'd like to create a module to connect to the Twitter Streaming API, since the CPAN Net::twitter::Stream seems old and defunct now (doesn't use OAUTH). It doesn't need to be anything fancy or extremely polished, just a learning exercise.

Since I don't have any colleagues or friends that program, I was hoping you all might be able to guide me along to figuring this out. To start with, here's some documentation for the Twitter Streaming API:
Overview: https://dev.twitter.com/streaming/overview
Connecting to a streaming endpoint: https://dev.twitter.com/streaming/overview/connecting
Streaming API Request parameter: https://dev.twitter.com/streaming/overview/request-parameters

I already have my Twitter app setup completed with all my needed authorization tokens and keys. I'm thinking the steps needed are 1. connect to stream using OAUTH -> create a connection that stays open and constantly receives data -> parse data into something readable.

Does this sound like something reasonable for someone with no real programming experience and a beginner's grasp on Perl?

Ellie Crabcakes
Feb 1, 2008

Stop emailing my boyfriend Gay Crungus

Seems like a good learning project. I'd recommend AnyEvent for listening to the stream.

Hughmoris
Apr 21, 2007
Let's go to the abyss!
My web knowledge is even weaker than my Perl. My script uses Mechanize to log into a website and retrieve a few pages. If I don't want to have to perform a new login every time I run the script, how do I go about it? Is it a cookie that I want to save, or session information of some sort? Sort of like the 'Remember Me' option you have when you use a browser to login.

Mithaldu
Sep 25, 2007

Let's cuddle. :3:

Hughmoris posted:

My web knowledge is even weaker than my Perl. My script uses Mechanize to log into a website and retrieve a few pages. If I don't want to have to perform a new login every time I run the script, how do I go about it? Is it a cookie that I want to save, or session information of some sort? Sort of like the 'Remember Me' option you have when you use a browser to login.

Session information is stored on the server, however the cookies usually contain the id of the session which is sent to the server to tell it which data to load for you from its database. To more directly answer your question: You want to save the cookie jar.

Have a look at this code: https://github.com/wchristian/SomethingAwful-FreshBookmarks/blob/master/bookmarks.pl

Hughmoris
Apr 21, 2007
Let's go to the abyss!

Mithaldu posted:

Session information is stored on the server, however the cookies usually contain the id of the session which is sent to the server to tell it which data to load for you from its database. To more directly answer your question: You want to save the cookie jar.

Have a look at this code: https://github.com/wchristian/SomethingAwful-FreshBookmarks/blob/master/bookmarks.pl

Thanks, I'll give this a look.

dbcooper
Mar 21, 2008
Yams Fan
Anyone at YAPC::NA right now?

Sebbe
Feb 29, 2004

For anyone who hasn't seen it; there are livestreams of YAPC::NA on their YouTube channel.

Mithaldu
Sep 25, 2007

Let's cuddle. :3:
https://www.youtube.com/watch?v=gmmVGPdcItM

Hughmoris
Apr 21, 2007
Let's go to the abyss!
Is there a good way (on Windows) for a Perl script to track the utilization of a specific application? For instance, if I want to track how often/long I have the Spotify process running each day. I typically turn my desktop on in the morning and shut it off at night. I'm thinking I can have the Perl script auto launch on startup but I'm not sure how to monitor for the launch of a specific app.

Beardless Woman
May 5, 2004

M for Mysterious
I don't have a Windows box, so I don't have any way of testing it out, but it looks like you may be able to achieve what you're looking for through the use of WMI with the DBD::WMI module.

The Win32_ProcessStartTrace and Win32_ProcessStopTrace classes/tables are probably going to have what you're looking for.

Checking for starting processes should be as easy as a query like
code:
SELECT * FROM Win32_ProcessStartTrace
And checking for stopping processes should work with something like
code:
SELECT * FROM Win32_ProcessStopTrace

Hughmoris
Apr 21, 2007
Let's go to the abyss!

Beardless Woman posted:

I don't have a Windows box, so I don't have any way of testing it out, but it looks like you may be able to achieve what you're looking for through the use of WMI with the DBD::WMI module.

The Win32_ProcessStartTrace and Win32_ProcessStopTrace classes/tables are probably going to have what you're looking for.

Checking for starting processes should be as easy as a query like
code:
SELECT * FROM Win32_ProcessStartTrace
And checking for stopping processes should work with something like
code:
SELECT * FROM Win32_ProcessStopTrace

Thanks for this, I'll give it a shot!

Adbot
ADBOT LOVES YOU

FreshFeesh
Jun 3, 2007

Drum Solo
I'm trying to iterate through an alphabetized list and edit/remove entries based on particular criteria, but as I scale up the code I want to make sure I'm being as clean as possible, since I haven't touched this stuff in a while.

code:
@array = ('cat', 'dog 1', 'dog 2', 'dog 3', 'duck');

Desired output:    cat | dog 1, 2, 3 | duck
Here's my code which does the job, but looks fairly inefficient to me:
code:
for my $i (0 .. $#array) {
	$array[$i-1] =~ m/(\w+)\b/;
	if ($array[$i] =~ m/^$1\b/) {
		$array[$i] =~ m/(\d+)$/;
		$output[-1] .= ", $1";
	}
	else { push(@output, $array[$i]); }
}
It outputs correctly, but I'd be grateful for any suggestions you guys have for ways I can clean it up, so when I scale it out to a more complicated list it's easier to manage.

FreshFeesh fucked around with this message at 12:06 on Jul 24, 2016

  • Locked thread