Chuck wrote:
> I have ActivePerl 5.6.0 on Win2000 (in a DOS box). I want to
> find all .CSV files starting in the directory where the perl
> script is. I have a program but no files are processed. Can
> someone help me to get this to work? Here is the code:
>
> #########################################################

use strict;
use warnings;

> use File::Find;
> #... some other code
> # Main code begins here.
> find(\&proc_file,'.');
>
> close(OUTFILE);
>
> print "\nDone. Wrote file to $outfile.\n";
> exit;
>
> ######################## end of main ###########################
> sub proc_file
> # Process filename in $File::Find::name or $_.
> # This actually changes to the dir where the file is found.
> {my(@lin,$i,$l,$s);
>
> if (!(-e $_))
> {print "$_ does not exist.\n";
> return;
> }

    unless (-e) {
        print "$_ does not exist.\n;
        return;
    }

but it's not really useful to check whether the find() call
was correct - you can just believe it!

> if ($Find::File::name !~ m/\.csv$/) # Process only csv files.
> {return;
> }

    return unless $File::Find::name =~ /\.csv$/i;
or
    return unless /\.csv$/;

> if (!(-T $Find::File::name)) # If not a text file, return.
> {return;
> }

    return unless -T $File::Find::name;
or
    return unless -T;

It's also very unlikely that you would find a binary csv file,
and even if you do it's just a problem with the content that
you have to hadle anyway. What I mean is that you could
have a text file with a .csv extension that wasn't a csv file,
so checking that it's a text file doen't buy you much.

> print "Processing $_\n";
> open(INFILE, $_) || die "Could not open $_. $!";
> @lin=<INFILE>;
> chomp(@lin);
> writeln("<begtab>");
>
> for ($i=0; $i<=$#lin; $i++) # Process each line.
> {
> $l=$lin[$i];
> $l=~s/,/<Tc>/;
> $l="<Tr>" . $l;
> writeln($l);
> } # for

    foreach (@lin)
    {
        s/,/<Tc>/g;
        s/^/<Tr>/;
        writeln ($_);
    }


> writeln("<endtab>");
> close(INFILE);
>
> return;
> } # proc_file

It would help you a lot if you laid out your source a little better
with indentation and spaces atound the operators, but in this
case the (obligatory) 'use strict' would have pointed out your
use of Find::File::name straight away. People have been hung
for less :-)

HTH,

Rob




-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to