Hi
i have the following code:
if(($line!=1) and (@field!='\$')){
print ( "\nTRY TO CONNECT TO DATABASE................\n");
my $dbh = DBI->connect($dsn, $user, $pass);
print ("CONNECTED TO DATABASE\n");
eval
... (1 Reply)
Hi Gurus,
I am having 2 parameters as below
parm1=value1
parm2=parm1
I want to evaluate parm1 value using eval echo \$$parm2 and later i want to assign this value to other variable which i will be using in if statement like :
if ]; then
do this.......
fi
could you please suggest... (5 Replies)
I have file called myfile which has the text "myserver" in it. I need to have a command to ping "myserver". How would I do that?
I tried
when I type at the terminal I get the output as . How do I do something like a ?
thanks,
Nick (5 Replies)
Hi all,
some small script with eval turned me to crazy.
my OS is linux
Linux s10-1310 2.6.16.53-0.8.PTF.434477.3.TDC.0-smp #1 SMP Fri Aug 31 06:07:27 PDT 2007 x86_64 x86_64 x86_64 GNU/Linux
below script works well
#!/bin/bash
eval ssh remotehost date
eval ssh remotehost ls
below... (1 Reply)
Hi All,
I read the above written code (perl code) in another perl script and evaluates this code for each line of text file,but using exit statement in code make this not to work and i could not get the desired results. However if i use return it works fine. I just need to know why it doesn't... (1 Reply)
Discussion started by: sarbjit
1 Replies
6. Forum Support Area for Unregistered Users & Account Problems
Hello,
I believe that the following man page contains an error: <www dot unix dot com>/man-page/posix/1posix/eval/
In section "EXAMPLES", the fourth line should probably be:
eval y='$'$x
rather than:
$fooeval y='$'$x
Regards,
Jérôme DUBOIS. (1 Reply)
Hi,
I am trying to use eval command to evaluate a variable(HAPROXY_LISTENER_rabbitmq_project-test-BRHM_PORT) which consists of '-' but unfortunately the eval command is unable to interpret the value of variable and trims the variable name after '-' and produces the string output rather than the... (10 Replies)
Hi,
I am Pradnya Gandhe trying to use in shell script.
I want to use a bit complicated command using eval command in a shell script.
<path to>\wsadmin.sh -lang jython -conntype NONE -c "AdminApp.install('war file path', '] -MapWebModToVH ] -MapRolesToUsers ] ]')"
Works correctly as expected... (2 Replies)
Hi Guys,
I wrote a collection of bash functions years ago and now need to use them again but
I'm getting some error messages when eval tries to expand the variables names.
I recollect that I used the shopt command to set one of the options but I can't quite
remember the command that I... (8 Replies)
Perl::Critic::Policy::ErrorHandling::RequireCheckingRetuUserlContributed PPerl::Critic::Policy::ErrorHandling::RequireCheckingReturnValueOfEval(3)NAME
Perl::Critic::Policy::ErrorHandling::RequireCheckingReturnValueOfEval - You can't depend upon the value of "$@"/"$EVAL_ERROR" to tell
whether an "eval" failed.
AFFILIATION
This Policy is part of the core Perl::Critic distribution.
DESCRIPTION
A common idiom in perl for dealing with possible errors is to use "eval" followed by a check of $@/$EVAL_ERROR:
eval {
...
};
if ($EVAL_ERROR) {
...
}
There's a problem with this: the value of $EVAL_ERROR can change between the end of the "eval" and the "if" statement. The issue is object
destructors:
package Foo;
...
sub DESTROY {
...
eval { ... };
...
}
package main;
eval {
my $foo = Foo->new();
...
};
if ($EVAL_ERROR) {
...
}
Assuming there are no other references to $foo created, when the "eval" block in "main" is exited, "Foo::DESTROY()" will be invoked,
regardless of whether the "eval" finished normally or not. If the "eval" in "main" fails, but the "eval" in "Foo::DESTROY()" succeeds,
then $EVAL_ERROR will be empty by the time that the "if" is executed. Additional issues arise if you depend upon the exact contents of
$EVAL_ERROR and both "eval"s fail, because the messages from both will be concatenated.
Even if there isn't an "eval" directly in the "DESTROY()" method code, it may invoke code that does use "eval" or otherwise affects
$EVAL_ERROR.
The solution is to ensure that, upon normal exit, an "eval" returns a true value and to test that value:
# Constructors are no problem.
my $object = eval { Class->new() };
# To cover the possiblity that an operation may correctly return a
# false value, end the block with "1":
if ( eval { something(); 1 } ) {
...
}
eval {
...
1;
}
or do {
# Error handling here
};
Unfortunately, you can't use the "defined" function to test the result; "eval" returns an empty string on failure.
Various modules have been written to take some of the pain out of properly localizing and checking $@/$EVAL_ERROR. For example:
use Try::Tiny;
try {
...
} catch {
# Error handling here;
# The exception is in $_/$ARG, not $@/$EVAL_ERROR.
}; # Note semicolon.
"But we don't use DESTROY() anywhere in our code!" you say. That may be the case, but do any of the third-party modules you use have them?
What about any you may use in the future or updated versions of the ones you already use?
CONFIGURATION
This Policy is not configurable except for the standard options.
SEE ALSO
See thread on perl5-porters starting here: <http://www.xray.mpe.mpg.de/mailing-lists/perl5-porters/2008-06/msg00537.html>.
For a nice, easy, non-magical way of properly handling exceptions, see Try::Tiny.
AUTHOR
Elliot Shank "<perl@galumph.com>"
COPYRIGHT
Copyright (c) 2008-2011 Elliot Shank.
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. The full text of this license
can be found in the LICENSE file included with this module.
perl v5.16.32014-0Perl::Critic::Policy::ErrorHandling::RequireCheckingReturnValueOfEval(3)