PugSA has asked for the wisdom of the Perl Monks concerning the following question:

This node falls below the community's minimum standard of quality and will not be displayed.

Replies are listed 'Best First'.
Re: search replace with variable
by davorg (Chancellor) on Apr 21, 2006 at 15:39 UTC

    You don't say what you think the problem is, but I'm guessing that you are expecting either $_ or the contents of @trt_files to be updated by what you are doing. Perhaps you need a closer look at what is going on.

    foreach (@trt_files) # Each time round the loop, $_ # is set to an alias to one of the # elements of @trt_files. { $record = $_; # $record now contains the _value_ # of $_. It is _not_ an alias into # @trt_files. $record =~ s/date/$date/; # This changes $record # (it doesn't change $_ # or @trt_files). print "$_\n"; # Prints the (unchanged) value of $_ }

    If I'm right, then what you actually want is far simpler than what you have.

    foreach (@trt_files) { s/date/$date/; print "$_\n"; }
    --
    <http://dave.org.uk>

    "The first rule of Perl club is you do not talk about Perl club."
    -- Chip Salzenberg