perl - Reading in the First Line from a .txt File, Removnig it from the .txt., and Sliding all of the Other Lines Up by 1 Unit -
i have .txt file in each line 1 element. subject suggests, i'd input first row .txt. then, i'd remove .txt file i've inputted it. @ same time, i'd slide each element 1 row such former second row element becomes new first row.
i'm not quite sure how proceed beyond: open( $l, '<', 'input.txt' ) or die "can not open input.txt: $!";
use strict; if ($#argv) { print "\nusage: test.pl filename\n\n"; exit(); } $f; if (open($f, $argv[0])) { print scalar(<$f>); $s = join('', <$f>); close($f); if (open($f, '>', $argv[0])) { print $f $s; close($f); } } else print "\ncan't open input file $argv[0]\n\n";
or sub
sub slidefile($) { $filename = shift(); $f; if (open($f, $filename)) { <$f>; $s = join('', <$f>); close($f); if (open($f, '>', $filename)) { print $f $s; close($f); } } }
Comments
Post a Comment