bop has asked for the wisdom of the Perl Monks concerning the following question:

Hi Perl Monks,

I'm trying to sort a large file using the cygwin sort (so maybe this question should be rather addressed to a cygwin forum, but I don't actually think that it is a cygwin problem). As the file is much larger than can fit in memory, I set the directory where cygwin should store any sorted runs temporarily. As I like to keep my tmp directory small (I think /tmp is just a waste of space in most cases), I typically set that directory to `pwd`. This works for the cygwin internal version of perl:
$ perl -e 'system "sort -T `pwd` --buffer-size=10 ../somefile.txt"' | +head
But fails for an external installation of perl (I also tried the external 32 bit version, which fails just the same):
$ /cygdrive/c/Perl64/bin/perl -e 'system "sort -T `pwd` --buffer-size= +10 ../somefile.txt"' | head sort: cannot create temporary file: `pwd`/sort1JB3UE: No such file or +directory
The perl versions are:
$ perl --version This is perl, v5.8.8 built for cygwin-thread-multi-64int (with 8 registered patches, see perl -V for more detail) Copyright 1987-2006, Larry Wall Perl may be copied only under the terms of either the Artistic License + or the GNU General Public License, which may be found in the Perl 5 source ki +t. Complete documentation for Perl, including FAQ lists, should be found +on this system using "man perl" or "perldoc perl". If you have access to + the Internet, point your browser at http://www.perl.org/, the Perl Home Pa +ge. $ /cygdrive/c/Perl64/bin/perl --version This is perl, v5.10.0 built for MSWin32-x64-multi-thread (with 3 registered patches, see perl -V for more detail) Copyright 1987-2007, Larry Wall Binary build 1002 [283697] provided by ActiveState http://www.ActiveSt +ate.com Built Jan 10 2008 10:53:05 Perl may be copied only under the terms of either the Artistic License + or the GNU General Public License, which may be found in the Perl 5 source ki +t. Complete documentation for Perl, including FAQ lists, should be found +on this system using "man perl" or "perldoc perl". If you have access to + the Internet, point your browser at http://www.perl.org/, the Perl Home Pa +ge.
Any explanation and/or work arounds (other than increasing /tmp) would be much apcodeciated!
Thank you,
bop

Replies are listed 'Best First'.
Re: sort system call problem with activestate perl
by Anonymous Monk on Jul 03, 2008 at 13:17 UTC
    in windows, the default shell is cmd.exe, in cygwin its bash or csh or ...
      To elaborate a bit more: Windows handles `pwd` as a literal. Since it can't create a file in the directory `pwd` (because it doesn't exist), it fails.

      One workaround is to use Cwd to obtain the current working dir in a platform-independent way.

        Thank you Moritz,

        that makes sense. However, I don't really know how I can call Cwd from cygwin ("command not found" - I must have a thick day), but this works, working around the string literal issue:
        perl -e 'my $path = `pwd`; system "sort -T " . $path . " --buffer-size=10 ../somefile.txt"'
        
        thank you,
        bop

        PS: I forgot to mention previously that I use such a small buffer size in order to recreate the problem I had (but I'm sure you guessed that).
Re: sort system call problem with activestate perl
by starbolin (Hermit) on Jul 04, 2008 at 04:44 UTC

    An ethereal Anonymous Monk asides:

    "(I think /tmp is just a waste of space in most cases)"
    I "most" cases /tmp is mounted from it's own partition and therefor has it's own set of buffers. This is considered by some to be a good thing.


    s//----->\t/;$~="JAPH";s//\r<$~~/;{s|~$~-|-~$~|||s |-$~~|$~~-|||s,<$~~,<~$~,,s,~$~>,$~~>,, $|=1,select$,,$,,$,,1e-1;print;redo}