Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re: Perl v5.13.7 is released

by Anonymous Monk
on Nov 21, 2010 at 17:54 UTC ( [id://872803]=note: print w/replies, xml ) Need Help??


in reply to Perl v5.13.7 is released

Most important change if you ask me

All built-in functions that operate directly on array or hash containers now also accept hard references to arrays or hashes:

|----------------------------+---------------------------| | Traditional syntax | Terse syntax | |----------------------------+---------------------------| | push @$arrayref, @stuff | push $arrayref, @stuff | | unshift @$arrayref, @stuff | unshift $arrayref, @stuff | | pop @$arrayref | pop $arrayref | | shift @$arrayref | shift $arrayref | | splice @$arrayref, 0, 2 | splice $arrayref, 0, 2 | | keys %$hashref | keys $hashref | | keys @$arrayref | keys $arrayref | | values %$hashref | values $hashref | | values @$arrayref | values $arrayref | | ($k,$v) = each %$hashref | ($k,$v) = each $hashref | | ($k,$v) = each @$arrayref | ($k,$v) = each $arrayref | |----------------------------+---------------------------|

Replies are listed 'Best First'.
Re^2: Perl v5.13.7 is released
by LanX (Saint) on Nov 21, 2010 at 22:34 UTC
    that's brilliant! :)

    Cheers Rolf

      ... even if it smells a little bit like PHP.

      Alexander

      --
      Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so". ;-)
        Me thinks being forced to write push @{ $ref->[0]{key} }, "AoHoA" also has a special odor... ;-)

        Cheers Rolf

Re^2: Perl v5.13.7 is released
by arkturuz (Curate) on Nov 22, 2010 at 14:23 UTC
    I don't like that change. It adds more to the syntax confusion than it takes away. If I'm pushing values into an array, I expect the argument to be some kind of array. It feels natural in Perl. All those sigil-mangling changes (and I'd like to include Perl6's sigil immutability here) stray from that (relatively simple) direction.

    Automatic dereferencing syntax (meaning: s/@$/@/ or s/@{$ref}/@ref/) would be more useful. For example:

    |----------------------------+---------------------------|
    | Traditional syntax         | Auto syntax               |
    |----------------------------+---------------------------|
    | push @$arrayref, @stuff    | push @arrayref, @stuff    |
    | unshift @$arrayref, @stuff | unshift @arrayref, @stuff |
    | pop @$arrayref             | pop @arrayref             |
    | shift @$arrayref           | shift @arrayref           |
    | splice @$arrayref, 0, 2    | splice @arrayref, 0, 2    |
    | keys %$hashref             | keys @hashref             |
    | keys @$arrayref            | keys @arrayref            |
    | values %$hashref           | values @hashref           |
    | values @$arrayref          | values @arrayref          |
    | ($k,$v) = each %$hashref   | ($k,$v) = each @hashref   |
    | ($k,$v) = each @$arrayref  | ($k,$v) = each @arrayref  |
    |----------------------------+---------------------------|
    
    I was following the p5p discussion about these changes, but I kept silent, so it's probably too late for this kind of rant now :)
      > Automatic dereferencing syntax (meaning: s/@$/@/ or s/@{$ref}/@ref/) would be more useful.

      You're well aware of the fact that @ref and $ref are different variables with disjunct name-spaces in Perl?

      IMHO this ambiguity would produce hard to track bugs.

      Cheers Rolf

        I'm aware that this is special case for those core functions operating on arrays. So, it's not so hard to track it at all, I think.

        Actually, I don't understand why we need such syntax simplifications it they're not done through all the Perl. Changing Perl philosophy in one place, and not changing it in another is inconsistent and wrong. For example, we still don't have saner defaults for simple object-oriented programming although it is relatively simple to patch the core as demonstrated before on p5p.

      I don't like that change. It adds more to the syntax confusion than it takes away.

      My immediate reaction is also one of disappointment.
      Given time, I expect we'll be able to push $arref1, $arref2
      Not sure if that will make me more disappointed or less disappointed ....

      Cheers,
      Rob
        Given time, I expect we'll be able to push $arref1, $arref2
        I don't think so (if you expect that would be equivalent to push $arref1, @$arref2), because it's ambiguous (do you want to push the ref $arref2 itself or the array's elements?), while the current change isn't. Only the programmer can resolve that ambiguity...

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others having a coffee break in the Monastery: (5)
As of 2024-04-25 14:12 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found