texuser74 has asked for the wisdom of the Perl Monks concerning the following question:
I want to sort the attribute values inside <tag refid="5,8,7,3,2,1"> and remove the commas.
i.e. input: <tag refid="5,8,7,3,2,1"> some other text
output: <tag refid="1 2 3 5 7 8"> some other text
test.txt:
<tag refid="5,8,7,3,2,1"> some other text
but my present code is printing wrong with extra text.open(IN, "<test.txt") || die "\nCan't open test.txt \n"; $/=""; { local $/ = '<tag refid="'; print OUT scalar <IN>; for (<IN>) { s@(.*?)">@ my $var = $1; $var @e; print "$_\n" for sort { $a cmp $b } split /,/; } } close(IN); close(OUT);
Pls help me in correcting this.1 some other text 2 3 5 7 8
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: sorting difficulty
by moritz (Cardinal) on May 07, 2008 at 09:59 UTC | |
by texuser74 (Monk) on May 07, 2008 at 10:22 UTC | |
by moritz (Cardinal) on May 07, 2008 at 10:26 UTC | |
by texuser74 (Monk) on May 07, 2008 at 10:31 UTC | |
|
Re: sorting difficulty
by jwkrahn (Abbot) on May 07, 2008 at 10:14 UTC |