Both of these work great (thanks):
next if $_ =~ /(^20$|^80$|^Header$)/;
next if m/^(?:Header|[28]0)$/;
So now my results are:
bash-2.03$ ./clean.pl data.txt
10
5201
8001
0
3802
bash-2.03$
How can you have the parsed info printed?
Can you still use the $_??
So the goal would be:
bash-2.03$ ./clean.pl data.txt
10
5201
8001
0
3802
##The Rest##
Header
20
80
bash-2.03$
I thought I could do this:
#!/bin/perl
use strict;
use warnings;
while( <> ) { #read from stdin one line or record at a time
next if $_ =~ /(^20$|^80$|^Header$)/;
print ;
if ($_ == /(^20$|^80$|^Header$)/){
$rest = $_;
print "##The Rest##\n";
print $rest;
}
}
data.txt:
Header
10
20
5201
8001
0
80
3802
BUT lol... Its not working:
bash-2.03$ ./clean.pl data.txt
10
5201
8001
0
##The Rest##
0
3802
bash-2.03$
Help if you can..... Thanks up front....
Rob
-----Original Message-----
From: James Edward Gray II <[EMAIL PROTECTED]>
Sent: Apr 22, 2004 6:59 AM
To: rmck <[EMAIL PROTECTED]>
Cc: [EMAIL PROTECTED]
Subject: Re: next if question
On Apr 22, 2004, at 8:54 AM, rmck wrote:
> hi,
>
> I have a while statement that does a next if a match is made against a
> reg exprerssion of some numbers.
>
>
> data file:
> Header
> 10
> 20
> 5201
> 8001
> 0
> 80
> 3802
>
>
>
> #!/bin/perl
> use strict;
> use warnings;
>
> while( <> ) { #read from stdin one line
> or record at a time.
> next if $_ =~ /(20|80|Header|)/; # =~ means match not equal to.
> print ;
> }
>
> results:
> bash-2.03$ ./clean.pl data.txt
> 10
> 0
> bash-2.03$
>
> I would like it to have the results as so:
> 10
> 5201
> 0
> 8001
> 3802
>
>
> How do I force my reg exp to match only 20, and 80. Not 8001 or 5201?
next if m/^(?:Header|[28]0)$/;
Hope that helps.
James
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>