This will leave the last line in the file while putting it at the beginning as well:
use strict; use warnings; my @array; open( my $orig, '<', 'original_file' ); open( my $backup, '+>', 'original_backup' ); while (<$orig>) { push ( @array, $_ ); print( $backup $_ ); } close($orig); open( my $new_orig, '+>', 'original_file' ); print( $new_orig $array[-1] ); print( $new_orig @array ); close( $new_orig );
This will copy the last line to the beginning while removing it from the end
use strict; use warnings; my @array; open( my $orig, '<', 'original_file' ); open( my $backup, '+>', 'original_backup' ); while (<$orig>) { push( @array, $_ ); print( $backup $_ ); } close($orig); open ( my $new_orig, '+>', 'original_file' ); print( $new_orig pop @array ); print( $new_orig @array ); close ( $new_orig );
Sample input data:
is a test!!! this
In reply to Re: placing an existing line from my XML file to the top of the file
by james28909
in thread placing an existing line from my XML file to the top of the file
by gasjunkie_jabz
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |