#!/usr/local/bin/perl -w
#===========================================================
# Get/Organize Parm & Variables
#===========================================================
if ($ARGV[0]) { $parm = $ARGV[0];}
else { print "Prameter missing.... \n";
die "Program Terminated... \n";
}
chomp($parm);
@parm_list = split(/\|/,$parm);
$a = @parm_list;
if ($a != 2) { die "Number of parameters not satisfied\n";}
else { ($first_item_num,
$last_item_num)= @parm_list;
}
$first_item_num =~ s/^\s+|\s+$//g; #trim
$last_item_num =~ s/^\s+|\s+$//g;
$seq = 0; # create a variable
%cat_key_hash =(); # init hashes
%cat_dtl_hash =();
#=======================================================================================#
# M A I N P R O G R A M
#=======================================================================================#
open_files();
load_hash();
print_list();
close_files();
#=======================================================================================#
# E N D O F P R O G R A M #
#=======================================================================================#
sub open_files{
$datadir = "/dir";
open (INP, "<$datadir/$flat_file")|| die "Couldn't open Flat file, $!\n";
open (OUTRPT, ">$datadir/$file_rpt");
}
#=======================================================================================#
sub load_hash{
while(<INPEDI>) {
chomp;
$inp_str = $_ ;
## Let inp_str =>CAT_NUM DESCRIPTION PRICE
($inp_cat_num,
$inp_desc,
$inp_price) = split(/\|/,$inp_str);
if ($cat_key_hash{$inp_cat_num}) { $seq = $cat_key_hash{$f_cust_po}
$seq ++
($cat_key_hash{$inp_cat_num}) = $seq;
# concatenate sequence number with catalog number
# to make the key to be unique
($cat_dtl_hash{$inp_cat_num.$seq}) = $inp_str;
}
elsif
if ($cat_key_hash{$inp_cat_num}) { $seq = 1;
($cat_key_hash{$inp_cat_num}) = $seq;
($cat_dtl_hash{$inp_cat_num.$seq}) = $inp_str;
}
} #end while
} #end sub
#=======================================================================================#
sub print_list{
# order your key list
@key_list = sort {$a <=> $b} (keys %cat_key_hash);
foreach $key (@klist){
if (( $key >= first_cat_num) and ( $key <= $last_cat_num))
{ $seq = $cat_key_hash{$key}; #find how many records for that catalog#
for (i=1, i <=$seq, i++) { #print all the details
# You may split and format the output
$dtl_key = $key.$i; # create key
print "$cat_dtl_hash{$dtl_key}\n";
} # end for
} #end if
} # end print_list
#=======================================================================================#
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.