but I get this error:#!/usr/bin/perl use warnings; use strict; open (DATA, "dic") || die "Error opening the input file\n"; print "Reading mapping file\n"; print "----------------------------\n"; open (INFILE, "trial.txt") || die "Error opening the input file\n"; print "Reading input file\n"; print "----------------------------\n"; my %dict; while (my $line = <INFILE>) { my $old_string = $line; while ( <DATA> ) { my ( $key, $val ) = /^(\d+)\s+(\w+)/; $dict{ $val } = $key; } my $cc = join '', keys %dict; my ( $min ) = my ( $max ) = map length, keys %dict; for ( map length, keys %dict ) { $min = $_ if $min > $_; $max = $_ if $max < $_; } my $pattern = qr/\b([$cc]{$min,$max})\b/; ( my $new_string = $old_string ) =~ s/$pattern/ exists $dict{ $1 } ? $ +dict{ $1 } : $1 /eg; print "$new_string\n"; } close (INFILE); close (DATA);
Not that 19969 is my last line in dictionary file. and also how can I ignore the cases in matching? for example in dictionary file April exists but april does not, so I tend to make it case insensetive. thanks in advance.Reading mapping file ---------------------------- Reading input file ---------------------------- april 1168 0.06781456 Use of uninitialized value in concatenation (.) or string at seek.pl l +ine 29, <DATA> line 19969. Use of uninitialized value in concatenation (.) or string at seek.pl l +ine 29, <DATA> line 19969. Unmatched [ in regex; marked by <-- HERE in m/\b([ <-- HERE ]{,})\b/ a +t seek.pl line 29, <DATA> line 19969.
In reply to Re^3: search and replace
by Anonymous Monk
in thread search and replace
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |