ramya2005 has asked for the wisdom of the Perl Monks concerning the following question:
use strict; use warnings; my $ENABLE = 0; my $REQUIRE = 1; my $DISABLE = 2; my $DataRates = 'basic-2.0 1.0 basic-5.5'; my %DataRatesHash = (1.0 => $DISABLE, 2.0 => $DISABLE, 5.5 => $DISABL +E, 48.0 =>$DISABLE, 54.0=>$DISABLE); foreach my $rate (split(/ /, $DataRates)) { if(my ($rate1) = $rate =~/basic-(.+)/) { print "Data Rate - $rate \n"; %DataRatesHash->{$rate1} = $REQUIRE; print %DataRatesHash->{$rate1}; print "\n"; } else { print "Data Rate - $rate \n"; %DataRatesHash->{$rate} = $ENABLE; print %DataRatesHash->{$rate}; print "\n"; } } print %DataRatesHash->{2.0} ; print %DataRatesHash->{1.0} ; print %DataRatesHash->{5.5} ; print %DataRatesHash->{48.0} ;
Data Rate - basic-2.0 1 Data Rate - 1.0 0 Data Rate - basic-5.5 1 2212
Data Rate - basic-2.0 1 Data Rate - 1.0 0 Data Rate - basic-5.5 1 1012 # Since I modified the hash inside the loop
2005-10-05 Retitled by planetscape, as per Monastery guidelines
Original title: 'What is wrong with my code?'
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: hash, deref & looping problem
by pg (Canon) on Oct 04, 2005 at 23:12 UTC | |
by Zed_Lopez (Chaplain) on Oct 04, 2005 at 23:22 UTC | |
by ramya2005 (Scribe) on Oct 04, 2005 at 23:38 UTC | |
|
Re: hash, deref & looping problem
by davido (Cardinal) on Oct 04, 2005 at 23:21 UTC | |
|
Re: hash, deref & looping problem
by GrandFather (Saint) on Oct 04, 2005 at 23:11 UTC | |
by pg (Canon) on Oct 04, 2005 at 23:14 UTC |