CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Intermediate: Re: [rfransix] One Line at a Time Please: Edit Log



FishMonger
Veteran / Moderator

Jun 18, 2010, 8:26 AM


Views: 2843
Re: [rfransix] One Line at a Time Please

Please, ALWAYS use the code tags when posting your code.

Why are you using the -slw switches? Remove them, they are not needed.

Use the 3 arg form of open and a lexical var for the filehandle instead of the bareword.

ALWAYS check the return code of an open call to verify that it was successful and take action if it wasn't.


Code
open my $person_fh, '<', "f1" or die "failed to open 'f1' $!";



There's no reason to have that truncate statement.

Vars should be declared in the smallest scope that they require and the var names should be descriptive.
e.g., change:

Code
my $line; 

while ($line = <PERSON>) {

to:

Code
while ( my $person = <$person_fh> ) {


Using the nested while loops is not what you want. When the outer loop processes the first line, the inner loop will process the entire "f2" file before outer loop moves on to the second line.


(This post was edited by FishMonger on Jun 18, 2010, 8:27 AM)


Edit Log:
Post edited by FishMonger (Veteran) on Jun 18, 2010, 8:27 AM


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives