Getting result from other perl script through system call -
i know can use require , in different fashion, i'm toying around perl , ran don't know how explain.
here's first script:
use 5.16.2; use warnings; sub { print "hello"; } get(); test script:
use 5.16.2; use warnings; $val=system('perl test.pl'); print "$val\n"; #prints: hello0, surmised 0 return code system i looked how ignore 0 , got wrong, led me this:
print '', system('perl test.pl'); #also prints hello0 $val='', system('perl test.pl'); print "$val\n"; #prints: hello this works, have absolutely no idea why. i'm confused why 1 preceding didn't work. please explain?
this:
print '', system('perl test.pl'); calls print 2 arguments, namely '' (the empty string: no effect) , system('perl test.pl') (which evaluates 0, saw, provided perl test.pl runs successfully).
using more parentheses more explicit, can write above as:
print('', system('perl test.pl')); or can write as:
my $val = system 'perl test.pl'; # prints 'hello', sets $val 0 print '', $val; # prints 0 this:
my $val='', system('perl test.pl'); declares $val local variable , sets '' (the empty string), , (unrelatedly) calls system('perl test.pl'). using parentheses explicitness:
(my $val = ''), system('perl test.pl'); or:
my $val = ''; system('perl test.pl'); # prints 'hello', discards exit-status
Comments
Post a Comment