Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re: What would you change?

by friedo (Prior)
on May 17, 2008 at 03:34 UTC ( #687061=note: print w/ replies, xml ) Need Help??


in reply to What would you change?

I never liked the print syntax. That whole optional-parameter-but-with-no-comma thing really gets my goat. I'd rather just always use select instead of sticking the filehandle in the print statement, but I don't. It eats me up inside, I tell you.

I can never remember what the syntax is for taking a slice on a hashref. I have to fiddle with it every time, no matter how many times it comes up. Rather than dealing with an appalling mess of curlies and sigils, I would really liked to have had a slice operator that could be used like my @stuff = slice $href, qw/key1 key2 key3/; Yeah, I could probably write it myself, but I'm lazy.


Comment on Re: What would you change?
Select or Download Code
Replies are listed 'Best First'.
Re^2: What would you change?
by ikegami (Pope) on May 17, 2008 at 03:55 UTC

    I never liked the print syntax. That whole optional-parameter-but-with-no-comma thing really gets my goat

    There been an alternative for quite some time.

    use IO::Handle qw( ); STDOUT->print("Hello World!\n");

    Works on any handle.

    I would really liked to have had a slice operator

    How does adding slice break perl's backwards compatibility?

Re^2: What would you change?
by Porculus (Hermit) on May 17, 2008 at 21:20 UTC
    Rather than dealing with an appalling mess of curlies and sigils...

    I can't recall ever wanting to take a slice of a hashref myself, but this line aroused my curiosity, so I investigated to see just how bad it could be.

    First I went for the naive approach:

    my @stuff = @$href{ qw/key1 key2 key3/ };

    And was rather surprised to discover that I'd got it right first try!

    Perhaps the reason this seems intuitive to me and not to you because I already habitually write $$href{key1} rather than $href->{key1}, so I'm used to using double sigils to dereference things? (Henceforth I shall use this consistency as an argument in favour of my preferred syntax!)

      For extra clarity (to me, anyway), I prefer to write it as:

      my @stuff = @{$hashref}{ qw(key1 key2 key3) }; # or my @keys = qw(key1 key2 key3); my @stuff2 = @{$hashref}{ @keys };

      (with the extra curlies). For some reason I never was crazy about the arrow shortcut here. In fact... umm... how do I correctly write the above using the arrow? I can't get it to work.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (12)
As of 2015-07-28 16:12 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (258 votes), past polls