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";
> $fixhash{"his"}="impossible";
> 
> then it would end up
> 
> "this would be so awesome"
> 
> Thanks!
> David
> 
> 

I don't know if it's faster, but it's different:
#!/usr/bin/perl

use strict;
use warnings;

my %fixhash = ();
$fixhash{"could"}="would";
$fixhash{"cool"}="awesome";
$fixhash{"beso"}="nope";
$fixhash{"his"}="impossible";

my $str = "this could be so cool";
print "$str\n";

my @words = split /(\w+)/, $str;
for my $word ( @words ){
  $word = $fixhash{$word} || $word;
}
$str = join( '', @words );
print "$str\n";

__END__

-- 
Just my 0.00000002 million dollars worth,
  Shawn

Programming is as much about organization and communication
as it is about coding.

I like Perl; it's the only language where you can bless your
thingy.

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to