develooper Front page | perl.perl5.porters | Postings from March 2001

Sophomore Uses List Context; Cops Interrogate

From:
Joe Smith
Date:
March 14, 2001 10:42
Subject:
Sophomore Uses List Context; Cops Interrogate
Message ID:
3AAFBB69.CA34456D@inwap.com
> 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

-- 
Joe.Smith@inwap.com    See http://www.inwap.com/ for details



nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About