|
|
sybperl-l Archive
Up Prev Next
From: "Klein, Shoshana R" <Shoshana dot Klein at gs dot com>
Subject: using map to cut out a number of rows from a file
Date: Nov 22 2000 10:22PM
Below I wrote code that surprisingly works. I'd like to add one more command
to remove n number of header rows from a file.
Unfortunately I'm not aware of a command that does that.
I'd appreciate if you could give me that command. I don't want to have to
read in the file andbypass the first 2 header rows, I'd like to
add it to the list of map commands below.
By the way, there is a reason to my madness, I need to Generically read in
many different files and based on file names and layout descriptions stored
in our database & manipulate the data according to specific needs.
Below I have code that splits a file based on a split character stored
in our database and isolates a particular column of data (also derived from
a database field) and then further splits that column based on a column
deimiter stored in our
database. Then in step 2 I sort that array and in step Three I get rid of
duplicate items.
I'd like to add a step into STEP 1 to remove the first 2 or n number of rows
(The HEADER ROWS)
STEP 1
@array2=
#map { (split /,/);} #
splits values within a column by comma
map { (split /$split_delim/);} # splits
values within a column by the delimiter character given
#map { (split /:/)[3]; } #
isolates the 4th element only
map { (split /$field_delim/)[$col_delim_num]; } # isolates the nth
element
map { $_, (s/\"//g); } #
remove double quotes
map {$_,(chomp);} # remove
new line character
****** I'd like to drop the first 2 rows of the file here*******
;
STEP 2
@array3=
#sort array
map { $_->[0]}
sort { $a->[1] cmp $b->[1]}
#map {[$_, (split /,/)] }
map {[$_, (split /$split_delim/)] }
@array2;
STEP 3
@array3 = ("",@array3); @array3= kill_duplicates(@array3);
@array3 = sort {$a <=> $b} @array3;
#extract distinct items
print " array3 sorted @array3 \n";
|