Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw

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
Node Status?
node history
Node Type: note [id://734575]
[james28909]: id just rename the subrouties perl what kind of data they are getting. something easy to remember too. like if get_data were returning movies titles, rename get_data to movies or movie_titles or get_movie_titles.

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (5)
As of 2017-05-24 04:22 GMT
Find Nodes?
    Voting Booth?