10 lines only

T

Todd Anderson

Hello,
I have a script that needs to open a fat file > determine which lines
represent lines say 251-260 (@billingnumber) and ($yes_row)> and which
lines represent the ignored lines ($hold_row) > then do a bunch of stuff
to the lines i want ($yes_row).
The code below isn't finding the yes_lines. (probably if($billingnumber
ne "$e_number"){ is wrong.)
Any help is appreciated.
Thanks in advance for your help.

open (USERS, "$file") || &billerror
("$file Billing Notice" );
flock(USERS, 2);
while (<USERS>)
{
$line = $_;
chomp $line;
@line = $line;
@fields = split (/\|/, $line);
$billingnumber = @billingnumber;
foreach $line (@line){
$e_number++;
if($billingnumber ne "$e_number"){ # Save all the ignored lines
$hold_row .="$line\n"; }
else{ $yes_row .="$line\n"; #find the lines i want
@yes_row = $yes_row;
}#else
}#e_number

foreach $line2 (@yes_row){
chomp $line2;
@fields = split (/\|/, $line2);
#do a bunch of stuff to yes lines
}# foreach line2
}#while
flock(USERS, 8);
close (USERS);
 
G

Gunnar Hjalmarsson

Todd said:
I have a script that needs to open a fat file > determine which
lines represent lines say 251-260 (@billingnumber) and ($yes_row)>
and which lines represent the ignored lines ($hold_row) > then do a
bunch of stuff to the lines i want ($yes_row).
The code below isn't finding the yes_lines. (probably
if($billingnumber ne "$e_number"){ is wrong.)

That code makes no sense to me. It's badly written, and accordingly
difficult to debug. Ask the author for help.
 
A

A. Sinan Unur

I have a script that needs to open a fat file > determine which lines

That sentence just does not make any sense to me. I do not know what a
'fat file' is and you do not provide any sample data so how can anyone
guess which comparison works or not. It is impossible to find a solution
to your problem without having some data to test with.
represent lines say 251-260 (@billingnumber) and ($yes_row)> and which
lines represent the ignored lines ($hold_row) > then do a bunch of ....

The code below isn't finding the yes_lines. (probably if($billingnumber
ne "$e_number"){ is wrong.) Any help is appreciated.
Thanks in advance for your help.

open (USERS, "$file") || &billerror
("$file Billing Notice" );

Don't call subroutines using the & sign unless you know the difference
between &billerror and billerror(). (see perldoc perlsub).
flock(USERS, 2);
while (<USERS>)
{
$line = $_;
chomp $line;
@line = $line;

WTF? What on earth could be the purpose of these three lines? Have you
given an iota of thought to what you wanted to do?
@fields = split (/\|/, $line);
$billingnumber = @billingnumber;

Do you really want to store the number of elements of @billingnumber in
$billingnumber or something else?
foreach $line (@line){
$e_number++;
if($billingnumber ne "$e_number"){ # Save all the ignored lines

$billingnumber holds the number of elements in @billingnumber.
$hold_row .="$line\n"; }
else{ $yes_row .="$line\n"; #find the lines i want
@yes_row = $yes_row;
}#else
}#e_number

foreach $line2 (@yes_row){
chomp $line2;
@fields = split (/\|/, $line2);
#do a bunch of stuff to yes lines
}# foreach line2
}#while
flock(USERS, 8);

What are these magic numbers you are using with flock?

use Fcntl ':flock';

....
flock USERS, LOCK_EX;
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,774
Messages
2,569,598
Members
45,151
Latest member
JaclynMarl
Top