while (<>) {
  chomp;
      next if /^#/;
      next if /^$/;

      $CONF{(split/=/)[0]}=(split/=/)[1];
}





-----Original Message-----
From: Binish A R <[EMAIL PROTECTED]>
To: Perl Beginners <beginners@perl.org>
Cc: [EMAIL PROTECTED]
Sent: Fri, 26 Aug 2005 23:04:58 +0530
Subject: Re: Need an explanation

[EMAIL PROTECTED] wrote: maybe this is brief:

while (<>) {
   chomp;
       next if /^#/;
       next if /^$/;
       my ($var1,$var2)=split /=/;
       $CONF{$var1}=$var2;
}



-----Original Message-----
From: Binish A R <[EMAIL PROTECTED]>
To: Perl Beginners <beginners@perl.org>
Sent: Fri, 26 Aug 2005 22:28:22 +0530
Subject: Need an explanation

I've a file, which has entries like the following ...

IDENTIFIER1=value1;
IDENTIFIER2=value2;
IDENTIFIER3=value3;

etc

I've got to parse the above file and am using a hash to do the same ...
Here is my code ...


while (<>) {
   chomp;
       next if /^#/;
       next if /^$/;
       %CONF = split /=/;
}


But %CONF contains only the last key/value pair :-/

So I had to modify the above script to

while (<>) {
   chomp;
   next if /^#/;
       next if /^$/;
       $ref = [ split /=/ ];
   $CONF{$ref->[0]} = $ref->[1];
}

The above is working fine.

So my question is why isn't the first code working?
I don't want to use too many variables in my script,
even with my second script I needed an extra variable viz $ref.

Is it possible to get the job done using the first script?



--
/binish/  [Image removed]




________________________________________________________________________
Check Out the new free AIM(R) Mail -- 2 GB of storage and industry-leading spam and email virus protection.



but that requires two xtra variable, $var1, $var2 :(
--
/binish/  [Image removed]




________________________________________________________________________
Check Out the new free AIM(R) Mail -- 2 GB of storage and industry-leading spam and email virus protection.


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