Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change

Re: oct and vec

by Zaxo (Archbishop)
on Aug 07, 2007 at 08:50 UTC ( #630977=note: print w/replies, xml ) Need Help??

in reply to oct and vec

The first argument of vec says what variable it acts on. The third says how many bits make a unit in the vector. The second is the offset in units of the third argument where things will happen.

ord applied to a string returns ord of its first character.

Thus, vec($foo,0,8) = ord($foo); is a no-op, replacing the first character of $foo by itself. In more depth:

$ perl -e'my $foo = "qa"; vec($foo,0,8) = ord $foo;print $foo,$/'
$ perl -e'my $foo = "qa"; vec($foo,1,8) = ord $foo;print $foo,$/'
$ perl -e'my $foo = "qa"; vec($foo,2,8) = ord $foo;print $foo,$/'
Further increments of the second argument would place NUL in the intermediate positions of the string.

Update: I just noticed that the op is ==, numerical equality. I think that should always be true, but there might be tricky edge cases related to encoding.

After Compline,

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://630977]
[Discipulus]: figuring.. i'm still just use the side pm chat..
[erix]: (all this while karls guitar gently weeps...)
[planetscape]: (invade Hungary)++ #I'm hungry
[stonecolddevin]: i went too far down the irc rabbithole to hook this back up there
[Discipulus]: .. yes erix until NodeReaper put jhon coltrane again

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (10)
As of 2017-06-22 21:13 GMT
Find Nodes?
    Voting Booth?
    How many monitors do you use while coding?

    Results (531 votes). Check out past polls.