in reply to pattern matching and return values
Here's an example using a simple hash (instead of a hash-ref as you're dealing with). This solution declares the hash, and then assigns to it using a hash slice. It has limitations. For example, you have to know up front how many items you're capturing. But it works pretty well.
my $string = "This is that is other is"; my %hash; if ( @hash{'a', 'b', 'c'} = $string =~ m/(This).+(that).+(other).+/ ) { print "$_ = $hash{$_}\n" foreach keys %hash; }
As for how to "do" a hash slice given a hash-ref, it's like this:
@{$x}{'a', 'b', 'c'} = ( list );
(...that is, if memory serves.)
UPDATE: I just realized, this is my 1000th post! Enjoy!
Dave
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: pattern matching and return values
by wfsp (Abbot) on Jul 18, 2004 at 05:39 UTC |