Avatar of Dan-LL
Dan-LL asked on

Array in a hurry

getting late here in UK, got to have this done before I can go to bed, lol...

Could someone tell me how to do this better with an array or something, new to perl but under presure to get this done for a friend.


if ($sndteam eq "1") {$sndteam = $onename};
if ($sndteam eq "2") {$sndteam = $twoname};
if ($sndteam eq "3") {$sndteam = $threename};
if ($sndteam eq "4") {$sndteam = $fourname};
if ($sndteam eq "5") {$sndteam = $fivename};

can it be looped through in an array, the "digit" number changes 1 to 5 and the $[number]name changes one to five.

Many thanks
Scripting LanguagesPerl

Avatar of undefined
Last Comment
Dan-LL

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
ozo

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
See how we're fighting big data
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
ozo

but if  $onename = 2 and $sndteam = 1
then after
  if ($sndteam eq "1") {$sndteam = $onename};
  if ($sndteam eq "2") {$sndteam = $twoname};
$sndteam will be  $twoname
is that what you wanted?
ASKER
Dan-LL

fantastic, thanks that works a treat.

I have no idea how on earth it works but for now, working is enough, thanks for getting me sorted so quickly.

Best Regards Dan
PS, yep, you are Genius....
ASKER
Dan-LL

fantastic, thanks that works a treat, your first answer was spot on, the second answer is too confusing for this time of night, lol...

I have no idea how on earth it works but for now, working is enough, thanks for getting me sorted so quickly.

Best Regards Dan
PS, yep, you are Genius....
This is the best money I have ever spent. I cannot not tell you how many times these folks have saved my bacon. I learn so much from the contributors.
rwheeler23
ozo

It may not be quite the same as the original code if $[number]name can be 2, 3, 4 or 5
because one if may affect the next. but the single assignment will not look at it again
I don't know if your code requires that behaviour
ASKER
Dan-LL

i have tested the first code over and over and it produces what I need with no prolems

it is just to translate a param from a form, the person that wrote the form was lazy and put all values from comp's as numbers, I made a string txt file to translate them into something useful as our staff have to look up the values as list of numbers rather than plain english texts.

anyway thanks a million, time for bed, hoooo ray.