eval vs eval

2017-05-14 Thread Uri Guttman
On 05/14/2017 08:02 AM, Shawn H Corey wrote: On Sun, 14 May 2017 02:08:11 +0100 lee wrote: I haven't used 'eval' before, and this seems inherently dangerous. eval EXPR; eval; These are dangerous. eval BLOCK This is not. just to clarify and add to shawn&#x

Re: Alternatives to eval

2011-04-25 Thread Shawn H Corey
On 11-04-25 09:20 PM, siegfr...@heintze.com wrote: Is there a counterpart to the lisp set function in Perl? Not really. Consider using a hash instead. $hash{x} = 23; To view your data structures, use Data::Dumper; use Data::Dumper; print Dumper( \%hash ); Data::Dumper is a standard module

Re: Alternatives to eval

2011-04-25 Thread Jeff Pang
2011/4/26 : > > > $s = "$x = 23"; > eval $s; > > eval a string is considered a bad way. You may store and read the variables to and from a pure Perl data structure storage, like Tie::Hash. Regards. -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For

Alternatives to eval

2011-04-25 Thread siegfried
Ooops, I forgot to use plain text when I sent this the first time. Sorry if this appears twice. I want read some variable names and values out of a flat (xml) file and assign them. I suppose I could write $s = "$x = 23"; eval $s; Is this the best way? Is there a better way? In lis

Re: Trap syntax error inside eval?

2010-10-01 Thread C.DeRykus
s ($@); > > > I use: > > if (not $@) {return 1;} > > > > OR > > return 1 if (not $@); > > > > the syntax error does not get printed out. I assumed that these statements > were logically equal, so, what gives? I'm not sure. As Ruud mentioned, the

Re: Trap syntax error inside eval?

2010-10-01 Thread Dr.Ruud
On 2010-10-01 04:37, Jon Hermansen wrote: sub is_valid_xml { my ($content) = @_; eval { my $xs = XML::Simple->new(); my $ref = $xs->parse_string($content); }; return 1 unless ($@); } Don't test the truth of $@, but use the return value

Re: Trap syntax error inside eval?

