Jay Savage                                                    
             <[EMAIL PROTECTED]                                             
             l.com>                                                     To 
                                       "[EMAIL PROTECTED]"            
             08/02/2005 05:43          <[EMAIL PROTECTED]>, beginners 
             PM                        perl <beginners@perl.org>           
                                                                        cc 
                                                                           
             Please respond to                                     Subject 
                Jay Savage             Re: reg exp using \G                
             <[EMAIL PROTECTED]                                             
                  l.com>                                                   
                                                                           
                                                                           
                                                                           
                                                                           







Please don't top post. I think you've been asked this before.


On 8/2/05, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
> ok I understand now...thanks, but I tried it and it is still stopping at
> original1.1
> I then modified it to print YESSSS if ($1) but never saw YESSSS in
STDOUT.


Tha's because as a one liner it doesn't use parentheses. And also
becuase YESSSSS isn't a string, it's a constant. Do you have warnings
turned on? warnings and strict would catch these sorts of things.

    print "Yes" if $1;   # or
    if ($1) {print "Yes"}

Your choice.


> > #!/usr/bin/perl
> > use strict;
> > use warnings;
> >
> > while (<DATA>) {
> >     if (/AA/ ... /(CC)/) {
> >         print;
> >         if ($1) {
> >             while (<DATA>) {
> > # this regex defines when your section is done
> >                 last if /^\s*$/;
> >                 print;
> >             }
>
> # so you don't have to spin over the rest of the file
> last;
>
> >         }
> >     }
> > }

I think we need a clearer description of what you want to do here. At
least I do. will your last line have "original.1"? Or will it have
something else? i don't think anyone knows what "the "end of
original.1" means. "original.1" is a string, and the current code
matches that string. If you need to match the end of the string, use
'/original\.1$/'.

I think, though that you mean the end of some block of lines in your data
file.

It looks to me like you want something along the lines of :

  while(<>) {
    if (/allsets/ .. /original\.1/) {
      print;
    } elsif (/media/ .. /Total/) {
      print;
    }
  }

-- j
--------------------------------------------------



BOTTOM POST

I got it working and the code I am using is now

        open (ARC, "archiver -lv |") or die $!;
        my $flag=0;
        foreach (<ARC>)
        {
                if (/(?i)allsets/)
                {
                        $flag=1;
                }
                if ($flag==1)
                {
            print $_;
      }
}

as opposed to

if (/allsets/ .. /original1.1/ )

because I needed the data after original1.1.

thank you
derek






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