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

  Main Index MAIN
Search Posts SEARCH
Who's Online WHO'S
Log in LOG

Home: Perl Programming Help: Beginner:
Looping through segments


Louis Mc

Apr 6, 2000, 10:16 PM

Post #1 of 1 (2257 views)
Looping through segments Can't Post

I need to know how to loop this properly. Maybe I'm starting off wrong with the substring?

The data looks like this (actually about 6000 characters longer):


The data comes to me as @info. I used to get this one string at a time, so it was easier. Now I get from 10 to 50 strings at a time. I sort the strings by c23 then populate a web form with a text reply box for each string. I started out doing this:

foreach $i (0 .. $#input) {
$passData{"friend_id$i"} = substr($input[$i], 0, 3);
$passData{"response_cd$i"} = substr($input[$i], 3, 2);
$passData{"mdl_id$i"} = substr($input[$i], 5, 3);
$passData{"seq_id$i"} = substr($input[$i], 8, 4);
$passData{"pos_id$i"} = substr($input[$i], 12, 7);
$passData{"depl_no$i"} = substr($input[$i], 19, 2);
$passData{"vend_pn$i"} = substr($input[$i], 21, 12);

Which worked great with a single string, because I always knew that $i would be 0. Which I placed here:

<table border=1>
<td>Name: $passData{'friend_id0'}</td>
<td>Response: $passData{'response_cd0'}</td>
<td>Model: $passData{'mdl_id0'}</td>
...etc, etc.

Now I need to find out how many [$i]'s are created, then make a loop that looks like this (please be kind to the beginner)
$NumberLines = @info;

for ($i = 1; $i < '$NumberLines'; $i++) {

<table border=1>
<td>Name: $passData{'friend_id[$i]?'}</td>
#need to increment '?' for each table.
<td>Response: $passData{'response_cd?'}</td>
<td>Model: $passData{'mdl_id?'}</td>
# Create a table placing
# vend_id1 here, and vend_id2,3,4,5...
# in the next table, until end
$i = 1;
while ($i < '$NumberLines'){
<table border=1>
<td>Name: $passData{'friend_id[$i]?'}</td>
continue {


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

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