in reply to need help in writing aperl script

see get n lines before or after a pattern, Re: modifying a file with regex!, perlintro, open, readline, rename, Re^5: Remove a Line, perlintro, open, close, readline, rename, Re: Rewriting into file, @ARGV, Getopt::Long, Re^2: Write to existing file with character insert

Modifying an existing file is three steps :)

  1. read old file
  2. create a new file
  3. rename new file to name of old file

perlintro covers all three steps, as does Modern Perl and http://learn.perl.org/books/beginning-perl/

Path::Tiny makes it even easier to work with paths

Replies are listed 'Best First'.
Re^2: need help in writing aperl script
by jag194u (Initiate) on May 27, 2015 at 03:15 UTC
    I have started writing the script to open a file and parse through the lines.but iam troubling with pattern matching and insert the words in the resulting line.
    open my $file ,"+<","reg" or die $!; while (my $line = <$file>) { chomp $line; print "$line\n" }

      I have started writing the script to open a file and parse through the lines.but iam troubling with pattern matching and insert the words in the resulting line.

      Ok then, then look here :)