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

Re: [FWP] From the Perl Conference 3.0 Perl quiz (1)



Vicki Brown wrote:
> What _is_ the single unshown thing that makes this work without a syntax
> error? (and how?)
> 
> This amused me... (I amuse easily).
> If you do put in those print statements,
> 
>    print "hello, ";
>    } BEGIN {
>      @ARGV = <*m*>;
>    print "world\n";
> 
> what do you get? and why?

spoiler --v




































if i run with the -n switch, the program runs.
this is because the script becomes:

while (<>) {              # from -n

print "hello, ";
} BEGIN {
  @ARGV = <*m*>;
print "world\n";

}                         # from -n

what the script does is print a single "world\n",
followed by one "hello, " for every line in
every file in your cwd that contains the letter "m".

is this correct?
--
Steve Lane <sml@zfx.com>

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