This just came in on the perl5-porters mailing list and as it is both an
interesting story and one which teaches a valuable PERL lesson.
Ted
----- Forwarded message from Joe Smith <[log in to unmask]
> Many operators behave differently depending on context: in this case, the
> backtick. The statement:
>
> my($f) = `fortune`;
>
> ...puts the backtick operator in list context, so it returns a list, where
> each element is one line from the program's output.
>
> S. wants to be a developer when he graduates; he certainly has
> the most important thing down, which is to always be exploring and learning
> new things. In the process of converting his website from PHP to perl for
> no especially good reason, he wrote the above line.
>
> If he had written the code correctly:
>
> my $f = `fortune`;
>
> ...the backtick operator would have been in scalar context, assigned
> its complete result to $f for printing, and you wouldn't be reading
> this sad story.
>
> Last week, the administrators at his school just happened to take a look at
> his webpage when fortune pulled up this quote:
>
> I put the shotgun in an Adidas bag and padded it
> out with four pairs of tennis socks, not my style
> at all, but that was what I was aiming for: If they
> think you're crude, go technical; if they think
> you're technical, go crude. I'm a very technical
> boy. So I decided to get as crude as possible.
> These days, though, you have to be pretty technical
> before you can even aspire to crudeness.
> - Johnny Mnemonic, by William Gibson
>
> Because only the first line about the shotgun was stored in $f and shown on the
> webpage, it wasn't immediately obvious that this was a quote.
http://slashdot.org/yro/01/03/13/208259.shtml
----- End forwarded message -----
--
Ted Ashton ([log in to unmask]), Info Sys, Southern Adventist University
==========================================================
[about him:]
It is rare to find learned men who are clean, do not stink and have a sense
of humour.
[attributed variously to Charles Louis de Secondat Montesquieu and to the
Duchess of Orleans]
-- Leibniz, Gottfried Whilhem (1646-1716)
==========================================================
Deep thoughts to be found at http://www.southern.edu/~ashted
|