in reply to Regular expression and rename file help

If the name VALUE in files always the same and you using right OS(*nix like) you can do what you need just using sh, like this very simple example:
#!/bin/sh cat file | sed ``/VALUE/s//$1/'' > file.`date "+%s"`
Otherwise, try this code:
use strict; use warnings; my $user_input = shift || die "I need input"; my $file = "file"; open FH, $file or die "can't open $file for reading $!"; my @arr = <FH>; close FH; foreach(@arr){ s/VALUE/$user_input/g; } open FH, ">$file" or die "can't open $file for writing $!"; print FH @arr; close FH; rename $file, $file.time;

Replies are listed 'Best First'.
Re^2: Regular expression and rename file help
by kitty (Novice) on Feb 03, 2006 at 10:22 UTC
    Thankyou for the explanation, the rename function was not working as i had not closed the filehandler, i did not notice it at first but then figured it out. i was actually trying to build a small parser for the file. and perl was the easiest scripting language to learn. i went on to extract some parameters at first and try to run the program, will try to continue with more parameters. thank you again :)
      and perl was the easiest scripting language to learn.

      Fine to know you solved your problem, whatever it was. But are you sure of what you're saying?!? Don't misunderstand me, I love Perl - and I dislike the line-noise-reputation it unfortunately has in certain circles. But I wouldn't catalogue it as "easy" so... easily.

      As another side note, since it seems that quite a lot of people had difficulties to understand your post, may I suggest you to read How do I post a question effectively??