Yes Robert, I have been playing around with the code for awhile and finally got
it to work as you have described below. Thanks!

Kathy


--- "Robert Raisch" wrote:
For the record, while looking for whitespace is valuable (though it begs the
definition of a "blank" line), none of the replies I have seen will acually
work in the context of the example code as expected since they do not test
the contents of $fileLine.  They test $_, which by the time we get to the
test, isn't what we think it is.

This is easily shown by:

        while(my $line = <STDIN>) {
                chomp $line;
                do {
                        print "Blank line!\n";
                        next;
                } if /^\s*$/;
                print "Non-blank line\n";
        }

which will print "Blank line" no matter what is entered.

Changing to

        while(my $line = <STDIN>) {
                chomp $line;
                do {
                        print "Blank Line!\n";
                        next;
                } if $line =~ /^\s*$/;          ## Note reference to $line
                print "Non-blank line\n";
        }

will make this example perform as expected.

So, given the example code of the original query, what I am sure people
meant was:

        next if $fileLine =~ /^\s*$/;

Which within the context of the example, will indeed skip blank lines or
lines which contain only whitespace.

/rr


-----Original Message-----
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED]]On Behalf Of Tonuzi
Selim
Sent: Friday, October 11, 2002 12:35 PM
To: Katherine Richmond; [EMAIL PROTECTED]
Subject: Re: How to skip over a blank line


The best way is the following :

next if /^\s*$/;

Selim.


 --- Katherine Richmond
<[EMAIL PROTECTED]> a $E9crit$A0: > Hi
everyone,
>
> I am parsing a file and need to recognize when I
> have come to a blank line. Can
> you tell me how to do this? Here is my code so far:
>
> while ( defined($fileLine = <IN>) ) {
>
>       chomp ($fileLine);
>
>       #if this line is blank, go to next line
>
>       #if ($fileLine
>
>       print "\nOne line: " . $fileLine;
> }
>
>
> Thank you,
> Kathy
>
> _______________________________________________
> ActivePerl mailing list
> [EMAIL PROTECTED]
> To unsubscribe:
http://listserv.ActiveState.com/mailman/mysubs

___________________________________________________________
Do You Yahoo!? -- Une adresse @yahoo.fr gratuite et en fran$E7ais !
Yahoo! Mail : http://fr.mail.yahoo.com
_______________________________________________
ActivePerl mailing list
[EMAIL PROTECTED]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

--- end of quote ---

_______________________________________________
ActivePerl mailing list
[EMAIL PROTECTED]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Reply via email to