[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

Re: [FWP] So, you think you know Perl?



Today around 8:40pm, abigail@foad.org hammered out this masterpiece:

: Your exercise for today:
: 
:    1) Predict what 
: 
:           echo "" | perl -ple 'print q'
: 
:       does.
: 
: 
:    2) Run the above command and compare it with your prediction.
: 
: 
:    3) Explain any differences.

I expected a blank new line, such as what you get if you 'print b'
instead.  The actual output is a result of 'q' being a perl operator,
try qq, qx and qr to learn more.

It could have something to do with comming to the end of the block
scope.

Oh, wait.  The real code being executed is something close to this:

while(<>){print q}continue\{print or die qq(-p destination: $!\n)}}

I can reproduce this behavior with:

  perl -le'while(<>){print q}continue\{print or die qq(-p destination: $!\n)}}'

or:

  while (defined($_ = <ARGV>)) {
      print 'continue\\{print or die qq(-p destination: $!\\n)';
  }

Cool trick.

-- 
Casey West


==== Want to unsubscribe from Fun With Perl?  Well, if you insist...
==== Send email to <fwp-request@technofile.org> with message _body_
====   unsubscribe