Re: How can I name my scalar with a for loop?

Re: How can I name my scalar with a for loop?

am 19.12.2007 09:46:44 von vorticitywolfe

On Dec 12, 11:20 pm, ddun...@taos.com (Darren Dunham) wrote:
> vorticitywo...@gmail.com wrote:
> > Close to what I asked for, didn't quite work for my use, since I'm
> > trying to define the variable as $Q1 not just print Q1.
>
> > My goal is to define a bunch of identical labels in a perl tk gui
> > rather than repeating thousands of lines of code.
> > that is the final result will be like this:
>
> > $Q1=$side->Label(-text=>$stn1)->pack();
>
> > where $Q1 is defined by the for loop.
>
> But the name 'Q1' isn't special, right? Don't use individually named
> scalars, stick the references in an array.
>
> my @label_refs;
> foreach my $stn (@stn)
> {
> push @label_refs, $side->Label(-text=>$stn)->pack();
>
> }
>
> Depending on what you're doing, it might be easier to store in a hash so
> you can pull them by name:
>
> my %label_refs;
> foreach my $stn (@stn)
> {
> $label_refs{$stn}=$side->Label(-text=>$stn)->pack();
>
> }
>
> --
> Darren Dunham ddun...@taos.com
> Senior Technical Consultant TAOS http://www.taos.com/
> Got some Dr Pepper? San Francisco, CA bay area
> < This line left intentionally blank to confuse you. >



Thank you everyone,

That is enough to get me somewhere :-) I'll keep working out the
logistics and go from there! Thanks again!

Jonathan