SPUG: Fw: Uniq in perl
Dean Hudson
dean at ero.com
Mon Mar 19 21:55:17 CST 2001
On Mon, Mar 19, 2001 at 06:25:08PM -0800, Scott Blachowicz wrote:
> 1) The $last in the regexp needs to be escaped for use there (e.g.
> with "\Q$last\E" if I remember correctly.
only if you want it to work without insidious bugs. ne is prolly the
best choice.
> 2) That doesn't work if $_ happens to test false (as would happen with
> a blank line if @in were full of chomp()'d lines).
blank chomp()'d lines don't make sense in the context of uniq(1). the
following should produce similar output:
open (UNIQ, "|/usr/bin/uniq") or die;
print UNIQ while(<>);
my $last = "";
print grep {$_ ne $last and $last = $_} <>;
so 2) is thusly outside of the project's scope. unfortunately the grep
doesn't deal with any of uniq's command line options which may in turn
be _in_ scope.
dean.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
POST TO: spug-list at pm.org PROBLEMS: owner-spug-list at pm.org
Subscriptions; Email to majordomo at pm.org: ACTION LIST EMAIL
Replace ACTION by subscribe or unsubscribe, EMAIL by your Email-address
For daily traffic, use spug-list for LIST ; for weekly, spug-list-digest
Seattle Perl Users Group (SPUG) Home Page: http://www.halcyon.com/spug/
More information about the spug-list
mailing list