in reply to replacing while keeping the position of the element in the file

use strict; use warnings; #emulate reading from 1st file my %lookup = (); while (<DATA>) { chomp; my $key = (split /_/)[0]; $lookup{$key} = $_; } #emulate 2nd file my @input = ("I would like to learn this ! .", "OK ?"); foreach my $line (@input) { my @tokens = map {$lookup{$_} || 'unknown'} split /\s+/, $line; print "@tokens\n"; } 1; __DATA__ I_pron would_mod like_v to_to learn_v this_pron ._sent OK_ok ?_quest
Hanlon's Razor - "Never attribute to malice that which can be adequately explained by stupidity"
  • Comment on Re: replacing while keeping the position of the element in the file
  • Download Code