FIND: Parameterformat falsch (parameter format not correct)

F

FMAS

I have downwloaded a professional script to do some tagging on a text.
This script should read files from a directory but I get an error
message:
FIND:: paramater format not correct

Here the critical parts of the script:

use Tk;
use Tk::BrowseEntry;
use Tk::Dialog;

if ($#ARGV < 2) {
die "\nUsage: general_tagger.pl <input_dir> <output_dir>
<label_file>\n\nIMPORTANT: This script enables you to delete files in
the input directory\nwith the Skip button. Create a backup now!!\n\n";
}
else {
$intextfiledir = "${ARGV[0]}\";
$outtextfiledir = "${ARGV[1]}\";
$labelfile = $ARGV[2];
}

(@infilelist) = read_filelist($intextfiledir);
($label_width, @labels) = read_labels($labelfile);

my $num_labels = $#labels + 1;
my $current_start = "0.0";
my $current_end = "0.0";
my $text_start = "0.0";
my $text_end = "0.0";

$current_file = "";
$fileonly = "";
$index = -1;
$num_files = $#infilelist + 1;
$done = $index + 1;

(...)


sub read_filelist {
my ($dir) = @_;
my ($file, @filelist);

open(FIND, "find $dir | ") or die "Couldn't run find...\n";
$file = <FIND>; # Get rid of bogus first line
while ($file = <FIND>) {
chop $file;

next if ($file !~ /\w/);
push(@filelist, $file);
}

return (@filelist);
}

The script was written in '99. I am running it on an XP computer. Is
this the reason for the error message?

Thanks in advance for any suggestion

Francois
 
J

Joe Smith

FMAS said:
I have downwloaded a professional script to do some tagging on a text.
This script should read files from a directory but I get an error
message:
FIND:: paramater format not correct
open(FIND, "find $dir | ") or die "Couldn't run find...\n";

The script was written in '99. I am running it on an XP computer. Is
this the reason for the error message?

Yes, 'find' is a Unix command. You need to use File::Find instead.

#! perl
print join "\n",read_filelist("C:/temp");

use File::Find;

my @filelist;
sub wanted {
next if -d; # Don't include directory names
push @filelist,$File::Find::name if /\w/;
}

sub read_filelist {
my $dir = shift;
find(\&wanted,$dir);
@filelist;
}
 
G

gnari

FMAS said:
I have downwloaded a professional script to do some tagging on a text.
This script should read files from a directory but I get an error
message:
FIND:: paramater format not correct

Here the critical parts of the script:
[snip


sub read_filelist {
my ($dir) = @_;
my ($file, @filelist);

open(FIND, "find $dir | ") or die "Couldn't run find...\n";
$file = <FIND>; # Get rid of bogus first line
while ($file = <FIND>) {
chop $file;

replace these 4 lines with:
opendir(DIR,$dir) or die "Couldn't open dir '$dir' :$!";
while ($file = readdir DIR) {
next if ($file !~ /\w/);
push(@filelist, $file);
change to:
push(@filelist, "$dir/$file");
add here:
closedir DIR;
return (@filelist);
}
The script was written in '99. I am running it on an XP computer. Is
this the reason for the error message?

no the reason is that the script used a stupid method to read
a directory

gnari
 
A

Anno Siegel

FMAS said:
I have downwloaded a professional script to do some tagging on a text.
^^^^^^^^^^^^
No. Like much Perl software that is freely downloadable, this is not
professional Perl code.
This script should read files from a directory but I get an error
message:
FIND:: paramater format not correct

Here the critical parts of the script:

No strict, no warnings.
use Tk;
use Tk::BrowseEntry;
use Tk::Dialog;

if ($#ARGV < 2) {

Better written as "@ARGV < 3". The author doesn't seem to know that an
array returns the number of its elements in scalar context.
die "\nUsage: general_tagger.pl <input_dir> <output_dir>
<label_file>\n\nIMPORTANT: This script enables you to delete files in
the input directory\nwith the Skip button. Create a backup now!!\n\n";
}
else {
$intextfiledir = "${ARGV[0]}\";
$outtextfiledir = "${ARGV[1]}\";
$labelfile = $ARGV[2];
}

This doesn't compile, the backslashes are bogus. Ignoring them, the code
inconsistently and uselessly quotes two of the three arguments.
(@infilelist) = read_filelist($intextfiledir);
($label_width, @labels) = read_labels($labelfile);

my $num_labels = $#labels + 1;

"$num_labels = @labels". Wherever "$num_labels" is used, "@labels" in
scalar context could be used. The variable is superfluous.
my $current_start = "0.0";
my $current_end = "0.0";
my $text_start = "0.0";
my $text_end = "0.0";

Quoting numeric values is unnecessary and can lead to subtle errors.

[rest of code snipped]

The code bears all the hallmarks of an inexperienced Perl programmer.
The error you received won't be the only one, just judging from the first
few lines. Find something better.

Anno
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,534
Members
45,008
Latest member
Rahul737

Latest Threads

Top