I am running the following script using data from a configuration file. For some reason unknown to me same values are returned instead of different ones as shown in the bottom. Can someone explain what I am doing wrong?
Thanks.

The config file myconfig.cfg:

CCBFile|NDM|/u1/cdunix/work/blprobr1|S${TODAY}.00?|${TODAY}CCB

The script -

#!/apps/bin/perl -w $TODAY = "20030518"; $config_file = "myconfig.cfg"; open (CONFIG, "$config_file") || die "Can't open $config_file for read +ing : $!\n"; while ( defined ($_ = <CONFIG>) ) {<br> my($job,$type,$dir,$file,$pattern) = split(/\|/,$_); my $val1 = file_eval($file); my $val2 = file_eval($pattern); print "val1 : $val1\n"; print "val2 : $val2\n"; } close(CONFIG); sub file_eval { my ($value) = @_; $match = '([0-9A-Za-z._%?#]*)(\$\{\w+\})([0-9A-Za-z._%?#]*)'; if ( $value =~ /$match/g ) { print "\nvalue is : $value\n"; ($p1,$p2,$p3) = /$match/; print "\n p1 is $p1\n"; print "\n p2 is $p2\n"; print "\n p3 is $p3\n"; $px = eval "$p2"; $filex = $p1 . $px . $p3; print "\n filex is $filex\n"; } return $filex; }
The output -
value is : S${TODAY}.00? p1 is S p2 is ${TODAY} p3 is .00? filex is S20030518.00? value is : ${TODAY}CCB p1 is S p2 is ${TODAY} p3 is .00? filex is S20030518.00? val1 : S20030518.00? val2 : S20030518.00? <- should be 20030518CCB


In reply to Getting same output doing pattern matching by tariqahsan

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.