Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re^2: Performing addition on hex value extracted from a string

by AnomalousMonk (Archbishop)
on Feb 21, 2019 at 19:12 UTC ( [id://1230321]=note: print w/replies, xml ) Need Help??


in reply to Re: Performing addition on hex value extracted from a string
in thread Performing addition on hex value extracted from a string

my ($addr) = $line1 =~ /addr:(0x(?:[[:xdigit:]]{2})+)/;

If the hex value really is an address as  'addr' suggests, is there any guarantee the hex digits will always be paired, i.e., always be an even number of digits? If they are not paired, won't the lack of a boundary assertion sometimes cause an incorrect value to be extracted from the string?

c:\@Work\Perl\monks>perl -wMstrict -le "my $line1 = 'addr:0xabcde'; my ($addr) = $line1 =~ /addr:(0x(?:[[:xdigit:]]{2})+)/; print qq{'$addr'}; " '0xabcd'


Give a man a fish:  <%-{-{-{-<

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1230321]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others examining the Monastery: (4)
As of 2024-03-29 15:22 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found