Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re: reduce like iterators

by BrowserUk (Patriarch)
on Jan 03, 2011 at 18:49 UTC ( [id://880233]=note: print w/replies, xml ) Need Help??


in reply to reduce like iterators

Compress() is easily defined in terms of a generic adjacent pairing routine:

#! perl -slw use strict; sub adjacentPairs (&@) { my $code = shift; map { local( $a, $b ) = @_[ $_-1, $_ ]; $code->(); } 1 .. @_; } print adjacentPairs{ defined $b && $a eq $b ? () : $a } qw[a a a b c c a a d e e e e]; __END__ C:\test>compress abcade

Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://880233]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (2)
As of 2024-04-19 18:38 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found