M
Mike Flannigan
I have some code below that works fine. It finds duplicates on
one field and marks them as duplicates. But I'd like to also
remove all quotes (") from the file also. The 3 commented out
lines are some of my attempts at doing this. They all give errors
like:
"Applying substitution (s///) to @array will act on scalar
(@array) at . . . line 31. Can't modify private array in
substitution (s///0 at . . . line 31 near "s/"//s;"
I can get this done outside this script, but was wondering if
there is an easy way to do this inside this script.
Mike Flannigan
________________________________
use strict;
use warnings;
my $old_file = 'bb1.txt';
my $new_file = 'bb2.txt';
open WPIN, $old_file or die "Cannot open $old_file: $!";
my @data = map [ split /\t/, $_, 6 ], <WPIN>;
close WPIN;
#@data =~ s/"//gs;
open WPOUT, ">", $new_file or die "$0: open $new_file: $!";
my %saw;
for my $line (@data) {
# $line =~ tr/"//d;
if ($saw{ $line->[ 4 ] }++) {
print "found dup\n";
$line->[ 0 ] .= "+++++";
}
# @$line =~ tr/"//d;
print WPOUT join("\t" => @$line);
}
close WPOUT or warn "$0: close $new_file: $!";
__END__
DATA
Canoe Valley Grapevine Hills Brewster valley 292756N1030910W "TX, Texas"
Cantrell Mountain Hacienda Uvalde summit 291204N0995833W "TX, Texas"
Casa Grande Peak The Basin Brewster summit 291603N1031711W "TX, Texas"
Cassiano Park San Antonio West Bexar park 292449N0983144W "TX, Texas"
Cedar Grove Cemetery Sanderson Terrell cemetery 300754N1022309W "TX,
Texas"
Centeno Park San Antonio West Bexar park 292513N0983232W "TX, Texas"
one field and marks them as duplicates. But I'd like to also
remove all quotes (") from the file also. The 3 commented out
lines are some of my attempts at doing this. They all give errors
like:
"Applying substitution (s///) to @array will act on scalar
(@array) at . . . line 31. Can't modify private array in
substitution (s///0 at . . . line 31 near "s/"//s;"
I can get this done outside this script, but was wondering if
there is an easy way to do this inside this script.
Mike Flannigan
________________________________
use strict;
use warnings;
my $old_file = 'bb1.txt';
my $new_file = 'bb2.txt';
open WPIN, $old_file or die "Cannot open $old_file: $!";
my @data = map [ split /\t/, $_, 6 ], <WPIN>;
close WPIN;
#@data =~ s/"//gs;
open WPOUT, ">", $new_file or die "$0: open $new_file: $!";
my %saw;
for my $line (@data) {
# $line =~ tr/"//d;
if ($saw{ $line->[ 4 ] }++) {
print "found dup\n";
$line->[ 0 ] .= "+++++";
}
# @$line =~ tr/"//d;
print WPOUT join("\t" => @$line);
}
close WPOUT or warn "$0: close $new_file: $!";
__END__
DATA
Canoe Valley Grapevine Hills Brewster valley 292756N1030910W "TX, Texas"
Cantrell Mountain Hacienda Uvalde summit 291204N0995833W "TX, Texas"
Casa Grande Peak The Basin Brewster summit 291603N1031711W "TX, Texas"
Cassiano Park San Antonio West Bexar park 292449N0983144W "TX, Texas"
Cedar Grove Cemetery Sanderson Terrell cemetery 300754N1022309W "TX,
Texas"
Centeno Park San Antonio West Bexar park 292513N0983232W "TX, Texas"