Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked

Re: large file issue?

by Shendal (Hermit)
on Oct 25, 2000 at 22:06 UTC ( #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 (Sexton) 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
Node Status?
node history
Node Type: note [id://38452]
[SuicideJunkie]: talexb Apgrade is the highest point it will reach. They're informing you that it will all be downhill from here until the software hits a PEgrade, or impacts the terrain depending on the details of the orbit.

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (12)
As of 2017-07-25 18:19 GMT
Find Nodes?
    Voting Booth?
    I came, I saw, I ...

    Results (376 votes). Check out past polls.