Ask a Question related to Perl / CGI, Design and Development.
-
Mallik #1
What is eval?
Can anybody explain the functionality of eval in brief?
Thanks in advance,
Mallik.
Mallik Guest
-
Eval()
I know i could use EVAL to evaluate VARs but what about if i want to evaluate a Var that have a funtion onit? like A="math.Cos(65)" B=Eval(A);... -
eval vs. set?
I'm trying to dynamically create movieclip instances. They seem to be created fine, but when I go to move them it does not work. I've tried line 1... -
eval'
I am retrieving the following string from the database. " and upper(gsa_template_data_header) >= '".$start_selection."' and... -
eval
PHP-Code: eval('?>'.$string) Vars: eval('$string="'.str_replace('"','\\"',$string).'";'); ------------------------ -
Help with eval
I am trying to write a perl script that can parse a verilog file with syntax like: `if ABC == 1 abc is set something `else abc not set `endif... -
James Edward Gray II #2
Re: What is eval?
On Jan 29, 2004, at 6:26 AM, Mallik wrote:
perldoc -f eval> Can anybody explain the functionality of eval in brief?
James
James Edward Gray II Guest
-
Bradley A. Brown #3
RE: What is eval?
[url]http://www.perldoc.com/perl5.8.0/pod/func/eval.html[/url]
Bradley
-----Original Message-----
From: Mallik [mailto:mallikarjunk@softima.com]
Sent: Thursday, January 29, 2004 7:26 AM
To: Perl Beginners
Subject: What is eval?
Can anybody explain the functionality of eval in brief?
Thanks in advance,
Mallik.
--
To unsubscribe, e-mail: [email]beginners-unsubscribe@perl.org[/email]
For additional commands, e-mail: [email]beginners-help@perl.org[/email]
<http://learn.perl.org/> <http://learn.perl.org/first-response>
Bradley A. Brown Guest
-
Jeff 'Japhy' Pinyan #4
Re: What is eval?
On Jan 29, Mallik said:
For starters, please read 'perldoc -f eval'. All Perl functions are>Can anybody explain the functionality of eval in brief?
explained in detail in the standard documentation.
eval() has two forms. The first takes a string, and treats it as Perl
code. It compiles and executes it, returning whatever value is
appropriate. If there is a fatal error, it sets the $@ variable.
my $string = "make the vowels capitals";
my $from = "aeiou";
my $to = "AEIOU";
eval "\$string =~ tr/$from/$to/";
# now $string is mAkE thE vOwEls cApItAls
We had to use eval() here, because tr/// doesn't interpolate variables.
If we'd just done
$string =~ tr/$from/$to/;
we'd be changing $ to $, f to t, r to o, o to o, and m to o, and the
string would be "oake the vowels capitals".
The other form is eval { CODE }. This executes a block of code in a
fail-safe environment. If there are any fatal errors, the $@ is set, and
the block is exited. A common use for this is:
print "Give me a number: ";
chomp(my $n = <STDIN>);
my $result = eval { 100 / $n };
if ($@) { print "You tried dividing by zero.\n" }
Basically, if we didn't use eval { } here, the program would die if the
user entered the number 0.
--
Jeff "japhy" Pinyan [email]japhy@pobox.com[/email] [url]http://www.pobox.com/~japhy/[/url]
RPI Acacia brother #734 [url]http://www.perlmonks.org/[/url] [url]http://www.cpan.org/[/url]
<stu> what does y/// stand for? <tenderpuss> why, yansliterate of course.
[ I'm looking for programming work. If you like my work, let me know. ]
Jeff 'Japhy' Pinyan Guest
-
Rob Hanson #5
RE: What is eval?
It evaluates the code that you give it. It can be used when you need to
create code on the fly, like this...
my $cmd = 'print';
my $arg = 'Hello World';
eval("$cmd '$arg'");
This is useful for allowing a user to pass code to the program (for whatever
reason).
The other use it to trap errors.
my $this = 1;
my $that = 2;
eval {
if ($this != $that) {
die "They don't match!";
}
};
print $@;
In this case the "die" doesn't terminate the program, it only terminates the
eval. And $@ stores the error message that was "thrown" in the eval. So
this prints the error message without abnormally terminating the program.
This is akin to the try/catch blocks in other languages (the Errors gives
you try/catch functionality by using eval).
Hope that helps.
Rob
-----Original Message-----
From: Mallik [mailto:mallikarjunk@softima.com]
Sent: Thursday, January 29, 2004 7:26 AM
To: Perl Beginners
Subject: What is eval?
Can anybody explain the functionality of eval in brief?
Thanks in advance,
Mallik.
--
To unsubscribe, e-mail: [email]beginners-unsubscribe@perl.org[/email]
For additional commands, e-mail: [email]beginners-help@perl.org[/email]
<http://learn.perl.org/> <http://learn.perl.org/first-response>
Rob Hanson Guest
-
Steve Grazzini #6
Re: What is eval?
Mallik wrote:
There are two different flavors of eval().> Can anybody explain the functionality of eval in brief?
The "string" version looks like this:
eval $code;
And it treats its argument as a string containing Perl source code,
which it compiles and executes.
The "block" version looks like this:
eval { $obj->might_die() };
And its argument is just an ordinary block (like the body of an
"if" statement). Both forms will trap fatal errors and place the
error in $@.
There's a more complete explanation in "perlfunc"
% perldoc -f eval
--
Steve
Steve Grazzini Guest
-
Rob Dixon #7
Re: What is eval?
James Edward Gray II wrote:
How succinct!>
> On Jan 29, 2004, at 6:26 AM, Mallik wrote:
>>> > Can anybody explain the functionality of eval in brief?
> perldoc -f eval
/R
Rob Dixon Guest
-
ashishgupta62@gmail.com #8
Re: What is eval?
Hi,
I am writing some script here i have noticed that first character of Japanese string (when used in eval function) is replaced with result1 or result2 variable.
Here is the script that i am using
#!/usr/bin/perl
my $string1 = "<japanese string>";
my $string2 = "Type";
my $result1 = "S";
my $result2 = "G";
my $length = 8;
print "EXPECTED\n";
print "$string2: $result1\n";
print "$string1: $result1\n";
print "$string1: $result2\n";
print "\n";
print "ACTUAL\n";
eval (
"format TEST = \n"
. $string2 . ':' . ' ' x ($length - length($string2)) .' @' . "\n"
. '$result1'."\n"
. $string1 . ':' . ' ' x ($length - length($string1)) .' @' . "\n"
. '$result1'."\n"
. $string1 . ':' . ' ' x ($length - length($string1)) .' @' . "\n"
. '$result2'."\n"
. ".\n");
$�~ = 'TEST';
write;
Output of script:
EXPECTED
Type: S
^Cv: S
^Cv: G
ACTUAL
Type: S
SCv:
GCv:
Can someone please explain me why eval function not abale to give result as expected
Thanks in advance
Junior Member
- Join Date
- Aug 2011
- Posts
- 1



Reply With Quote

