in reply to hash key regular expression pattern
Try this
#! perl -sw use strict; my %cat = ( 'C[AEIOU]NWAY' => 'AAA', '(BOSTON|CHICAGO)' => 'BBB', '(LAS VEGAS|NEVADA)' => 'CCC', '(DALLAS|AUSTIN)' => 'DDD', '(NASHVILLE|M[AEIOU]MPHIS)' => 'EEE', ); my $variable = 'CHICAGO'; for (keys %cat) { print $cat{$_}, $/ if $variable =~ /$_/; } __END__ #Output c:\test>211023 BBB c:\test>
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: hash key regular expression pattern
by FamousLongAgo (Friar) on Nov 07, 2002 at 14:31 UTC |