For Programmers: Free Programming Magazines  


Home > Archive > PERL Beginners > August 2005 > Re: Need an explanation









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Re: Need an explanation
angelflowercn@aim.com

2005-08-26, 6:56 pm

maybe this is brief:

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



-----Original Message-----
From: Binish A R <binishar@poornam.com>
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.

Binish A R

2005-08-26, 6:56 pm

angelflowercn@aim.com wrote:

> maybe this is brief:
>
> while (<> ) {
> chomp;
> next if /^#/;
> next if /^$/;
> my ($var1,$var2)=split /=/;
> $CONF{$var1}=$var2;
> }
>
>
>
> -----Original Message-----
> From: Binish A R <binishar@poornam.com>
> 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//*

Get Thunderbird <http://www.mozilla.org/products/thunderbird/>


angelflowercn@aim.com

2005-08-26, 6:56 pm

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

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





-----Original Message-----
From: Binish A R <binishar@poornam.com>
To: Perl Beginners <beginners@perl.org>
Cc: angelflowercn@aim.com
Sent: Fri, 26 Aug 2005 23:04:58 +0530
Subject: Re: Need an explanation

angelflowercn@aim.com wrote: maybe this is brief:

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



-----Original Message-----
From: Binish A R <binishar@poornam.com>
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=3Dvalue1;
IDENTIFIER2=3Dvalue2;
IDENTIFIER3=3Dvalue3;

etc

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


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


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

So I had to modify the above script to

while (<> ) {
=A0=A0 chomp;
=A0=A0 next if /^#/;
=A0=A0=A0=A0=A0=A0 next if /^$/;
=A0=A0=A0=A0=A0=A0 $ref =3D [ split /=3D/ ];
=A0=A0 $CONF{$ref->[0]} =3D $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/=A0 [Image removed]




________________________________________
________________________________
Check Out the new free AIM(R) Mail -- 2 GB of storage and=20
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=20
industry-leading spam and email virus protection.

Binish A R

2005-08-26, 6:56 pm

angelflowercn@aim.com wrote:

> while (<> ) {
> chomp;
> next if /^#/;
> next if /^$/;
>
> $CONF{(split/=/)[0]}=(split/=/)[1];
> }
>
>
>
>
>
> -----Original Message-----
> From: Binish A R <binishar@poornam.com>
> To: Perl Beginners <beginners@perl.org>
> Cc: angelflowercn@aim.com
> Sent: Fri, 26 Aug 2005 23:04:58 +0530
> Subject: Re: Need an explanation
>
> angelflowercn@aim.com wrote: maybe this is brief:
>
> while (<> ) {
> chomp;
> next if /^#/;
> next if /^$/;
> my ($var1,$var2)=split /=/;
> $CONF{$var1}=$var2;
> }
>
>
>
> -----Original Message-----
> From: Binish A R <binishar@poornam.com>
> 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.
>
>

Thatz ... I appreciate that :D


--
*//binish//*

Get Thunderbird <http://www.mozilla.org/products/thunderbird/>


Manav Mathur

2005-08-27, 6:55 pm


----- Original Message -----
From: <angelflowercn@aim.com>
To: <binishar@poornam.com>
Cc: <beginners@perl.org>
Sent: Friday, August 26, 2005 10:37 PM
Subject: Re: Need an explanation


> maybe this is brief:
>
> while (<> ) {
> chomp;
> next if /^#/;
> next if /^$/;
> my ($var1,$var2)=split /=/;
> $CONF{$var1}=$var2;
> }
>
>
>
> -----Original Message-----
> From: Binish A R <binishar@poornam.com>
> 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]
>



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

%conf=(%conf,split/=/) ;
}



Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2009 codecomments.com