Re: Faster way to do a regexp using a hash

2009-12-20 Thread John W. Krahn
sftriman wrote: I've been wondering for a long time... is there a slick (and hopefully fast!) way to do this? foreach (keys %fixhash) { $x=~s/\b$_\b/$fixhash{$_}/gi; } So if $x="this could be so cool" and $fixhash{"could"}="would"; $fixhash{"COOL"}="awesome"; $fixhash{"beso"}="nope"; $fi

Re: Faster way to do a regexp using a hash

2009-12-20 Thread Erez Schatz
2009/12/20 sftriman : > I've been wondering for a long time... is there a slick (and hopefully > fast!) way > to do this? > > foreach (keys %fixhash) { >    $x=~s/\b$_\b/$fixhash{$_}/gi; > } You can do a global substitute of the sentence and see if they match any key in the hash. i.e.: $x =~ s/\b

Re: Faster way to do a regexp using a hash

2009-12-20 Thread Shawn H Corey
sftriman wrote: > I've been wondering for a long time... is there a slick (and hopefully > fast!) way > to do this? > > foreach (keys %fixhash) { > $x=~s/\b$_\b/$fixhash{$_}/gi; > } > > So if > > $x="this could be so cool" > > and > > $fixhash{"could"}="would"; > $fixhash{"COOL"}="awesome"

Faster way to do a regexp using a hash

2009-12-20 Thread sftriman
I've been wondering for a long time... is there a slick (and hopefully fast!) way to do this? foreach (keys %fixhash) { $x=~s/\b$_\b/$fixhash{$_}/gi; } So if $x="this could be so cool" and $fixhash{"could"}="would"; $fixhash{"COOL"}="awesome"; $fixhash{"beso"}="nope"; $fixhash{"his"}="impo