PERL: Remove duplicates, then sort and number, from form POST info.

Discussion in 'Programming' started by Nintendo, Sep 16, 2008.

  1. #1
    Is it possible to change this code...

    #!/usr/bin/perl
    use CGI ':standard';

    my $q=new CGI;
    my $code=$q->param('code');

    @lines=split (/\n/, $code);

    print "Content-type: text/html\n\n";
    print "<html>
    <head>
    <title>Sorted text</title>
    <H1>Sorted and numbered text</H1><PRE>";
    my $loop=1;
    foreach (@lines) {
    print $loop."WWW".$_."\n";
    $loop++;
    };
    print "</PRE></body></html>";

    to include these little codes...

    # Remove duplicates
    my %unique;
    @unique{map {lc} @lines} = @lines;

    # Then sort
    print "$unique{$_}<br />" foreach sort {$a cmp $b} keys %unique;

    to Remove duplicates and sort, and then number the form POST info?
     
    Nintendo, Sep 16, 2008 IP