LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 02-17-2004, 03:06 AM   #1
morbid_ru
LQ Newbie
 
Registered: Dec 2003
Posts: 6

Rep: Reputation: 0
Need help with perl loop!


Hello.

Here is the problem.
My cgi script receives variables.

@pairs = split(/&/, $query);
foreach $pair (@pairs) {
($name, $value) = split(/=/, $pair);
$variable{$name} = $value;

$name is $item_name1, $item_name2, $item_name3, $item_name4 ... etc

I would like to make a loop:

for ($count = 1; $count <= 100; $count++) {
($item_name,$item_number) = split(/\|/, $variable{'item_number$count});
print "$item_no, ";
}

however this does not work. I'm sure taht the problem is in:
$variable{'item_number$count}

What is the correct way of saying this in PERL?
Thanks.
 
Old 02-17-2004, 04:42 AM   #2
Berng
Member
 
Registered: Dec 2003
Location: Siberia,Russia
Distribution: Basically RedHat
Posts: 34

Rep: Reputation: 15
$variable{"item_number$count"}
or
$variable{'item_number'.$count}
or
$variable{"item_number".$count}
The first variant looks the better one...
BestRegards,
Oleg
 
Old 02-17-2004, 05:15 AM   #3
morbid_ru
LQ Newbie
 
Registered: Dec 2003
Posts: 6

Original Poster
Rep: Reputation: 0
RE

Thanks Oleg.

$variable{"item_number$count"} works.

Regards,
Max
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
How to break if loop in Perl? Barca Programming 9 08-03-2011 01:15 PM
Perl: Where am I in a foreach loop? jrtayloriv Programming 3 01-30-2005 10:43 PM
loop through string with perl lfur Programming 2 07-03-2004 08:05 AM
Need help with perl loop! morbid_ru Programming 1 02-24-2004 01:14 PM
Loop in this perl script is not working meluser Programming 2 04-01-2003 08:59 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 04:40 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration