Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Help with perl, checking code (longish post)

2 views
Skip to first unread message

Shanna

unread,
Jul 26, 2006, 2:52:37 PM7/26/06
to
Hello,

I am wondering if someone could please take a look at this code to make

sure I am on the right track. I am teaching perl to myself and would
just like to make sure I am on the right path with what I have so far.
My code is suppose to take an input file check a one field to make sure

it is populated, then if it is check to make sure the required fields
for the given action are populated. If everything is correct then it
is to write the record to an Excel file (which I don't have the code
for this yet as I am trying to find how to do this).


Here is my code as it sits now:


#!/usr/bin/perl


use strict;
use warnings;


my $vendorFile = $ARGV[0];


open(my $VendorFile, $InFile) || die "Can't open file '$inFile': $!";


my @correctColumnName = (
"Key_Number", # 0
"Ferguson_Code", # 1
"Code_Change", # 2
"Manufacturer_Code", # 3
"Action", # 4
"Block_ID", # 5
"Vendor", # 6
"Block_Header", # 7
"Block_SubHeader", # 8
"B2B_Description", # 9
"Block_Image_File_Name", #10
"Line_Item_Description", # 11
"Installation_Instructions_PDF_File_Name", # 12
"Product_Specifications_PDF_File_Name", # 13
"Parts_Breakdown_PDF_File_Name", # 14
"Product_Image_File_Name" # 15
"Warranty_PDF" #16
"Model_Name" #17
"Size" #18
"Attribute_1" #19
"Attribute_2" #20
"Attribute_3" #21
"Attribute_4" #22
"Attribute_5" #23
"Required_Accessories" #24
"Optional_Accessories" #25
"
);


while (<VENDORFILE>) {
chomp;
my @linedata = split '\t';
my ($fieldname, $fieldPosition);
my $i;


foreach $i (0 .. $#linedata) {
$linedata[$i] = trimString($lineData[$i]);
}
if ($. == 1) {
my @columnName = split '\t';
my $i = 0;


foreach $i (0 .. $#correctColumnName) {
if ($correctColumnName[$i] ne $columnName[$i] {
die "Error: Columns are out of order
\n\t($columnName[$i] should be
$correctColumnName[$i]\n\t"; }
else {
$columnPosition{$correctColumnName[$i]} = $i; }
}
} else {
$lineCount++;
if (defined($linedata[6]) && $linedata[6] =~ /\w/) {
my $vendorname = $linedata[6];
$vendorname =~ tr/[a-z]/[A-Z]/;
if (!defined($vendorxlations{$vendorname})) {
print "Error on line $.: Vendor Name $linedata[6] not
found in
Vendorinput.txt\n":
$errorcount++;
}
}
if (!defined($linedata[4] || !$linedata[4] =~ /\w/) {

print "Error on line $.: No action in the Action
column\n";
} elsif ($linedata[4] eq "NEWPRODUCT") {
foreach $fieldname (@correctColumnName[0, 1,
4, 6]) {
elsif ($linedata[4] eq "DEACTIVEATEPROD" ||
"DELETEPROD") {
foreach $fieldname (@correctColumnName[2])}


Thank you for any comments you provide! Have a wonderful day!
Shanna

0 new messages