Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

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 clean.data 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","clean.data","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);

Cheers,
Shendal

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.


Comment on Re: large file issue?
Select or Download Code
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.
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

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (13)
As of 2014-09-22 17:47 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (198 votes), past polls