Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

jgamble's scratchpad

by jgamble (Pilgrim)
on Aug 10, 2010 at 23:34 UTC ( [id://854170]=scratchpad: print w/replies, xml ) Need Help??

# # @newlist = semijoin($expr, $itemcount, @list); # # $expr - A string to be used in a join() call. # $itemcount - The number of items in a list to be joined. # It may be negative. # @list - The list # # Create a new list by performing a join on I<$itemcount> elements at +a # time on the original list. Any leftover elements from the end of the # list become the last item of the new list, unless I<$itemcount> is # negative, in which case the first item of the new list is made from +the # leftover elements from the front of the list. # sub semijoin { my($jstr, $itemcount, @oldlist) = @_; my(@newlist); return @oldlist if ($itemcount <= 1 and $itemcount >= -1); if ($itemcount > 0) { push @newlist, join $jstr, splice(@oldlist, 0, $itemcount) while @oldlist; } else { $itemcount = -$itemcount; unshift @newlist, join $jstr, splice(@oldlist, -$itemcount, $i +temcount) while $itemcount <= @oldlist; unshift @newlist, join $jstr, splice( @oldlist, 0, $itemcount) if @oldlist; } return @newlist; }
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others meditating upon the Monastery: (7)
As of 2024-04-25 08:19 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found