isarana
asked on
Perl arrays or hash? or hashes of arrays? or array of hashes?
I have a stream of data being passed to me which I then unpack into arrays. For each item of the first array I must find the matching item(s) in the other arrays and print them out in a table. Pseudo-code Example:
Array1=(A-Group A,B-2002 Fabrication,C-2003 Fabrication)
Array2=(A001-PRI-RED-DESCR IPTION, A001-PRI-BLU-DESCRIPTION, A001-PRI-BLK-DESCRIPTION,
A001-PRI-GRN-DESCRIPTION, A001-PRI-YLW-DESCRIPTION, A001-PRI-MLT-DESCRIPTION,
A002-PRI-RED-DESCRIPTION, A002-PRI-BLK-DESCRIPTION, A002-PRI-BLU-DESCRIPTION,
B001-PRI-RED-DESCRIPTION, B001-PRI-BLK-DESCRIPTION, B001-MIN-BLK-DESCRIPTION,
B001-MIN-MLT-DESCRIPTION,
C010-COL1-RED-DESCRIPTION, C010-COL1-YLW-DESCRIPTION,
C010-PRI-TRQ-DESCRIPTION, C010-MIN-BLK-DESCRIPTION, C010-MIN-MLT-DESCRIPTION)
Array3=(A001-CODE1:3.0000- CODE2:0.00 00-CODE3:3 .0000-CODE 4:12.2500- CODE5:4.44 00,
A002-CODE1:3.0000-CODE2:0. 0000-CODE3 :3.0000-CO DE4:12.250 0,
B001-CODE1:3.0000-CODE2:0. 0000,
C010-CODE2:3.0000-CODE3:0. 0000-CODE4 :1.0000-CO DE5:0.5000 -CODE6:0.2 500-CODE8: 4.0600-COD E12:3.3600 )
Array4=(A001-Vision-Vision 2-Vision3, A002-Vision-Vision2-999,
B001-Vision-Vision2-vision 3-Vision4,
C010-Vision3-Vision4-Visio n8)
Array5=(A001-2002 Collection-102-1.00-Large- Soon--2002 0310-20020 414,A002-2 002 Collection-001-1.00-Large- Soon-See Thomas-20010310-20010414,B 001-Cha Cha-002-1.00-Medium-Immedi ately--200 10310-2001 0414,C010- Blah-44-2. 00-Small-I mmediately --20010310 -20020414)
foreach item(Array1)
find matching item(s) in array2, get fields,
if COL1 found print COLOR:DESCRIPTION in cell 1
if COL2 found print COLOR:DESCRIPTION in cell 2
find matching lines in array3, print code selections to drop down listbox in cell 3
find matching lines in array4, print SIZE in cell 4, QTY in cell 5
Of course, there could be hundreds of items in array1. Probably no more than 50 items in any of the other 3 arrays.
The items in arrays2,3 & 4 will always be in A,B,C,D order. If I'm searching for A, I could stop when I find no more A's and hold my place if I knew how...nested if statements?
What's the best way to get the fields out of each line when they're delimited by a hyphen? Should I create hashes of some sort? Can I unpack into hashes? I couldn't find much info on packing/unpacking....
What's the best way to handle the processing of so much data? Is it even possible? This is only a small part of the program, but it's got me stumped.
Here's a bit of the actual code I use to unpack data:
sub GetTable1{
my($bits,$message) =@_;
while ($table eq "01"){
$alpha = unpack "x$bits A1", $message;$bits+=1;
$alpha_description = unpack "x$bits A70", $message;$bits+=70;
$table = unpack "x$bits A2", $message;$bits+=2;
push(@Array1,$alpha);
}
return($bits);
}
sub GetTable2{
my($bits,$message) =@_;
while ($table eq "02"){
$alpha = unpack "x$bits A1", $message;$bits+=1;
$column_indicator = unpack "x$bits A4", $message;$bits+=4;
$color_code = unpack "x$bits A3", $message;$bits+=3;
$color_description = unpack "x$bits A70", $message;$bits+=70;
$table = unpack "x$bits A2", $message;$bits+=2;
push(@Array2,"$alpha-$colu mn_indicat or-$color_ code-$colo r_descript ion");
}
return($bits);
}
Help, this is way over my head! And I have 28 tables to parse!
Array1=(A-Group A,B-2002 Fabrication,C-2003 Fabrication)
Array2=(A001-PRI-RED-DESCR
A001-PRI-GRN-DESCRIPTION, A001-PRI-YLW-DESCRIPTION, A001-PRI-MLT-DESCRIPTION,
A002-PRI-RED-DESCRIPTION, A002-PRI-BLK-DESCRIPTION, A002-PRI-BLU-DESCRIPTION,
B001-PRI-RED-DESCRIPTION, B001-PRI-BLK-DESCRIPTION, B001-MIN-BLK-DESCRIPTION,
B001-MIN-MLT-DESCRIPTION,
C010-COL1-RED-DESCRIPTION,
C010-PRI-TRQ-DESCRIPTION, C010-MIN-BLK-DESCRIPTION, C010-MIN-MLT-DESCRIPTION)
Array3=(A001-CODE1:3.0000-
A002-CODE1:3.0000-CODE2:0.
B001-CODE1:3.0000-CODE2:0.
C010-CODE2:3.0000-CODE3:0.
Array4=(A001-Vision-Vision
B001-Vision-Vision2-vision
C010-Vision3-Vision4-Visio
Array5=(A001-2002 Collection-102-1.00-Large-
foreach item(Array1)
find matching item(s) in array2, get fields,
if COL1 found print COLOR:DESCRIPTION in cell 1
if COL2 found print COLOR:DESCRIPTION in cell 2
find matching lines in array3, print code selections to drop down listbox in cell 3
find matching lines in array4, print SIZE in cell 4, QTY in cell 5
Of course, there could be hundreds of items in array1. Probably no more than 50 items in any of the other 3 arrays.
The items in arrays2,3 & 4 will always be in A,B,C,D order. If I'm searching for A, I could stop when I find no more A's and hold my place if I knew how...nested if statements?
What's the best way to get the fields out of each line when they're delimited by a hyphen? Should I create hashes of some sort? Can I unpack into hashes? I couldn't find much info on packing/unpacking....
What's the best way to handle the processing of so much data? Is it even possible? This is only a small part of the program, but it's got me stumped.
Here's a bit of the actual code I use to unpack data:
sub GetTable1{
my($bits,$message) =@_;
while ($table eq "01"){
$alpha = unpack "x$bits A1", $message;$bits+=1;
$alpha_description = unpack "x$bits A70", $message;$bits+=70;
$table = unpack "x$bits A2", $message;$bits+=2;
push(@Array1,$alpha);
}
return($bits);
}
sub GetTable2{
my($bits,$message) =@_;
while ($table eq "02"){
$alpha = unpack "x$bits A1", $message;$bits+=1;
$column_indicator = unpack "x$bits A4", $message;$bits+=4;
$color_code = unpack "x$bits A3", $message;$bits+=3;
$color_description = unpack "x$bits A70", $message;$bits+=70;
$table = unpack "x$bits A2", $message;$bits+=2;
push(@Array2,"$alpha-$colu
}
return($bits);
}
Help, this is way over my head! And I have 28 tables to parse!
How do you print COLOR:DESCRIPTION in cell 1 ?
isarana,
What exactly do you mean by a cell? Are you referring to columns in a HTML table?
Given the above array, can you pl post how you want the output to look like?
Please explain in detail the exact output that you want.
This will help you get a more accurate answer., faster.
What exactly do you mean by a cell? Are you referring to columns in a HTML table?
Given the above array, can you pl post how you want the output to look like?
Please explain in detail the exact output that you want.
This will help you get a more accurate answer., faster.
Yes , with references you can hadle all types of datasructures: matrices, trees and s.o.
I was going to write you the all the code but now I' ll post just part of it to be sure that that's what you want.
(the third part - ..."find matching lines in array3, print code selections to drop down listbox in cell 3 " ?It's easy to fill that to I didi't wrote it just becouse you have post sub GetTable3)
.....
## the data structure (reference to hash of arrays):
$ref3 = {A=>["CODE1", "CODE2", "CODE3", "CODE4", "CODE5"],
B=>["CODE1", "CODE2"],
C=>["CODE1", "CODE3", "CODE4", "CODE5"],
D=>["CODE2", "CODE3", "CODE5", "CODE6", "CODE7", "CODE8"] };
## the code to print that part of the table
#(jump box in a the third column with the code for the proper item):
print "<TD>";
print '<SELECT name="code">';
foreach $code ( @{$ref3->{$item}} ) {
print "<OPTION>$code</OPTION>";
}
print "</SELECT>";
print "<TD>";
.......
I was going to write you the all the code but now I' ll post just part of it to be sure that that's what you want.
(the third part - ..."find matching lines in array3, print code selections to drop down listbox in cell 3 " ?It's easy to fill that to I didi't wrote it just becouse you have post sub GetTable3)
.....
## the data structure (reference to hash of arrays):
$ref3 = {A=>["CODE1", "CODE2", "CODE3", "CODE4", "CODE5"],
B=>["CODE1", "CODE2"],
C=>["CODE1", "CODE3", "CODE4", "CODE5"],
D=>["CODE2", "CODE3", "CODE5", "CODE6", "CODE7", "CODE8"] };
## the code to print that part of the table
#(jump box in a the third column with the code for the proper item):
print "<TD>";
print '<SELECT name="code">';
foreach $code ( @{$ref3->{$item}} ) {
print "<OPTION>$code</OPTION>";
}
print "</SELECT>";
print "<TD>";
.......
ASKER
Tsvetomir, Not sure what your code prints out, I actually need 4 different drop down lists, maybe I can do something like:
foreach $code ( @{$ref3->{$item}} )
{ if($code eq @Array1[$count]{
print "<OPTION>$code</OPTION>" ;}
}
And actually it's a bit more complicated since the keys in the other arrays could be A1, A2, A3 and all must print in separate sections under title A...
maneshr,
Cell refers HTML table...it has to print out something like this:
__________________________ __________ __________ __
TITLE: A
__________________________ __________ __________ _
A-1
-------------------------- ---------- ---------- ---
1ST BOX 2ND BOX SELECT BOX
RED DESC CODE1
BLU DESC CODE2
BLK DESC CODE3
GRN DESC CODE4
YLW DESC CODE5
MLT DESC
-------------------------- ---------- ---------- --
SIZE1: 245 SIZE2: 1597 SIZE3: 987
__________________________ __________ __________ __
A-2
-------------------------- ---------- ---------- --
1ST BOX 2ND BOX SELECT BOX
RED DESC CODE1
BLU DESC CODE2
BLK DESC CODE3
CODE4
-------------------------- ---------- ---------- --
SIZE1: 245 SIZE2: 1597 SIZE3: 987
__________________________ __________ __________ _________
TITLE: B
__________________________ __________ __________ _________
B-1
-------------------------- ---------- ---------- ---------
1ST BOX 2ND BOX SELECT BOX
RED DESC BLK DESC CODE1
BLK DESC MLT DESC CODE2
-------------------------- ---------- ---------- ------
SIZE1: 467 SIZE2: 849
I'll mock up an HTML page so you can see how it's supposed to look...it would be much easier if I just received all the data for A, then all the data for B, then C etc.
foreach $code ( @{$ref3->{$item}} )
{ if($code eq @Array1[$count]{
print "<OPTION>$code</OPTION>" ;}
}
And actually it's a bit more complicated since the keys in the other arrays could be A1, A2, A3 and all must print in separate sections under title A...
maneshr,
Cell refers HTML table...it has to print out something like this:
__________________________
TITLE: A
__________________________
A-1
--------------------------
1ST BOX 2ND BOX SELECT BOX
RED DESC CODE1
BLU DESC CODE2
BLK DESC CODE3
GRN DESC CODE4
YLW DESC CODE5
MLT DESC
--------------------------
SIZE1: 245 SIZE2: 1597 SIZE3: 987
__________________________
A-2
--------------------------
1ST BOX 2ND BOX SELECT BOX
RED DESC CODE1
BLU DESC CODE2
BLK DESC CODE3
CODE4
--------------------------
SIZE1: 245 SIZE2: 1597 SIZE3: 987
__________________________
TITLE: B
__________________________
B-1
--------------------------
1ST BOX 2ND BOX SELECT BOX
RED DESC BLK DESC CODE1
BLK DESC MLT DESC CODE2
--------------------------
SIZE1: 467 SIZE2: 849
I'll mock up an HTML page so you can see how it's supposed to look...it would be much easier if I just received all the data for A, then all the data for B, then C etc.
isarana,
Where does A-1, A-2, B-1 etc. come from?
i cannot see them in the "array" that you posted at the top. So where do they come from?
Where does A-1, A-2, B-1 etc. come from?
i cannot see them in the "array" that you posted at the top. So where do they come from?
ASKER
maneshr-
I have edited the original question to clarify...I was trying to simplify my question, but I guess I just made it more confusing...
If Array1 has (A,B,C,D)
Then Array2,Array3 and Array4 can have any number of A's, B's, C's, and D's...could have A1 through A100, B1 through B25, C1 through C50, etc. A is the main category, 1-100 would be subcategories.
I have edited the original question to clarify...I was trying to simplify my question, but I guess I just made it more confusing...
If Array1 has (A,B,C,D)
Then Array2,Array3 and Array4 can have any number of A's, B's, C's, and D's...could have A1 through A100, B1 through B25, C1 through C50, etc. A is the main category, 1-100 would be subcategories.
ASKER
mock up of how it should look is at
http://www.dr9.com/furlessleader/
(in this mockup, the edit buttons would open a pop-up to edit the data but non functional now)
As in above edited question, I'm pushing from a stream of data into arrays...don't know if I should be pushing into hashes, or making hashes of hashes, or just keep in arrays and go through Arrays2-5 looking for match for each item in Array1 and print. Since there's potentially hundreds of categories and subcategories, I'm not sure what most efficient is...
http://www.dr9.com/furlessleader/
(in this mockup, the edit buttons would open a pop-up to edit the data but non functional now)
As in above edited question, I'm pushing from a stream of data into arrays...don't know if I should be pushing into hashes, or making hashes of hashes, or just keep in arrays and go through Arrays2-5 looking for match for each item in Array1 and print. Since there's potentially hundreds of categories and subcategories, I'm not sure what most efficient is...
isarana,
".. A is the main category, 1-100 would be subcategories..."
Aha!!Now that makes more sense. That plus the update to the data in the original question is very helpful.
".mock up of how it should look is at http://www.dr9.com/furlessleader/.."
Again, this is very useful too.
Given this wealth of new & useful info, i am in a better position to provide you with a working solution.
I will keep you posted on the progress of the script.
".. A is the main category, 1-100 would be subcategories..."
Aha!!Now that makes more sense. That plus the update to the data in the original question is very helpful.
".mock up of how it should look is at http://www.dr9.com/furlessleader/.."
Again, this is very useful too.
Given this wealth of new & useful info, i am in a better position to provide you with a working solution.
I will keep you posted on the progress of the script.
isarana,
".. http://www.dr9.com/furlessleader/.."
Quick question.
The output of the script will be in a basic HTML table, based on the above URL.
However, you will have to add the colors, captions, images and other elements.
Let me know if this is ok with you.
".. http://www.dr9.com/furlessleader/.."
Quick question.
The output of the script will be in a basic HTML table, based on the above URL.
However, you will have to add the colors, captions, images and other elements.
Let me know if this is ok with you.
isarana,
Another question.
i can see inconsistency in your data for Array5
Array5=(A001-2002 Collection-102-1.00-Large- Soon-20020 310-200204 14,A002-20 02 Collection-001-1.00-Large- Soon-See
Thomas-20010310-20010414,B 001-Cha Cha-002-1.00-Medium-Immedi ately-2001 0310-20010 414,C010-B lah-44-2.0 0-Small-Im mediately- 20010310-2 0020414)
A002 has NOTES (See Thomas) column in it, but none of the others have that column.
Can you please explain that?
Another question.
i can see inconsistency in your data for Array5
Array5=(A001-2002 Collection-102-1.00-Large-
Thomas-20010310-20010414,B
A002 has NOTES (See Thomas) column in it, but none of the others have that column.
Can you please explain that?
ASKER
"...Let me know if this is ok with you."
I appreciate any help at all!
"...A002 has NOTES (See Thomas) column in it, but none of the others have that column."
I again have edited original question so there is a blank field in Array5 for Notes column. I am building a string delimited by hyphens '-', in some cases the field will be blank...my mistake in illustrating Array5.
right now I have something like the following:
foreach $line(@Array1){
($category,$description)=s plit(/-/,$ line);
foreach $line(@Array2){
if($line =~ /$category/ ){
($categorykey,$pri_min_ind ,$color_co de,$descri ption)=spl it(/\,/,$l ine);
print "html table with variables here";
}
}
print "<select>";
foreach $line(@Array3){
if($line =~ /$category/ ){
($categorykey,$code,$quant ity)=split (/-/,$line );
print "<option>$code $quantity</option>";
}
}
}
and so forth. (In reality, $catagory is not just letter A, it's a unique 6 digit code but I'm trying to simplify it here)
The problem with this code is I end up going through all the lines of each array, but since the array is sorted I can stop as soon as I find one that's different. For example, if I'm searching for matches to 'B', I can leave after I get to 'C'. I tried doing a 'last' if there was no match, but same example is if I'm looking for 'B', I come into the array on 'A'. I'd like to be able to come into the array on the first occurance of 'B' and leave after the last occurance of 'B' since there's so many items.
Any thoughts appreciated, thanks!
I appreciate any help at all!
"...A002 has NOTES (See Thomas) column in it, but none of the others have that column."
I again have edited original question so there is a blank field in Array5 for Notes column. I am building a string delimited by hyphens '-', in some cases the field will be blank...my mistake in illustrating Array5.
right now I have something like the following:
foreach $line(@Array1){
($category,$description)=s
foreach $line(@Array2){
if($line =~ /$category/ ){
($categorykey,$pri_min_ind
print "html table with variables here";
}
}
print "<select>";
foreach $line(@Array3){
if($line =~ /$category/ ){
($categorykey,$code,$quant
print "<option>$code $quantity</option>";
}
}
}
and so forth. (In reality, $catagory is not just letter A, it's a unique 6 digit code but I'm trying to simplify it here)
The problem with this code is I end up going through all the lines of each array, but since the array is sorted I can stop as soon as I find one that's different. For example, if I'm searching for matches to 'B', I can leave after I get to 'C'. I tried doing a 'last' if there was no match, but same example is if I'm looking for 'B', I come into the array on 'A'. I'd like to be able to come into the array on the first occurance of 'B' and leave after the last occurance of 'B' since there's so many items.
Any thoughts appreciated, thanks!
isarana,
"..I appreciate any help at all! ..."
Excellent!! i already have a basic code that shows the output in a format very close to HTML.
Would you like to see that first, before i proceed to putting that output in a HTML table?
If yes, then i will expect feedback from you on the output.
Let me know.
".....my mistake in illustrating Array5....."
So is this the correct representation for Array5?
Array5=(A001-2002 Collection-102-1.00-Large- -Soon-2002 0310-20020 414,A002-2 002 Collection-001-1.00-Large- Soon-See Thomas-20010310-20010414,B 001-Cha Cha-002-1.00-Medium--Immed iately--20 010310-200 10414,C010 -Blah-44-2 .00-Small- -Immediate ly--200103 10-2002041 4)
NOTE: the 2 -'s after the size column for A001, B001 & A002
"..I appreciate any help at all! ..."
Excellent!! i already have a basic code that shows the output in a format very close to HTML.
Would you like to see that first, before i proceed to putting that output in a HTML table?
If yes, then i will expect feedback from you on the output.
Let me know.
".....my mistake in illustrating Array5....."
So is this the correct representation for Array5?
Array5=(A001-2002 Collection-102-1.00-Large-
NOTE: the 2 -'s after the size column for A001, B001 & A002
ASKER
"...Would you like to see that first, before i proceed to putting that output in a HTML table?"
Whatever is easiest for you, I can wait unless you'd prefer earlier feedback.
"...So is this the correct representation for Array5?"
"...NOTE: the 2 -'s after the size column for A001, B001 & A002"
Actually, only the 2 -'s after the effective column on A001,B001,C002.
Parsing Array5 would be:
($categorykey,$categorytit le,$mod_nu mber,$quan tity,$size ,$effectiv e,$notes,$ from_year, $to_year)= split(/-/, $line);
so $notes would be blank for A001, prints "See Thomas" for A002, blank for B001 and C010.
I build the array by unpacking:
sub GetTable5{
my($bits,$message) =@_;
while ($table eq "05"){
$categorykey = unpack "x$bits A6", $message;$bits+=6;
$categorytitle = unpack "x$bits A30", $message;$bits+=30;
$mod_number = unpack "x$bits A3", $message;$bits+=3;
$quantity = unpack "x$bits A4", $message;$bits+=4;
$size = unpack "x$bits A10", $message;$bits+=10;
$effective = unpack "x$bits A10", $message;$bits+=10;
$from_year = unpack "x$bits A8", $message;$bits+=8;
$to_year = unpack "x$bits A8", $message;$bits+=8;
$notes = unpack "x$bits A70", $message;$bits+=70;
$table = unpack "x$bits A2", $message;$bits+=2;
push(@Array5,"$categorykey -$category title-$mod _number-$q uantity-$s ize-$effec tive-$note s-$from_ye ar-$to_yea r");
}
return($bits);
}
(Note: although the dates are shown on the screen as 10-March-2002, when I unpack them $from_year is 20020310 and $to_year is20020414, I run them through a date conversion to display. )
Whatever is easiest for you, I can wait unless you'd prefer earlier feedback.
"...So is this the correct representation for Array5?"
"...NOTE: the 2 -'s after the size column for A001, B001 & A002"
Actually, only the 2 -'s after the effective column on A001,B001,C002.
Parsing Array5 would be:
($categorykey,$categorytit
so $notes would be blank for A001, prints "See Thomas" for A002, blank for B001 and C010.
I build the array by unpacking:
sub GetTable5{
my($bits,$message) =@_;
while ($table eq "05"){
$categorykey = unpack "x$bits A6", $message;$bits+=6;
$categorytitle = unpack "x$bits A30", $message;$bits+=30;
$mod_number = unpack "x$bits A3", $message;$bits+=3;
$quantity = unpack "x$bits A4", $message;$bits+=4;
$size = unpack "x$bits A10", $message;$bits+=10;
$effective = unpack "x$bits A10", $message;$bits+=10;
$from_year = unpack "x$bits A8", $message;$bits+=8;
$to_year = unpack "x$bits A8", $message;$bits+=8;
$notes = unpack "x$bits A70", $message;$bits+=70;
$table = unpack "x$bits A2", $message;$bits+=2;
push(@Array5,"$categorykey
}
return($bits);
}
(Note: although the dates are shown on the screen as 10-March-2002, when I unpack them $from_year is 20020310 and $to_year is20020414, I run them through a date conversion to display. )
isarana,
".. I can wait unless you'd prefer earlier feedback...."
i would prefer feedback as early, & as often, as possible to prevent a whole lot of rework late in the game.
"..Parsing Array5 would be:.."
if you dont mind, please do not post any code.
Help me with the data and i will take care of the code.
Thanks :-)
I should have a basic stripped down version of the code here soon.
".. I can wait unless you'd prefer earlier feedback...."
i would prefer feedback as early, & as often, as possible to prevent a whole lot of rework late in the game.
"..Parsing Array5 would be:.."
if you dont mind, please do not post any code.
Help me with the data and i will take care of the code.
Thanks :-)
I should have a basic stripped down version of the code here soon.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
### Part 2 of the Code. Continued from previous comment.
foreach $Array1 (@Array1){
($main,$main_name)=split(/ -/,$Array1 );
foreach $Array2 (@Array2){
if ($Array2=~ /^($main\d+)\-(.*)/){
push(@$1,$2);
$sub_hash{$1}++;
}
}
}
foreach $Array1 (@Array1){
($main,$main_name)=split(/ -/,$Array1 );
print "<B>Category: $main TITLE: $main_name</B>\n";
foreach $Array2 (sort keys %sub_hash){
if ($Array2=~ /^($main)(\d+)/){
print "\tCategory/Seq: $1/$2";
foreach $Array5 (@Array5){
if ($Array5=~ /^$Array2\-/){
@a5_info=split(/-/,$Array5 );
print "\tName: $a5_info[1] MOD:$a5_info[2]\n";
}
}
print "\t\t\tPrimary\n";
print "\t\t",join("\n\t\t",@$Arr ay2),"\n";
foreach $Array3 (@Array3){
if ($Array3=~ /^$Array2\-(.*)/){
$option=$1;
$option=~ s/:/ /g;
@option=split(/-/,$option) ;
print "\t\t\tCode Quantity:\n";
print "\t\t",join("\n\t\t",@opti on),"\n";
}
}
foreach $Array4 (@Array4){
if ($Array4=~ /^$Array2\-(.*)/){
undef (@alpha);
undef (@numeric);
$option=$1;
@option=split(/-/,$option) ;
foreach (@option){
if (/^\d+$/){
push(@numeric,$_);
}else{
push(@alpha,$_);
}
}
print "\t\t\tAdd Fields\n";
print "\t\tAlpha:\t",join("\t",@ alpha),"\n ";
print "\t\tNumeric:\t",join("\t" ,@numeric) ,"\n";
}
}
foreach $Array5 (@Array5){
if ($Array5=~ /^$Array2\-/){
@info=split(/-/,$Array5);
## Convert date from YYYYMMDD to DD-MON-YYYY format.
$info[7]=~ s/(\d{4})(\d{2})(\d{2})/$3 -$fmonths[ $2]-$1/;
$info[8]=~ s/(\d{4})(\d{2})(\d{2})/$3 -$fmonths[ $2]-$1/;
print qq{\t\tQuantity: $info[3]\t\tSize: $info[4]
\t\tEffective: $info[5]
\t\tNotes: $info[6]
\t\tAvailable Dates: $info[7] \t to:\t $info[8]\n};
}
}
} ## End of Hash' if
}
}
foreach $Array1 (@Array1){
($main,$main_name)=split(/
foreach $Array2 (@Array2){
if ($Array2=~ /^($main\d+)\-(.*)/){
push(@$1,$2);
$sub_hash{$1}++;
}
}
}
foreach $Array1 (@Array1){
($main,$main_name)=split(/
print "<B>Category: $main TITLE: $main_name</B>\n";
foreach $Array2 (sort keys %sub_hash){
if ($Array2=~ /^($main)(\d+)/){
print "\tCategory/Seq: $1/$2";
foreach $Array5 (@Array5){
if ($Array5=~ /^$Array2\-/){
@a5_info=split(/-/,$Array5
print "\tName: $a5_info[1] MOD:$a5_info[2]\n";
}
}
print "\t\t\tPrimary\n";
print "\t\t",join("\n\t\t",@$Arr
foreach $Array3 (@Array3){
if ($Array3=~ /^$Array2\-(.*)/){
$option=$1;
$option=~ s/:/ /g;
@option=split(/-/,$option)
print "\t\t\tCode Quantity:\n";
print "\t\t",join("\n\t\t",@opti
}
}
foreach $Array4 (@Array4){
if ($Array4=~ /^$Array2\-(.*)/){
undef (@alpha);
undef (@numeric);
$option=$1;
@option=split(/-/,$option)
foreach (@option){
if (/^\d+$/){
push(@numeric,$_);
}else{
push(@alpha,$_);
}
}
print "\t\t\tAdd Fields\n";
print "\t\tAlpha:\t",join("\t",@
print "\t\tNumeric:\t",join("\t"
}
}
foreach $Array5 (@Array5){
if ($Array5=~ /^$Array2\-/){
@info=split(/-/,$Array5);
## Convert date from YYYYMMDD to DD-MON-YYYY format.
$info[7]=~ s/(\d{4})(\d{2})(\d{2})/$3
$info[8]=~ s/(\d{4})(\d{2})(\d{2})/$3
print qq{\t\tQuantity: $info[3]\t\tSize: $info[4]
\t\tEffective: $info[5]
\t\tNotes: $info[6]
\t\tAvailable Dates: $info[7] \t to:\t $info[8]\n};
}
}
} ## End of Hash' if
}
}
ASKER
maneshr,
"...* Verify if the data in the Array is accurate and exactly like you want it."
PERFECT!
"... * Verify that output of the script is close to the HTML page that you want."
I added my HTML code for table formatting, VERY NICE!
"... * Verify that the script works fine on your server."
1) I had trouble with the 2nd foreach loop
foreach $Array2 (@Array2){
if ($Array2=~ /^($main\d+)\-(.*)/){
push(@$1,$2);
$sub_hash{$1}++;
}
}
where it didn't like "push(@$1,$2)" so I changed to" push(@1,$2)" and it compiled.
Can you explain what this part of the code does?
2) print "\t\t\tPrimary\n";
print "\t\t",join("\n\t\t",@$Arr ay2),"\n";
gives me no values, if I change it to
print "\t\t",join("\n\t\t",@Arra y2),"\n";
it prints out the entire line. Is it because I made the change above?
Thanks for all your effort!
"...* Verify if the data in the Array is accurate and exactly like you want it."
PERFECT!
"... * Verify that output of the script is close to the HTML page that you want."
I added my HTML code for table formatting, VERY NICE!
"... * Verify that the script works fine on your server."
1) I had trouble with the 2nd foreach loop
foreach $Array2 (@Array2){
if ($Array2=~ /^($main\d+)\-(.*)/){
push(@$1,$2);
$sub_hash{$1}++;
}
}
where it didn't like "push(@$1,$2)" so I changed to" push(@1,$2)" and it compiled.
Can you explain what this part of the code does?
2) print "\t\t\tPrimary\n";
print "\t\t",join("\n\t\t",@$Arr
gives me no values, if I change it to
print "\t\t",join("\n\t\t",@Arra
it prints out the entire line. Is it because I made the change above?
Thanks for all your effort!
isarana,
"..PERFECT!..."
Excellent!!
".. VERY NICE! ..."
Great news!!!
".. I had trouble with the 2nd foreach loop.."
What exactly do you mean by trouble? Do you mean you got an error in Perl OR you could not understand that line of code?
The entire for loop MUST remain as-is & should not be modified.
I will be happy to explain what it means, as long as you keep it the way it is.
Let me know.
".. it prints out the entire line. Is it because I made the change above?..."
I am sure it is due to the change you made, cause even now the script works just fine with the original code in it.
"..PERFECT!..."
Excellent!!
".. VERY NICE! ..."
Great news!!!
".. I had trouble with the 2nd foreach loop.."
What exactly do you mean by trouble? Do you mean you got an error in Perl OR you could not understand that line of code?
The entire for loop MUST remain as-is & should not be modified.
I will be happy to explain what it means, as long as you keep it the way it is.
Let me know.
".. it prints out the entire line. Is it because I made the change above?..."
I am sure it is due to the change you made, cause even now the script works just fine with the original code in it.
ASKER
maneshr,
"...What exactly do you mean by trouble? Do you mean you got an error in Perl OR you could not understand that line of code?"
I get the following compile error in Perl:
Number found where operator expected at testcost.cgi line 51, near "@$1"
(Missing operator before 1?)
syntax error at testarrays.cgi line 51, near "@$1"
Execution of testarrays.cgi aborted due to compilation errors.
"...What exactly do you mean by trouble? Do you mean you got an error in Perl OR you could not understand that line of code?"
I get the following compile error in Perl:
Number found where operator expected at testcost.cgi line 51, near "@$1"
(Missing operator before 1?)
syntax error at testarrays.cgi line 51, near "@$1"
Execution of testarrays.cgi aborted due to compilation errors.
isarana,
"..Number found where operator expected at testcost.cgi line 51, near "@$1".."
Are you using the -w switch? Are you using the strict module?
Can you pl. post the >exact< code that you are using here?
Let me know.
"..Number found where operator expected at testcost.cgi line 51, near "@$1".."
Are you using the -w switch? Are you using the strict module?
Can you pl. post the >exact< code that you are using here?
Let me know.
ASKER
maneshr,
Server has this version of perl:
This is perl, version 5.003 with EMBED
Server has this version of perl:
This is perl, version 5.003 with EMBED
isarana,
"..This is perl, version 5.003 with EMBED ..."
i am using perl, version 5.005_02 built for sun4-solaris on my server.
Meanwhile, in addition to the above questions, let me know what OS you are on.
"..This is perl, version 5.003 with EMBED ..."
i am using perl, version 5.005_02 built for sun4-solaris on my server.
Meanwhile, in addition to the above questions, let me know what OS you are on.
ASKER
maneshr,
Here's exact code:
#!/usr/local/bin/perl
unshift(@INC, '.');
use CGI;
MAIN: {
$query = new CGI;
print $query->header;
print $query->start_html;
@fmonths =('Dummy','Jan','Feb','Mar ','Apr','M ay','Jun', 'Jul','Aug ','Sep','O ct','Nov', 'Dec');
@Array1=('A-Group A','B-2002 Fabrication','C-2003 Fabrication');
@Array2=('A001-PRI-RED-DES CRIPTION', 'A001-PRI- BLU-DESCRI PTION','A0 01-PRI-BLK -DESCRIPTI ON','A001- PRI-GRN-DE SCRIPTION' ,'A001-PRI -YLW-DESCR IPTION','A 001-PRI-ML T-DESCRIPT ION','A002 -PRI-RED-D ESCRIPTION ','A002-PR I-BLK-DESC RIPTION',' A002-PRI-B LU-DESCRIP TION','B00 1-PRI-RED- DESCRIPTIO N','B001-P RI-BLK-DES CRIPTION', 'B001-MIN- BLK-DESCRI PTION','B0 01-MIN-MLT -DESCRIPTI ON','C010- COL1-RED-D ESCRIPTION ','C010-CO L1-YLW-DES CRIPTION', 'C010-PRI- TRQ-DESCRI PTION','C0 10-MIN-BLK -DESCRIPTI ON','C010- MIN-MLT-DE SCRIPTION'
);
@Array3=('A001-CODE1:3.000 0-CODE2:0. 0000-CODE3 :3.0000-CO DE4:12.250 0-CODE5:4. 4400','A00 2-CODE1:3. 0000-CODE2 :0.0000-CO DE3:3.0000 -CODE4:12. 2500','B00 1-CODE1:3. 0000-CODE2 :0.0000',' C010-CODE2 :3.0000-CO DE3:0.0000 -CODE4:1.0 000-CODE5: 0.5000-COD E6:0.2500- CODE8:4.06 00-CODE12: 3.3600'
);
@Array4=('A001-Vision-Visi on2-Vision 3',
'A002-Vision-Vision2-999',
'B001-Vision-Vision2-visio n3-Vision4 ',
'C010-Vision3-Vision4-Visi on8'
);
@Array5=('A001-2002 Collection-102-1.00-Large- Soon--2002 0310-20020 414',
'A002-2002 Collection-001-1.00-Large- Soon-See Thomas-20010310-20010414',
'B001-Cha Cha-002-1.00-Medium-Immedi ately--200 10310-2001 0414',
'C010-Blah-44-2.00-Small-I mmediately --20010310 -20020414'
);
print "<table border=1 bgcolor=#CCCCFF>";
foreach $Array1 (@Array1){
($main,$main_name)=split(/ -/,$Array1 );
foreach $Array2 (@Array2){
if ($Array2=~ /^($main\d+)\-(.*)/){
push(@$1,$2);
$sub_hash{$1}++;
}
}
}
foreach $Array1 (@Array1){
($main,$main_name)=split(/ -/,$Array1 );
print "<tr><td colspan=3 bgcolor=#000066>
<font color=white><B>CATEGORY:
$main
<B>TITLE: $main_name</B></font></td> </tr>";
foreach $Array2 (sort keys %sub_hash){
if ($Array2=~ /^($main)(\d+)/){
print "<tr><td colspan=3 bgcolor=#CCCCCC>
Category/Seq: $1/$2 ";
foreach $Array5 (@Array5){
if ($Array5=~ /^$Array2\-/){
@a5_info=split(/-/,$Array5 );
print "Name: $a5_info[1]
MOD:$a5_info[2]</td></tr>" ;
}
}
print "<tr><td>Primary:";
print "<br>",join("<br>",@$Array 2),"</td>" ;
foreach $Array3 (@Array3){
if ($Array3=~ /^$Array2\-(.*)/){
$option=$1;
$option=~ s/:/ /g;
@option=split(/-/,$option) ;
print "<td>Code Quantity:</td><td>";
print " ",join("<br>",@opti on),"</td> </tr>";
}
}
foreach $Array4 (@Array4){
if ($Array4=~ /^$Array2\-(.*)/){
undef (@alpha);
undef (@numeric);
$option=$1;
@option=split(/-/,$option) ;
foreach (@option){
if (/^\d+$/){
push(@numeric,$_);
}else{
push(@alpha,$_);
}
}
print "<tr><td>Add Fields</td></tr>";
print
"<tr><td>Alpha:",join("<br >",@alpha) ,"</td></t r>";
print
"<tr><td>Numeric:",join("< br>",@nume ric),"</td ></tr>";
}
}
foreach $Array5 (@Array5){
if ($Array5=~ /^$Array2\-/){
@info=split(/-/,$Array5);
## Convert date from YYYYMMDD to DD-MON-YYYY format.
$info[7]=~ s/(\d{4})(\d{2})(\d{2})/$3 -$fmonths[ $2]-$1/;
$info[8]=~ s/(\d{4})(\d{2})(\d{2})/$3 -$fmonths[ $2]-$1/;
print
qq{<tr><td>Quantity:$info[ 3]<br>Size : $info[4]
<br>Effective: $info[5] <br>Notes:
$info[6]
<br>Available Dates: $info[7] to:
$info[8]</td></tr>};
}
}
} ## End of Hash' if
}
}
print "</table>";
print $query->end_html;
}
Here's exact code:
#!/usr/local/bin/perl
unshift(@INC, '.');
use CGI;
MAIN: {
$query = new CGI;
print $query->header;
print $query->start_html;
@fmonths =('Dummy','Jan','Feb','Mar
@Array1=('A-Group A','B-2002 Fabrication','C-2003 Fabrication');
@Array2=('A001-PRI-RED-DES
);
@Array3=('A001-CODE1:3.000
);
@Array4=('A001-Vision-Visi
'A002-Vision-Vision2-999',
'B001-Vision-Vision2-visio
'C010-Vision3-Vision4-Visi
);
@Array5=('A001-2002 Collection-102-1.00-Large-
'A002-2002 Collection-001-1.00-Large-
'B001-Cha Cha-002-1.00-Medium-Immedi
'C010-Blah-44-2.00-Small-I
);
print "<table border=1 bgcolor=#CCCCFF>";
foreach $Array1 (@Array1){
($main,$main_name)=split(/
foreach $Array2 (@Array2){
if ($Array2=~ /^($main\d+)\-(.*)/){
push(@$1,$2);
$sub_hash{$1}++;
}
}
}
foreach $Array1 (@Array1){
($main,$main_name)=split(/
print "<tr><td colspan=3 bgcolor=#000066>
<font color=white><B>CATEGORY:
$main
<B>TITLE: $main_name</B></font></td>
foreach $Array2 (sort keys %sub_hash){
if ($Array2=~ /^($main)(\d+)/){
print "<tr><td colspan=3 bgcolor=#CCCCCC>
Category/Seq: $1/$2 ";
foreach $Array5 (@Array5){
if ($Array5=~ /^$Array2\-/){
@a5_info=split(/-/,$Array5
print "Name: $a5_info[1]
MOD:$a5_info[2]</td></tr>"
}
}
print "<tr><td>Primary:";
print "<br>",join("<br>",@$Array
foreach $Array3 (@Array3){
if ($Array3=~ /^$Array2\-(.*)/){
$option=$1;
$option=~ s/:/ /g;
@option=split(/-/,$option)
print "<td>Code Quantity:</td><td>";
print " ",join("<br>",@opti
}
}
foreach $Array4 (@Array4){
if ($Array4=~ /^$Array2\-(.*)/){
undef (@alpha);
undef (@numeric);
$option=$1;
@option=split(/-/,$option)
foreach (@option){
if (/^\d+$/){
push(@numeric,$_);
}else{
push(@alpha,$_);
}
}
print "<tr><td>Add Fields</td></tr>";
"<tr><td>Alpha:",join("<br
"<tr><td>Numeric:",join("<
}
}
foreach $Array5 (@Array5){
if ($Array5=~ /^$Array2\-/){
@info=split(/-/,$Array5);
## Convert date from YYYYMMDD to DD-MON-YYYY format.
$info[7]=~ s/(\d{4})(\d{2})(\d{2})/$3
$info[8]=~ s/(\d{4})(\d{2})(\d{2})/$3
qq{<tr><td>Quantity:$info[
<br>Effective: $info[5] <br>Notes:
$info[6]
<br>Available Dates: $info[7] to:
$info[8]</td></tr>};
}
}
} ## End of Hash' if
}
}
print "</table>";
print $query->end_html;
}
ASKER
maneshr,
More info:
This is perl, version 5.003 with EMBED
built under solaris at May 4 1997 13:48:18
+ suidperl security patch
Copyright 1987-1996, Larry Wall
Running on Unix server
More info:
This is perl, version 5.003 with EMBED
built under solaris at May 4 1997 13:48:18
+ suidperl security patch
Copyright 1987-1996, Larry Wall
Running on Unix server
ASKER
maneshr,
Solaris 2.5.1 Unix Server...the server is in England, I'm going to try it on a server here in the States and see if it makes any difference.
Solaris 2.5.1 Unix Server...the server is in England, I'm going to try it on a server here in the States and see if it makes any difference.
ASKER
No, same error.
isarana,
"..see if it makes any difference...."
What is the Perl version of this US based server?
Let me know.
"..see if it makes any difference...."
What is the Perl version of this US based server?
Let me know.
ASKER
maneshr,
Both servers are Unix Solaris with
This is perl, version 5.003 with EMBED
built under solaris at May 4 1997 13:48:18
+ suidperl security patch
I'm not sure what the suidperl security patch is, and if that's interfering.
Both servers are Unix Solaris with
This is perl, version 5.003 with EMBED
built under solaris at May 4 1997 13:48:18
+ suidperl security patch
I'm not sure what the suidperl security patch is, and if that's interfering.
isarana,
"..Both servers are Unix Solaris with .."
Hmm!!! this confirms my fears about the Perl version being at the root of this problem.
Let me work on a round-a-bout way to address this.
NOTE: This method will not be as flexible as the previous method.
"..Both servers are Unix Solaris with .."
Hmm!!! this confirms my fears about the Perl version being at the root of this problem.
Let me work on a round-a-bout way to address this.
NOTE: This method will not be as flexible as the previous method.
isarana,
So far i have not been able to find a single, reliable workaround to the problem.
Is it possible for you to upgrade the Perl version on your servers, or host on a server that has the recent version?
Let me know.
So far i have not been able to find a single, reliable workaround to the problem.
Is it possible for you to upgrade the Perl version on your servers, or host on a server that has the recent version?
Let me know.
ASKER
maneshr,
I did find a server with version 5.005 and lo and behold, it works perfectly!!! My program is supposed to switch to the server with 5.005 within the month, so I'll have to wait until then....
Thanks for all your help, points coming to you.
I did find a server with version 5.005 and lo and behold, it works perfectly!!! My program is supposed to switch to the server with 5.005 within the month, so I'll have to wait until then....
Thanks for all your help, points coming to you.
isarana,
"..I did find a server with version 5.005 and lo and behold, it works perfectly!!! ...."
Excellent!!! That is good news indeed!!
Glad to know you got the solution you were looking for.
"..I did find a server with version 5.005 and lo and behold, it works perfectly!!! ...."
Excellent!!! That is good news indeed!!
Glad to know you got the solution you were looking for.