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:
Looping through segments

 



Louis Mc
Deleted

Apr 6, 2000, 10:16 PM

Post #1 of 1 (872 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):

a23b2c23d234e234567f2g23456789012
a23b2c23d234e234567f2g23456789012
a23b2c23d234e234567f2g23456789012

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>
<tr>
<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>
<tr>
<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>
etc...
# Create a table placing
# vend_id1 here, and vend_id2,3,4,5...
# in the next table, until end
}
-----------------------
or
-----------------------
$i = 1;
while ($i < '$NumberLines'){
<table border=1>
<tr>
<td>Name: $passData{'friend_id[$i]?'}</td>
etc...
}
continue {
$i++;
}

 
 


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

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