Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re: Use an incrementing counter as a variable

by Happy-the-monk (Canon)
on Sep 11, 2017 at 11:54 UTC ( [id://1199087]=note: print w/replies, xml ) Need Help??


in reply to Use an incrementing counter as a variable

Greetings,

I don't actually get, why you want this. If I read you right, first you are saying you want the counter as a name.

what is the way of using an auto-incrementing counter as a variable name

Then at the end you are saying, you want it as a value, and your code shows you add it as a value.

I will get to know that I have the values "bin_1", "bin_2" etc

So it looks to me line you have to make up your mind about what it is you want. Nevertheless, this solution gives you both the names and the values:

my $counter=0; my %names; while(<>) { $counter++; $names{"bin_".$counter} = "bin_".$counter; } use Data::Dumper qw(Dumper); print Dumper \%names;

So maybe that's a starting point.

Cheers, Sören

Créateur des bugs mobiles - let loose once, run everywhere.
(hooked on the Perl Programming language)

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1199087]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others lurking in the Monastery: (5)
As of 2024-04-25 10:22 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found