Re: many variables and one value

[email protected] ("John W. Krahn")
Newsgroups perl.beginners
Message-ID <[email protected]>
Chas. Owens wrote:
> On Thu, Jun 12, 2008 at 21:04, Noah <[email protected]> wrote:
>>
>> Hi there,
>>
>> I am trying to get the following variables to all equal 1.  what is the
>> easiest way to do that/
>>
>> $loginCount, $areaCount, $stateCount, $cityCount, $elementCount = 1;
> snip
> 
> $loginCount = $areaCount = $stateCount = $cityCount = $elementCount = 1;
> 
> But the fact that you named them all count is a sign that you might
> want a hash instead:
> 
> my %count;
> @count{qw/login area state city element/} = (1,1,1,1,1);


my %count = map { $_ => 1 } qw/ login area state city element /;


my %count;
$_ = 1 for @count{ qw/ login area state city element / };



John
-- 
Perl isn't a toolbox, but a small machine shop where you
can special-order certain sorts of tools at low cost and
in short order.                            -- Larry Wall
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.