Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked

Re: $1, etc. are not just strings

by gam3 (Curate)
on Jan 04, 2007 at 16:36 UTC ( #592980=note: print w/replies, xml ) Need Help??

in reply to $1, etc. are not just strings

I like to use this syntax to capture from regular expresions.
if (my ($a, $b) = ("$key$val" =~ /(..)(...)/)) { $hash2{$a} = $b; }
#!/usr/bin/perl use Test::More "no_plan"; use Devel::Size "total_size"; my $key = "aa"; my $val = "a00"; my %hash1; my %hash2; while (length($key) == 2) { $hash1{$key} = $val; if (my ($a, $b) = ("$key$val" =~ /(..)(...)/)) { $hash2{$a} = $b; } ++$key; ++$val; } is(keys(%hash1), keys(%hash2), "same number of keys"); is_deeply(\%hash1, \%hash2, "is_deeply same"); is(total_size(\%hash1), total_size(\%hash2)); __END__ ok 1 - same number of keys ok 2 - is_deeply same ok 3
-- gam3
A picture is worth a thousand words, but takes 200K.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://592980]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (4)
As of 2017-07-21 03:21 GMT
Find Nodes?
    Voting Booth?
    I came, I saw, I ...

    Results (318 votes). Check out past polls.