Thank you Wiggins!  I have changed everything that you suggested and I think
I am much closer.  However, I have run into an error w/ the Read line.

foreach my $file (@files) {
  $image->Read (file=> $file)

Bad filehandle: brian.jpg at C:/Program Files/PerlEdit/scripts/test_3.pl
line 17

as you can see the script is seeing the file name in the image directory.  I
re-read chapter 11 Learning Perl on Bad Filehandles but I'm still having
trouble.  Any suggestion would be greatly appreciated.

Thanks!

Brian 


-----Original Message-----
From: Wiggins d Anconia [mailto:[EMAIL PROTECTED]
Sent: Thursday, September 09, 2004 12:28 PM
To: Brian Volk; Beginners (E-mail)
Subject: Re: perl crashing at $image->Read (file=> \*ARGV);


> 
> Hi All, 
>  
> I my perl script is crashing perl at this line;
>  
> $image->Read (file=> \*ARGV);
>  
> I know that it is this line because I have commented out everything else
> around it.  When I just have the Read statment, perl will crash.   Here is
> the script, can someone please suggest what I am doing wrong.
>  
> Thanks!
>
----------------------------------------------------------------------------
> ---------------------
> #!/user/local/bin/perl -w
>  
> use strict;
> use Image::Magick;
>  
> my $images = "C:/images";
>     opendir (IMAGES, $images) or die "can not open $images: $!";
>  
> # load @ARGV for (<>)
>  
> @ARGV = map { "$images/$_" } grep { !/^\./ } readdir IMAGES; 
>

my @files = map { "$images/$_" } grep { !/^\./ } readdir IMAGES;

Not sure why you are using @ARGV just for its special qualities (aka the
<> operator) why not name our variables, we are allowed too.
  
> my $image = Image::Magick->new(magick=>'JPEG');
>  
> # Read images, Scale down and Write to new directory
>  
> while (<>) {

No need to use a while here, since you already have a complete array,

foreach my $file (@files) {

>     $image->Read (file=> \*ARGV)

By naming our variables we now see that we are dealing with a filename,
rather than a typeglob reference.  

$image->Read(file => $file)

The example you are using assumes that *ARGV contains an opened
filehandle to the file itself, *but* within the loop you are executing
on each line. See perldoc perlop for more. I would skip using the
special nature of the variables until you understand them. Try using
specifically named variables until the program works, then reduce it if
you must.

>     and $image->Scale (width=>'50', height=>'50')
>     and $image->Write ("C:/images")

C<Write> expects a filename argument, not a directory, or a handle.

>     and close (ARGV);

Not sure why these statements are strung together with C<and> they can
be separate, you haven't really benefited by making them a single
statement. And you wouldn't normally close ARGV.

>     }
>  
> closedir IMAGES;
>  

You can close your dir earlier in the process, since you are done
reading from it.

> Brian Volk
> HP Products
> 317.289.9950 x1245
>  <mailto:[EMAIL PROTECTED]> [EMAIL PROTECTED]
>  

http://danconia.org

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to