SPUG: VERY weird syntax "error"...

Jason Lamport jason at strangelight.com
Sat Dec 30 00:57:34 CST 2000


I was wondering if someone could explain this VERY puzzling behavior. 
Consider these three programs, which *should* be symantically 
identical:

---------------------------------------
#!/usr/bin/perl

use strict;

my @foo;

print ( $foo[ rand ]
);

-----------------------------------------
#!/usr/bin/perl

use strict;

my @foo;

print (
$foo[ rand ]
);

----------------------------------------
#!/usr/bin/perl

use strict;

my @foo;

print (
@foo[ rand ]
);

---------------------------------------

The first and third do exactly what I would expect (nothing). 
However, the second one dies with:

Global symbol "$foo" requires explicit package name at ./test.pl line 8.
Execution of ./test.pl aborted due to compilation errors.
Exit 255

What the...?!?!?!  The only difference between this program and the 
one above it is the insertion of a single newline, which should have 
no effect whatsoever.

I've tried this with Perl 5.6 on Linux and Perl 5.004 on both Linux 
and MacOS, with identical results.

-jason

 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
     POST TO: spug-list at pm.org       PROBLEMS: owner-spug-list at pm.org
      Subscriptions; Email to majordomo at pm.org:  ACTION  LIST  EMAIL
  Replace ACTION by subscribe or unsubscribe, EMAIL by your Email-address
 For daily traffic, use spug-list for LIST ;  for weekly, spug-list-digest
  Seattle Perl Users Group (SPUG) Home Page: http://www.halcyon.com/spug/





More information about the spug-list mailing list