in reply to Re: Writing a simple RSS feed 'grabber' with XML::Parser.
in thread Writing a simple RSS feed 'grabber' with XML::Parser.
So, we've asked Perl to construct an array, take a reference to it, then dereference that reference to pick out one of the items, then discard the reference, which then garbage-collects the array. All when we could have written that this way:my $ticker=['http://perlmonks.org/index.pl?node_id=30175&xmlstyle=rss' +, "http://rss.news.yahoo.com/rss/science"]->[rand 2];
saving two characters of typing, and all that mess of creating the new array and reference and garbage collecting. We're simply constructing a list, then picking out an element of that list with a literal slice (a construct I suggested for Perl 3, by the way {grin}).my $ticker=('http://perlmonks.org/index.pl?node_id=30175&xmlstyle=rss' +, "http://rss.news.yahoo.com/rss/science")[rand 2];
To optimize this further, I'd go with a qw for that first list:
And in recent versions of Perl, you can even drop that outer set of parens:my $ticker=(qw(http://perlmonks.org/index.pl?node_id=30175&xmlstyle=rs +s http://rss.news.yahoo.com/rss/science))[rand 2];
my $ticker=qw(http://perlmonks.org/index.pl?node_id=30175&xmlstyle=rss http://rss.news.yahoo.com/rss/science)[rand 2];
I saw bracket-arrow-bracket as a "cute syntax" once. I'm trying to stomp it out, because there's an equivalent construct (as I showed) that is a lot less work for Perl. Please don't propogate "cute syntax" that is more expensive.
-- Randal L. Schwartz, Perl hacker
Be sure to read my standard disclaimer if this is a reply.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: Writing a simple RSS feed 'grabber' with XML::Parser.
by demerphq (Chancellor) on Oct 20, 2004 at 10:51 UTC | |
|
Re^3: Writing a simple RSS feed 'grabber' with XML::Parser.
by Juerd (Abbot) on Oct 20, 2004 at 10:47 UTC | |
by merlyn (Sage) on Oct 20, 2004 at 11:04 UTC | |
|
Re^3: Writing a simple RSS feed 'grabber' with XML::Parser.
by Anonymous Monk on Oct 20, 2004 at 11:27 UTC |