I hope this helps your understanding, and also that it helps you understand some of the Perl idiom.#!/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"; }
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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |