Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

special character question

by dicty (Sexton)
on Mar 03, 2013 at 23:21 UTC ( #1021543=perlquestion: print w/ replies, xml ) Need Help??
dicty has asked for the wisdom of the Perl Monks concerning the following question:

Hi Monks,

In the code below, what does "$@" mean?

eval { store(\%hash, "$dir/pre_hash"); };

print "Error writing to file: $@\n" if $@;

Thanks!

Dicty

Comment on special character question
Re: special character question
by tobyink (Abbot) on Mar 03, 2013 at 23:25 UTC

    perlvar tells you all you need to know about Perl's special variables.

    If a fatal error occurs within an eval call, the error message is stored in $@, and execution resumes from after the eval.

    So the code in your example calls a function called store and if that raises a fatal error, prints it to STDOUT.

    package Cow { use Moo; has name => (is => 'lazy', default => sub { 'Mooington' }) } say Cow->new->name
Re: special character question
by choroba (Abbot) on Mar 03, 2013 at 23:26 UTC
    See Error Variables. $@ is the error (or exception raised) in the last eval.
    لսႽ ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ
Re: special character question
by vinoth.ree (Parson) on Mar 04, 2013 at 05:09 UTC

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1021543]
Approved by tobyink
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (5)
As of 2014-08-01 06:14 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (257 votes), past polls