Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!cs.utexas.edu!uunet!convex!convex.COM From: tchrist@convex.COM (Tom Christiansen) Newsgroups: comp.lang.perl Subject: Re: Is there an easy way around this problem? Keywords: perl error "Arguments too long", help, please Message-ID: <5349@convex.convex.com> Date: 12 Feb 90 04:27:08 GMT References: <237@cmic.UUCP> Sender: news@convex.com Reply-To: tchrist@convex.COM (Tom Christiansen) Organization: CONVEX Software Development, Richardson, TX Lines: 53 In article <237@cmic.UUCP> garvey%cmic@mips.com writes: >I was in the middle of creating a perl script for archiving off certain files >plucked from the news, when I got the message "Arguments too long". > >Is there an easy way around this? There seems to be a limit built into the ><$dir/*> of about 250 files (no it's not 256). Have I done something wrong? >Why would there be a limit? I'm sure I'm not running out of memory, >and Larry says in the first page of the man-page "Unlike most Unix utilities, >perl does not arbitrarily limit the size of your data -- if you've got the >memory". What gives? The problem is that perl is using a shell to glob the pattern. There is a basic limitation on the length of the command args imposed by your shell, your exec system call, or both. What this actually works out to be varies from system to system. On my system, the real number is #define NCARGS 3*NBPG /* # characters in exec arglist */ which for me is 3*4k, or 12168 bytes. Your string is already 29 bytes long, add one for another slash, and now each file that the star expands into takes another 30+length($afile) bytes. The workaround (until and if Larry builds globbing into perl without having to call the shell) is to recode using the opendir() built-ins if you have them. Instead of: $dir = "/users/garvey/tmp/archive/tmp"; foreach $afile (<$dir/*>) { print ($afile, "\n"); } use the virtually equivalent (but not snagged by NCARGS problems): opendir(DIRECT, $dir); foreach $afile (sort grep (!/^\./, readdir(DIRECT))) { print $dir, '/', $afile, "\n"; } closedir(DIRECT); This is actually more powerful than the <*.*> method, because you can do perl-style globbing with grep. >E-mail replies preferred. And duly sent. --tom -- Tom Christiansen {uunet,uiucdcs,sun}!convex!tchrist Convex Computer Corporation tchrist@convex.COM "EMACS belongs in : Editor too big!"