I need to make a separate line for each category so each row will consist of one part number and one category. This will then be output as a table in PHP/MySQL. The parts will be called from the table according to the category. It will result in a parts lookup on a web site.
Example:
part number categories
21030 3005 3006 3007
Question: What is the Perl script for me to change the above to the following:
21030 3005
21030 3006
21030 3007
I know Perl won't work on Excel files. Should I export it as CSV or Tab separated? I know nothing about Perl, unfortunately, but I do remember that it is good at the above sort of thing, and want to save myself a week or more of effort.
Would PHP be a better tool for this job?
Regards,
Steve
[perl] my ( $part, $categories) = split( /,/, lc); [/perl]
I'm not too hot on database structure with all that linking. When I do it I just give everything an ID and sort it out myself! :D
I'm sure one of the other guys will help you out with that one.
[edited by: Dabrowski at 7:44 pm (utc) on Sep. 22, 2008]
Thanks!
use strict;
open( CSV, "part_info.csv") ¦¦ die "Open file failed!\n";
my @lines_in_csv = <CSV>;
close( CSV);
my $parts;
foreach( @lines_in_csv) {
my ( $part, $categories) = split( /,/, lc);
$parts -> {$part} = [ split( /\s+/, $categories)];
}
open( NEWCSV, ">new_part_info.csv") ¦¦ die "File open failed\n";
foreach my $partno ( sort keys( %$parts)) {
foreach my $category ( sort @{ $parts -> {$partno}}) {
## Now you can do something with $partno and $category
## $partno is your original part number
## $category will change each time singularly while $partno stays the same
print "$partno - $category\n";
print NEWCSV "$partno,$category\n";
}
}