Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re^4: how read data from file

by rammohan (Acolyte)
on Jan 18, 2014 at 10:56 UTC ( [id://1071090]=note: print w/replies, xml ) Need Help??


in reply to Re^3: how read data from file
in thread how read data from file

This node falls below the community's threshold of quality. You may see it by logging in.

Replies are listed 'Best First'.
Re^5: how read data from file
by CountZero (Bishop) on Jan 18, 2014 at 12:13 UTC
    Just add in the beginning of the loop a test which checks whether this line has anything else than whitespace.
    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;
    You can also replace the whole loop with this one line:
    print map substr($_, 0, 2), grep m/\S/, <$FH>;
    Of course, far less readable and more difficult to understand.

    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

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1071090]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others pondering the Monastery: (3)
As of 2024-04-26 00:19 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found