Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re^4: Perl cheat sheet (dualvars)

by lodin (Hermit)
on Jan 07, 2009 at 08:07 UTC ( [id://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

Replies are listed 'Best First'.
Re^5: Perl cheat sheet (dualvars)
by ikegami (Patriarch) 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
Domain Nodelet?
Node Status?
node history
Node Type: note [id://734575]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others admiring the Monastery: (5)
As of 2024-03-28 21:05 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found