in reply to How do I modify a line within the file itself?
You should always use strict. It will save your life. Start now.
You should always open files with three arguments.
You should make your code as readable as possible, including use of $_ as the default input.
use strict; use warnings; my $file = $ARGV[0]; open(my $fh, "<", $file) or die "Can't open $file: $!"; while ( <$fh> ) { chomp; # $_ is default input if ( /\>/ ) { # $_ is still default input, # match is default operation my @modify_line = split( /\s/ ); # $_ is still default input my $line = $modify_line[0]; # if you are going to use an array print $line; }
Not that you should do it this way. Use File::Slurp::Tiny.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: How do I modify a line within the file itself?
by Anonymous Monk on Jul 08, 2015 at 23:53 UTC | |
by 1nickt (Canon) on Jul 09, 2015 at 02:30 UTC | |
by BrowserUk (Patriarch) on Jul 09, 2015 at 03:45 UTC | |
by Anonymous Monk on Jul 09, 2015 at 03:21 UTC | |
by 1nickt (Canon) on Jul 09, 2015 at 10:22 UTC | |
by Anonymous Monk on Jul 09, 2015 at 09:05 UTC |