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/