develooper Front page | perl.fwp | Postings from November 2007

Re: The "flaming X-wing" secret operator

Thread Previous | Thread Next
From:
philippe.bruhat
Date:
November 29, 2007 03:24
Subject:
Re: The "flaming X-wing" secret operator
Message ID:
20071129085425.GA23021@plop.home.bruhat.net
On Wed, Nov 28, 2007 at 05:09:57PM -0500, Mr. Shawn H. Corey wrote:
> Philippe Bruhat (BooK) wrote:
>> Hi,
>>
>> Just thought I should share this with the FWP crowd.
>>
>> I had to do something special with the first line of a file, before
>> running the whole while(<>) loop on it. I ended up with this:
>>
>>     @data{@fields} =<>=~ $re;
>>
>> Rafael helped me give this new operator a name (#perlfr transcript):
>>
>>     15:13 <@BooK> OMG c'est quoi =<>=~ comme secret op ?
>>     15:14 <@rgs> le x-wing touché avec une aile en feu
>>
>> Rough translation:
>>
>>     15:13 <@BooK> OMG what is =<>=~ for a secret op ?
>>     15:14 <@rgs> the hit x-wing starfighter with a wing on fire
>>
>> Cog, are you still writing this OGSOP book? ;-)
>>
>
> Actually, it's:
>
>  @data{@fields} = ( <> =~ $re );
>

Actually, it's not:

    use strict;
    use warnings;
    use Data::Dumper;
    
    my @fields = qw( H M S );
    my $re = qr/(\d\d):(\d\d):(\d\d)/;
    my %data;
    
    # DATA is the pilot, for the sake of the example
    @data{@fields} =<DATA>=~ $re;
    
    print Dumper \%data;
    
    __DATA__
    the time is now 03:14:15

Which outputs:

    $VAR1 = {
              'H' => '03',
              'M' => '14',
              'S' => '15'
            };

Why would I need parentheses, when the hash slice gives me a list
context already?

-- 
 Philippe Bruhat (BooK)

 For every winner, there must be one or more losers.
                                (Moral to the Sage story in Groo #111 (Epic))

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About