From djgoku at gmail.com Thu Aug 3 07:34:05 2006 From: djgoku at gmail.com (djgoku) Date: Thu, 3 Aug 2006 09:34:05 -0500 Subject: [Kc] Scalar + Shift? Message-ID: <99dd19c90608030734i2b652146g7a26ad753928153b@mail.gmail.com> So I was looking at Net::IRC irctest file which is given as a "working bot" example and seen something I don't get (my $scalar = shift;) and haven't seen a comment explaining why this done. The only thing I can come up with it shifts off $scalar and makes it empty/"clears any value"/undef right? Looking at more examples uses of modules on cpan.org they're are also shifting scalars. perldoc -f shift #Says nothing about shifting scalar variables. From djgoku at gmail.com Thu Aug 3 07:47:43 2006 From: djgoku at gmail.com (djgoku) Date: Thu, 3 Aug 2006 09:47:43 -0500 Subject: [Kc] Scalar + Shift? In-Reply-To: <49d805d70608030737x77dcd82bgeaeb0999bf9fbd54@mail.gmail.com> References: <99dd19c90608030734i2b652146g7a26ad753928153b@mail.gmail.com> <49d805d70608030737x77dcd82bgeaeb0999bf9fbd54@mail.gmail.com> Message-ID: <99dd19c90608030747m2dcbe0bdsf460e357e9119a42@mail.gmail.com> On 8/3/06, Joshua McAdams wrote: > shift operates on @_ by default, so when you do a: > > my $scalar = shift; > > you are really doing a: > > my $scalar = shift @_; /me smacks forehead > which shifts the first argument passed to a subroutine off of the > array of arguments and into the scalar variable. haha I knew that really! =\ From eric at alliances.org Thu Aug 3 07:44:41 2006 From: eric at alliances.org (Eric) Date: Thu, 3 Aug 2006 9:44:41 -0500 Subject: [Kc] =?utf-8?q?Scalar_+_Shift=3F?= In-Reply-To: <99dd19c90608030734i2b652146g7a26ad753928153b@mail.gmail.com> References: <99dd19c90608030734i2b652146g7a26ad753928153b@mail.gmail.com> Message-ID: <6983ab56170c1a98d58b9196156e3f97@mail> nah... they're doing some shortcutting. my $scalar = shift; is the same thing as saying: my $scalar = shift @_; Depending on the context, it could be pulling parameters off of a function call or pulling the first item off of "the current thing". Eric On Thu, 3 Aug 2006 09:34:05 -0500, djgoku wrote: > So I was looking at Net::IRC irctest file which is given as a > "working bot" example and seen something I don't get (my $scalar = > shift;) and haven't seen a comment explaining why this done. The only > thing I can come up with it shifts off $scalar and makes it > empty/"clears any value"/undef right? > > Looking at more examples uses of modules on cpan.org they're are also > shifting scalars. > > perldoc -f shift #Says nothing about shifting scalar variables. > _______________________________________________ > kc mailing list > kc at pm.org > http://mail.pm.org/mailman/listinfo/kc -- Eric From amoore at mooresystems.com Thu Aug 3 08:03:13 2006 From: amoore at mooresystems.com (Andrew Moore) Date: Thu, 3 Aug 2006 10:03:13 -0500 Subject: [Kc] Scalar + Shift? In-Reply-To: <99dd19c90608030734i2b652146g7a26ad753928153b@mail.gmail.com> References: <99dd19c90608030734i2b652146g7a26ad753928153b@mail.gmail.com> Message-ID: <20060803150313.GB7126@mooresystems.com> On Thu, Aug 03, 2006 at 09:34:05AM -0500, djgoku wrote: > So I was looking at Net::IRC irctest file which is given as a [ snip the actual question which got answered ] In case you're actually wanting to use that module for something useful, you may find that using POE::Component::IRC works out better. Net::IRC seems to be pretty out of date, unsupported, not well liked, and that kind of thing. See also IRC::Bot, which is built on POE::Component::IRC, IIRC. -Andy From djgoku at gmail.com Thu Aug 3 07:59:28 2006 From: djgoku at gmail.com (djgoku) Date: Thu, 3 Aug 2006 09:59:28 -0500 Subject: [Kc] Scalar + Shift? In-Reply-To: <6983ab56170c1a98d58b9196156e3f97@mail> References: <99dd19c90608030734i2b652146g7a26ad753928153b@mail.gmail.com> <6983ab56170c1a98d58b9196156e3f97@mail> Message-ID: <99dd19c90608030759ue62d5bbt467fe7f4ac7e70ec@mail.gmail.com> On 8/3/06, Eric wrote: > nah... they're doing some shortcutting. > my $scalar = shift; > > is the same thing as saying: > > my $scalar = shift @_; > > Depending on the context, it could be pulling parameters off of a function call or pulling the first item off of "the current thing". That mistake doesn't make me feel so good about what I have learned so far in Perl, since I am just finishing up Learning Perl 4th edition. I guess making mistakes makes you remember not to do that again, and remember there is lots of shortcuts that can be used =). From eric at alliances.org Thu Aug 3 08:29:24 2006 From: eric at alliances.org (Eric) Date: Thu, 3 Aug 2006 10:29:24 -0500 Subject: [Kc] =?utf-8?q?Scalar_+_Shift=3F?= In-Reply-To: <99dd19c90608030759ue62d5bbt467fe7f4ac7e70ec@mail.gmail.com> References: <99dd19c90608030759ue62d5bbt467fe7f4ac7e70ec@mail.gmail.com> Message-ID: I wouldn't be too concerned. This particular issue is similar to something like: my @x = split; You just need to realize that the command doesn't make sense without an argument. None is given, so it must be using "the current thing" - whatever that may be in the particular context. Eric On Thu, 3 Aug 2006 09:59:28 -0500, djgoku wrote: > On 8/3/06, Eric wrote: >> nah... they're doing some shortcutting. >> my $scalar = shift; >> >> is the same thing as saying: >> >> my $scalar = shift @_; >> >> Depending on the context, it could be pulling parameters off of a > function call or pulling the first item off of "the current thing". > > That mistake doesn't make me feel so good about what I have learned so > far in Perl, since I am just finishing up Learning Perl 4th edition. I > guess making mistakes makes you remember not to do that again, and > remember there is lots of shortcuts that can be used =). > _______________________________________________ > kc mailing list > kc at pm.org > http://mail.pm.org/mailman/listinfo/kc -- Eric From davidnicol at gmail.com Thu Aug 3 11:56:22 2006 From: davidnicol at gmail.com (David Nicol) Date: Thu, 3 Aug 2006 13:56:22 -0500 Subject: [Kc] Using Perl In-Reply-To: <44CE9127.7050505@jays.net> References: <99dd19c90607270901o7d8bef91x499f2b73118492df@mail.gmail.com> <77b74a1e1210ec12a2f4808495feb6d4@mail> <99dd19c90607271508t22db7cd2o4f9314e318e977da@mail.gmail.com> <44C977FA.8040103@alliances.org> <1154181192.24818.6.camel@walkabout> <79A0B354-A745-4133-BD08-947E7D515463@goebel.ws> <44CE9127.7050505@jays.net> Message-ID: <934f64a20608031156m2720efe0p255d5650fadbbbda@mail.gmail.com> On 7/31/06, Jay Hannah wrote: > > > > LOGFILE="all_server_shutdown.txt" \ > > COMMAND="psshutdown" \ > > CLOPTIONS="-s -t 1 -u ${USERNAME} -p ${PASSWORD}" \ > > /usr/bin/perl -ne 'BEGIN { $d=("-")x5; $r="REM"; $fn=$ENV > > {LOGFILE}; @cmd=($ENV{COMMAND}." ".$ENV{CLOPTIONS}." \\\\"," >> > > $fn"); $fl=<>; print "$r ${fl}erase $fn\n"; } next if /^(#)|($r)/; > > tr/a-z\r\n /A-Z/d; $_=(/^(SVR_)|(other)/i?"$r\n$r [$d$_$d]\n":join > > ($_, at cmd)."\n"); print;' < $1 > $2 > > Huh. I can't even get that to run. The error I get: > > line 5: $1: ambiguous redirect the backslashes are suspicious. Don't need backslashes between env var definitions in bash. Don't need them when entering a multi-line one-liner either when its in single-quotes, as this one is. But the \ after the definition of $ENV{CLOPTIONS} (which one imagines has to do with tricked-out hooves) will make bash think the following line, where you're invoking perl, is part of the previous line, so perl doesn't get invoked at all and the >> redirect, in that case, is in fact ambiguous. That's my guess. Have a nice day. -- David L Nicol "...although it may be / a pile of debris" From frank at wiles.org Thu Aug 3 14:05:57 2006 From: frank at wiles.org (Frank Wiles) Date: Thu, 3 Aug 2006 16:05:57 -0500 Subject: [Kc] Scalar + Shift? In-Reply-To: References: <99dd19c90608030759ue62d5bbt467fe7f4ac7e70ec@mail.gmail.com> Message-ID: <20060803160557.6d628b6e.frank@wiles.org> On Thu, 3 Aug 2006 10:29:24 -0500 Eric wrote: > I wouldn't be too concerned. This particular issue is similar to > something like: > > my @x = split; > > You just need to realize that the command doesn't make sense without > an argument. None is given, so it must be using "the current thing" > - whatever that may be in the particular context. Which 99% of the time is a horrible way to code, in my opinion. Being just slightly more specific can turn that guessing game into a easy to understand line of code such as: my @csv_data = split( /,/, $data_line ); --------------------------------- Frank Wiles http://www.wiles.org --------------------------------- From djgoku at gmail.com Fri Aug 4 08:44:16 2006 From: djgoku at gmail.com (djgoku) Date: Fri, 4 Aug 2006 10:44:16 -0500 Subject: [Kc] HTTP Links Message-ID: <99dd19c90608040844v1153ea64u9a52f3f9804866c@mail.gmail.com> I was browsing around (perl.org) and found (http://www.perl.org/books/beginning-perl/) which has a bunch of html links to PDFs to download for the book Beginning Perl. What I wanted to do was to parse the html for *pdf links then use File::Fetch to get the PDFs, there might of been a module for this but not sure how it would act on http links in multiline comments, so I thought I would just create something. Well first night was up til 2:30AM trying to think of regexp to parse the PDF links, which didn't go to well. I also noticed that some of the html links were commented out which I didn't want in my results, just LIVE links. So I had to work out a way to parse for single/multi line comments and discard accordingly, but to make sure that there were no links prematch of (). So after two nights I think I have all the bases covered. Though currently my program prints the html with the results. I haven't parsed out the http links yet, that is next, then fetching. http://djgoku.dyndns.org/dj_goku/get_http.pl From scratchcomputing at gmail.com Fri Aug 4 09:03:23 2006 From: scratchcomputing at gmail.com (Eric Wilhelm) Date: Fri, 4 Aug 2006 09:03:23 -0700 Subject: [Kc] HTTP Links In-Reply-To: <99dd19c90608040844v1153ea64u9a52f3f9804866c@mail.gmail.com> References: <99dd19c90608040844v1153ea64u9a52f3f9804866c@mail.gmail.com> Message-ID: <200608040903.23295.ewilhelm@cpan.org> # from djgoku # on Friday 04 August 2006 08:44 am: > What I wanted >to do was to parse the html for *pdf links then use File::Fetch to get >the PDFs, there might of been a module for this but If you want a programming exercise, go ahead and write it. If you want a *learning* exercise, learn to search CPAN. Probably the most important thing to learn about Perl is how to not write code. http://search.cpan.org/search?query=html+links&mode=all >not sure how it >would act on http links in multiline comments, so I thought I would >just create something. Why are you trying to parse links within the comments? There's only three of them on that page and they appear to be commented for a reason. If you're trying to solve the general case of finding links hidden in comments, then use an XML parser to grab the comments and a regular expression to look inside them (you can't count on anything in the comments being valid HTML.) Of course, anything automated should ignore the comments, but let me know what you come up with so I can add comments to my pages that will crash it :-) --Eric -- Turns out the optimal technique is to put it in reverse and gun it. --Steven Squyres (on challenges in interplanetary robot navigation) --------------------------------------------------- http://scratchcomputing.com --------------------------------------------------- From djgoku at gmail.com Fri Aug 4 09:13:54 2006 From: djgoku at gmail.com (djgoku) Date: Fri, 4 Aug 2006 11:13:54 -0500 Subject: [Kc] HTTP Links In-Reply-To: <200608040903.23295.ewilhelm@cpan.org> References: <99dd19c90608040844v1153ea64u9a52f3f9804866c@mail.gmail.com> <200608040903.23295.ewilhelm@cpan.org> Message-ID: <99dd19c90608040913t3cdd3066ic0eaa5f07b8b47b1@mail.gmail.com> On 8/4/06, Eric Wilhelm wrote: > # from djgoku > # on Friday 04 August 2006 08:44 am: > > > What I wanted > >to do was to parse the html for *pdf links then use File::Fetch to get > >the PDFs, there might of been a module for this but > > If you want a programming exercise, go ahead and write it. If you want > a *learning* exercise, learn to search CPAN. Probably the most > important thing to learn about Perl is how to not write code. > > http://search.cpan.org/search?query=html+links&mode=all > > >not sure how it > >would act on http links in multiline comments, so I thought I would > >just create something. > > Why are you trying to parse links within the comments? There's only > three of them on that page and they appear to be commented for a > reason. If you're trying to solve the general case of finding links > hidden in comments, then use an XML parser to grab the comments and a > regular expression to look inside them (you can't count on anything in > the comments being valid HTML.) Of course, anything automated should > ignore the comments, but let me know what you come up with so I can add > comments to my pages that will crash it :-) No see, I am not wanting commented lines nor http links within comments being single/multiline, and with my first attempt at doing the regexp it was printing out the http links, not it isn't. I guess I can try some modules and see how the fair with multiline comments. From scratchcomputing at gmail.com Fri Aug 4 12:52:59 2006 From: scratchcomputing at gmail.com (Eric Wilhelm) Date: Fri, 4 Aug 2006 12:52:59 -0700 Subject: [Kc] HTTP Links In-Reply-To: <99dd19c90608040913t3cdd3066ic0eaa5f07b8b47b1@mail.gmail.com> References: <99dd19c90608040844v1153ea64u9a52f3f9804866c@mail.gmail.com> <200608040903.23295.ewilhelm@cpan.org> <99dd19c90608040913t3cdd3066ic0eaa5f07b8b47b1@mail.gmail.com> Message-ID: <200608041252.59516.ewilhelm@cpan.org> # from djgoku # on Friday 04 August 2006 09:13 am: >see how the fair with multiline comments. me thinks they fare well $ cat link_extract #!/usr/bin/perl use warnings; use strict; use HTML::SimpleLinkExtor; my $extor = HTML::SimpleLinkExtor->new(); {local $/; $extor->parse();} print join("\n", $extor->links, ''); $ curl -s http://www.... | ./link_extract | grep '\.pdf' http://.../3145_Intro.pdf http://.../3145_Chap01.pdf ... Read the source and you'll see that it subclasses all the way down to HTML::Parser, which seems pretty quick, correct, and time-tested. If you look at the credits, the caliber of the authors listed might also imply that this stuff all works pretty well. --Eric -- "...the bourgeoisie were hated from both ends: by the proles, because they had all the money, and by the intelligentsia, because of their tendency to spend it on lawn ornaments." --Neal Stephenson --------------------------------------------------- http://scratchcomputing.com --------------------------------------------------- From davidnicol at gmail.com Fri Aug 4 15:02:31 2006 From: davidnicol at gmail.com (David Nicol) Date: Fri, 4 Aug 2006 17:02:31 -0500 Subject: [Kc] HTTP Links In-Reply-To: <99dd19c90608040844v1153ea64u9a52f3f9804866c@mail.gmail.com> References: <99dd19c90608040844v1153ea64u9a52f3f9804866c@mail.gmail.com> Message-ID: <934f64a20608041502q719a1636r23d47de6e29c4c83@mail.gmail.com> wget `lynx -dump http://www.perl.org/books/beginning-perl | grep pdf | cut -b6- ` -- David L Nicol all your grammar nit are belong to us From ggoebel at goebel.ws Thu Aug 3 11:43:56 2006 From: ggoebel at goebel.ws (Garrett Goebel) Date: Thu, 3 Aug 2006 13:43:56 -0500 Subject: [Kc] Scalar + Shift? In-Reply-To: <99dd19c90608030759ue62d5bbt467fe7f4ac7e70ec@mail.gmail.com> References: <99dd19c90608030734i2b652146g7a26ad753928153b@mail.gmail.com> <6983ab56170c1a98d58b9196156e3f97@mail> <99dd19c90608030759ue62d5bbt467fe7f4ac7e70ec@mail.gmail.com> Message-ID: <99AA428A-DCEF-4468-A36F-E6CC3D4C99B9@goebel.ws> On Aug 3, 2006, at 9:59 AM, djgoku wrote: > That mistake doesn't make me feel so good about what I have learned so > far in Perl, since I am just finishing up Learning Perl 4th edition. Don't sweat it. You've probably heard the story about interview with the extremely successful person. It went something like this: Q: How did you become so successful? A: Experience. Q: How did you gain experience? A: Good decisions. Q: And how did you learn to make those good decisions? A: Bad decisions. ...And congratulations on finishing Learning Perl! If you are one of those people who enjoys the journey more than actually reaching the final destination... then with Perl you're practically guaranteed a long strange trip ;) Oh, if you're intending to start next on the "Learning Perl Objects, References, and Modules" book I gave you way back when... you might consider picking up a copy of "Intermediate Perl" instead. It is what the new edition of the aforementioned book turned into. And it's only 256 pages. Or actually... being a Perl Mongers groups, I could contact O'Reilly on your behalf and have them send you a copy for review. The catch is, you'd have to write up a book review. If you're interested, email me your postal address. The books generally take a few weeks to arrive. Some time shortly after Learning Perl and Intermediate Perl, it would be good to pick up a copy of Perl Best Practices (PBP). Better to get into good habits early on. I'm still working little by little to rehabit myself to the practices espoused in PBP. It's much harder once you're firmly entrenched in your bad habits ;) cheers, Garrett From jay at jays.net Sun Aug 6 09:10:16 2006 From: jay at jays.net (Jay Hannah) Date: Sun, 06 Aug 2006 11:10:16 -0500 Subject: [Kc] Scalar + Shift? In-Reply-To: <99dd19c90608030759ue62d5bbt467fe7f4ac7e70ec@mail.gmail.com> References: <99dd19c90608030734i2b652146g7a26ad753928153b@mail.gmail.com> <6983ab56170c1a98d58b9196156e3f97@mail> <99dd19c90608030759ue62d5bbt467fe7f4ac7e70ec@mail.gmail.com> Message-ID: <44D61468.8040106@jays.net> djgoku wrote: > That mistake doesn't make me feel so good about what I have learned so > far in Perl, since I am just finishing up Learning Perl 4th edition. I > guess making mistakes makes you remember not to do that again, and > remember there is lots of shortcuts that can be used =). You now know more Perl than 5.9 billion people alive today, so I think you should feel GREAT! j Omaha.pm From djgoku at gmail.com Sun Aug 6 11:14:44 2006 From: djgoku at gmail.com (djgoku) Date: Sun, 6 Aug 2006 13:14:44 -0500 Subject: [Kc] HTTP Links In-Reply-To: <200608041252.59516.ewilhelm@cpan.org> References: <99dd19c90608040844v1153ea64u9a52f3f9804866c@mail.gmail.com> <200608040903.23295.ewilhelm@cpan.org> <99dd19c90608040913t3cdd3066ic0eaa5f07b8b47b1@mail.gmail.com> <200608041252.59516.ewilhelm@cpan.org> Message-ID: <99dd19c90608061114w5eddc62et342cefff5a7ce942@mail.gmail.com> On 8/4/06, Eric Wilhelm wrote: > # from djgoku > # on Friday 04 August 2006 09:13 am: > > >see how the fair with multiline comments. > > me thinks they fare well > > $ cat link_extract > #!/usr/bin/perl > use warnings; use strict; use HTML::SimpleLinkExtor; > my $extor = HTML::SimpleLinkExtor->new(); > {local $/; $extor->parse();} > print join("\n", $extor->links, ''); > > $ curl -s http://www.... | ./link_extract | grep '\.pdf' > http://.../3145_Intro.pdf > http://.../3145_Chap01.pdf > ... #!/usr/bin/perl # # My second try, for get_http.pl # Syntax: get_http.pl filename (pdf|html|tar|etc) # Todo: Add use for web links (http://blah.com/blah use strict; use warnings; use HTML::SimpleLinkExtor; my $extor = HTML::SimpleLinkExtor->new(); # Filename Stuff my $source = shift @ARGV; $extor->parse_file($source); my @links = $extor->links; # Filetype Stuff my $filetype = '*'; $filetype = shift @ARGV if (@ARGV); # Print only found $filetype foreach (@links) { print "$_\n" if (m{\s*\.$filetype}i); } From frank at wiles.org Mon Aug 7 07:43:25 2006 From: frank at wiles.org (Frank Wiles) Date: Mon, 7 Aug 2006 09:43:25 -0500 Subject: [Kc] HTTP Links In-Reply-To: <99dd19c90608061114w5eddc62et342cefff5a7ce942@mail.gmail.com> References: <99dd19c90608040844v1153ea64u9a52f3f9804866c@mail.gmail.com> <200608040903.23295.ewilhelm@cpan.org> <99dd19c90608040913t3cdd3066ic0eaa5f07b8b47b1@mail.gmail.com> <200608041252.59516.ewilhelm@cpan.org> <99dd19c90608061114w5eddc62et342cefff5a7ce942@mail.gmail.com> Message-ID: <20060807094325.ac1003da.frank@wiles.org> On Sun, 6 Aug 2006 13:14:44 -0500 djgoku wrote: > On 8/4/06, Eric Wilhelm wrote: > > # from djgoku > > # on Friday 04 August 2006 09:13 am: > > > > >see how the fair with multiline comments. > > > > me thinks they fare well > > > > $ cat link_extract > > #!/usr/bin/perl > > use warnings; use strict; use HTML::SimpleLinkExtor; > > my $extor = HTML::SimpleLinkExtor->new(); > > {local $/; $extor->parse();} > > print join("\n", $extor->links, ''); > > > > $ curl -s http://www.... | ./link_extract | grep '\.pdf' > > http://.../3145_Intro.pdf > > http://.../3145_Chap01.pdf > > ... > > #!/usr/bin/perl > # > # My second try, for get_http.pl > # Syntax: get_http.pl filename (pdf|html|tar|etc) > # Todo: Add use for web links (http://blah.com/blah > > use strict; > use warnings; > > use HTML::SimpleLinkExtor; > > my $extor = HTML::SimpleLinkExtor->new(); > > # Filename Stuff > my $source = shift @ARGV; > $extor->parse_file($source); > my @links = $extor->links; > > # Filetype Stuff > my $filetype = '*'; > $filetype = shift @ARGV if (@ARGV); > > # Print only found $filetype > foreach (@links) { > print "$_\n" if (m{\s*\.$filetype}i); > } > _______________________________________________ > kc mailing list > kc at pm.org > http://mail.pm.org/mailman/listinfo/kc Here is a slightly more robust version: #!/usr/bin/perl use strict; use warnings; use HTML::SimpleLinkExtor; use Getopt::Long; my $extor = HTML::SimpleLinkExtor->new(); # Some defaults my $local_file; my $remote_url; my $file_type = '*'; # Parse commandline options GetOptions( 'file=s' => \$local_file, 'url=s' => \$remote_url, 'type=s' => \$file_type ); # Handle a local file or a url my @links; if( $local_file ) { $extor->parse_file( $local_file ); @links = $extor->links; } elsif ( $remote_url ) { my $ua = LWP::UserAgent->new; my $response = $ua->get($remote_url) or die "Cannot retrieve URL '$remote_url': $!"; if( $response->is_success ) { $extor->parse( $reponse->content ); @links = $extor->links; } else { die "Unable to retrieve the URL '$remote_url': $!"; } } else { die "You must define either a -file or a -url"; } if( $file_type ne '*' ) { print join("\n", grep( /\.$file_type/i, @links ) ); } else { print join("\n", @links); } # EOF You can now call it like so: get_http.pl -file /path/to/file -type pdf get_http.pl -file=/path/to/file -type=pdf get_http.pl -url=http://www.blah.com -type=gif get_http.pl -u=http://www.blah.com -t=pdf --------------------------------- Frank Wiles http://www.wiles.org --------------------------------- From scratchcomputing at gmail.com Mon Aug 7 09:01:01 2006 From: scratchcomputing at gmail.com (Eric Wilhelm) Date: Mon, 7 Aug 2006 09:01:01 -0700 Subject: [Kc] HTTP Links In-Reply-To: <20060807094325.ac1003da.frank@wiles.org> References: <99dd19c90608040844v1153ea64u9a52f3f9804866c@mail.gmail.com> <99dd19c90608061114w5eddc62et342cefff5a7ce942@mail.gmail.com> <20060807094325.ac1003da.frank@wiles.org> Message-ID: <200608070901.02462.ewilhelm@cpan.org> # from Frank Wiles # on Monday 07 August 2006 07:43 am: >? ?Here is a slightly more robust version: But how do you know it's more robust if you can't test it? Here's a minor refactoring into a modular form. Start with: perl -e 'my $package = require("./extract_links"); my $main = eval("\\&${package}::main"); $main->("-h");' Then break the stuff in main() out into individual subs. getoptions() would be a good first candidate if you parse the options into a hash. Then your tests could do: my ($opts, @args) = bin::extract_links::getoptions(qw( --url http://example.com --type html )); ok(ref($opts), 'is a hash'); ok(@args == 0); is($opts->{url}, 'http://example.com'); # etc (or even is_deeply) So, when you add the feature "figure out whether it is a url", you can test that the DWIM is working without having a network connection. You could, of course, use IPC::Run and do tests that way, but you can't unit test if there aren't units. --- extract_links #!/usr/bin/perl use warnings; use strict; =head1 NAME extract_links - extract links from HTML documents =cut package bin::extract_links; use HTML::SimpleLinkExtor; use Getopt::Helpful; sub main { my (@args) = @_; my $extor = HTML::SimpleLinkExtor->new(); # Some defaults my $local_file; my $remote_url; my $file_type = '*'; # Parse commandline options my $opts = Getopt::Helpful->new( usage => "CALLER --file /path/to/file [options]\n" . " or\n" . " --url http://example.com [options]", ['file=s', \$local_file, '/path/file.html','read a file'], ['url=s' , \$remote_url, 'http://example.com/','fetch a url'], ['type=s', \$file_type , 'html|pdf','type of file to get'], '+help', ); $opts->Get_from(\@args); # Handle a local file or a url my @links; if( $local_file ) { $extor->parse_file( $local_file ); @links = $extor->links; } elsif ( $remote_url ) { my $ua = LWP::UserAgent->new; my $response = $ua->get($remote_url) or die "Cannot retrieve URL '$remote_url': $!"; if( $response->is_success ) { $extor->parse( $response->content ); @links = $extor->links; } else { die "Unable to retrieve the URL '$remote_url': $!"; } } else { $opts->usage("You must define either a -file or a -url"); } if( $file_type ne '*' ) { print join("\n", grep( /\.$file_type/i, @links ) ); } else { print join("\n", @links); } } package main; if($0 eq __FILE__) { bin::extract_links::main(@ARGV); } # vi:ts=2:sw=2:et:sta my $package = 'bin::extract_links'; # EOF --Eric -- "Because understanding simplicity is complicated." --Eric Raymond --------------------------------------------------- http://scratchcomputing.com --------------------------------------------------- From ggoebel at goebel.ws Mon Aug 7 09:32:53 2006 From: ggoebel at goebel.ws (Garrett Goebel) Date: Mon, 7 Aug 2006 11:32:53 -0500 Subject: [Kc] HTTP Links In-Reply-To: <99dd19c90608061114w5eddc62et342cefff5a7ce942@mail.gmail.com> References: <99dd19c90608040844v1153ea64u9a52f3f9804866c@mail.gmail.com> <200608040903.23295.ewilhelm@cpan.org> <99dd19c90608040913t3cdd3066ic0eaa5f07b8b47b1@mail.gmail.com> <200608041252.59516.ewilhelm@cpan.org> <99dd19c90608061114w5eddc62et342cefff5a7ce942@mail.gmail.com> Message-ID: <56553CF7-A38B-4844-8A39-F140EE76D2BD@goebel.ws> Here's a third try for you using: o Getopt::Long for command line option processing o LWP::UserAgent to fetch content from uri's instead of a file o Documentation #!/usr/bin/perl use strict; use warnings; use version; our $VERSION = qv(0.0.3); use Getopt::Long; use Pod::Usage; use Regexp::Common qw(URI); use LWP::UserAgent; use HTML::SimpleLinkExtor; # Specify and process command line options my %Config; GetOptions( \%Config, 'uri|u=s', 'extension|ext|e=s', 'help|h|?', 'man|m') or pod2usage(2); pod2usage(1) if $Config{help}; pod2usage(-exitstatus => 0, -verbose => 2) if $Config{man}; pod2usage('--uri is required!') if !$Config{uri}; # Check that uri schema is supported by HTTP::Request for GET requests my $valid_uri = 0; for my $scheme (qw(HTTP FTP file NNTP gopher)) { $valid_uri++ if $Config{uri} =~ /$RE{URI}{$scheme}/; } $valid_uri++ if $Config{uri} =~ /$RE{URI}{HTTP}{-scheme => 'https'}/; pod2usage("invalid or unsupported uri: $Config{uri}") if !$valid_uri; $Config{extension} ||= '*'; # Fetch content from uri and print extracted links my $ua = LWP::UserAgent->new; my $request = HTTP::Request->new(GET => $Config{uri}); my $response = $ua->request($request); if (!$response->is_success) { die("Unable to process request for uri: $Config{uri}:\n", $response->status_line); } my $content = $response->content; my $extor = HTML::SimpleLinkExtor->new; $extor->parse($content); foreach my $link ($extor->links) { next if $link !~ m/\.$Config{extension}/ixms; print "$link\n"; } 1; __END__ =head1 NAME link_extract.pl =head1 SYNOPSIS link_extract.pl --uri=http://www.perl.org/books/beginning-perl/ -e=pdf Options: --uri|u source uri (file:///foo.pdf, http://foo.com/ bar.html) supported schemes: http https ftp file news gopher --extension|ext|e file extension of links to be extracted -help brief help message -man full documentation =head1 OPTIONS =over 4 =item B<-help> Print a brief help message and exits. =item B<-man> Prints the manual page and exits. =back =head1 DESCRIPTION B will fetch and parse the content of the given -- uri and print a list of all links matching the supplied file --extension. On Aug 6, 2006, at 1:14 PM, djgoku wrote: > #!/usr/bin/perl > # > # My second try, for get_http.pl > # Syntax: get_http.pl filename (pdf|html|tar|etc) > # Todo: Add use for web links (http://blah.com/blah > > use strict; > use warnings; > > use HTML::SimpleLinkExtor; > > my $extor = HTML::SimpleLinkExtor->new(); > > # Filename Stuff > my $source = shift @ARGV; > $extor->parse_file($source); > my @links = $extor->links; > > # Filetype Stuff > my $filetype = '*'; > $filetype = shift @ARGV if (@ARGV); > > # Print only found $filetype > foreach (@links) { > print "$_\n" if (m{\s*\.$filetype}i); > } > _______________________________________________ > kc mailing list > kc at pm.org > http://mail.pm.org/mailman/listinfo/kc > From matthew at veradox.com Mon Aug 7 15:46:21 2006 From: matthew at veradox.com (Matthew Wilson) Date: Mon, 07 Aug 2006 17:46:21 -0500 Subject: [Kc] Aug 8 meeting In-Reply-To: <56553CF7-A38B-4844-8A39-F140EE76D2BD@goebel.ws> References: <99dd19c90608040844v1153ea64u9a52f3f9804866c@mail.gmail.com> <200608040903.23295.ewilhelm@cpan.org> <99dd19c90608040913t3cdd3066ic0eaa5f07b8b47b1@mail.gmail.com> <200608041252.59516.ewilhelm@cpan.org> <99dd19c90608061114w5eddc62et342cefff5a7ce942@mail.gmail.com> <56553CF7-A38B-4844-8A39-F140EE76D2BD@goebel.ws> Message-ID: <44D7C2BD.2050100@veradox.com> Who's planning on attending tomorrow night's meeting? I'll be there... Now you don't use that as a reason /*not* /to attend. Feel free to use it as a reason *to* attend. -Matthew Wilson -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.pm.org/pipermail/kc/attachments/20060807/01c35b17/attachment.html From don.ellis at gmail.com Mon Aug 7 20:49:37 2006 From: don.ellis at gmail.com (Don Ellis) Date: Mon, 7 Aug 2006 22:49:37 -0500 Subject: [Kc] Aug 8 meeting In-Reply-To: <44D7C2BD.2050100@veradox.com> References: <99dd19c90608040844v1153ea64u9a52f3f9804866c@mail.gmail.com> <200608040903.23295.ewilhelm@cpan.org> <99dd19c90608040913t3cdd3066ic0eaa5f07b8b47b1@mail.gmail.com> <200608041252.59516.ewilhelm@cpan.org> <99dd19c90608061114w5eddc62et342cefff5a7ce942@mail.gmail.com> <56553CF7-A38B-4844-8A39-F140EE76D2BD@goebel.ws> <44D7C2BD.2050100@veradox.com> Message-ID: I plan to be there, too. Does the place have wireless? That would be an excuse to bring my laptop along. --Don Ellis [Interesting - a plain 'reply' just sent the reply to Matt. I had to do a 'reply all' or manually intervene to get the reply to go to the group.] On 8/7/06, Matthew Wilson wrote: > > Who's planning on attending tomorrow night's meeting? > > I'll be there... Now you don't use that as a reason **not* *to attend. > Feel free to use it as a reason *to* attend. > > -Matthew Wilson > > _______________________________________________ > kc mailing list > kc at pm.org > http://mail.pm.org/mailman/listinfo/kc > > -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.pm.org/pipermail/kc/attachments/20060807/dc85b22a/attachment.html From djgoku at gmail.com Mon Aug 7 21:39:56 2006 From: djgoku at gmail.com (djgoku) Date: Mon, 7 Aug 2006 23:39:56 -0500 Subject: [Kc] Aug 8 meeting In-Reply-To: <44D7C2BD.2050100@veradox.com> References: <99dd19c90608040844v1153ea64u9a52f3f9804866c@mail.gmail.com> <200608040903.23295.ewilhelm@cpan.org> <99dd19c90608040913t3cdd3066ic0eaa5f07b8b47b1@mail.gmail.com> <200608041252.59516.ewilhelm@cpan.org> <99dd19c90608061114w5eddc62et342cefff5a7ce942@mail.gmail.com> <56553CF7-A38B-4844-8A39-F140EE76D2BD@goebel.ws> <44D7C2BD.2050100@veradox.com> Message-ID: <99dd19c90608072139h1be40e53ye63c643fc4970f1@mail.gmail.com> On 8/7/06, Matthew Wilson wrote: > > Who's planning on attending tomorrow night's meeting? > > I'll be there... Now you don't use that as a reason *not* to attend. Feel > free to use it as a reason *to* attend. I will be there. From mike at handuma.com Mon Aug 7 23:37:37 2006 From: mike at handuma.com (Michael Morgan) Date: Tue, 8 Aug 2006 01:37:37 -0500 Subject: [Kc] [KC] Aug 8 meeting Message-ID: Hi Everyone, I have to pick up a friend at the airport at 7:05 pm but I should be able to get to Planet Sub before the end of the meeting. Michael From djgoku at gmail.com Tue Aug 8 07:28:32 2006 From: djgoku at gmail.com (djgoku) Date: Tue, 8 Aug 2006 09:28:32 -0500 Subject: [Kc] Aug 8 meeting In-Reply-To: References: <99dd19c90608040844v1153ea64u9a52f3f9804866c@mail.gmail.com> <200608040903.23295.ewilhelm@cpan.org> <99dd19c90608040913t3cdd3066ic0eaa5f07b8b47b1@mail.gmail.com> <200608041252.59516.ewilhelm@cpan.org> <99dd19c90608061114w5eddc62et342cefff5a7ce942@mail.gmail.com> <56553CF7-A38B-4844-8A39-F140EE76D2BD@goebel.ws> <44D7C2BD.2050100@veradox.com> Message-ID: <99dd19c90608080728p6ef9ccdexd35dcc7b778adbda@mail.gmail.com> On 8/7/06, Don Ellis wrote: > I plan to be there, too. Does the place have wireless? That would be an > excuse to bring my laptop along. I don't think they do, though doesn't mean there isn't an open WIFI in the neighborhood =). From crash3m at gmail.com Tue Aug 8 08:07:02 2006 From: crash3m at gmail.com (crash3m) Date: Tue, 8 Aug 2006 10:07:02 -0500 Subject: [Kc] Aug 8 meeting In-Reply-To: <44D7C2BD.2050100@veradox.com> References: <99dd19c90608040844v1153ea64u9a52f3f9804866c@mail.gmail.com> <200608040903.23295.ewilhelm@cpan.org> <99dd19c90608040913t3cdd3066ic0eaa5f07b8b47b1@mail.gmail.com> <200608041252.59516.ewilhelm@cpan.org> <99dd19c90608061114w5eddc62et342cefff5a7ce942@mail.gmail.com> <56553CF7-A38B-4844-8A39-F140EE76D2BD@goebel.ws> <44D7C2BD.2050100@veradox.com> Message-ID: c-ya there On 8/7/06, Matthew Wilson wrote: > > Who's planning on attending tomorrow night's meeting? > > I'll be there... Now you don't use that as a reason *not* to attend. Feel > free to use it as a reason *to* attend. > > -Matthew Wilson > > _______________________________________________ > kc mailing list > kc at pm.org > http://mail.pm.org/mailman/listinfo/kc > > -- Got gmail? I do hahaha From amoore at mooresystems.com Tue Aug 8 14:04:20 2006 From: amoore at mooresystems.com (Andrew Moore) Date: Tue, 8 Aug 2006 16:04:20 -0500 Subject: [Kc] Aug 8 meeting In-Reply-To: <44D7C2BD.2050100@veradox.com> References: <99dd19c90608040844v1153ea64u9a52f3f9804866c@mail.gmail.com> <200608040903.23295.ewilhelm@cpan.org> <99dd19c90608040913t3cdd3066ic0eaa5f07b8b47b1@mail.gmail.com> <200608041252.59516.ewilhelm@cpan.org> <99dd19c90608061114w5eddc62et342cefff5a7ce942@mail.gmail.com> <56553CF7-A38B-4844-8A39-F140EE76D2BD@goebel.ws> <44D7C2BD.2050100@veradox.com> Message-ID: <20060808210420.GA22640@mooresystems.com> On Mon, Aug 07, 2006 at 05:46:21PM -0500, Matthew Wilson wrote: > Who's planning on attending tomorrow night's meeting? Sorry, I'm not going to be able to make it tonight. Based on the mailing list archives from this month, it seems like some topics which may come up are: * How do you do interactive logins over SSH to other machines? - Net::SSH - expect - ssh secret keys - qx( /usr/bin/ssh ... ) * Should the September meeting be at Barley's at 119th and Quivera? * What are $_ and @_, and what's up with optional arguments to functions? * parsing HTML with (and without) HTML::SimpleLinkExtor * If you're interested in reviewing an O'Reilly book for the gang in coming months, Garrett (our fearless moderator in absentia) can order a copy of it FOR FREE, provided that you present the review to us, write it up, and allow it to be used for promotion or something. (Garrett, are there any actual available rules to this?) As always, I doubt that there will be any official agenda. If you want to ask about or contribute anything about these topics or any other ones, show up and speak up! Look for the gang in one of the front rooms of Planet Sub at 50th and Main in KCMO. If someone could fire off an email tomorrow listing some of the highlights or attendees from tonight, it would be much appreciated. Have fun! -Andy From ggoebel at goebel.ws Wed Aug 9 10:41:56 2006 From: ggoebel at goebel.ws (Garrett Goebel) Date: Wed, 9 Aug 2006 12:41:56 -0500 Subject: [Kc] Book Reviews In-Reply-To: <20060808210420.GA22640@mooresystems.com> References: <99dd19c90608040844v1153ea64u9a52f3f9804866c@mail.gmail.com> <200608040903.23295.ewilhelm@cpan.org> <99dd19c90608040913t3cdd3066ic0eaa5f07b8b47b1@mail.gmail.com> <200608041252.59516.ewilhelm@cpan.org> <99dd19c90608061114w5eddc62et342cefff5a7ce942@mail.gmail.com> <56553CF7-A38B-4844-8A39-F140EE76D2BD@goebel.ws> <44D7C2BD.2050100@veradox.com> <20060808210420.GA22640@mooresystems.com> Message-ID: On Aug 8, 2006, at 4:04 PM, Andrew Moore wrote: > * If you're interested in reviewing an O'Reilly book for the gang in > coming months, Garrett (our fearless moderator in absentia) can > order a copy of it FOR FREE, provided that you present the review to > us, write it up, and allow it to be used for promotion or > something. (Garrett, are there any actual available rules to this?) Requesting books for review is achieved by having one of the KCPM facilitators contact marsee at oreilly dot com and request the book on the reviewer's behalf. The next time I send in a request, I'll let Marsee know to consider myself, David Nicol, and Andrew Moore as the current KCPM facilitators. Here is the link to the O'Reilly book review guidelines: http://ug.oreilly.com/bookreviews.html When you write a review, you should send a copy to kc at pm dot org and marsee at oreilly dot org with the subject heading prefix: "Book Review" followed by the title of the book. Then nudge the KCPM facilitators until your book review shows up at http://kc.pm.org/ reviews.shtml. Actually writing reviews for the books requested goes a long way toward insuring the good will of O'Reilly on their supporting our free books for review. I.e., I'm not prone to send in book requests for people that don't have a track record of writing reviews. The book reviews don't have to be long or favorable. A short honest review does the trick. If you get writer's block, you can always look for book reviews on slashdot.org or amazon. Do try to put a personal spin on it... i.e. don't be a plagiarist ;) O'Reilly likes to encourage you to post your reviews to amazon and slashdot as well. But that is your prerogative. cheers, Garrett From davidnicol at gmail.com Wed Aug 9 13:46:25 2006 From: davidnicol at gmail.com (David Nicol) Date: Wed, 9 Aug 2006 15:46:25 -0500 Subject: [Kc] outsourced web page hit counter with moving averages Message-ID: <934f64a20608091346je97c2cdr5bcb62b2e2e1f204@mail.gmail.com> too much coffee... I have been meaning to write this little thing for some years, since hit counters were a Big Deal, which was a long time ago. Details at http://tipjar.com/nettoys/counter.html I guess I had to wait for iframes to happen before setting it up was sufficiently simple -- it used to be to do that kind of thing you needed to dynamically generate numbered images on the fly. -- David L Nicol all your grammar nit are belong to us From djgoku at gmail.com Wed Aug 9 15:05:20 2006 From: djgoku at gmail.com (djgoku) Date: Wed, 9 Aug 2006 17:05:20 -0500 Subject: [Kc] August Meeting Notes Message-ID: <99dd19c90608091505h35a863f6o1343d02bab640ca5@mail.gmail.com> * Talk a little about Perl default ($_) * Perl6 (Pugs/Contributing) * Perl 6 IRC Channel (irc.perl.org #Perl6) * * Wireless: The two that brough laptops found some open APs to use. From crash3m at gmail.com Thu Aug 10 00:33:12 2006 From: crash3m at gmail.com (crash3m) Date: Thu, 10 Aug 2006 02:33:12 -0500 Subject: [Kc] August Meeting Notes In-Reply-To: <99dd19c90608091505h35a863f6o1343d02bab640ca5@mail.gmail.com> References: <99dd19c90608091505h35a863f6o1343d02bab640ca5@mail.gmail.com> Message-ID: We also discussed previous/current employment (and position), OSes, living situation, wifi technology's (mainly antennae), and a bit of other off-topic stuff On 8/9/06, djgoku wrote: > * Talk a little about Perl default ($_) > * Perl6 (Pugs/Contributing) > * Perl 6 IRC Channel (irc.perl.org #Perl6) > * > * Wireless: The two that brough laptops found some open APs to use. > _______________________________________________ > kc mailing list > kc at pm.org > http://mail.pm.org/mailman/listinfo/kc > -- Got gmail? I do hahaha From davidnicol at gmail.com Thu Aug 10 09:31:30 2006 From: davidnicol at gmail.com (David Nicol) Date: Thu, 10 Aug 2006 11:31:30 -0500 Subject: [Kc] August Meeting Notes In-Reply-To: References: <99dd19c90608091505h35a863f6o1343d02bab640ca5@mail.gmail.com> Message-ID: <934f64a20608100931i2413c5dcn73ebf407caf27f01@mail.gmail.com> And Aurora had half a banana-strawberry odwalla and ran around. From JYOUNG79 at kc.rr.com Thu Aug 31 09:01:44 2006 From: JYOUNG79 at kc.rr.com (JYOUNG79 at kc.rr.com) Date: Thu, 31 Aug 2006 11:01:44 -0500 Subject: [Kc] infix pointer question Message-ID: Just curious if someone wouldn't mind explaining how the 'infix' pointer works? I've been looking at some code here at work that an outside programmer did a long time ago. I'm totally confused as to how this works: ----------------------------- At first it looks like it's getting info for the scalar $HKrepobj... ----------------------------- # Grab the HKreport data block my $HKrepobj = $repobj->getHKreportobj( ); sub getHKreportobj { my ( $obj ) = @_; return $obj->{ 'HKreport' }; } # end sub getreportobj ----------------------------- Next it's getting info for the scalar $madeinstr... ----------------------------- my $madeinstr = $HKrepobj->getmadein( ); sub getmadein { my ( $obj ) = @_; # Make a shortcut to the actual data hash. # my $dh = $obj->{ 'data' }; # return $dh->{ 'madein' }; return $obj->{ 'data' }{ 'madein' }; } # end sub getmadein I've researched a little about this - it looks like 'infix' pointers dereference a reference?? I understand tha t a reference is a value that holds the location to another value but the syntax above just doesn't seem to make any sense to me. Instead of using 'infix' pointers why not just return a regular scalar value or array? Thanks. Jay From davidnicol at gmail.com Thu Aug 31 14:01:19 2006 From: davidnicol at gmail.com (David Nicol) Date: Thu, 31 Aug 2006 16:01:19 -0500 Subject: [Kc] infix pointer question In-Reply-To: References: Message-ID: <934f64a20608311401n64586958k5659d2eb783733b9@mail.gmail.com> You appear to have a good handle on the subject you are asking for an explanation of. It is not clear to me what part of the apparently clear source code you included in your question is not clear to you. Here's Dave's Intoductory Lecture on the "skinny arrow" operator in Perl: * the syntax is taken from how C++ invokes methods on objects. * Between braces in multilevel containers, the -> is optional * in perl 6, -> may be replaced with dot to look more like Java instead of more like C. > sub getmadein > { > my ( $obj ) = @_; > # Make a shortcut to the actual data hash. > # my $dh = $obj->{ 'data' }; #X > # return $dh->{ 'madein' }; #X > return $obj->{ 'data' }{ 'madein' }; > } # end sub getmadein uncommenting the lines I marked #X should have merely a very slight performance, and no semantic, effect. > I've researched a little about this - it looks like 'infix' pointers > dereference a reference?? I understand that > a reference is a value that holds the location to another value but > the syntax above just doesn't seem to make any sense to me. Instead of > using 'infix' pointers why not just return a regular scalar value or > array? It appears to me that the code you quote does exactly that: the methods you quote are access methods that pull specific data out of a complex container. The arguments for using explicit accessors are as follows: * abstract the data container implementation so it may be modified in one place * code that calls an accessor is less noisy in context than code that directly accesses the data within the complex structure. The parts of the perl distribution documentation that deal with these issues are perlref, perlreftut, perllol, perldata, and others referenced w/in those. Perl distributed documentation may be read at the command line interface with "perldoc X" where X is the name of a documentation page; they are also all available at http://perldoc.perl.org/ From amoore at mooresystems.com Thu Aug 31 14:28:54 2006 From: amoore at mooresystems.com (Andrew Moore) Date: Thu, 31 Aug 2006 16:28:54 -0500 Subject: [Kc] infix pointer question In-Reply-To: References: Message-ID: <20060831212854.GA21965@mooresystems.com> Hi Jay - I'm not a computer linguist, and I don't even play one on TV, so I'll get all of the terminology wrong. But I can give you the gist of this stuff if you give me some slack on the jargon... On Thu, Aug 31, 2006 at 11:01:44AM -0500, JYOUNG79 at kc.rr.com wrote: > Just curious if someone wouldn't mind explaining how the 'infix' > pointer works? I've been looking at some code here at work that an > outside programmer did a long time ago. I'm totally confused as to how > this works: The "->" operator essentially does two vaguely similar things. One is that it dereferences references. In other words, it lets you get at the stuff that a reference points to. The other thing it does is call methods on an object. You're running into both types of usage here. First, here's a somewhat simpler description of dereferencing. If you have a reference to a hash (a hashref), you can use "->" to get at its insides: my $hashref = { dog => 'fido', cat => 'fluffy', cow => 'bessie' }; That $hashref points to an (unnamed) hash. Since it's a reference, you use "->" to get to the internals. print "my dog's name is: " . $hashref->{'dog'}; You can also have references to arrays (and scalars and filehandles...). See 'perldoc perlref' and 'perldoc perlreftut' for more information on this stuff. Now, if you have an object (which is typically just a hashref that has been 'blessed'), it typically has methods associated with it. (They're just subroutines defined in the object's package). To call these, you use "->", too. You may have seen this if you use the DBI object: my $error = $db->do( 'delete from table where id = 4' ); Here, $db is a DBI object and we're calling the "do" method on it. You can probably go in the DBI.pm file somewhere and see the definition of do: sub do { # some funky database magic here. } or, maybe you use the object oriented interface to CGI: print $q->header('text/html'); Here, $q is a CGI object, and we're calling the "header" method on it. That returns a string. see these perldocs for more information on this object stuff: perlboot - beginner's object oriented tutorial perltoot - Tom's OO tutorial perltooc - Tom's OO Class data tutorial Now, to confuse the issue, as I said before many objects are blessed hashrefs. Since they're hashrefs, sometimes people like to use "->" to dereference them and get at some of their internals. This isn't always the best object oriented policy, but it (usually) works. let's look at your code: > ----------------------------- > At first it looks like it's getting info for the scalar $HKrepobj... > ----------------------------- > > # Grab the HKreport data block > my $HKrepobj = $repobj->getHKreportobj( ); $repobj is probably an object that they're calling the 'getHKreportobj' method of. Go look in the .pm file that defines the class that $repobj is a member of and look for "sub getHKreportobj" for the definition of what gets run. > > > sub getHKreportobj > { > my ( $obj ) = @_; > return $obj->{ 'HKreport' }; > } # end sub getreportobj Hey, there it is! Since this sub is being called as a method, it's automagically passed an argument of the object itself. This is often called $self, but I see here it's called $obj. That's fine. This is an accessor method. It pretty much just returns a piece of object data. The way it gets that data is to dereference the hashref called $obj with "$obj->{ 'HKreport' }; You could stick a call to Data::Dumper in there to see what $obj looks like inside. I'll bet it would be enlightening. Try: use Data::Dumper; warn Data::Dumper->Dump( [ $obj ], [ 'obj' ] ); > > ----------------------------- > Next it's getting info for the scalar $madeinstr... > ----------------------------- > > my $madeinstr = $HKrepobj->getmadein( ); call the 'getmadein' method on the $HKrepobj object. > sub getmadein > { > my ( $obj ) = @_; > # Make a shortcut to the actual data hash. > # my $dh = $obj->{ 'data' }; > # return $dh->{ 'madein' }; > return $obj->{ 'data' }{ 'madein' }; > } # end sub getmadein Here's a dereference into $obj to get to the 'data' element. The value held in the 'data' element appears to me to be another hashref, and we're accessing the 'madein' element of that one. (I believe that this is more formally written as "$obj->{ 'data' }->{ 'madein' };" but you can leave out that second arrow because it's kind of redundant) put another call to Data::Dumper in there to see that the object here is a hashref with a hashref stuck inside one of its elements. Maybe something like this: $obj = bless( { data => { madein => 'USA', foo => 'bar' }, HKreport => 'blue' }, 'HK::Report ) notice that the thing that is in 'data' is another hashref. Maybe a quick read of 'perldoc perldata' or 'perldoc perllol' or 'perldoc perldsc' would be useful here. > > I've researched a little about this - it looks like 'infix' pointers > dereference a reference?? I understand tha > t a reference is a value that holds the location to another value but > the syntax above just doesn't seem to make any sense to me. Instead of > using 'infix' pointers why not just return a regular scalar value or > array? I believe that it is returning a scalar in most of these cases. It's getting that scalar out of a hashref, though. Note that hashrefs, arrayrefs, and ojbects are just scalars themselves. They may hold references to larger things like hashes, though. > > Thanks. > > Jay You bet! If you want more information on this and you do better talking about it than reading perldocs, ask at the next meeting. I bet that saying "Can anyone explain the two uses of the skinny arrow to me, please?" would result in a lively discussion. I hope I remember to bring a pencil and paper that day. -Andy From davidnicol at gmail.com Thu Aug 31 14:59:51 2006 From: davidnicol at gmail.com (David Nicol) Date: Thu, 31 Aug 2006 16:59:51 -0500 Subject: [Kc] infix pointer question In-Reply-To: <20060831212854.GA21965@mooresystems.com> References: <20060831212854.GA21965@mooresystems.com> Message-ID: <934f64a20608311459p69a16ff4x8394477d0d7a5e02@mail.gmail.com> On 8/31/06, Andrew Moore wrote: > (I believe that this > is more formally written as "$obj->{ 'data' }->{ 'madein' };" but you > can leave out that second arrow because it's kind of redundant) you can also leave out the quotes around the key names because barewords in curlies used as hash keys are interpreted as names, even in the presence of similarly named functions: # perl -wle 'sub f(){print "called f"}; $h{f} = 4; print keys %h' f # perl -wle 'sub f(){print "called f"}; $h{ f } = 4; print keys %h' f # perl -wle 'sub f(){print "called f"}; $h{ f() } = 4; print keys %h' called f 1 # perl -wle 'sub f(){print "called f"}; $h{ $x=f } = 4; print keys %h' Name "main::x" used only once: possible typo at -e line 1. called f 1 # perl -wle 'sub f(){print "called f"}; $h{ $x="f" } = 4; print keys %h' Name "main::x" used only once: possible typo at -e line 1. f # From scratchcomputing at gmail.com Thu Aug 31 16:02:30 2006 From: scratchcomputing at gmail.com (Eric Wilhelm) Date: Thu, 31 Aug 2006 16:02:30 -0700 Subject: [Kc] infix pointer question In-Reply-To: <934f64a20608311459p69a16ff4x8394477d0d7a5e02@mail.gmail.com> References: <20060831212854.GA21965@mooresystems.com> <934f64a20608311459p69a16ff4x8394477d0d7a5e02@mail.gmail.com> Message-ID: <200608311602.30881.ewilhelm@cpan.org> # from David Nicol # on Thursday 31 August 2006 02:59 pm: ># perl -wle 'sub f(){print "called f"}; $h{ f() } = 4; print keys %h' >called f >1 Another way to call it (or, more commonly, you want the value of a constant -- but we should be using Readonly now, right?), put a unary + before it. $ perl -wle 'sub f(){print "called f"; "thbbt" }; $h{+f} = 4; print keys %h' called f thbbt --Eric -- The opinions expressed in this e-mail were randomly generated by the computer and do not necessarily reflect the views of its owner. --Management --------------------------------------------------- http://scratchcomputing.com --------------------------------------------------- From davidnicol at gmail.com Thu Aug 31 16:20:38 2006 From: davidnicol at gmail.com (David Nicol) Date: Thu, 31 Aug 2006 18:20:38 -0500 Subject: [Kc] infix pointer question In-Reply-To: <200608311602.30881.ewilhelm@cpan.org> References: <20060831212854.GA21965@mooresystems.com> <934f64a20608311459p69a16ff4x8394477d0d7a5e02@mail.gmail.com> <200608311602.30881.ewilhelm@cpan.org> Message-ID: <934f64a20608311620v3924f404p15b4cc126cc663a0@mail.gmail.com> On 8/31/06, Eric Wilhelm wrote: > > Another way to call it (or, more commonly, you want the value of a > constant -- but we should be using Readonly now, right?), put a > unary + before it. > > $ perl -wle 'sub f(){print "called f"; "thbbt" }; $h{+f} = 4; print keys %h' > called f > thbbt > > --Eric unary plus not turning its argument into a number has always bothered me a little. It's a short way to say scalar(f) but it has some side effect such that ~~ is preferred in golf -- perhaps simply that ~~ will not bind to whatever is left of it and try to do addition. ~~, the double tilde, does bitwise xor on its argument, twice. -- Although efforts have been taken to mitigate the problem, this message may contain flippancy, hyperbole and/or confusing assertions. Please reply directly to davidnicol at gmail.com for clarification of any points appearing unclear, vague, cruel, frustrating, threatening, negative, dilletantish or otherwise unprofessional before taking action based on misintepretation or misconstruction of such points: the world is complex and we're all in it together.