On Sun, Jun 08, 2003 at 11:41:26PM -0500 Jerry Preston wrote:
> I am not sure if this can be done or not, but I want to create a counter on
> the fly so to speak.
>
> foreach $id ( @IDS ) {
> $cnt = "$id"."_cnt";
> $cnt++;
> }
>
> All I get is "item_cnt". Is there a way to do this?
I can only assume what you want. It looks suspiciously as though you
wanted to create new variables with the name "$id"."_cnt". You can do
that with symbolic references (I know that some would now want me to
shred into pieces):
foreach $id (@IDS) {
$cnt = "$id"."_cnt";
$$cnt++;
}
This is _not_ advisable, wont work with properly declared lexcical
variables (variables declared with my() can't be accessed through a
symbolic reference) and will fail if you 'use strict;'. To do it
properly better create a hash:
my %cnt; # all your counters in here
foreach my $id (@IDS) {
$cnt{ $id . "_cnt" }++;
}
Doing it with symbolic references is apt to fail at some later point and
you will then have a very bad time at debugging your scripts. Better
leave your fingers off that and use a hash (or even array in this case).
Tassilo
--
$_=q#",}])!JAPH!qq(tsuJ[{@"tnirp}3..0}_$;//::niam/s~=)]3[))_$-3(rellac(=_$({
pam{rekcahbus})(rekcah{lrePbus})(lreP{rehtonabus})!JAPH!qq(rehtona{tsuJbus#;
$_=reverse,s+(?<=sub).+q#q!'"qq.\t$&."'!#+sexisexiixesixeseg;y~\n~~dddd;eval
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]