I am parsing a file which consists of decimal as well as hexadecimal values separated by ":":
foreach $line (<INFO>) {
my ($seq_no, $size_in_bytes, $Hitcount, $buffer) = split /:/, $line;
# $size in_bytes is a hexadecimal value.
print "check 1 $size_in_bytes\n"; # printing some value in hexadecimal
$size_in_bytes = hex($size_in_bytes);
print "check 2 $size_in_bytes\n"; # Printing ZERO??
}
I tried below approach also but still it is giving ZERO only.
$dec_num = sprintf("%d", hex($num));
Can you please tell me how can I convert string to Decimal
Since the problem is with superfluous spaces in your fields, you should split like this instead
split /\s*:\s*/, $line
That way the spaces will be removed if there are any, but the split
will still work fine if not.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.