[Chicago-talk] is this still on?

Sean Blanton sean at blanton.com
Mon May 18 09:10:22 PDT 2020


I was glad to see an email on this channel once again!

Regards,
Sean

Sean Blanton
sean at blanton.com


On Mon, May 18, 2020 at 9:26 AM Jay S <me at heyjay.com> wrote:

> Hi Steve thanks for the write up.
> It nice to hear from you.
> Jay
>
> On Mon, May 18, 2020 at 1:58 AM Steven Lembark <lembark at wrkhors.com>
> wrote:
>
>> On Sun, 17 May 2020 15:01:45 -0400
>> James E Keenan <jkeenan at pobox.com> wrote:
>>
>> > On 5/17/20 12:49 PM, Jay S wrote:
>> > > Hi Perl mongers, I'm not sure if this list is still on|active.
>> > > I hope everyone is doing well and staying sane.
>> > > I haven't programmed in a long time and can't remember stuff.  How
>> > > do make a list out of a hash?
>> > >
>> > > Instead of:
>> > > my $ClubID = $data{ClubID};
>> > > my $GameCode = $data{GameCode};
>> > > my $DateStarted = $data{DateStarted};
>> > > my $GameType = $data{GameType};
>> > >
>> > > I'd like to do something like this but can't remember the proper
>> > > incantation:
>> > > my ($ClubID, $GameCode, $DateStarted, $GameType) = @data(qw[ClubID
>> > > GameCode DateStarted GameType]);
>>
>> You are looking for a "hash slice":
>>
>> Quick refresher: The data type you are extracting from is specified
>> by curly or square braces:
>>
>>   foo{ ... }  access foo as a  hash
>>   foo[ ... }  access foo as an an array
>>
>> You are extracting a list of values (vs. key+value pairs) which
>> leaves you with:
>>
>>     @foo{ ... }
>>
>> to pull out the values of interest.
>>
>> qw takes open-close pairs, I tend to prefer parens since they look
>> look more "list-ish" to me and doesn't get mistaken for an arrayref.
>>
>> Leaves:
>>
>>     my ($ClubID, $GameCode, $DateStarted, $GameType)
>>     = @data{ qw( GameCode DateStarted GameType ) };
>>
>> or
>>     my @keyz = [ qw( GameCode DateStarted GameType ) ];
>>
>>     ...
>>
>>     my ($ClubID, $GameCode, $DateStarted, $GameType) = @data{ @keyz };
>>
>> or
>>
>>     state $keyz = [ qw( GameCode DateStarted GameType ) ];
>>
>>     ...
>>
>>     my ($ClubID, $GameCode, $DateStarted, $GameType) = @data{ @$keyz };
>>
>>
>> Note that perl recently added a "kv-slice" which returns the
>> keys and values using a '%' sigil instead of '@':
>>
>>     my ($ClubID, $GameCode, $DateStarted, $GameType) = %data{ @keyz };
>>
>> this would provide a list of key-value pairs suitable for assigning
>> to a new hash (if you saw that while experimenting you mistyped a
>> '%' instead of a '@'.
>>
>> Zei gesund
>>
>> --
>> Steven Lembark
>> Workhorse Computing
>> lembark at wrkhors.com
>> +1 888 359 3508
>> _______________________________________________
>> Chicago-talk mailing list
>> Chicago-talk at pm.org
>> https://mail.pm.org/mailman/listinfo/chicago-talk
>>
> _______________________________________________
> Chicago-talk mailing list
> Chicago-talk at pm.org
> https://mail.pm.org/mailman/listinfo/chicago-talk
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.pm.org/pipermail/chicago-talk/attachments/20200518/0d74f361/attachment.html>


More information about the Chicago-talk mailing list