Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
Well, perl has many subtleties - if you dig long enough. The most irritating thing I have come over in perl is the difference between arrays and lists:
$_ = "ace"; my($a, $b, $c) = (/a/, /b/, /c/);
Intuitively one would expect the above code to be similar to my($a, $b, $c) = (1, undef, 1). But this is not the case. // returns the empty list when it fails - ouch. That means the result will be my($a, $b, $c) = (1, (), 1). Which in turn means that $a = 1, $b = 1 and $c = undef

I have learnt to avoid such situations in my own code, but often I find modules that suprises me still. I belivieve CGI's param method returns the empty list if it doesn't find a parameter:

my %foo = (BAR => $cgi->param('bar'), BAZ => $cgi->param('baz'), ZOT => $cgi->param('zot'), );
If the parameters 'bar' and 'baz' was missing, your %foo would look like:
%foo = (BAR => "BAZ",
        ZOT => "zots value");

Another thing which is kind of icky is the my $foo if 0 construct. It is if IIRC documented as something you shouldn't rely on, but I have actually found good use for this once :-)

A comment to your complaint about the builtins, if you want your own lc function, but still call the perl builtin lc:

use subs qw|lc|; sub lc { lc shift } print lc("BAR");
This will not work, because lc now is recursive. So how do you access the builtin lc now ? There is actually a package named CORE:: which provides access to all builtins functions:
use subs qw|lc|; sub lc { CORE::lc shift } print lc("BAR");
Autark

In reply to RE: Subtle Quirks by autark
in thread Subtle Quirks by beppu

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (2)
As of 2024-04-25 20:41 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found