in reply to Re^4: how read data from file
in thread how read data from file
You can also replace the whole loop with this one line:use Modern::Perl; open my $FH, '<', '/home/jack/Desktop/Perl_file.txt' or die "Could not + open file: $!"; while (my $line = <$FH>) { next unless $line =~ m/\S/; # loop again unless line contains at l +east one non-white-space character my $char = substr($line, 0, 2); print $char; } close $FH;
Of course, far less readable and more difficult to understand.print map substr($_, 0, 2), grep m/\S/, <$FH>;
CountZero
A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James
My blog: Imperial Deltronics
|
|---|