Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

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

by AnomalousMonk (Archbishop)
on Feb 21, 2019 at 19:12 UTC ( #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? | Other CB clients
Other Users?
Others meditating upon the Monastery: (4)
As of 2023-02-07 05:44 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    I prefer not to run the latest version of Perl because:







    Results (38 votes). Check out past polls.

    Notices?