Removing duplicate IDs
0 answers - 1763 bytes -

macromedia wrote:
Hi,
Hello,
I added your changes to my script but now I get no output. See code below:
Syntax: perl test.pl in.srt out.srt
#!/usr/local/bin/perl
require 5.000;
my %tags = ();
my %seen;
my $input = $ARGV[0];
my $output = $ARGV[1];
open (FILE, "< $input") or die "cannot open $input: $!\n";
open (UTPUTFILE, "$output");
chomp(my @lines = <FILE>);
my @chars = grep !$seen{$[1]}++,
map {
my ($id) = m{<a id=(\w+)>};
[ $_, $id, scalar $id =~ /^\d+$/ ];
}@lines;
map $[0],
sort {
$b->[2] <=$a->[2]
or
( $a->[2] ? $a->[1] <=$b->[1] : $a->[1] cmp $b->[1] )
or
$a->[0] cmp $b->[0]
grep !$seen{$[1]}++,
map {
my ( $id ) = /<a id=(\w+)>/;
[ $_, $id, scalar $id =~ /^\d+$/ ];
print UTPUTFILE ;
close UTPUTFILE;
close FILE;
If you had made the changes I indicated then your program should look
something like:
#!/usr/local/bin/perl
require 5.000;
my %tags = ();
my %seen;
my $input = $ARGV[0];
my $output = $ARGV[1];
open (FILE, "< $input") or die "cannot open $input: $!\n";
open (UTPUTFILE, "$output") or die "cannot open $output: $!\n";
my @chars = grep !$seen{$[1]}++, map {
my ($id) = m{<a id=(\w+)>};
[ $_, $id, scalar $id =~ /^\d+$/ ];
} @lines;
my @sorted_chars = sort {
$b->[2] <=$a->[2]
or
($a->[2] ? $a->[1] <=$b->[1] : $a->[1] cmp $b->[1])
or
$a->[0] cmp $b->[0]
} @chars;
my @result = map { $[0] } @sorted_chars;
print UTPUTFILE @result;
close UTPUTFILE;
close FILE;
John