Here is one way:
open X, ">>output.txt";
while (<>) {
s/^\s*//;
print X "$_";
}
close X;
Since it looks like you are coming from unix environment, you could do:
format.pl *.txt
which will read in all files one after the other automatically. Now if you
want some breakout, then we will need a little more work. Then you might
use opendir and check to see if extension is .txt. If not read the next
record otherwise print out the name of the file and do your processing.
Hope this helps.
Wags ;)
-----Original Message-----
From: Jennifer Pan [mailto:[EMAIL PROTECTED]]
Sent: Thursday, July 12, 2001 09:33
To: [EMAIL PROTECTED]
Subject: open FILE problem
Hello all, I came across this problem opening up files that are fed in
from command line using "ls". I do not know why this script did not
work. Appreciated any input.
#!/usr/local/bin/perl
# I am trying to feed all the files in this directory to do text
processing and save the processed txt into an #output called outout.txt
while ($LINE = <STDIN>) {
chomp $LINE;
open (AFILE, "$LINE") or die ( "cannot open $LINE");
open X, ">>output.txt";
while ($LINE1 = <AFILE>) {
$LINE1 =~ s/^\s*//;
print X "$LINE1";
}
close X;
close AFILE;
}
at prompt I typed
ls *.txt | perl format.pl
it never worked!!!! it always "die" cannot open $LINE. I don't
understand why
thanks
-jen