Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

RE: Subtle Quirks

by autark (Friar)
on Jul 28, 2000 at 19:28 UTC ( #24880=note: print w/ replies, xml ) Need Help??


in reply to Subtle Quirks

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


Comment on RE: Subtle Quirks
Select or Download Code
RE: RE: Subtle Quirks
by merlyn (Sage) on Jul 28, 2000 at 19:33 UTC
    That's why I would probably not write this:
    my %foo = (BAR => $cgi->param('bar'), BAZ => $cgi->param('baz'), ZOT => $cgi->param('zot'), );
    But rather this:
    my %foo; $foo{$_} = param($_) for qw(bar baz zot);
    It's more compact and maintainable.

    -- Randal L. Schwartz, Perl hacker

RE: RE: Subtle Quirks
by PipTigger (Friar) on Jul 30, 2000 at 11:58 UTC
    Autark, are you an Anteater? Beppu-san and I attended UC Irvine together so your "zot" made me wonder. If so, did you graduate ICS? Hmmm. Beppu-san and I were unenchanted with the puter department so we didn't finish. Maybe I'll go back and grad someday. I doubt Beppu-san would ever want to go back but maybe I'm wrong. TTFN.

    -PipTigger

    p.s. Initiate Nail Removal Immediately!
      | Autark, are you an Anteater?

      No, I don't eat ants. Perhaps if they were covered in chocolate - but then again, maybe not.

      #!/usr/bin/perl -l require 5.006; sub AUTOLOAD { &{(map{eval"sub{$_}"}qw{bless\$zot ${+shift}.=chr(+pop^ +32) ${+pop} print$^T})[index+(split /::/, $AUTOLOAD)[1], "T"]} +} my $zot; { my @zot = (2,97,85,84,65,82,75,2,0,78,69,0,2,97,78,84,69,65,84,69, +82,2); for(tie our $zot, (); @zot && ($zot = shift @zot);) { $# = $zot } }
      Btw, what is the connection between metavariables and ants ?

      Autark - not an ant, nor an anteater.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (17)
As of 2014-07-29 17:07 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (224 votes), past polls