Re: pie multiline replace

[email protected] (Richard Lee)
Newsgroups perl.beginners
Message-ID <[email protected]>
Gunnar Hjalmarsson wrote:
> bill lam wrote:
>> Sorry this must be a faq but I cannot find any answer in google.
>
> Google?? If you think it's a FAQ, you'd better check the Perl FAQ.
>
>     perldoc -q "insert a line"
>
Within that basic form, add the parts that you need to insert, change,
or delete lines.

To prepend lines to the beginning, print those lines before you enter
the loop that prints the existing lines.

        open my $in,  '<',  $file      or die "Can't read old file: $!";
        open my $out, '>', "$file.new" or die "Can't write new file: $!";

        print "# Add this line to the top\n"; # <--- HERE'S THE MAGIC

        while( <$in> )
                {
                print $out $_;
                }

   close $out;

I was just going over this... but shouldn't it be

print $out "# Add this line to the top\n"; #     ??? or did I miss 
something?

[root@RLEE perl]# perl -v

This is perl, v5.10.0 built for i386-linux-thread-multi

Copyright 1987-2007, Larry Wall

Perl may be copied only under the terms of either the Artistic License 
or the
GNU General Public License, which may be found in the Perl 5 source kit.

Complete documentation for Perl, including FAQ lists, should be found on
this system using "man perl" or "perldoc perl".  If you have access to the
Internet, point your browser at http://www.perl.org/, the Perl Home Page.

[root@RLEE perl]#
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.