Link to home
Start Free TrialLog in
Avatar of Madness
Madness

asked on

Perl not reading all lines of file properly

DOH!!!  Stupid mistake.  I fixed it.  Had a variable double counting occasionally that just so happened to print nearly all of my old stuff and very little of the new.  (KICK!) :-)

I have a perl script that reads in data from a flatfile relational database and prints the appropriate info for the user.  It is getting hard to maintain, so I imported it into a Microsoft Excel document using the delimiters I had set up.  I can modify it much easier now.  I saved the file as a .csv comma delimitered fields.  Now when I read the file with my program, all fields and rows I added/modified while in Excel do not appear.  I don't know why.  Any help would be greatly appreciated.  I use a command like this to read the file.

open (In_File,"mxdata.csv");
while (<In_File>)
{
     ($num,$name,$r1,$r2,$r3) = split(/,/,$_,5);
     if ("$name" eq $input{'name'})
     {
          $numarray{$pointer} = $num;
          $namarray{$pointer} = $name;
          etc..........
          There are multiple names.
      }
      $pointer++
}

Thanks for the help.
Avatar of Madness
Madness

ASKER

Edited text of question
Avatar of Madness

ASKER

Edited text of question
May be you simply have a (disk) syncing problem.

Are these, Excel and your perl script, two seperate processes?
If so and they run simultaniouslly, your perl script just reads
from the file what it contains when the open() call is executed.
Rewriteing (Excel) the file while reading (perl) may return
unexpected results.
ASKER CERTIFIED SOLUTION
Avatar of bron_a
bron_a

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of ozo
Some comments:
Always check the return value from open

      open(In_File,"mxdata.csv") || warn "Can't open xdata.csv  $!";

Using consecutive $pointer++ hashes suggest using an array instead

      push(@namarray,$name);
      #etc...

Quoting "$name" is not neccesary

      if( $name eq $input{'name'} ){ ... }

Other than ommiting that test, and truncating $r3 if it contains a comma,
(which doesn't need to be escaped in the split)
I don't see much point to bron_a's suggested re-write.