in reply to Run a variable as a line of code?

Not answering your immediate question, but a Perl idiom worth knowing is the edit inplace:

@ARGV = @files; $^I = '.bak'; while (<>) { # do something with each line of each file # The original line contents is in $_ # print prints to the new version of the file s/foo/bar/g; print; }

Update: Fix @ARGV - thanks QM :)


DWIM is Perl's answer to Gödel

Replies are listed 'Best First'.
Re^2: Run a variable as a line of code?
by QM (Parson) on Apr 03, 2006 at 22:28 UTC
    Is that supposed to be
    @ARGV = @files;
    ??

    -QM
    --
    Quantum Mechanics: The dreams stuff is made of

Re^2: Run a variable as a line of code?
by lev36 (Sexton) on Apr 06, 2006 at 17:53 UTC

    Thanks, GrandFather, but that brings up an interesting thing.

    I liked your code because it was more elegant, so I switched mine to use Perl's edit inplace - but then noticed that the updated file no longer had the original owner.

    My original script kept the original owner on the file, without having to 'chown' it back, and we do need to retain the original owners in this case.

      Sorry, I'm a Windows user and don't generally notice that sort of issue. If no-one replies to the question buried in this thread, repost it as a SoPW in its own right.


      DWIM is Perl's answer to Gödel