Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw

Mason and $@

by rkg (Hermit)
on Jan 25, 2004 at 18:12 UTC ( #323992=perlquestion: print w/replies, xml ) Need Help??

rkg has asked for the wisdom of the Perl Monks concerning the following question:


Mason scoping question. Here's a reduction that illustrates the issue:

Why does this work properly (that is, the error message is sent off to the component)

<html> <body> % eval { die "this is an error"; }; % if ($@) { % my $message = $@; % $m->comp('/comps/error.comp', message=> $message); % } </body> </html>
But this does not work properly (a blank string is sent off the component)
<html> <body> % eval { die "this is an error"; }; % if ($@) { % $m->comp('/comps/error.comp', message=> $@); % } </body> </html>
Thanks for any insight.



Ok, since (notice the quotes)

$m->comp('/comps/error.comp', message=> "$@");
does work properly, I'm wondering if the issue is Mason, or if $@ has magic properties...

is $@ a simple scalar, or something more?

Replies are listed 'Best First'.
Re: Mason and $@
by Fletch (Bishop) on Jan 25, 2004 at 19:13 UTC

    $@ can be changed by any intermediate steps which happen to cause it to change. I can't think it's out of the question that some part of the component resolution code is using an eval which is succeeding and thus clearing it out. Like $1 or $!, unless you can absolutely count on other code not doing something to change it your best bet's copying it (either explicitly or through stringifying it).

Re: Mason and $@
by coec (Chaplain) on Jan 25, 2004 at 20:39 UTC
    A stab in the dark here, but it would be useful to see what $@ contains. I'm thinking that it would be expected to get an error if $@ contains one or more spaces. Maybe a
    print Data::Dumper $@
    or similar?

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://323992]
Approved by valdez
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (5)
As of 2023-05-30 18:40 GMT
Find Nodes?
    Voting Booth?

    No recent polls found