Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re: RFC: CGI::Tables

by chip (Curate)
on May 09, 2003 at 16:03 UTC ( [id://256912]=note: print w/replies, xml ) Need Help??


in reply to RFC: CGI::Tables

Minor point, but your creates %attrs hashes by copying the incoming hash (if any), but it could just use its ref directly. So instead of:

my %attrs = %{shift @$data}

You could say:

my $attrs = (ref($data->[0]) eq 'HASH') ? shift @$data : {}

Then refer to $attrs->{FOO}.

    -- Chip Salzenberg, Free-Floating Agent of Chaos

Replies are listed 'Best First'.
Re^2: RFC: CGI::Tables (topicalize with for)
by Aristotle (Chancellor) on May 10, 2003 at 18:13 UTC
    Or maybe
    my $attrs = ref eq 'HASH' ? $_ : {} for shift @$data;
    which I find a lot less clumsy. Update: was ref $_ before.

    Makeshifts last the longest.

      Absolutely; I often topicalize with for. But I'd also write "ref $_" as "ref" or "ref()" -- concision!

          -- Chip Salzenberg, Free-Floating Agent of Chaos

        I don't generally like foo() much for routines that operate on $_. In this case I added it because I'd've had to if I'd written
        'HASH' eq ref ? $_ : {}
        as the question mark is then parsed as a pattern delimiter instead of as part of a ternary. I usually write my comparisons that way around. But here neither the parens nor the variable is necessary as the following eq is unambiguous as to its meaning.

        Makeshifts last the longest.

      Oops! Your substitution is actually really broken, because when $data[0] isn't a HASH, it gets thrown away. This is a Bad Thing. I didn't notice it at first, which is also a Bad Thing. :-,

          -- Chip Salzenberg, Free-Floating Agent of Chaos

        I knew full well about that, but didn't pay close enough attention to know it's undesired. Also a Bad Thing..

        Makeshifts last the longest.

Log In?
Username:
Password:

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

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

    No recent polls found