Beefy Boxes and Bandwidth Generously Provided by pair Networks Bob
Do you know where your variables are?
 
PerlMonks  

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.


Comment on Re: $1, etc. are not just strings
Select or Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://592980]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (9)
As of 2014-04-23 21:23 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    April first is:







    Results (555 votes), past polls