in reply to Re: nodelocked vs floating
in thread nodelocked vs floating

Thanks for the answer. I am trying it out. Can you help me to know what the below line does? I am getting compilation error here. for my $license (sort grep /^Node/, keys $hash{$product}->%*)

Replies are listed 'Best First'.
Re^3: nodelocked vs floating
by tybalt89 (Monsignor) on Nov 23, 2018 at 05:50 UTC

    Must be an older perl :(

    Replace

    $hash{$product}->%*

    with

    %{ hash{$product}}
      I am using strawberry version.I think it should be for my $license (sort grep /^Node/, keys %{$hash{$product}}
Re^3: nodelocked vs floating
by kcott (Archbishop) on Nov 23, 2018 at 09:00 UTC

    G'day vkknava,

    Just to expand on tybalt89's reply, the ->%* (along with ->$*, ->@*, etc.) is a newer feature called "Postfix Dereference Syntax".

    If you're using Perl version

    • 5.18 or earlier, it's unavailable;
    • 5.20 or 5.22 you'll need to add "use feature 'postderef'";
    • 5.24 or later, it should just work without doing anything else.

    See the doco link for more complete details. Also look at the following section, "Postfix Reference Slicing", which provides similar syntax for array and hash slices.

    Although it did take a little while to get used to, I do find this new syntax greatly improves code readability. If you have an appropriate Perl version, I recommend you try it.

    — Ken

      Thanks Ken. I have changed it like this and its working. I am using strawberry version.

        for my $license (sort grep /^Node/, keys %{$hash{$product}})
        "Thanks Ken."

        You're welcome.

        "I am using strawberry version."

        Strawberry provides many versions of Perl. It's the version of Perl that was important here. You can find that with the "perl -v" command.

        As an example, you can see that I'm currently using version 5.28:

        $ perl -v This is perl 5, version 28, subversion 0 (v5.28.0) built for darwin-th +read-multi-2level ...

        Which means I can write:

        $ perl -E 'my $href = { key => 42 }; my %h = $href->%*; say $h{key}' 42

        — Ken