[ale] Shell scripting

Fletch fletch at phydeaux.org
Mon Feb 10 10:26:35 EST 2003


>>>>> "David" == David S Jackson <dsj at sylvester.dsj.net> writes:

[...]


    David> Hey perl gurus, how would you do a "uniq" in perl?

open( UNIQ, "| uniq > $outfile" ) or die "pipe to uniq failed: $!\n";


        :)


        If you mean naitively in perl, then you'd keep a hash of lines
already seen.

my %seen;
while( <FOO> ) {
  next if $seen{ $_ }++;

  ## whatever . . . 
}


        If you're looking for uniq-ness on other than a line
granularity you'd of course need to extract whatever from the line
(using split(), a regex, index(), Astro::MoonPhase) and use that as
the key to your seen hash.


-- 
Fletch                | "If you find my answers frightening,       __`'/|
fletch at phydeaux.org   |  Vincent, you should cease askin'          \ o.O'
770 294-0820 (m)      |  scary questions." -- Jules                =(___)=
                      |                                               U
_______________________________________________
Ale mailing list
Ale at ale.org
http://www.ale.org/mailman/listinfo/ale






More information about the Ale mailing list