in reply to Bit operation

you're writing C style perl, but for #1 the |= operand should work fine. Though you don't need all those leading zeroes, unless you think it helps you read the function better, you could just do  $a |= 0x8;

You can't change the value of $a by using it as a function parameter in MyGetFunc. You'll want to either return that as a value, or pass in a reference to the variable, and access it directly. ex.  $a = MyGetFunc() would change the value of $a, but passing it to a function would not, unless you passed a reference to $a.

Not sure I understand the whole question, what are you asking about regarding a regex? Are you extracting some string? And are they seperated by attribute:string: value? If so , then you may just need to use split on the colon delimiter and store the values separately.) (then use the perl function "hex" to convert a string of hexadecimal digits to a hex integer value)

Replies are listed 'Best First'.
Re^2: Bit operation
by jethro (Monsignor) on Jan 12, 2011 at 14:30 UTC
    perl -e ' sub dom { $_[0]=2;} $x=1; dom($x); print $x,"\n";' #prints 2

    Although it is not best practice to do so you can change parameters of subroutines

      Fine. I stand corrected... and I'm pretty sure the guy asking about how to use a bitwise or will find this practice very useful. Buwahahaha. :)
Re^2: Bit operation
by Anonymous Monk on Jan 12, 2011 at 14:24 UTC
    You can't change the value of $a by using it as a function parameter in MyGetFunc.

    Sure you can, perl is perl :)

    sub lunch { $_[0]++ } my $foo = 1; warn $foo; lunch($foo); warn $foo; __END__ 1 at - line 3. 2 at - line 5.
    search for alias in perlsub

      I assume what raybies was referring to was that unless $a is within a scope that encloses the subroutine (which it is in your case but may not necessarily be in the OP's case) then it *can* be modified without having to return it.

      However, in my experience, having been bitten way too many times by not paying attention to scopes and mis-using "global variables", in my humble opinion, it is much, much better to be careful and discipline oneself to think of it more along the lines as raybies posed it by keeping things more encapsulated and planning for the variable to be local to the subroutine and then explicitly returning values that you want to change...or to at least be clearer, through the use of references as some of the other responders suggested, that you are doing the change.

      But that is just my opinion and certainly your comment is, to the best of my knowledge, right.

      ack Albuquerque, NM

        You seem to be referring to accessing and changing global variables from inside a subroutine. But notice that Anonymous Monk's example doesn't use global variables. It uses the the fact that perl actually uses call-by-reference when calling a subroutine. The variable @_ contains references to the variables that were used in the subroutine invocation. That is why it is so important to use something like my ($bla,$x,@f)= @_; in subroutines. Because otherwise you are in danger of changing values at a distance.