Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
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

Replies are listed 'Best First'.
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?
Lady_Aleena goes to read, may take a bit.
[Lady_Aleena]: Um, okay...
[karlgoethebier]: Lady_Aleena see also the source code of Shell
[Lady_Aleena]: ACK! Way over my head.

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (7)
As of 2017-06-26 09:00 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    How many monitors do you use while coding?















    Results (574 votes). Check out past polls.