Hi Rob,

Thanks for taking the time to look at my code.  We'll I should have included the 
entire source but did not want to burn up people's bandwidth.  Yes, I do have strict 
and warnings in my code.  I run the SctiTE IDE for my development work on a windows 
2000 box ( I am a RH man though!).  What I was checking was to see if the code ever 
made it inside of the while loop.  That is why I have two different  HI on either side 
of the while loop.

What I am trying to do is to process a file that has say 1000 orders in it all pretty 
much of the same format.  I want to open up the file, and then using a while loop go 
down through all of the order one-at-a-time and once I have all the fields populated 
and I have reached a certain line at the end of each order write the data to the 
database.  Then have it all reset, and process the next order; and do this until the 
EOF.  That is the goal.  I have been pouring of chapter 4 in the Programming Perl 
bible and trying to set up the while loop to do just that.

I am using the code that some one from this list so graciously wrote to help me 
out--Sharad Gupta.  Any help is appreciated.

Thanks,

Trevor

-----Original Message-----
From: Rob Dixon [mailto:[EMAIL PROTECTED]
Sent: Tuesday, August 05, 2003 3:01 PM
To: [EMAIL PROTECTED]
Subject: Re: While loop on a file handle


Sorry guys. There's a keyboard shortcut set up on my PC that
sends my current mail that I often hit accidentally. It means
I occasionally post half-finished mails. I'll knuckle-down
and fix it. This is the post as it should have been:



Hi Trevor.

Trevor Morrison wrote:
>
> I am trying to step through each line of a file that contains orders that
> were placed through a Internet shopping cart.  I have this code:

Do you have

  use strict;
  use warnings;

:?

>  open(ORDER,$order) or die "Error opening \"$order\": $OS_ERROR\n";

While you're testing I prefer

  open ORDER, $order or die $!

as the closing newline will stop Perl from reporting the source line and
filename of the call to 'die'.

> print "HI\n";
>  while (defined($_ = <ORDER>)) {
>     print "Hi there \n";
>
> I am trying to test each line against a bunch of if statements and then go
> on to the next order when the line matches a rag expression and then the data
> for the order is dumped to MySql database.

Do you mean a regular expression? It's usually best to reiterate /unless/
the order matches some closure criteria.

> Now, when I execute the Perl program, it will print the first "Hi",
> but fails to print the second "Hi There".

Do you just mean 'doesn't print ..' or does your program fail in some
way?

It's a dangerous thing to retype your code. You will usually type
what it's supposed to look like, rather how it actually looks. Try
cutting and pasting a copy of part of your your program, when we will be
able to guess much better. What you have written is fine except that,
as Alan points out, it's the same as

  while (<ORDER>) BLOCK

> I know that I am missing something here, but what is it?

Let us know :)

Rob



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to