I defined it like this:
#!/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);
but I get this error:
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.
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.

In reply to Re^3: search and replace by Anonymous Monk
in thread search and replace by Anonymous Monk

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.