This is just a variation on one of the most asked questions,
and therefore a FAQ.
Study perldoc -q intersection, and come back if you
have some code to show.
Abigail | [reply] |
Hashes sound like the way forward
open(my $cities_fh => 'cities.txt') or die "ack: $!";
my %cities;
chomp, $cities{lc substr $_, 0, 3} = $_
while <$cities_fh>;
open(my $devices_fh => 'devices.txt') or die "ack: $!";
/^dev-([a-z]+)/ and print "$cities{$1} $_"
while <$devices_fh>;
So create a hash with the keys as the first three letters of the city, lower-cased, and the values as the city & state name. Then iterate through the devices file grabbing the city identifier then printing out the city & state name along with the filename.
| [reply] [d/l] |
This smells very strongly of homework! Anyway, first it would be very nice if you were to try to do this on your own. We're all very happy to help you find errors in your code/logic and to suggest alternative ways of doing things, but not too many of us enjoy writing your code for you, especially if it is schoolwork.
You might want to give us examples of the two files too. From what you've given us, I'd say telling us the first two lines of file 1 and the matching two lines from file 2 would work. I'm not sure if there are key elements that match up your arrays or if you just want to associate the first entry in file 1 with the first entry in file 2, etcetera. . .
Either way, you need to open both files, read data in, process it through an algorithm (which at this point isn't clear), and put the data into an array (or maybe a hash). You haven't said how you plan to output the results either, to file or to screen. . .
- - Arden. | [reply] |
Do you have data in sequencial order ?
ie.. wic1 => Wickliffe and wic2 => Wickville?
If that's the case, it is very easy for you. From cityfile you can generate 'wic1' type entries, put it in the hash, read device file line-by-line and make outfile.
If that's not the case, then you can apply String::Approx to do matching.
artist. | [reply] |