Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re: Regex to Array lookup question

by dave_the_m (Monsignor)
on Apr 05, 2020 at 21:51 UTC ( #11115104=note: print w/replies, xml ) Need Help??


in reply to Regex to Array lookup question

Something like the following should do it efficiently:
my %keys = ( 'skc' => "clear-day", 'few' => "partly-cloudy-day", 'sct' => "partly-cloudy-day", 'bkn' => "cloudy", 'wind' => "wind", ); my $keys = join '|', map quotemeta, sort keys %keys; my $pattern = qr/(....)($keys)(...)/; while (<DATA>) { s/$pattern/$1$keys{$2}$3/; print; }

Dave.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (3)
As of 2020-10-24 17:55 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My favourite web site is:












    Results (246 votes). Check out past polls.

    Notices?