Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re^4: Perl cheat sheet (dualvars)

by lodin (Hermit)
on Jan 07, 2009 at 08:07 UTC ( #734575=note: print w/ replies, xml ) Need Help??


in reply to Re^3: Perl cheat sheet
in thread Perl cheat sheet

$! was an unfortunate choice of variable. :-) It's a dualvar so it has different values if treated as a string or as a numerical.

open my $fh, '<', 'this does not exist'; printf "%s (%d)\n", $!, $!; __END__ No such file or directory (2)
It's better to just create a copy and pass that, if the subroutine doesn't copy the argument.

lodin


Comment on Re^4: Perl cheat sheet (dualvars)
Select or Download Code
Re^5: Perl cheat sheet (dualvars)
by ikegami (Pope) on Jan 07, 2009 at 09:23 UTC

    The example was fine. It doesn't make sense for logger to need the dualvar.

    • If you wanted to pass the error string to the sub, the caller would use "$!".
    • If you wanted to pass the error number to sub, the caller would use 0+$!.
    • If the sub needs both an error string and an error number, it would take two arguments.
    • If the sub wants to look at $!, it wouldn't take it as an argument.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (4)
As of 2015-07-06 00:39 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (68 votes), past polls