RE: Regular expressionHi Javeed. This code: foreach (@attt) { /=/ && ( ($out) = (split (/=/))[1] ); } stores the string "HELLO" in the variable $out. Then, if you issue print "$out" you would get a "HELLO".
But when I read your e-mail again I realized that you want to store the entire last line. So yoy should use this code instead: foreach (@attt) { /=/ && ( $out = $_ ); } The foreach (@attt) starts a loop storing every line of @attt in a default variable called $_ Then, if the regul. exp "/=/" matches against the default variable $_, the && statement is executed, storing the variable $_ in the variable $out. For clarifying purposes, you could write the same code as: foreach $line (@att) { if ($line =~ /=/){ $out = $line ; print "$out"; } } And if you want to get rid of the blank spaces in the last line, add try this: foreach $line (@attt) { if ($line =~ /=/){ $out = $line ; $out =~ s/\s*//; print "$out"; } } I learnt all this from the O'reilly book "Learning Perl second edition". Tied hugs and warmfull kisses, Bruno Negrão. ----- Original Message ----- From: Javeed SAR To: Bruno Negrao - Perl List Sent: Monday, October 07, 2002 1:21 AM Subject: RE: Regular expression foreach (@attt) { /=/ && ( ($out) = (split (/=/))[1] ); } Can u explain this statement to me? Which is the variable i should use for printing the output? Regards -----Original Message----- From: Bruno Negrao - Perl List [mailto:[EMAIL PROTECTED]] Sent: Friday, October 04, 2002 6:54 PM To: [EMAIL PROTECTED] Subject: Re: Regular expression > Hi Javeed , > > the last element of the array is $attt[$#attt]. If you have one line per > element, that should do it. Right. This is the easiest way. But, just to answer him, what he could do using regular expression could be something like: foreach (@attt) { /=/ && ( ($out) = (split (/=/))[1] ); } Bruno. > > R > > At 14:24 04/10/2002 +0530, Javeed SAR wrote: > > >I have the following output in array @attt > >I want the last line in a variable $out. > >What should the regular expression be? > > > > > >attribute type "SYNC_CHECK" > > created 04-Oct-02.09:36:42 by javeed.clearuser@BLRK35ED > > "for testing" > > owner: HIS\javeed > > group: HIS\clearuser > > scope: this VOB (ordinary type) > > value type: string > > Attributes: > > SYNC_CHECK = "HELLO" > > > > > >Regards > >j > > > -- > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > > -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]