On Apr 22, rmck said:

>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$)/){

You don't want to use == here, you want to use =~.

>$rest = $_;
>print "##The Rest##\n";
>print $rest;
> }
>}

Here's how I'd do it:

  my @rest = ();
  while (<>) {
    if (/^(20|80|Header)$/) { push @rest, $_ }
    else { print }
  }
  print "## The Rest ##\n";
  print @rest;

-- 
Jeff "japhy" Pinyan      [EMAIL PROTECTED]      http://www.pobox.com/~japhy/
RPI Acacia brother #734   http://www.perlmonks.org/   http://www.cpan.org/
CPAN ID: PINYAN    [Need a programmer?  If you like my work, let me know.]
<stu> what does y/// stand for?  <tenderpuss> why, yansliterate of course.


-- 
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