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.


In reply to Re: find and replace by Corion
in thread find and replace by texuser74

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.