troubleshooting Question

loop through string array

Avatar of Dan-LL
Dan-LL asked on
PerlScripting Languages
10 Comments1 Solution1396 ViewsLast Modified:
Can someone tell me if this can be done and how as I have almost got it right, erm no I have not...

ozo gave me this one liner that works a treat
$r1t = (undef, $onename, $twoname,  $threename, $fourname, $fivename)[$r1t] || $r1t;

for my $i (1 .. 4){
$r.$i.t = (undef, $onename, $twoname,  $threename, $fourname, $fivename)[$r.$i.t] || $r.$i.t;

it does not return the same values as writing it long hand like this, any ideas if the code can be looped.

$r1t = (undef, $onename, $twoname,  $threename, $fourname, $fivename)[$r1t] || $r1t;
$r2 = (undef, $onename, $twoname,  $threename, $fourname, $fivename)[$r2t|| $r2;
$r3 = (undef, $onename, $twoname,  $threename, $fourname, $fivename)[$r3 || $r3;
$r4 = (undef, $onename, $twoname,  $threename, $fourname, $fivename)[$r4] || $r4t
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 10 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 10 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros