First, thanks in advance!
I am rather new to Perl and need to some help with a particular section of a short script written another so I can fix it for my problem. I'm extracting sqlite blob data.
==Begin Script==
#!/usr/bin/perl
use strict;
use vars qw { $FILE };
$FILE = shift;
if ($FILE eq "") {
die "Syntax: $0 [filename]\n";
}
&parse($FILE);
sub parse {
my($FILE) = @_;
open(FILE, "<$FILE") || die "$FILE: $!";
mkdir("./maptiles-output", 0755);
while(<FILE>) {
# This is part I'm trying to figure out
chomp;
my $j = 0;
my $contents = $_;
next unless ($contents =~ /^INSERT /);
my ($junk1, $sql, $junk) = split(/\(|\)/, $contents);
my ($zoom, $x, $y, $flags, $length, $data) = split(/\,/, $sql)
+;
$data =~ s/^X'//;
$data =~ s/'$//;
my $filename = "./maptiles-output/$x,$y\@$zoom.png";
next if int(length($data))<128;
print $filename . "\n";
open(OUT, ">$filename") || die "$filename: $!";
print int(length($data)) . "\n";
while($j < length($data)) {
my $hex = "0x" . substr($data, $j, 2);
print OUT chr(hex($hex));
$j += 2;
}
close(OUT);
}
close(FILE);
}