Creatnig Dynamic Arrays

I have a string which I split into an array delimited by the underscore symbol;

my $string = d1156295_012424_PA01dc_ftxcv_ux12b1x0xxxxxxxxx_trctag_marchc_fy_cs_018
my @stringElements = split(/_/,$string);

I now whish to dynamically create an array with the name made up of two of the elements of @stringElements, i.e. $stringElements[0] and $stringElements[5] the array should be called @d1156295trctag.

I tried soing this:
my @{@stringElements[0]}.{@stringElements[5]}...but then how do I refer to it later??

I intend to fill this array with data and would like to eventually access the data by writing something like:

print @d1156295trctag[0]

How do I go about doing this and what it stuff referred to?

Thanks, - Troyh
TroyhAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

roee_fCommented:
What you look for is called "Symbolic References". It can be source of strange bugs, so use strict makes it illegal.
If you're sure that that is what you want, here is an example:

#!/usr/bin/perl
use strict;
use warnings;

# Your code
my $string = "d1156295_012424_PA01dc_ftxcv_ux12b1x0xxxxxxxxx_trctag_marchc_fy_cs_018";
my @stringElements = split(/_/,$string);

my $name = "$stringElements[0]$stringElements[5]";

print "$name\n";

# you have to disable "refs" strictness" in oreder to use
# symbolic reverences
no strict "refs";
push @{$name}, "Hello";
push @{$name}, "World";
${$name}[2] = "Bye";

print "${$name}[0] ${$name}[1]. ${$name}[2].\n";

# re-enable "refs" strictnes as soon as you can
use strict "refs";
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
ozoCommented:
#It's probably safer to
use strict;
my %name;
my $name=$stringElements[0].$stringElements[5];
@{$name{$name}} = qw(Hello World Bye);
print "@{$name{$name}}[0,1]. $name{$name}->[-1].\n";
0
roee_fCommented:
It's the ongoing debate between safety and readablity.

Oh, and ny the way, Troyh, you probably mean
# printing Scalar
print $d1156295trctag[0]

not
# printing slice
print @d1156295trctag[0]

When printing single-element slice there's no visible difference, but there is.

0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Perl

From novice to tech pro — start learning today.