EMSDN.COM
Question 'Omitting duplicate IDs in output file' on 'Perl'
Tag:
Perl, Perl
/
Home
Guide
Back To HomePage
Submit My Question
Free Register
Join MailList
Development
Development
Networking
Networking
Java
Java
BSD
BSD
KDE
KDE
Apache
Apache
Windows
Windows
Security
Security
Standards
Standards
Perl
NAVIGATION
Free Register
Join MailList
Submit Question
CATEGORIES
Perl
REFERRENCE
If you have some good idea, Cilck and mail to us please...
LINKS
Home
»
Perl
Omitting duplicate IDs in output file
0 answers - 1860 bytes -
I need some help. I can't figure out how to omit duplicate IDs in the output file.
#!/usr/local/bin/perl
require 5.000;
my %tags = ();
my $input = $ARGV[0];
my $output = $ARGV[1];
open (FILE, "< $input") or die "cannot open $input: $!\n";
open (UTPUTFILE, "$output") or die "cannot open $input: $!\n";
chomp(my @lines = <FILE>);
my @chars = 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 "$_\n" for @result;
close UTPUTFILE;
close FILE;
IN.SRT
<a id=ab>
<a id=1>
<a id=ab>
<a id=15>
<a id=2>
<a id=fa>
<a id=5>
<a id=13>
<a id=20>
<a id=fa>
<a id=3>
<a id=7>
<a id=5>
<a id=21>
<a id=2>
<a id=bc>
<a id=22>
<a id=15>
<a id=fa>
<a id=25>
<a id=8>
<a id=24>
<a id=2>
<a id=ab>
<a id=16>
<a id=15>
<a id=bc>
UT.SRT
<a id=1>
<a id=2>
<a id=2>
<a id=2>
<a id=3>
<a id=5>
<a id=5>
<a id=7>
<a id=8>
<a id=13>
<a id=15>
<a id=15>
<a id=15>
<a id=16>
<a id=20>
<a id=21>
<a id=22>
<a id=24>
<a id=25>
<a id=ab>
<a id=ab>
<a id=ab>
<a id=bc>
<a id=bc>
<a id=fa>
<a id=fa>
<a id=fa>
Re: Omitting duplicate IDs in output file
max
4000
letters.
Your nickname that display:
In order to stop the spam:
1 + 0
=
QUESTION ON "Perl"
Trapping errors
Trapping errors
Using v?snprintf/strlcpy/strlcat when useful
pointer to subroutine?
pointer to subroutine?
Configure hangs on fcntl test when trying to bulid Perl 5.8.0 on AIX 4.3.3.0
make test hangs on AIX 4.3.3 and cannot be killed
Threads signalling
How to get the file's end-lines?
Change 28152: Upgrade to Encode-2.17
A rule by any other name...
internal error in Bytecode.pm
Remove sv_derived_from From Public API
A rule by any other name...
Something comparable to Template Toolkit in Python?
Thread suspend/resume
array question
things that go BOOM! on the context stack :-(
ext/IPC/SysV/t/ipcsysv.t using test.pl
array question
EMSDN.COM
Home
-
About Us
-
Contact
-
Privacy Statement
-
Link Exchange
-
Bookmark
-
Map.XML
-
Rss.Xml
Copyright 2001-2009 by EMSDN.COM Information Technology Co.,Ltd All rights reserved
0.172