RE: inserting BLOB data
"Jim Cant" <[email protected]> Wed, 12 Dec 2007 19:54:27 -0500
| Newsgroups | gmane.comp.db.mysql.perl |
|---|---|
| Message-ID | <[email protected]> |
I agree that if all you want to do is find some strings in file there are
simpler ways; Perl would be my choice.
You'll find my attempt at this below; it 'greps' binary files (it's been a
boring afternoon ;-)
..snip...
>
>>The contents of the file.
>>The reason i wanted to insert the contents of the file
>into the table was so I could query the table and be able
>to extract out substrings of that particular content.
.. snip ...
>Very expensive. It all depends what you have to do.
>Perhaps just using
>perl/awk/sed on the file on disk?
# Finds a pattern (regular expression) in a binary file(s) (or standard
input)
# Prints out the position in the file of each occurence of the pattern
# and the occurence itself (separated by a tab)
# Usage: perl bingrep.pl <regEx> < file ... >
#
# example : perl bingrep.pl 321 myData.dat / finds
'321'
# example : perl bingrep.pl [AD]C myData.dat / finds
'AC' or 'DC'
# example : perl bingrep.pl [0-9]{3}-[0-9]{3}-[0-9]{4} / finds
phone numbers
use English;
# Ignore newlines so file looks like one big string of characters.
undef $INPUT_RECORD_SEPARATOR;
# Slurp the entire file into a single variable
$file = <>;
# The 1st argument on the command line is the pattern we're looking for.
$regularExpression = shift @ARGV;
# Split the file using the pattern as the delimiter, retaining the
# delimiter. Resulting array has the delimeter in every other element.
@parts = split( /($regularExpression)/, $file );
$filePostion = 0;
for ( $i = 0; $i < $#parts; $i += 2 )
{
$filePostion += length( $parts[ $i ] );
print "$filePostion\t$parts[ $i+1]\n";
$filePostion += length( $parts[ $i+1 ] );
}
--
MySQL Perl Mailing List
For list archives: http://lists.mysql.com/perl
To unsubscribe: http://lists.mysql.com/[email protected]