Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid

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.


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?

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

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (3)
As of 2021-10-20 19:42 GMT
Find Nodes?
    Voting Booth?
    My first memorable Perl project was:

    Results (82 votes). Check out past polls.