FetchURL with GIF files

M

maw246

I'm fairly new to Perl, so I hope this doesn't seem like a stupid
question.

I'm trying to download an image using a Perl script, because I want to
be able to automate the image download process. My code looks like
this:
#-----------------------
use Win32::Internet;
$inet = new Win32::Internet();

$myfile =
$inet->FetchURL("http://image.weather.com/web/common/wxicons/31/30.gif");
open (OUTP, ">30.gif");
print OUTP $myfile;
#-----------------------
It seems very simple, right? And when I use this to download a text
file or html file, it works just fine. However, when I use this same
code to download other file types-- such as the GIF file in this code
example, ZIP files, or PDFs-- the associated viewing applications see
the files as corrupt and won't open them. Yet when I download the GIF
via internet explorer and file compare it against what I downloaded in
perl, no differences are found . . . but there's a slight difference in
file size.

Can anyone tell me what I'm doing wrong? If so, please offer a
specific solution, because as I wrote above, I'm a bit of a newbie.
--Thanks
 
A

A. Sinan Unur

(e-mail address removed) wrote in @f14g2000cwb.googlegroups.com:
I'm trying to download an image using a Perl script, because I want to
be able to automate the image download process. My code looks like
this:
#-----------------------

use strict;
use warnings;
use Win32::Internet;
$inet = new Win32::Internet();

$myfile =
$inet->FetchURL ("http://image.weather.com/web/common/wxicons/31/30.gif");
open (OUTP, ">30.gif");

You should always, yes always, check if open succeeded.

open my $out, '>', '30.gif' or die "Cannot open 30.gif: $!";
print OUTP $myfile;

perldoc -f binmode

You are better off using LWP rather than Win32 specific functionality:

use LWP::Simple;
getstore('http://image.weather.com/web/common/wxicons/31/30.gif');

or, from the command line:

C:\> perl -MLWP::Simple -e getstore q
{http://image.weather.com/web/common/wxicons/31/30.gif}

(This command should be entered as a single line).
Can anyone tell me what I'm doing wrong? If so, please offer a
specific solution, because as I wrote above, I'm a bit of a newbie.

You should take this opportunity to go over the posting guidelines for
this group.

Sinan.
 
T

Tad McClellan

I'm trying to download an image using a Perl script,

Can anyone tell me what I'm doing wrong?


Treating a binary file as if it was a text file, on a OS
where that makes a difference.

If so, please offer a
specific solution,


perldoc -q binary

How do I handle binary data correctly?
 
M

maw246

All,

Thanks for your input. I got it to work quite well with the
LWP::Simple::getstore() effort.
 

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,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top