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

"... atleast that is what I want..!"

and I want a pony... but I've never found a hayburner in my Christmas stocking.

Others monks have explained the shortcomings of your eval print $param; but, for emphasis:

>perl 848064_xyz.pl 'egal("20090316","7006")' 'egal(20090316,7006)' is $param at line 10 'egal(20090316,7006)' Line 11 $param: |'egal(20090316,7006)'| At 13, $test: 'egal(20090316,7006)' Use of uninitialized value in concatenation (.) or string at 848064_xy +z.pl line 22. ++++ >

And, just BTW, note that your double_quotes -- the "s -- don't pass through the windows shell (my Linux box is down, but IIRC, you'll have a mirror-image issue there).

Here's your code, slightly modified at 5, 6, 9, 10, 12, 19 and 34 for illustration (thus, "line 26" in my previous reply is now line 38).

#!/usr/bin/perl use strict; use warnings; # OP says: Now I am calling the script : # 001: perl xyz.pl 'egal("20090316","7006")' my $param = shift; chomp $param; print "\n\n\t $param is \$param at line 10\n\n"; eval print $param; print "\n\tLine 11 \$param: |$param| \n"; sub egal { my $result; my @arg = @_; my $test = $arg[0]; print "\n At 13, \$test: $test\n\n"; my @test = grep (/$test/i, @arg); print "\t $test[0] \n"; print "++++"; if ($#test == $#arg) { $result = 'true'; } else { $result = 'false'; } return $result; print " $result\n"; } egal($param); # call the sub!

Replies are listed 'Best First'.
Re^4: perl eval
by paribasu (Initiate) on Jul 05, 2010 at 18:47 UTC

    I have updated my problem. Hope it will make u understand the real problem... U run the second piece of code and will find the desired output i am expecting from the first piece... Please understand the problem first before answering.

      Your eval fails and you never check for it. But you were told that already. So please read the answers first before asking again.

      A reply falls below the community's threshold of quality. You may see it by logging in.