http://qs321.pair.com?node_id=1105974


in reply to localtime parse within hash init

Hi NetWallah,

...I'm also curious how this would look in perl6. (zip, perhaps ?) ...

You gave the hint yourself. Do you know zip of List::MoreUtils?

Regards
McA

Replies are listed 'Best First'.
Re^2: localtime parse within hash init
by NetWallah (Canon) on Nov 04, 2014 at 06:49 UTC
    Stackoverflow to the rescue!.

    This works:

    perl -MList::MoreUtils -E 'my %stuff=(otherinfo=>"this and that", dateinfo=>{List::MoreUtils::zip @{[qw|sec min hour mday mon year wday yday isdst|]} ,@{[localtime(time)]} }); say "sec=",$stuff{dateinfo}{sec}, " year=",$stuff{dateinfo}{year}'
    From the article ....
    ... They technically don't need to be named, just dereferenced. e.g. @$ref and @{qw( foo bar )} work just as well as @a. In other words, it has to start with @ (and not be a slice). (ikegami)

    Update:Loops(++) answered identically, at the same time I discovered this.

            "You're only given one little spark of madness. You mustn't lose it."         - Robin Williams

Re^2: localtime parse within hash init
by NetWallah (Canon) on Nov 04, 2014 at 06:35 UTC
    Thank you (++) - no - I was not aware of zip/mesh in List::MoreUtil.

    However, my attempt at using it fails:

    perl -MList::MoreUtils -E 'my %stuff=(otherinfo=>"this and that", dateinfo=>{List::MoreUtils::zip qw|sec min hour mday mon year wday yday isdst| ,localtime(time) }); say "sec=",$stuff{dateinfo}{sec}, " year=",$stuff{dateinfo}{year}' Type of arg 1 to List::MoreUtils::mesh must be array (not list) at -e +line 5, near ") }" Type of arg 2 to List::MoreUtils::mesh must be array (not localtime) a +t -e line 5, near ") }" Execution of -e aborted due to compilation errors.
    Any workarounds ? Why does it not like a list ?

            "You're only given one little spark of madness. You mustn't lose it."         - Robin Williams

      zip(@{[qw|sec min hour mday mon year wday yday isdst|]} , @{[localtime +]});

        Hi Loops,

        thank you for showing the right way to call it. I had to lough. In this case we really have a kind of 'sigilmania'. I'm not sure whether this is more elegant. ;-)

        Regards
        McA