Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Hello Monks,
This is an example script from a book. It is currently executed from a command line. I am having trouble understanding something. In line 7 the script reads my $out_dir = 'icons'; however in the command line call
perl make_thumbnail -dir thumb *.gif *.jpg ../*.tiff
they create a directory named "thumb". After executing the "thumb" directory has been created but what happens to the directory named "icons"? Is this in case the -dir parameter is empty it will use "icons" as a default.

How would one go about changing this script to be browser executable.
#!/usr/bin/perl -w use strict; use diagnostics; use Image::Magick; use Getopt::Long; use File::Basename; my $out_dir = 'icons'; my $geometry= '120x120'; GetOptions( 'geometry=s' => \$geometry, 'directory=s' => \$out_dir, ); mkdir $out_dir, 0777 or die "Cannot create $out_dir: $!" unless -d $ou +t_dir; foreach my $img (@ARGV) { my $rc; my $im = Image::Magick->new(); $rc = $im->Read($img); warn($rc), next if $rc; my $basename = basename $img; $basename =~ s/\.\w+$//; $rc = $im->Write("PNG:$out_dir/$basename.png"); warn($rc) if $rc; }

Replies are listed 'Best First'.
Re: Questions about command line script
by gjb (Vicar) on Nov 07, 2002 at 21:33 UTC

    On the command line you pass the option -dir with a value 'thumb'. In the code, GetOptions is called with a reference \$out_dir to the variable $out_dir. This function sets the variable to the value passed on the command line, i.e. 'thumb'.

    So mkdir makes the specified directory 'thumb' since the default value 'icons' has been overriden.

    Hope this helps, -gjb-

      Thanks for confirming, That was kind of what I thought.
      Tim
Re: Questions about command line script
by waswas-fng (Curate) on Nov 07, 2002 at 21:35 UTC
    1: 'directory=s' => \$out_dir, sets the same var to the command line switch input if available -- think of the line #7 ( not really 7 is it?) as setting a default if the command line switch is not used.

    2: take a look at CGI to output something usefull to a browser.
    -Waswas