RE: How to get the values

2007-06-20 Thread Nath, Alok (STSD)
Thanks .It serves the purpose. 

-Original Message-
From: Rob Dixon [mailto:[EMAIL PROTECTED] 
Sent: Wednesday, June 20, 2007 12:42 PM
To: beginners@perl.org
Cc: Nath, Alok (STSD)
Subject: Re: How to get the values

Nath, Alok (STSD) wrote:
> Hi,
>   I have a file from which I have to pick a line like this
>   and get the values of Par, Default and RootOnly.
> 
>   Par=som Default=yes RootOnly=no Shared=force
> 
>   I am trying something like below.But the code is becoming long.
> 
>   Anything simplistic will help.
> 
> Thanks
> Alok.
> 
> while( <> ){
> # print only if first character is not #
> my( $line ) = $_ ;
> chomp( $line ) ;
> 
> if($line =~ m/^Par=/){
> my @param ;
> @param = split( /\s+/, $line ) ;
> 
> foreach (@param){
>   Again do split based on = to get
> the values.
> }
> last ;
> }


The code below will put the data pairs into a hash. Is this what you
want?

HTH,

Rob


use strict;
use warnings;

my %data;

while (<>) {
  next unless /^Par=/;
  %data = /([^\s=]+)/g;
  last;
}

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




Re: How to get the values

2007-06-20 Thread Rob Dixon

Nath, Alok (STSD) wrote:

Hi,
I have a file from which I have to pick a line like this
and get the values of Par, Default and RootOnly.

	Par=som Default=yes RootOnly=no Shared=force 


I am trying something like below.But the code is becoming long.

Anything simplistic will help.

Thanks
Alok.

while( <> ){
# print only if first character is not #
my( $line ) = $_ ;
chomp( $line ) ;

if($line =~ m/^Par=/){
my @param ;
@param = split( /\s+/, $line ) ;

foreach (@param){
Again do split based on = to get
the values.
}
last ;
}



The code below will put the data pairs into a hash. Is this what you want?

HTH,

Rob


use strict;
use warnings;

my %data;

while (<>) {
 next unless /^Par=/;
 %data = /([^\s=]+)/g;
 last;
}

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