in reply to Re: Order of 'use' statement in Data::Dumper
in thread Order of 'use' statement in Data::Dumper

Not true.
use Data::Dumper;
is the same as
BEGIN { require Data::Dumper; Data::Dumper::->import(); }

Like psini already said, the problem is that Perl already had to decide whether Dumper is a function call or not before use Dumper; was encountered.

  1. Compile my %test_hash = ( a => { b=> 'c' } );
  2. Compile print Dumper %test_hash; (Dumper is treated as a *Dumper since no function named Dumper was found)
  3. Compile use Data::Dumper;
  4. Execute require Data::Dumper;
  5. Execute Data::Dumper::->import();
  6. [ Script has been compiled. Now start executing it ]
  7. Execute my %test_hash = ( a => { b=> 'c' } );
  8. Execute print(*Dumper %test_hash);

You can only omit parens on a function call to a function that's already been declared (but not necessarily defined) or if you annotate the function call with &.

Update: Added list showing execution flow.

Replies are listed 'Best First'.
Re^3: Order of 'use' statement in Data::Dumper
by ~~David~~ (Hermit) on Jul 16, 2009 at 18:55 UTC
    Thanks all... it now makes sense...