Path: utzoo!utgpu!jarvis.csri.toronto.edu!cs.utexas.edu!usc!apple!oliveb!mipos3!omepd!merlyn From: merlyn@iwarp.intel.com (Randal Schwartz) Newsgroups: alt.sources.d Subject: xargs in Perl (was Re: promoting Perl (was Re: uutraffic report (in perl))) Message-ID: <5304@omepd.UUCP> Date: 1 Dec 89 20:47:53 GMT References: <4025@mhres.mh.nl> <1194@radius.UUCP> <3273@convex.UUCP> <5261@omepd.UUCP> <1126@cirrusl.UUCP> <1989Nov28.064349.1421@eda.com> <14961@bfmny0.UU.NET> <13352@s.ms.uky.edu> <14964@bfmny0.UU.NET> <1989Nov29.234210.15875@NCoast.ORG> , emv@math (Edward Vielmetti) writes: | | Gentle reminder: many versions of Berzerklix don't have xargs. | | ++Brandon | | followed by the obvious, | | does anyone have a version of xargs in perl? Yeah, I wrote one when the discussion came up in c.u.q, and began my never-ending quest to post a Perl solution to nearly every problem posted there. :-) Lessee... where is it... ... oh yeah, here it is: ================================================== snip snip #!/usr/bin/perl $lengthmax = 512; @command = $#ARGV > -1 ? @ARGV : ("/bin/echo"); $lengthcommand = length(join(" ", @command)) + 1; while () { if ($lengthcommand + length($args) + length($_) > $lengthmax) { system @command, split(/\n/, $args); $err = 1 if $?; $args = ""; } $args .= $_; } if (length($args)) { system @command, split(/\n/, $args); $err = 1 if $?; } exit $err; ================================================== snip snip This was written under Perl2.0, and could probably be modded a bit under Perl3.0 (I see that 'stdin' is lowercase, for example...). Enjoy. Just another Perl hacker (but getting more visibility each day...), -- /== Randal L. Schwartz, Stonehenge Consulting Services (503)777-0095 ====\ | on contract to Intel's iWarp project, Hillsboro, Oregon, USA, Sol III | | merlyn@iwarp.intel.com ...!uunet!iwarp.intel.com!merlyn | \== Cute Quote: "Welcome to Oregon... Home of the California Raisins!" ==/ Brought to you by Super Global Mega Corp .com