Altough Abigail-II's solution is correct (as they practically always are), it's extremely dense with Perl idiom. I think that for a novice such as you, the solution raises a lot of questions. I made a version of Abigail-II's solution which is essentially the same, but IMHO a bit more geared to novices, with respect to the use of Perl's features. If I insulted your intelligence, I apologize:
#!/usr/bin/perl use strict; use warnings; use English; # Table 1 contains the find and replace values; my %substs = ( "jones" => "B0", "smith" => "B1", "adrew" => "B1", "larry" => "B3", ); # The 2nd table contains the data that I want to search in. my @data = ( [ "jones", "AAAAA", "BBBBB", "CCCCC"], [ "aaaaa", "AAAAA", "larry", "CCCCC"], [ "jones", "AAAAA", "BBBBBB","CCCCC"], [ "DDDDD", "AAAAA", "BBBBBB","larry"], [ "jones", "AAAAA", "andrew","CCCCC"], [ "jones", "smith", "BBBBBB","CCCCC"] ); # Loop over every element in the @data array. foreach my $row (@data) { foreach my $elem (@$row) { # $elem is an 'alias' for the value in the array, so # changing $elem changes the corresponding value in the # array. if ($substs{$elem}) { # We only want to change $elem when $elem is a key in the # substs hash. $elem = $substs{$elem} } } } # Print ", " between array values when the array is printed. $LIST_SEPARATOR = '", "'; # And show the resulting array. foreach my $row (@data) { print "[\"@$row\"]\n"; }
I hope this helps your understanding, and also that it helps you understand some of the Perl idiom.

Arjen


In reply to Re: find and replace project with values coming from a table by Aragorn
in thread find and replace project with values coming from a table by optiontrader

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.