I have this simple sub which nicely returns the dimensions of a locally stored gif file:
# Get the dimensions of a GIF file
sub gifdim{
my $file = @_;
my $bytes;
open (FILE,$file) || return();
read(FILE, $bytes, 10);
close(FILE);
$bytes =~ s/^GIF8[79]a// || return(); # Check for GIF header
$bytes =~ s/(.)(.)(.)(.)/$2$1$4$3/ || return(); # Swap bytes
unpack("S2",$bytes);
}
Now what I want is to amend the sub to be able to use it for remote files, so instead of passing in a local path/filename, I pass in a URL http://www.somesite.com/images/image.gif.
Essentially the task is to read the first 10 bytes of a remote file, specified by it's URL.
I've searched like crazy for a solution to this, came across the File::Remote module and similar tools that in my opinion overshoot the target like enabling remote file editing etc.
... in case the solution is basic Perl file handling knowledge ; yes I am a self-taught Perl novice just getting started.
Your help is much appreciated!
Jacob
# Get the dimensions of a GIF file
sub gifdim{
my $file = @_;
my $bytes;
open (FILE,$file) || return();
read(FILE, $bytes, 10);
close(FILE);
$bytes =~ s/^GIF8[79]a// || return(); # Check for GIF header
$bytes =~ s/(.)(.)(.)(.)/$2$1$4$3/ || return(); # Swap bytes
unpack("S2",$bytes);
}
Now what I want is to amend the sub to be able to use it for remote files, so instead of passing in a local path/filename, I pass in a URL http://www.somesite.com/images/image.gif.
Essentially the task is to read the first 10 bytes of a remote file, specified by it's URL.
I've searched like crazy for a solution to this, came across the File::Remote module and similar tools that in my opinion overshoot the target like enabling remote file editing etc.
... in case the solution is basic Perl file handling knowledge ; yes I am a self-taught Perl novice just getting started.
Your help is much appreciated!
Jacob