in reply to Perl printing in the wrong order

You're changing the file name ($ip) in the wrong place, so the first file gets two dates, the last one none, and the remaining get the date (which belongs to the next file) at the bottom...

I.e.,

you have: you want: ------------------------ ------------------------ date date (first file) (first file) ...data... ...data... date ------------------------ ------------------------ date ...data... ...data... date ------------------------ ------------------------ date ...data... ...data... date ------------------------ ------------------------ date ...data... ...data... date ------------------------ ------------------------ date (last file) (last file) ...data... ...data... ------------------------ ------------------------

Move the

$ip=$net.$counter;

to the beginning of the loop:

while ( $counter <= 14 ) { $ip=$net.$counter; ...

in which case you also no longer need the first occurrence before the loop.

(BTW, there's no need to open/close the same file multiple times.)

Replies are listed 'Best First'.
Re^2: Perl printing in the wrong order
by druisgod (Initiate) on Apr 29, 2011 at 13:27 UTC

    Thanks for the reply. That fixed the issue. So your saying that during the first iteration, it wrote to the initialized value, and on the second iteration, the value wasn't changed until after the print , so it put the print in twice on the same file. Ugh! Why do things look so much simpler after they've been solved? Thanks for your help!!

    I reopened the same file because Perl was saying I was trying to print to a closed filehandle. I was thinking that when I opened INFILE that it may have made LOGF close, so I reopened it.