in reply to Re^2: perl eval
in thread perl eval

... and 'Doh!' on /me.

Modify beginning at line 32 as follows:

} print "Inside the sub at line 34: |$result|\n"; return $result; } my $ result = egal($param); # call the sub! print "At line 39 (after the sub), \$result is: |$result|\n";

and, lo and behold the output, as above but with a difference after the uninit... :

... Use of uninitialized value in concatenation (.) or string at 848064_xy +z.pl line 22. ++++Inside the sub at line 34: |false| At line 39 (after the sub), $result is: |false|

Replies are listed 'Best First'.
Re^4: perl eval
by paribasu (Initiate) on Jul 05, 2010 at 18:59 UTC
    I dont want to call egal from the script itself. The name of the sub is coming through parameter and I just want to evaluate whatever is there in the parameter.
      and I just want to evaluate whatever is there in the parameter

      That might end in tears!

      use strict; use warnings; my $param = shift; eval $param; die $@ if $@;

      Let's see some files.

      $ perl spw848064 'system ls' reallyImportant.data spw848064 $

      You can see what's coming :-)

      $ perl spw848064 'system qw{rm -f reallyImportant.data}' $

      Oops!

      <!--$ perl spw848064 'system ls' spw848064 $

      It might be worth doing a little sanity checking before evaling willy-nilly.

      Cheers,

      JohnGG