> -----Original Message-----
> From: chris [mailto:[EMAIL PROTECTED]]
> Sent: Thursday, August 01, 2002 12:58 PM
> To: [EMAIL PROTECTED]
> Subject: Regexp to match by hash key and replace with hash value?
> 
> 
> Can I do the following with a single replace?
> 
> my %hash = ("1","abc", "2","xyz");
> my $line = '12';
> while( my($key, $val) = each(%hash) ) {
> $line =~ s/$key/$val/g;
> } 
> print $line . "\n";

Assuming your hash keys are all single digits:

   $line =~ s/(\d)/$hash{$1}/eg;

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to