"Hanson, Robert" <[EMAIL PROTECTED]> writes:
> One way is to do this...
>
> while ( my $line = ) {
> next if ( /^\s*$/ );
> }
NO! NO! NO! NO! NO! NO! NO! NO! NO! NO! NO! NO! NO! NO!
Your loop sets $line (but not $_),
but your RE checks $_ (but not $line).
There are two solutions to yo
On Jan 2, Booher Timothy B 1stLt AFRL/MNAC said:
>Why is ((/^\*+/) or (/^\s*$/)) improper?
>
>It breaks down to:
>( (/^\*+/) or (/^\s*$/) )
Yes... but neither of those are testing $line, they're testing $_.
>How is this different than: "next if $line =~ /^\*+/ or $line =~ /^\s*$/;"
>except tha
Why is ((/^\*+/) or (/^\s*$/)) improper?
It breaks down to:
(
(/^\*+/)
or
(/^\s*$/)
)
How is this different than: "next if $line =~ /^\*+/ or $line =~ /^\s*$/;"
except that it is less ambiguous?
tim
On Jan 2, Booher Timothy B 1stLt AFRL/MNAC said:
>First of all, why do I need to use defined() here is my code:
You don't.
>next if $line =~ ((/^\*+/) or (/^\s*$/));
That isn't written properly.
next if $line =~ /^\*+/ or $line =~ /^\s*$/;
Although, the first regex can be simplified to
On Jan 2, [EMAIL PROTECTED] said:
>That's right. But let me add my 5cents to it. If you decide to use the
>construct "while ( )..." then it better be
>while( defined() ) {
>//...
>}
Not so. First, doing defined() does not store a line in $_ -- for
that, you'd need defined($_ = ). Second, whi
2-8302 Ext. 3360 (DSN 872-)
FAX: 850-882-2201
-Original Message-
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]]
Sent: Wednesday, January 02, 2002 4:54 PM
To: [EMAIL PROTECTED]; [EMAIL PROTECTED]
Cc: [EMAIL PROTECTED]; [EMAIL PROTECTED]
Subject:RE: find blank line
That
On Jan 2, [EMAIL PROTECTED] said:
>open( MYFILE, "file.txt" ) or die;
>while ( my $line = ) {
>my ($a); // $a is undefined now.
>$line =~ /(\w+)\d+$/;
>$a = $1; // $a may be undef still if the preceding expression did not
>evaluate to true
>print "Value of a is <$a>\n"; // S
, 2002 2:44 PM
To: Booher Timothy B 1stLt AFRL/MNAC
Cc: Hanson, Robert; [EMAIL PROTECTED]
Subject: RE: find blank line
On Jan 2, Booher Timothy B 1stLt AFRL/MNAC said:
>Thanks so much - only one problem: when I try to use while (my $line =
>) { etc } I get a bunch of errors similar to this one:
&
ooher Timothy B 1stLt AFRL/MNAC
[mailto:[EMAIL PROTECTED]]
Sent: Wednesday, January 02, 2002 2:39 PM
To: Hanson, Robert
Cc: [EMAIL PROTECTED]
Subject: RE: find blank line
Thanks so much - only one problem: when I try to use while (my $line =
) { etc } I get a bunch of errors similar to this one:
On Jan 2, Booher Timothy B 1stLt AFRL/MNAC said:
>Thanks so much - only one problem: when I try to use while (my $line =
>) { etc } I get a bunch of errors similar to this one:
>
>Use of uninitialized value at JustForTest.pl line 13, chunk 5.
>
>Do you know what I am doing wrong?
The code given
thy B 1stLt AFRL/MNAC'; [EMAIL PROTECTED]
Subject: RE: find blank line
One way is to do this...
while ( my $line = ) {
next if ( /^\s*$/ );
}
Rob
-Original Message-
From: Booher Timothy B 1stLt AFRL/MNAC
[mailto:[EMAIL PROTECTED]]
Sent: Wednesday, January 02, 2002
Hey Tim,
This will check for lines that have nothing but white space in them and skip them.
White space
includes newlines as well...
Shawn
open(F,'file.txt');
while() {
next if(/^\s*$/);
blah...
}
close(F);
- Original Message -
From: "Booher Timothy B 1stLt AFRL/MNAC" <[EMAIL P
One way is to do this...
while ( my $line = ) {
next if ( /^\s*$/ );
}
Rob
-Original Message-
From: Booher Timothy B 1stLt AFRL/MNAC
[mailto:[EMAIL PROTECTED]]
Sent: Wednesday, January 02, 2002 5:19 PM
To: [EMAIL PROTECTED]
Subject: find blank line
When parsing a text file -
13 matches
Mail list logo