mercredi 1 avril 2015

Perl Convert String With New Lines To Hex(For Oracle)

I am parsing data from a document. However, I need to convert each column from the data into hex using perl. I will then use "utl cast to raw" to convert the text back into plain text once the data has been loaded.


The issue I am having is I can't seem to get all of the column data to convert to hex. I have tried all of these methods(shown in the code sample, but commented out..) , and I am still not able to convert it(the data still has new lines..) . Can someone help ?



sub convertHex2String
{
my($string ) = @_;
#$string =~ s/([a-fA-F0-9][a-fA-F0-9])/chr(hex($1))/egx;
$string = pack("H*", $string);
#$string =~ s/(.)/sprintf("%x",ord($1))/eg;
if(index($string, "\n") != -1)
{
print "string in hex:$string";
}
return $string;
}

Aucun commentaire:

Enregistrer un commentaire