[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

Re: [MacPerl] Perl Filter Demos?



Tom,

You can write this a bit more concisely as:


#!perl -wn

BEGIN {$last = '';}

print if $last ne $_ ;
$last = $_;

__END__


-Charles Albrecht
 charlesa@pobox.com

At 9:05 PM +0200 5/8/2000, Tom Maas wrote:
>:-) replying to myself...
>
>Ofcourse you may want to sort your text first using BBEdit's tools.
>That way you wil know that every line in your document wil be unique
>after running the filter.
>
>>>I would love to have some intriguing demo filters on hand at WWDC (the
>>>Apple World Wide Developers Conference) in a week or so.  They should
>>>have a strong "Gee Whiz!" factor.  It would also be nice if they can
>>>be explained to mortal programmers...
>>
>>Hi, This one i use quite often,
>>maybe the syntax isn't that clean, but it works.
>>It checks to see if there are double lines in the selection,
>>right obove each other. If there is, the last one is deleted.
>>
>>In fact every line is written back exept when the last one 
>>was identical.
>>
>>Hope this helps?
>>
>>Cheers, Tommy.
>>
>>#!perl -w
>>
>>$last ="str";                      #  just some phony init.
>>
>>while( @string = <> )              # as long as there is input
>>{
>>	foreach $string (@string)         # for every line in the inputbuffer
>>	{
>>		if($string eq $last)             # if the line is equal to the last one
>>	{	    
>>	}                                 # do nothing
>>	else
>>	{
>>		   print "$string";              # else write the line back.
>>		   $last = $string ;             # and put a new string in the variable 
>>last.
>>	}	
>>}	

# ===== Want to unsubscribe from this list?
# ===== Send mail with body "unsubscribe" to macperl-request@macperl.org