in reply to find and replace

The error in your script is that s/// does not work on arrays. You need to loop over the array and replace the full words with their abbreviations line by line:

... for my $line (@myin) { $line =~ s!$full!$abb!g; }; ...

That code is a bit inefficient as it will loop over the main text many times, and it also has some problems, because it doesn't take care that you only replace full words. For example the word examples would be replaced by egs by your script, which may or may not be what you want. If you only want to replace whole words, use the \b boundary in your regular expression:

... for my $line (@myin) { $line =~ s!\b$full\b!$abb!g; }; ...

Also, by doing the replacements step by step, you can get conflicts if one abbreviation is (or creates) a new word that also has an abbreviation - if you don't want that, you need to do all the replacements at once, which means you will need to build a better regular expression. But as I don't know if that is a problem for you, I will skip on that.

Replies are listed 'Best First'.
Re^2: find and replace
by texuser74 (Monk) on Nov 04, 2005 at 07:54 UTC
    Thanks Corion, now the output is correct.