2010-09-30 Thread Jon Hermansen
On Thu, Sep 30, 2010 at 8:34 PM, C.DeRykus wrote: > On Sep 30, 7:37 pm, jon.herman...@gmail.com (Jon Hermansen) wrote: > > Hey all, > > I have this block of code: > > > > sub is_valid_xml { > > > > > my ($content) = @_; > > > >

Re: Trap syntax error inside eval?

2010-09-30 Thread C.DeRykus
On Sep 30, 7:37 pm, jon.herman...@gmail.com (Jon Hermansen) wrote: > Hey all, > I have this block of code: > > sub is_valid_xml { > > >     my ($content) = @_; > > >     eval { > >         my $xs = XML::Simple->new(); > >         my $ref = $xs->parse

Trap syntax error inside eval?

2010-09-30 Thread Jon Hermansen
Hey all, I have this block of code: sub is_valid_xml { > my ($content) = @_; > > eval { > my $xs = XML::Simple->new(); > my $ref = $xs->parse_string($content); > }; > > return 1 unless ($@); > } > and when I pass in 'bla

Re: while and eval

2010-04-21 Thread Shawn H Corey
Uri Guttman wrote: "JWK" == John W Krahn writes: >> Also, how does 'eval' work and when is it useful? What is the difference if >> we put a block inside eval like: eval ( }; JWK> eval interprets a string as Perl code and compiles and runs it. If J

Re: while and eval

2010-04-21 Thread Uri Guttman
>>>>> "JWK" == John W Krahn writes: >> Also, how does 'eval' work and when is it useful? What is the difference if >> we put a block inside eval like: eval ( }; JWK> eval interprets a string as Perl code and compiles and runs it. If J

Re: while and eval

2010-04-21 Thread John W. Krahn
t does set $. to the total lines read. Also, how does 'eval' work and when is it useful? What is the difference if we put a block inside eval like: eval ( }; eval interprets a string as Perl code and compiles and runs it. If you are using a block eval then the block must be valid

while and eval

2010-04-21 Thread Arun P Menon
Hello All, Could you tell me what does the following do? 1 while (<>); Also, how does 'eval' work and when is it useful? What is the difference if we put a block inside eval like: eval ( }; -- Regards, Arun.P.Menon

Re: do block and eval block

2010-01-23 Thread Shlomi Fish
Hi Xiaolan! On Sunday 24 Jan 2010 05:37:49 Xiao Lan (小兰) wrote: > Hi, > > what's the difference between do a block and eval a block? > > sub test { > my $bl = shift; > eval $bl; > # do $bl; > } > > test { print "hello\n" }; Well,

do block and eval block

2010-01-23 Thread 小兰
Hi, what's the difference between do a block and eval a block? sub test { my $bl = shift; eval $bl; # do $bl; } test { print "hello\n" }; from the code, I see both do and eval work the same. Thanks. -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org

Re: Eval scoping question

2009-12-13 Thread C.DeRykus
On Dec 11, 10:52 am, rvtol+use...@isolution.nl (Dr.Ruud) wrote: > C.DeRykus wrote: > > Dr.Ruud: > >> C.DeRykus: > >>>      eval { asub() }; > >>>      die $@ if $@; > > >> You need to test the return of eval itself to be sure. > >

Re: Eval scoping question

2009-12-12 Thread Dr.Ruud
C.DeRykus wrote: Dr.Ruud: C.DeRykus: eval { asub() }; die $@ if $@; You need to test the return of eval itself to be sure. Example: perl -wle ' die "An error: ", $@ || "whoopy" if !eval{ asub(); 1 }; sub asub{ my $x = bless {}, "

Re: Eval scoping question

2009-12-11 Thread C.DeRykus
On Dec 10, 1:21 pm, rvtol+use...@isolution.nl (Dr.Ruud) wrote: > C.DeRykus wrote: > > On Dec 8, 1:57 am, dery...@gmail.com (C.DeRykus) wrote: > >> On Dec 8, 12:08 am, an...@melerit.se (Anders Hartman) wrote: > >> Also, in this case, I'd write the eval for compil

Re: Eval scoping question

2009-12-10 Thread C.DeRykus
On Dec 10, 12:57 pm, shawnhco...@gmail.com (Shawn H Corey) wrote: > C.DeRykus wrote: > > On Dec 8, 1:57 am, dery...@gmail.com (C.DeRykus) wrote: > >> On Dec 8, 12:08 am, an...@melerit.se (Anders Hartman) wrote: > > >>> ... > > >> ... > >> Also,

Re: Eval scoping question

2009-12-10 Thread Dr.Ruud
C.DeRykus wrote: On Dec 8, 1:57 am, dery...@gmail.com (C.DeRykus) wrote: On Dec 8, 12:08 am, an...@melerit.se (Anders Hartman) wrote: Also, in this case, I'd write the eval for compile-time and check for errors: eval { asub() }; die $@ if $@; No, sorry, that's a "

Re: Eval scoping question

2009-12-10 Thread Shawn H Corey
C.DeRykus wrote: > On Dec 8, 1:57 am, dery...@gmail.com (C.DeRykus) wrote: >> On Dec 8, 12:08 am, an...@melerit.se (Anders Hartman) wrote: >> >>> ... > >> ... >> Also, in this case, I'd write the eval for compile-time and check >> for err

Re: Eval scoping question

2009-12-10 Thread C.DeRykus
On Dec 8, 1:57 am, dery...@gmail.com (C.DeRykus) wrote: > On Dec 8, 12:08 am, an...@melerit.se (Anders Hartman) wrote: > >> ... > ... > Also, in this case, I'd write the eval for compile-time and check > for errors: > >      eval { asub() }; >      die $@ if $

Re: Eval scoping question

2009-12-09 Thread C.DeRykus
On Dec 8, 12:08 am, an...@melerit.se (Anders Hartman) wrote: > Hello, > > I which to use eval to execute subroutines dynamically. > > The following code snippet fails: > > #!/usr/bin/perl > > use strict; > use warnings; > > sub asub { >    our $abc; >

Re: Aw: Re: Eval scoping question

2009-12-08 Thread Shawn H Corey
pa...@arcor.de wrote: > Well, the OP said the method name is changing during the running time, so he > want to eval the method name. > So a AUTOLOAD method is right for him as far as I can think. AUTOLOAD introduces the possibility of code injection. So does eval. If the code is run

Aw: Re: Eval scoping question

2009-12-08 Thread pangj
- Original Nachricht Von: Shlomi Fish An: beginners@perl.org Datum: 08.12.2009 12:08 Betreff: Re: Eval scoping question > On Tuesday 08 Dec 2009 12:18:10 Jeff Pang wrote: > > Shlomi Fish: > > > On Tuesday 08 Dec 2009 11:46:59 Jeff Pang wrote:

Re: Eval scoping question

2009-12-08 Thread Shlomi Fish
On Tuesday 08 Dec 2009 12:18:10 Jeff Pang wrote: > Shlomi Fish: > > On Tuesday 08 Dec 2009 11:46:59 Jeff Pang wrote: > >> Shlomi Fish: > >>> Regarding using string eval "" - you can do the same using > >>> UNIVERSAL::can, which would be safer i

Re: Eval scoping question

2009-12-08 Thread Jeff Pang
Shlomi Fish: On Tuesday 08 Dec 2009 11:46:59 Jeff Pang wrote: Shlomi Fish: Regarding using string eval "" - you can do the same using UNIVERSAL::can, which would be safer in this case: <<<< __PACKAGE__->can("asub")->(@params); or define a package an

Re: Eval scoping question

2009-12-08 Thread Shlomi Fish
On Tuesday 08 Dec 2009 11:46:59 Jeff Pang wrote: > Shlomi Fish: > > Regarding using string eval "" - you can do the same using > > UNIVERSAL::can, which would be safer in this case: > > > > <<<< > > __PACKAGE__->can("asub")->(@

Re: Eval scoping question

2009-12-08 Thread Jeff Pang
Shlomi Fish: Regarding using string eval "" - you can do the same using UNIVERSAL::can, which would be safer in this case: <<<< __PACKAGE__->can("asub")->(@params); or define a package and use AUTOLOAD method? -- Jeff Pang http://home.arco

Re: Eval scoping question

2009-12-08 Thread Erez Schatz
2009/12/8 Anders Hartman : >>> Hello, >>> I which to use eval to execute subroutines dynamically. >>> The following code snippet fails: >>> >>> #!/usr/bin/perl >>> >>> use strict; >>> use warnings; >>> >>>

Re: Eval scoping question

2009-12-08 Thread Shlomi Fish
On Tuesday 08 Dec 2009 11:03:44 Anders Hartman wrote: > Jeff Pang skrev: > > Anders Hartman: > >> Hello, > >> > >> I which to use eval to execute subroutines dynamically. > >> > >> The following code snippet fails: > >> &g

Re: Eval scoping question

2009-12-08 Thread Anders Hartman
Jeff Pang skrev: Anders Hartman: Hello, I which to use eval to execute subroutines dynamically. The following code snippet fails: #!/usr/bin/perl use strict; use warnings; sub asub { our $abc; print $abc; } my $abc = "abc\n"; eval "asub"; exit 0; I don'

Re: Eval scoping question

2009-12-08 Thread Jeff Pang
Anders Hartman: Hello, I which to use eval to execute subroutines dynamically. The following code snippet fails: #!/usr/bin/perl use strict; use warnings; sub asub { our $abc; print $abc; } my $abc = "abc\n"; eval "asub"; exit 0; I don't think you want

Eval scoping question

2009-12-08 Thread Anders Hartman
Hello, I which to use eval to execute subroutines dynamically. The following code snippet fails: #!/usr/bin/perl use strict; use warnings; sub asub { our $abc; print $abc; } my $abc = "abc\n"; eval "asub"; exit 0; with the error: Use of uninitialized value i

Re: lettinf an external basgh command timeout inside eval

2009-10-22 Thread cerr
On Oct 21, 8:31 am, jimsgib...@gmail.com (Jim Gibson) wrote: > At 3:59 PM -0700 10/20/09, cerr wrote: > > >Hi, > > >I wanna execute an external bash command but timeout if it's taking > >longer than XX seconds. I've tried it like this: > >eval {

Re: lettinf an external basgh command timeout inside eval

2009-10-21 Thread Jim Gibson
At 3:59 PM -0700 10/20/09, cerr wrote: Hi, I wanna execute an external bash command but timeout if it's taking longer than XX seconds. I've tried it like this: eval { local $SIG{ALRM} = sub {die "alarm\n"}; alarm $timeout; $test = `$sshpassPATH . &q

lettinf an external basgh command timeout inside eval

2009-10-21 Thread cerr
Hi, I wanna execute an external bash command but timeout if it's taking longer than XX seconds. I've tried it like this: eval { local $SIG{ALRM} = sub {die "alarm\n"}; alarm $timeout; $test = `$sshpassPATH . " -p ".$clientpw."

Use of eval()

2009-10-14 Thread Steve Bertrand
Hi all, Although I've read the docs and have been practising with it, I'm a bit confused on the use of eval(). For some reason, it took a few swings of the hammer to get past wanting to look for array elements within $@ :P I think I now understand the dangers of using eval() to t

Re: eval and next

2009-10-07 Thread Jenda Krynicky
Date sent: Tue, 06 Oct 2009 15:45:44 +0200 From: Alexander Koenig To: beginners Subject:eval and next > Hi all, > > I have a Perl program where I use eval to catch errors. As they are Java > errors (via Inline::Jav

eval and next

2009-10-06 Thread Alexander Koenig
Hi all, I have a Perl program where I use eval to catch errors. As they are Java errors (via Inline::Java) I want my program to continue and just log the errors somewhere. My problem with this is, that I use the eval within a loop and I also use next in this loop to ignore some special cases

Re: question about eval usage

2009-06-23 Thread Jenda Krynicky
rt perl modules and found > > > > > something cryptic to myself: > > > > > > > > > > package Module; > > > > > > > > > > $Module::VERSION = '1.0'; > > > > > $Module::VERSION = eval $Module::V

Re: question about eval usage

2009-06-23 Thread Roman Makurin
On Tue, Jun 23, 2009 at 07:54:54PM +0200, Paul Johnson wrote: > > >From the docs: http://perldoc.perl.org/perlmodstyle.html#Version-numbering > Big thanks. -- If you think of MS-DOS as mono, and Windows as stereo, then Linux is Dolby Digital and all the music is free... -- To unsubscribe, e

Re: question about eval usage

2009-06-23 Thread Paul Johnson
> > > something cryptic to myself: > > > > > > > > package Module; > > > > > > > > $Module::VERSION = '1.0'; > > > > $Module::VERSION = eval $Module::VERSION; > > > > > > > > Why eval part is needed here ?

Re: question about eval usage

2009-06-23 Thread Jenda Krynicky
t; > > > > $Module::VERSION = '1.0'; > > > $Module::VERSION = eval $Module::VERSION; > > > > > > Why eval part is needed here ? > > > > It's not. What module was that? Maybe you skipped something that was > > the reason. >

Re: question about eval usage

2009-06-23 Thread Roman Makurin
On Tue, Jun 23, 2009 at 12:46:33PM +0200, Jenda Krynicky wrote: > From: Roman Makurin > > Just looked throught some standart perl modules and found > > something cryptic to myself: > > > > package Module; > > > > $Module::VERSION = '1.0&#x

Re: question about eval usage

2009-06-23 Thread Jenda Krynicky
From: Roman Makurin > Just looked throught some standart perl modules and found > something cryptic to myself: > > package Module; > > $Module::VERSION = '1.0'; > $Module::VERSION = eval $Module::VERSION; > > Why eval part is needed here ? It's no

question about eval usage

2009-06-23 Thread Roman Makurin
Hi all! Just looked throught some standart perl modules and found something cryptic to myself: package Module; $Module::VERSION = '1.0'; $Module::VERSION = eval $Module::VERSION; Why eval part is needed here ? Thanks PS: sorry for my english -- If you think of MS-DOS as mono, a

name space and invoking code with eval

2009-01-11 Thread okey
I can run a function this way (in the main package namespace): &main::aMainFunctionName(@param); How do I run it with a namespace var? $space = 'main'; eval \&${space}::aMainFunctionName(\@); Then, when and if that is possible, can I pass namespace to another package and

eval, ualarm and IO::Socket

2008-10-21 Thread Deviloper
Hi there, I just wanted to ask if somebody has implementet an "nonblocking" socket reader, which uses Time::HiRes ualarm() function (or nativ perls alarm function) to break the "waiting on data in socket (if the socket has no data)" after a view microsecond... (in eval bloc

Re: How to turn a user perl script in string format into actual perl commands that eval accepts in my script?

2008-10-19 Thread John W. Krahn
on'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 "variab

RE: How to turn a user perl script in string format into actual perl commands that eval accepts in my script?

2008-10-19 Thread Zhao, Bingfeng
I should use "eval EXPR", not "eval BLOCK". Thanks! -Original Message- From: Zhao, Bingfeng [mailto:[EMAIL PROTECTED] Sent: Monday, October 20, 2008 11:13 To: Perl Beginners Subject: How to turn a user perl script in string format into actual perl commands that eval

How to turn a user perl script in string format into actual perl commands that eval accepts in my script?

2008-10-19 Thread Zhao, Bingfeng
w/bar/"; 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. Best regards, Bingfeng

Re: eval and script performance ?

2008-10-16 Thread Justin Hawkins
Deviloper wrote: The last time I considered using eval is years ago. I remember that I had read an article somewhere that doing eval could lead to dramatic performance issues. I want to use eval{} to check my db-transactions. I looking for informations at perldoc eval, but there is nothing

Re: eval and script performance ?

2008-10-16 Thread Paul Johnson
On Thu, Oct 16, 2008 at 12:38:54PM +0100, Deviloper wrote: > The last time I considered using eval is years ago. I remember that I > had read an article somewhere that doing eval could lead to dramatic > performance issues. > > I want to use eval{} to check my db-transactions

eval and script performance ?

2008-10-16 Thread Deviloper
The last time I considered using eval is years ago. I remember that I had read an article somewhere that doing eval could lead to dramatic performance issues. I want to use eval{} to check my db-transactions. I looking for informations at perldoc eval, but there is nothing mentioned about

Re: Problem with Eval for Constructing AoA

2008-09-04 Thread Dr.Ruud
"John W. Krahn" schreef: > s/\\//g; > s/'/\\'/g; These two can be combined to s/(?=[\\'])/\\/g which I don't expect to be faster; it just makes it easier to add characters to be escaped. -- Affijn, Ruud "Gewoon is een tijger." -- To unsubscribe, e-mail: [EMAIL PR

Re: Problem with Eval for Constructing AoA

2008-09-04 Thread John W. Krahn
Gundala Viswanath wrote: Hi, Hello, This cowde below tries to convert the string in newick format into the corresponding data structure (Array of Array). But somehow the EVAL function doesn't work as expected. What's wrong with my code here? __BEGIN__ use Data::Dumper; use Carp

Re: Problem with Eval for Constructing AoA

2008-09-04 Thread Mr. Shawn H. Corey
> my $nstr= $nstr_in; > for ($nstr) { > s/\\//g; > s/'/\\'/g; > s/\(/['/g; > s/\)/']/g; > s/,/','/g; s/'\[/[/g; s/\]'/]/g; > } > > return eval{$nstr};

Problem with Eval for Constructing AoA

2008-09-04 Thread Gundala Viswanath
Hi, This cowde below tries to convert the string in newick format into the corresponding data structure (Array of Array). But somehow the EVAL function doesn't work as expected. What's wrong with my code here? __BEGIN__ use Data::Dumper; use Carp; my $str = "(foo,(bar,qux))&q

Re: Eval not working on code

2007-03-22 Thread Tom Phoenix
On 3/22/07, Kevin Old <[EMAIL PROTECTED]> wrote: Not sure why eval isn't working. Nothing is returned if I print $@ after the eval statement. What do you mean whan you say eval "isn't working"? What is it doing? Does it run any of the code? The code you inclu

Eval not working on code

2007-03-22 Thread Kevin Old
Hello everyone, I am using Class::InsideOut and am looping through some params passed and need to set their accessors (identified by the keys passed into my class), but the following code isn't working. Not sure why eval isn't working. Nothing is returned if I print $@ after the eval

Re: Eval Questions with blocks

2007-02-19 Thread Robert Boone
The general form for block eval is: #!/usr/bin/perl use strict; use warnings; eval { die 'There was an error!!!' . "\n"; }; if ($@) { print $@; } print 'On the other side.' . "\n"; Robert On Feb 19, 2007, at 4:13 PM, Gallagher, Tim F ((NE))

Eval Questions with blocks

2007-02-19 Thread Gallagher, Tim F \(NE\)
I am working my butt off trying to get eval blocks working. When I run a pert of perl code, if the code fails I dont want the script to terminate. Here is what I am talking about: [CODE] use Win32::Registry; eval{ my ($node) = 'ComputerName'; my ($hNode, $hKey, %values); $HKEY_LOC

RE: eval problem

2006-06-27 Thread Jorge Almeida
On Tue, 27 Jun 2006, Smith, Derek wrote: So could this `$SIG{'PIPE'}="IGNORE";' be considered a global similar to $ENV{"PATH"} = qq(/opt/SUNWsamfs/sbin:/usr/bin); Yes, %SIG is a global hash. Jorge -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED

RE: eval problem

2006-06-27 Thread Smith, Derek
-Original Message- From: Jorge Almeida [mailto:[EMAIL PROTECTED] Sent: Tuesday, June 27, 2006 9:37 AM To: John W. Krahn Cc: Perl Beginners Subject: Re: eval problem On Tue, 27 Jun 2006, John W. Krahn wrote: > Jorge Almeida wrote: >> What is happening? > > When find

Re: eval problem

2006-06-27 Thread Jorge Almeida
On Tue, 27 Jun 2006, John W. Krahn wrote: Jorge Almeida wrote: What is happening? When find dies a SIGPIPE signal is sent to the parent process which kills it. Thank you. Putting `$SIG{'PIPE'}="IGNORE";' in the beginning of my program solves my problem. Jorge -- To unsubscribe, e-mail

Re: eval problem

2006-06-27 Thread John W. Krahn
Jorge Almeida wrote: > Can someone help me to understand what's wrong with this? (Or: what I > didn't understand about eval?) > > $ perl -e 'use strict;use warnings;eval{open(OUT,"|file")};eval{print > OUT "aa\n";};eval{close OUT};;' >

eval problem

2006-06-27 Thread Jorge Almeida
Can someone help me to understand what's wrong with this? (Or: what I didn't understand about eval?) $ perl -e 'use strict;use warnings;eval{open(OUT,"|file")};eval{print OUT "aa\n";};eval{close OUT};;' Usage: file [-bcikLnNsvz] [-f namefile] [-F separa

RE:Setting variables with eval

2006-05-08 Thread Mirosław R
>> It works fine for me: >But you're cheating and not using my program! :-) >If I comment out the "use warnings" in my program then it works as >expected (at least, as *I* expected it to) >-- >Steve Swift (aka "Swifty") I used your program and it works for me in case: $a=1 print $a 1 Maybe U

Re: Setting variables with eval

2006-05-05 Thread Chad Perrin
On Fri, May 05, 2006 at 10:13:00AM -0400, Chas Owens wrote: > > By the way, $a and $b are special varaibles used by the sort function > and therefore do not need to be declared with "my", but it is bad form > to use them for anything but the sort function. For short examples it > is best to use $

Re: Setting variables with eval

2006-05-05 Thread Chas Owens
stem('clear'); system('perl -v'); print "Go on - try a few... Enter 'exit' to end.\n"; while (<>) { eval $_; if ($@) {print "[EMAIL PROTECTED]";} print ' ','.'x50," perltry on $^O\n" }; If I enter a s

Re: Setting variables with eval

2006-05-05 Thread Steve Swift
It works fine for me: But you're cheating and not using my program! :-) If I comment out the "use warnings" in my program then it works as expected (at least, as *I* expected it to) -- Steve Swift (aka "Swifty") -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [

Re: Setting variables with eval

2006-05-05 Thread Mr. Shawn H. Corey
strict; > use warnings; > system('clear'); > system('perl -v'); > print "Go on - try a few... Enter 'exit' to end.\n"; > while (<>) { >eval $_; >if ($@) {print "[EMAIL PROTECTED]";} >print ' 

Re: Setting variables with eval

2006-05-05 Thread John W. Krahn
('clear'); > system('perl -v'); > print "Go on - try a few... Enter 'exit' to end.\n"; > while (<>) { > eval $_; > if ($@) {print "[EMAIL PROTECTED]";} > print ' ','.'x50," perltry on $^

Re: Setting variables with eval

2006-05-05 Thread Bjørge Solli
; > use warnings; > system('clear'); > system('perl -v'); > print "Go on - try a few... Enter 'exit' to end.\n"; > while (<>) { >eval $_; >if ($@) {print "[EMAIL PROTECTED]";} >print ' ',&

Setting variables with eval

2006-05-05 Thread Steve Swift
"Go on - try a few... Enter 'exit' to end.\n"; while (<>) { eval $_; if ($@) {print "[EMAIL PROTECTED]";} print ' ','.'x50," perltry on $^O\n" }; If I enter a statement, such as "$a=1;" (without the quotes)

Re: eval{}

2006-03-07 Thread Jay Savage
On 3/7/06, Chas Owens <[EMAIL PROTECTED]> wrote: > On 3/7/06, Jay Savage <[EMAIL PROTECTED]> wrote: > snip > > Since eval traps die, 'eval{ eval {} or die [EMAIL PROTECTED];};' is a > > convenient > > method for propagating $@ out of deeply nested e

Re: eval{}

2006-03-07 Thread Chas Owens
On 3/7/06, Jay Savage <[EMAIL PROTECTED]> wrote: snip > Since eval traps die, 'eval{ eval {} or die [EMAIL PROTECTED];};' is a > convenient > method for propagating $@ out of deeply nested evals. It's just a way > to save writing lots of if blocks that do nothing

Re: eval{}

2006-03-07 Thread Jay Savage
On 3/6/06, Tom Allison <[EMAIL PROTECTED]> wrote: > Jay Savage wrote: > > > > > die on errors and just keep passing them up the line: > > > > eval { > > eval { > > eval { > > bad_system_call() or die &qu

Re: eval{}

2006-03-06 Thread Tom Phoenix
On 3/6/06, Tom Allison <[EMAIL PROTECTED]> wrote: > Will 'die' by itself propogate the contents of $@ ad infinitum? Well, not ad infinitum. But it will propagate, according to perldoc's entry on die(). Cheers! --Tom Phoenix Stonehenge Perl Training -- To unsubscribe, e-mail: [EMAIL PROTECTED] F

Re: eval{}

2006-03-06 Thread Tom Allison
Jay Savage wrote: die on errors and just keep passing them up the line: eval { eval { eval { bad_system_call() or die "$!\n"; } or die $@; } or die $@; }; print "eval says: [EMAIL PROTECTED]" if $@;

Re: eval{}

2006-03-06 Thread Jay Savage
t falls > into a few steps: > > read from network > read from database > write to database > do something else on network > write to network > > Being the cautious code writer I thought it would make sense to use > something like: > > eval{ > alarm(10); > "

Re: eval{}

2006-03-06 Thread Chas Owens
On 3/6/06, Tom Allison <[EMAIL PROTECTED]> wrote: > The problem I run into is throwing the exceptions up to the top eval{} > structure when I need to communicate that something didn't work right > so I can provide feedback to the network client connection. > > I suppose I

eval{}

2006-03-06 Thread Tom Allison
se do something else on network write to network Being the cautious code writer I thought it would make sense to use something like: eval{ alarm(10); "read from network" "read from database" } But each of these database calls has it's own eval{} around the database

printing the contents of the last eval

2006-02-22 Thread Ryan Gies
Inpecting $@ and caller() after an eval will yield: Error message (eval 6750):428 How does one view line 428. Are there formal hooks with which (immediately following an eval) one can: my $eval_number = ???; my $eval_contents = ???( $eval_number ); The debugger seems to do a

conclusion: about eval and stdin

2006-01-04 Thread Adriano Allora
hi to all and thanks to all suggested me some solution, using debug lines (or something similar) I understood how obtaining the output I want. Now, I'm writing this e-mail to show a possible way to do a discrete corrector: I write a regexp to substitute (maybe with another regexp including bac

RE: about eval and stdin

2006-01-03 Thread Timothy Johnson
text to replace it with. PATTERN: Te([^ ]+).*support REPLACEMENT: sticular Pattern Found! $_ => Tech Support $1 => ch Type "s" to confirm substitution, or press any other key to cancel: s COMMAND: s/Te([^ ]+

RE: about eval and stdin

2006-01-03 Thread Timothy Johnson
ne to: if(/($pattern)/gi) -Original Message- From: Adriano Allora [mailto:[EMAIL PROTECTED] Sent: Mon 1/2/2006 3:48 AM To: beginners@perl.org Cc: Subject: about eval and stdin hi to all, a friend of mi

Re: about eval and stdin

2006-01-02 Thread John Doe
pattern = (dir)ectory and replacement = $1, why the script > does not eval $1 as "dir"? how I can change the script to make it works > as I want? because there is no $1 at the point you test it. You get an $1 by putting '()' in a match/substitution. btw: What would be t

about eval and stdin

2006-01-02 Thread Adriano Allora
hi to all, a friend of mine ask me for a perl script to change regexp patterns in some texts (he can learn regexp, but I suppose he won't learn perl). So I start write this one to him. I have a problem: ==> with pattern = (dir)ectory and replacement = $1, why the script does not ev

Re: [PATCH] Test that constant overloading is propagated into eval

2005-12-27 Thread Adriano Ferreira
On 12/26/05, Robin Houston <[EMAIL PROTECTED]> wrote: > +# Check that constant overloading propagates into evals As a further confirmation of the fact, the following one-liner (using bigint and eval with strings) that used to output $ perl -Mbigint -e "my $x = eval '1+2

Re: Help with eval (WAS: which is more effective between map and foreach?)

2005-12-06 Thread Shawn Corey
Jennifer Garner wrote: And, I have another syntax question here. I can't know clearly the difference between eval "" and eval {}. I have run "perldoc -f eval" and read it,but still can't know clearly.Can you help me on this? eval {} or eval BLOCK is parsed only on

Re: eval without warnings

2005-09-28 Thread Bryan R Harris
" > > Here's a solution that works for the cases you've provided: > >sub try_eval { > local $@; > my $warning; > local $SIG{__WARN__} = sub { $warning = 1 }; > my $expr = shift; > my $val = eval $expr; > $val = $expr if $@ or

Re: eval without warnings

2005-09-27 Thread Jeff 'japhy' Pinyan
you've provided: sub try_eval { local $@; my $warning; local $SIG{__WARN__} = sub { $warning = 1 }; my $expr = shift; my $val = eval $expr; $val = $expr if $@ or $warning; return $val; } It catches fatal errors (via $@) and non-fatal warnings (via the __WARN__

Re: eval without warnings

2005-09-27 Thread Bryan R Harris
> On Tue, 27 Sep 2005, Bryan R Harris wrote: > >> I'd like to evaluate user input only where it makes sense, e.g. >> >> "2*(3+2)" ==> 10 >> "2*dog" ==> "2*dog" >> "mysquarefunction(2)" ==> 4 >> "3*mysquarefunction(2)" ==> 12 >> "some guy" ==> "some guy" > > What happens when they put somethin

Re: eval without warnings

2005-09-27 Thread Chris Devers
On Tue, 27 Sep 2005, Bryan R Harris wrote: > I'd like to evaluate user input only where it makes sense, e.g. > > "2*(3+2)" ==> 10 > "2*dog" ==> "2*dog" > "mysquarefunction(2)" ==> 4 > "3*mysquarefunction(2)" ==> 12 > "some guy" ==> "some guy" What happens when they put something in like "sys

eval without warnings

2005-09-27 Thread Bryan R Harris
I'd like to evaluate user input only where it makes sense, e.g. "2*(3+2)" ==> 10 "2*dog" ==> "2*dog" "mysquarefunction(2)" ==> 4 "3*mysquarefunction(2)" ==> 12 "some guy" ==> "some guy" I've tr

Re: What is this doing: eval 'exec /usr/bin/perl -T -w -S $0 ${1+"$@"}' if 0;

2004-08-09 Thread JupiterHost.Net
Jose Alves de Castro wrote: On Sun, 2004-08-08 at 04:06, JupiterHost.Net wrote: I found this code in a script right after the she-bang line: eval 'exec /usr/bin/perl -T -w -S $0 ${1+"$@"}' if 0; # not running under some shell What is it doing? Hi. From `perldoc perlrun`, u

Re: What is this doing: eval 'exec /usr/bin/perl -T -w -S $0 ${1+"$@"}' if 0;

2004-08-09 Thread Jose Alves de Castro
On Sun, 2004-08-08 at 04:06, JupiterHost.Net wrote: > I found this code in a script right after the she-bang line: > > eval 'exec /usr/bin/perl -T -w -S $0 ${1+"$@"}' > if 0; # not running under some shell > > What is it doing? Hi. From `perldoc p

What is this doing: eval 'exec /usr/bin/perl -T -w -S $0 ${1+"$@"}' if 0;

2004-08-07 Thread JupiterHost.Net
I found this code in a script right after the she-bang line: eval 'exec /usr/bin/perl -T -w -S $0 ${1+"$@"}' if 0; # not running under some shell What is it doing? Its like its executing itself again, but why? What the heck is: ${1+"$@"} ?? Wouldn't the eval

  1   2   3   >