aplonis has asked for the wisdom of the Perl Monks concerning the following question:
I can successfully eval a *.csh file in Perl using
backticks line-by-line. But I would like a report
if eval should fail.
In the code below, $@ gives complaints as if the
contents of the backticks were Perl code. So even
if the eval and backticks both run fine, $@ has
needless complaints.
Is there a workaround?
my $os_says = ''; my $pl_says = ''; if ( open FH, '/home/foo/bar.csh' ) { while (<FH>) { # no warnings; eval { $os_says .= `$_` }; # <- Fixed. Thanks Roger! if ($@) { $pl_says .= $@ } } print "OS says: $os_says \n"; print "Perl says: $pl_says \n"; }
Roger fixed this. I had been using parens, not braces, with my eval.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: $@ with backticks inside eval
by fizbin (Chaplain) on Aug 21, 2005 at 01:33 UTC | |
by aplonis (Pilgrim) on Aug 21, 2005 at 03:20 UTC | |
Re: $@ with backticks inside eval
by Roger (Parson) on Aug 20, 2005 at 23:42 UTC | |
by aplonis (Pilgrim) on Aug 21, 2005 at 03:05 UTC | |
Re: $@ with backticks inside eval
by Roy Johnson (Monsignor) on Aug 21, 2005 at 00:46 UTC | |
by aplonis (Pilgrim) on Aug 21, 2005 at 03:12 UTC |
Back to
Seekers of Perl Wisdom