--- Jennifer Pan <[EMAIL PROTECTED]> wrote:
> 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
On my system, ls produces a tabbed-columnar listing of the directory.
try ls -1
Better still, let the program handle it; instead of
> while ($LINE = <STDIN>) {
> chomp $LINE;
> open (AFILE, "$LINE") or die ( "cannot open $LINE");
try
for my $file (glob "*") {
open AFILE, $file or die "$! : $file";
then you won't need to do the ls or the chomp. =o)
__________________________________________________
Do You Yahoo!?
Get personalized email addresses from Yahoo! Mail
http://personal.mail.yahoo.com/