Guay, 

ooops..... that would be it!  someone's else's eyes are always better! 
Thanks for the nice explanation!  My code is now compiling smoothly! 
What do you mean when you say "  Just use $line inside the while, and you'll read one 
line at a time."  ???

I am doing this, aren't I? 

  FROM GUAY: [[  By the way, why are you reading one line in the whiles 
parentheses, and
then slurping the rest of the file into an array inside the while?   ]]

RESPONSE FROM DEREK : I did notice this after you pointed it out, so my 
goal is to read in all the lines and put them in their own element, then 
print out those specific elements.  Do you have any thoughts?

thanks!


Derek B. Smith
OhioHealth IT
UNIX / TSM / EDM Teams
614-566-4145





Guay Jean-Sébastien <[EMAIL PROTECTED]>
04/01/2004 05:10 PM

 
        To:     Perl Beginners <[EMAIL PROTECTED]>
        cc: 
        Subject:        RE: using strict


Hello Derek,

When using strict, the error message should point you to the line where 
the
error is. It's usually pretty darn good at pointing the right line. In 
this
case, I bet it's this one:

>        while ( defined($line = <CRITICALSERVERS>) ) {

There is no declaration of the $line variable. Try declaring it first, 
like
this:

        my $line;
        while ( defined($line = <CRITICALSERVERS>) ) {

I think that's the only variable that wasn't declared. If you get any more
error messages, you can check them out and figure out what's wrong.

Just a suggestion: You should use or instead of || when checking if a file
opened correctly, because if you ever want to do some operations on the
right side, or will bind less tightly and allow your operations to work
correctly without needing parentheses to fix the precedence.

By the way, why are you reading one line in the while's parentheses, and 
and
then slurping the rest of the file into an array inside the while? That
means your while will only be run once, because at the next iteration 
you'll
already be at the end of the file... Just use $line inside the while, and
you'll read one line at a time. 

You also chomped your line, which is good. Just remember to re-add the 
line
ending ("\n") when printing the lines as you're doing, or else all the 
lines
will be printed on a single, very long line.

I'll let the experts explain what soft references and barewords are. I've
never used either, as I come from the relatively new school of 
programming.
As I understand, they are features of the language that are dangerous to 
use
in some contexts, so use strict disallows them knowing that if you really
want to use them, you'll disable strict for the block of code where you 
use
it, and then re-enable it.

Hope this helps,


Jean-Sébastien Guay

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>




Reply via email to