yitzle wrote:
> `cat m.top.html m.mid.html m.arc.html m.bot.html > blah`
> How can this be done without a system call?

As a general rule, if your script contains 'system()' anywhere in it, you've 
done it wrong. This is especially true for simple file operations such as 
the above, and for anything else CPAN has yet to fail me. I can't remember 
the last time I was forced to shell out to get something done.

> Here's my first guess:
> @doc = ();
> for (qw/m.top.html m.mid.html m.arc.html m.bot.html/) {
>       open $FILE,"<","$root/$_";
>       my @tmp = <$FILE>;
>       @doc = (@doc,@tmp);
>       close $FILE;
> }
> open $FILE,">","blah";
> print $FILE $_ foreach(@doc);
> close $FILE;
>
> Is there something I'm missing?

Quite a lot, yes.

Always use the strict and warnings pragmas, no exceptions, and test to ensure 
operations on files, sockets etc have worked before moving on.
You don't need to loop your file contents in, and then loop them back out 
again separately later; one for loop will suffice for both.
Your syntax for the open() statements is a bit dodgy too :-)

Here's a fairly verbose chunk of code that ought to do what you want:

use strict;
use warnings;
open OUTFILE, ">blah" or die "error creating output file\n";
for my $infile (qw|m.top.html m.mid.html m.arc.html m.bot.html|){
  die "$infile not found" unless -r "$root/$infile"; # or use next to skip it
  open INFILE, "<$root/$infile" or die "error opening input file\n";
  print OUTFILE while (<INFILE>);
  close INFILE;
  }
close OUTFILE;

Keep in mind that there are plenty of other ways of doing this, some terser 
than others. You can even do this:

perl -pe m.top.html m.mid.html m.arc.html m.bot.html > blah

....which is Perl doing a very convincing cat impression.

-- 
[EMAIL PROTECTED] [pgp: 8A8FA6DE] 


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/


Reply via email to