Hi all. I'm new at perl. Just using it to strip some fields of a comma-delimited file. This code works when printing to the screen, but not to a file. Any help would be much appreciated.
#!/usr/bin/perl -w
#STRIPS last 5 fields off a comma-delimited file
#OPENS FILE
open (DI, ">DIAMOND20070126.txt") or die "I couldn't get at it";
# GRABS LINE
for $line(<DI>) {
# TOKENIZES LINE
@tokenized = split(/,/,$line);
# POPS END FIELDS OFF
for $i (17 .. 21){
pop(@tokenized);
}
#PUSHES REMAINING FIELDS INTO NEW ARRAY
@joined = join(',',@tokenized);
push(@trimmed,@joined);
}
#WRITES NEW ARRAY TO FILE
for $i (1 .. 20) {
print DI "@trimmed[$i]\n";
}
close DI;
#!/usr/bin/perl -w
#STRIPS last 5 fields off a comma-delimited file
#OPENS FILE
open (DI, ">DIAMOND20070126.txt") or die "I couldn't get at it";
# GRABS LINE
for $line(<DI>) {
# TOKENIZES LINE
@tokenized = split(/,/,$line);
# POPS END FIELDS OFF
for $i (17 .. 21){
pop(@tokenized);
}
#PUSHES REMAINING FIELDS INTO NEW ARRAY
@joined = join(',',@tokenized);
push(@trimmed,@joined);
}
#WRITES NEW ARRAY TO FILE
for $i (1 .. 20) {
print DI "@trimmed[$i]\n";
}
close DI;