Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling

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]
[karlgoethebier]: I'll take that right hand road...
[thezip]: Howdy y'all. Is it safe to just delete StrawberryPerl-> cpan->build directories?

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (10)
As of 2017-03-23 20:58 GMT
Find Nodes?
    Voting Booth?
    Should Pluto Get Its Planethood Back?

    Results (294 votes). Check out past polls.