Hello,

This is code I used and it executed in a wanted way.

foreach $outLine(@problemLines) {
if ($outLine =~ "cleartool: Error: Unable to create label" ) {
my @values = split('"',$outline);
my @label = @values[1];
my $pathName = @values[3];
my $Version = @values[5];
cleartool mklabel $RECURSE $REPLACE -version $Version $label $pathName;
}

Anyways, as per Bolliger's i/p I with try to use $_ instead of with outLine 
varible.

Thx PERL team.

-Pradeep.



----- Original Message ----
From: D. Bolliger <[EMAIL PROTECTED]>
To: beginners@perl.org
Sent: Wednesday, 25 October, 2006 4:36:10 PM
Subject: Re: Fw: Reg:need to find the particular pattern in a line and assign 
to variables.


pradeep reddy am Mittwoch, 25. Oktober 2006 09:02:
> John,
>
> Thx for your inputs.
>
> 1st i/p:

Hello

please don't top post so the discussion can be followed easily.

> Iam afraid, I cant read each line from array problemLines to outLine.

You don't show how you modified your code after John's advice. 

foreach (@problemLines) { # for all lines do:
   # handle the current line in $_ 
   # [no need for the $outLine variable]
}

> 2nd i/p:
>
> =~ /"([^"]+)"/g;------What is the logic in this expression?
> Can u bit ellaborate.
>
> I wanted to read the values in double quotes, from each line.

It does what you want: Extract (by capturing with ()) all (/g) strings ([^"]+) 
between two double quotes (/"<snip>"/). 

Look at the documentation (from command line): perldoc perlre

> And , Iam using this logic ---if ($outLine =~ / cleartool: Error: Unable to
> create label /)
> , to check for the patten in part of line..Is this correct?

Spaces are relevant. According to your output below, there is no space 
before "cleartool".

To check if it's correct, simply try it and look at the result.

Hope this helps!

Dani

[Original question & JWK's 1st answer:]
> ----- Original Message ----
> From: John W. Krahn <[EMAIL PROTECTED]>
> To: Perl Beginners <beginners@perl.org>
> Sent: Wednesday, 25 October, 2006 12:11:02 PM
> Subject: Re: Fw: Reg:need to find the particular pattern in a line and
> assign to variables.
>
> pradeep reddy wrote:
> > Hello all,
>
> Hello,
>
> > Iam new member to this group and also beginner to PERL.
> > Here is my question,plz let me know your inpus:
> > I have a PERL script which gives error report at the end.
> > Here is the output.
> >
> > cleartool: Error: Unable to create label "Pradeep" on
> > "/vob/rootinclude/paer.c" version "/main/3". cleartool: Error: Unable to
> > create label "Pradeep" on "/vob/rootinclude/pcme.h" version "/main/2".
> >
> > I need to grab the two elements between the two quotes.
> > Iam very much beginer to the PERL script.
> > Iam trying this bit of code, not sure how to go on.
> >
> > foreach (@problemLines) {
> >    push $outLine,@problemLines; /"here Iam trying to get the each line
> > into outLine"/
>
> The first argument to push() must be an array so that will not work.
>
> >   if ($outLine =~ / cleartool: Error: Unable to create label /) {   
> > /"here Iam trying to match the pattern"/ my @values = split(' "
> > ',$outline);    /"Here Iam splitting the outline"/ my $pathName =
> > @values[3];
> > my $Version = @values[5];
> > cleartool mklabel $RECURSE $REPLACE -version $Version $labelName
> > $pathName;   /"This is the comand Iam using"/ print "$_\n";
> >
> > }
>
> You probably want something like this:
>
> my ( $labelName, $pathName, $Version ) = $outline =~ /"([^"]+)"/g;
>
>
>
> John
> --
> Perl isn't a toolbox, but a small machine shop where you can special-order
> certain sorts of tools at low cost and in short order.       -- Larry Wall

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


                
__________________________________________________________
Yahoo! India Answers: Share what you know. Learn something new
http://in.answers.yahoo.com/

Reply via email to