Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re: golfing hash slices (Russ = 57)

by Russ (Deacon)
on Apr 13, 2001 at 08:55 UTC ( [id://72299]=note: print w/replies, xml ) Need Help??


in reply to golfing hash slices

This appears to work:
@{$entries[@entries]}{@fieldnames} = split ',' while(<>);
57 characters (not counting whitespace). :-)

Russ
Brainbench 'Most Valuable Professional' for Perl

Replies are listed 'Best First'.
(dkubb) Re: (2) golfing hash slices (dkubb = 30)
by dkubb (Deacon) on Apr 13, 2001 at 10:21 UTC

    You can drop the round brackets arount the <>, as we all use the $. (input line number variable) instead of @entries:

    @{$entries[$.-2]}{@fieldnames}=split','while<>;  #47 characters

    Of course, shortening the variable names would also reduce the size of this:

    @{$e[@e]}{@f}=split','while<>;  #30 characters

    In which case it is shorter to use the @e array size rather than $.

(sacked: autovivification) Re: Re: golfing hash slices (Russ = 57)
by sacked (Hermit) on Apr 13, 2001 at 12:06 UTC
    Ahh! That's what I couldn't see. You know how when you get stuck on something, sometimes it is difficult to approach it from other points of view? Well, that's where I was after staring at this problem for a while this afternoon. I knew I was missing something obvious. And your solution illustrates it-- autovivification. Thanks.

    --sacked

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others musing on the Monastery: (2)
As of 2024-04-25 21:50 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found