[Novalug] perl program using exec or system command help/advice.

Aaron Porter atporter@gmail.com
Tue May 26 20:14:41 EDT 2009


On Tue, May 26, 2009 at 4:44 PM, Bonnie Dalzell <bdalzell@qis.net> wrote:
> /usr/bin/ilbmtoppm -verbose abstract1.iff > abstract1.ppm

> i have not figured out how to feed wildcards to the program so that it
> would convert all *.iff files in a subdirectory to *.ppm files.
>
> so i tried writng a little perl program to do the conversion, figuring I
> could feed it a list of files as an array from STDIN or ARGS.

I can't help but think this is a nice place for bash, though as
written this assumes no spaecs in your filenames:

for file in `ls /path/to/*,iff | sed -e 's/.iff$//' ` ; do echo
"Converting $file"; /usr/bin/ilbmtoppm /path/to/$file.iff >
/target/directory/$file.ppm ; done

Or untested in perl:

#!/usr/bin/perl

$dir="/path/to/input";
opendir(DIR, $dir ) || die "can't open $dir: $!";
@files = grep { /iff$/ && -f "$dir/$_" } readdir(DIR);
closedir DIR;

for $src (@files) {
        $target = $src ;
        $target =~ s/iff$/ppm/;
        print "$src $target\n";
        @cmd = ("/usr/bin/ilbmtoppm", "--verbose", $src, ">", $target);
        system(@cmd) or warn "system @cmd failed: $?"
}



More information about the Novalug mailing list