Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery

Re: large file issue?

by Shendal (Hermit)
on Oct 25, 2000 at 22:06 UTC ( [id://38452]=note: print w/replies, xml ) Need Help??

in reply to large file issue?

Whenever you use system commands, you will want to make sure you check the exit status. Additionally, the error is stored in $!, and should give you an idea of why things are failing. Try something like this:
open(OUT,">outfile") || die; for($i=0;$i<=$#bigfile;$i++){ $bigfile[$i] =~ s/\0/ /g; print OUT "$bigfile[$i]"; } close(OUT); print "Compressing original file\n"; system("compress original.file") and die "Unable to compress data: $!\n"; print "Concatenating other data\n"; system("cat ./incoming/data.file ./static/data.file >> outfile") and die "Unable to cat data: $!\n"; print "Sorting Data File\n"; system("asort outfile 1 6 8 9") and die "Unable to sort data: $!\n"; print "Done.\n";
You may also want to use system in a list context, as it is faster and more secure, for example:
system("/path/to/asort","outfile","","1 6 8 9") and die "Unable to sort data: $!\n";
Lastly, your for loop isn't very perlish. You may want to try something like this:
open(OUT,">outfile") || die "Unable to open outfile: $!\n"; foreach (@bigfile) { s/\0/ /g; print OUT "$_"; } close(OUT);


Update: As runrig pointed out via the chatterbox, it ought to be and die after a system, since system returns 0 on success.

Update2: See merlyn's post RE: Re: large file issue?. $! is actually not what you want to look at.

Replies are listed 'Best First'.
RE: Re: large file issue?
by merlyn (Sage) on Oct 26, 2000 at 01:45 UTC
    Nope. You don't want to be looking at $! after system. The child exit status is in $? (as well as being the return value from system), and the child's reason for exiting is not available to you in any way shape or form. We went through this with tilly a few weeks ago. {grin}

    -- Randal L. Schwartz, Perl hacker

RE: Re: large file issue?
by clearcache (Beadle) on Oct 25, 2000 at 22:13 UTC
    thanks for the quick reply - I tried system(xxx) || die "$!" and it didn't tell me anything. ...and thanks for the system in list context hint - I had never thought of that. and the loop - yeah, I know...the loop is actually doing a lot more - I just took out some code to avoid identifying my employer/client ;)
      If you're going to try that, try system("blah") or die "$!\n"; instead... || has higher precedence and screws things up.
        Though the precedence thing doesn't matter here.. It's just a single statement, no ambiguity. Plus, system returns 0 (a false value) on success, counter to traditional Perl functions, so you'd need to use and instead of or.

Log In?

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

How do I use this?Last hourOther CB clients
Other Users?
Others perusing the Monastery: (4)
As of 2024-06-13 02:00 GMT
Find Nodes?
    Voting Booth?

    No recent polls found

    erzuuli‥ 🛈The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.