in reply to placing an existing line from my XML file to the top of the file
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
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: placing an existing line from my XML file to the top of the file
by gasjunkie_jabz (Novice) on Aug 20, 2015 at 22:08 UTC | |
by james28909 (Deacon) on Aug 21, 2015 at 00:40 UTC | |
by gasjunkie_jabz (Novice) on Aug 21, 2015 at 04:35 UTC | |
by james28909 (Deacon) on Aug 21, 2015 at 05:06 UTC |