Hi

This doesn't seem to work. I get a blank output. But yes the output that is
want is 

123456 ABCDEF
123456

Regards,
Sudhindra

-----Original Message-----
From: Jose Alves de Castro [mailto:[EMAIL PROTECTED] 
Sent: Tuesday, May 18, 2004 3:55 PM
To: Sudhindra Bhat
Cc: Perl Beginners
Subject: Re: Query

On Tue, 2004-05-18 at 07:36, Sudhindra Bhat wrote:
> Hi
> 
> Thanks. But there is a small issue. Considering the same example, the
piece
> of code sent by you prints 123456 which is not on the same line as "Test:"
> But it doesn't print the characters 123456 ABCDEF which is on the same
line
> as "Test:" 

That's because it is *not* printing the line with "Test:"... it is only
printing the lines between the one that matches "Test:" and the one that
matches "Results:"

This prevents the line with "Test:" from being printed:  !/Test:/

This prevents the line with "Results:" from being printed: !/Results:/

Exactly what output were you expecting?
Something like this, perhaps:

===
123456 ABCDEF

123456

(2)     
===

Would that be it?

If so, try 

while (<FILE>) {
  if ( /Test:/ .. /Results:/ ) {
    if ( /Test:/ )       { print $' }
    elsif ( /Results:/ ) { print $` }
    else                 { print }
  }
}

HTH,


jac

> Regards,
> Sudhindra
> 
> -----Original Message-----
> From: John W.Krahn [mailto:[EMAIL PROTECTED] 
> Sent: Monday, May 17, 2004 4:56 PM
> To: Perl Beginners
> Subject: Re: Query
> 
> On Monday 17 May 2004 03:15, Sudhindra Bhat wrote:
> >
> > Hi
> 
> Hello,
> 
> > I wanted some help on a piece of code that I was writing. Well the
> > requirement is like this. I have a file whose looks like this
> >
> > (1)     Test: 123456 ABCDEF
> >
> > 123456
> >
> > (2)     Results: ABCDEF
> >
> > Now I want my script to output all the contents between the two tags
> > Test and Results. i.e. 123456 ABCDEF 123456. Can someone help me with
> > this?
> 
> 
> while ( <FILE> ) {
>     if ( /Test:/ .. /Results:/ and !/Test:/ and !/Results:/ ) {
>         print
>         }
>     }
> 
> 
> 
> John
> -- 
> use Perl;
> program
> fulfillment
> 
> -- 
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> <http://learn.perl.org/> <http://learn.perl.org/first-response>
-- 
José Alves de Castro <[EMAIL PROTECTED]>
Telbit - Tecnologias de Informação

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