Zhao, Bingfeng wrote:
Hello,
Hello,
I encounter following requirements: 1. accept customized perl sentences; 2. provide variables exchange between customized perl sentences and my routine. Here is a sample: [code] use strict; use warnings; # we use $_ to pass value in and out $_ = qw/foo/;
Why are you assigning a list to a scalar? Perhaps you meant: $_ = q/foo/; Or: $_ = qq/foo/;
my $cmds = "print $_; $_ = qw/bar/";
Scalar variables are interpolated in double quoted strings so $cmds will be assigned the string 'print foo; foo = qw/bar/' which won't work correctly because you don't have a 'foo' filehandle and you can't use barewords (because of strict) or assign to them.
eval {$cmds};
eval {} is used to evaluate valid perl code but you have a single scalar variable in void context, hence the message "variable in void context". You want to do this instead:
eval $cmds;
my $result = $_; print $result; [/code] But I got a error: Useless use of private variable in void context at ss.pl line 7. So how can I do? Thanks in advance.
John -- Perl isn't a toolbox, but a small machine shop where you can special-order certain sorts of tools at low cost and in short order. -- Larry Wall -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/