CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner:
anyone OTHER THAN FISHMONGER know how to interpolate variable names in a loop?

 

First page Previous page 1 2 Next page Last page  View All


FishMonger
Veteran / Moderator

Aug 17, 2011, 12:01 PM

Post #26 of 32 (2283 views)
Re: [rmh_va] anyone OTHER THAN FISHMONGER know how to interpolate variable names in a loop? [In reply to] Can't Post


Quote
I do not have access to the code that creates these variables

In that case, what you previously told us was a lie.

You told us that the vars were being passed to you. If that's the case, they would have been passed via the @ARG array if passed as an arg to the script, and @_ if passed to a subroutine. In either case, they are being passed as an array/list and it would be up to you to use the array directly or to copy its values to the 8 other vars.

BTW, you were given a working solution in your original question, but apparently you were incapable of doing a copy/paste of that solution.


rmh_va
Novice

Aug 17, 2011, 12:21 PM

Post #27 of 32 (2279 views)
Re: [FishMonger] anyone OTHER THAN FISHMONGER know how to interpolate variable names in a loop? [In reply to] Can't Post

your solution did not work... I gave you a code snippet to run, and you were unable to get it to work, and didn't understand it...



All, please disregard Fishmongers comments... He has made this entire process (tyring to get a solution on this forum) a nightmare... He obviously doesn't have the first clue what I'm looking for, and won't admit this...

What I'm trying to do is field several perl variables in a loop... It'd be better if I had an array or a hash, I'd love that... but it is what it is.. code is provided that poduces these variables... I am attemting to process them in a loop...



I asked for help processing them in a loop, using tnterpolation to append the number at the end... no one had any suggesitons that worked... I provided source, still no solution....

here's the code:


I orignially asked if anyone knows how to fix my interpolation problem...



here's the code...



I have 8 variables... I would like to reference them in a loop without hard-coding the names...

$sub1 = 'var1name/var1text';

$sub2 = 'var2name/var2text';

$sub3 = 'var3name/var3text';

$sub4 = 'var4name/var1text';

$sub5 = 'var5name/var1text';

$sub6 = 'var6name/var1text';

$sub7 = 'var7name/var7text';

$sub8 = 'var8name/var8text';

print '<table>';

while ($i < 9) {

$temp = "$sub.$i";

@xr = split("/",$temp);

print '<tr><td>',$xr[0],'</td><td>',$xr[1],'';

$i++;

}

print '</table>';





I want to fix this statement: $temp = "$sub.$i";

I can't get the split to work with a variable name that's interpolated... so I made an assign stantement, just to see if I could interpolate and assign the variable another way... no luck...

can anyone out there make this code work? NOTE : Changing the variables the way they are passed is not an option... It's embedded in a client module, can't change it... So it's going to pass me 8 variables, as noted above...



thanks, and if you don't have specific knowledge to bring to bear on this issue, kindly exit without comment...


FishMonger
Veteran / Moderator

Aug 17, 2011, 12:26 PM

Post #28 of 32 (2278 views)
Re: [rmh_va] anyone OTHER THAN FISHMONGER know how to interpolate variable names in a loop? [In reply to] Can't Post


Quote
E:\TEMP\test>type to_the_idiot_rmh_va.pl
#!/usr/bin/perl

$var1 = 'var1name/var1text';

$var2 = 'var2name/var2text';

$var3 = 'var3name/var3text';

$var4 = 'var4name/var1text';

$var5 = 'var5name/var1text';

$var6 = 'var6name/var1text';

$var7 = 'var7name/var7text';

$var8 = 'var8name/var8text';

print '<table>';

while ($i < 9) {
$temp = eval('$var'.$i);
@xr = split("/",$temp);
print '<tr><td>',$xr[0],'</td><td>',$xr[1],'';
$i++;
}

E:\TEMP\test>to_the_idiot_rmh_va.pl
<table><tr><td></td><td><tr><td>var1name</td><td>var1text<tr><td>var2name</td><t
d>var2text<tr><td>var3name</td><td>var3text<tr><td>var4name</td><td>var1text<tr>
<td>var5name</td><td>var1text<tr><td>var6name</td><td>var1text<tr><td>var7name</
td><td>var7text<tr><td>var8name</td><td>var8text



fixles
Novice

Aug 17, 2011, 3:37 PM

Post #29 of 32 (2271 views)
Re: [rmh_va] anyone OTHER THAN FISHMONGER know how to interpolate variable names in a loop? [In reply to] Can't Post


In Reply To
All, please disregard Fishmongers comments... He has made this entire process (tyring to get a solution on this forum) a nightmare... He obviously doesn't have the first clue what I'm looking for, and won't admit this...


When you say All do you mean me? There's no one else here you must be talking to me.

Fishmonger is one of the most helpful, knowledgeable and well respected people on the forum. He posts helpful answers to just about every question posted here. Insulting him and being disrespectful to him will win you no friends here and quite likely stopped some of the other regular contributors from helping you (I assume Fishmonger is male because would be a bit of a sick name for a woman)

The problem is you don't understand the answer or haven't explained the problem correctly. 3 people have told you the same thing and your still mouthing off like you own the place.

You wont be able to see this because its your own actions but your acting like a complete dickhead and as such no one else will help you. I'm sure more than a few people have laughed at you today.

Its clear from the way your talking (despite its childish... style) that you are a loser not just here but in real life. This bad attitude you have will create animosity amongst people in droves. But you'll continue to shout and demand respect and authority which no one will give you. As Dale Carnegie said "Tell me how a person gets their felling of importance, and I'll tell you what sort of person they are."

Give it a rest and go home.


FishMonger
Veteran / Moderator

Aug 17, 2011, 4:47 PM

Post #30 of 32 (2267 views)
Re: [fixles] anyone OTHER THAN FISHMONGER know how to interpolate variable names in a loop? [In reply to] Can't Post


Quote
(I assume Fishmonger is male because would be a bit of a sick name for a woman)


You are correct about me being male, but I don't see why the username 'fishmonger' would be a sick (user)name for a woman.

dictionary.com

Quote
fishˇmonˇger
[fish-muhng-ger, -mong-]
noun Chiefly British .
a dealer in fish, especially for eating.


I starting using this username when I worked for my brother in the seafood business (wholesale, retail, and restaurant) and there are plenty of women in that business.
http://rosysatthebeach.com/


(This post was edited by FishMonger on Aug 17, 2011, 4:48 PM)


FishMonger
Veteran / Moderator

Aug 17, 2011, 8:03 PM

Post #31 of 32 (2260 views)
Re: [fixles] anyone OTHER THAN FISHMONGER know how to interpolate variable names in a loop? [In reply to] Can't Post

fixles,

I want to apologize to you for not thanking you for the complements that you gave to me. I participate in multiple forums and try to maintain a high level of discourse, but sometimes fail.


fixles
Novice

Aug 18, 2011, 2:06 AM

Post #32 of 32 (2250 views)
Re: [FishMonger] anyone OTHER THAN FISHMONGER know how to interpolate variable names in a loop? [In reply to] Can't Post

Hi Fishmonger,

No need to apologies you deserve some credit and appreciation for the effort you put in. Perl should employ you, your efforts no doubt help keep the language alive especially helping new users.

I think I've lowered the tone of this post quite enough but today is a new day. The username Fishmonger as you can see from dictionary.com a chiefly British word wouldn't be an ideal username for a woman as a fishy smell on a woman is an insult referring to her lady garden.

First page Previous page 1 2 Next page Last page  View All
 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives