Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re^7: How can I set a bit to 0 ?

by LanX (Saint)
on May 27, 2022 at 13:12 UTC ( [id://11144222]=note: print w/replies, xml ) Need Help??


in reply to Re^6: How can I set a bit to 0 ?
in thread How can I set a bit to 0 ?

> bartender1382 posts some nonsensical snippet that doesn't even compile ... and everyone has a ready made solution !!

you seem to miss that he's using constants, like so often in bit operations.

DB<44> use constant {upload =>0b1, getTicket =>0b10, downLoading=>0b +100}; DB<45> use warnings; use strict; say my $stats = upload | getTicket +| downLoading; 7 DB<46>

> The interesting thing with this thread is that I can't see how any of the replies (including GF's diversion) relate to the original post.

Now I'd be interested to know how I failed to answer exactly the question given in a concise way, especially given the level of the OP.

Plus explanation most others were lacking including the correct terminology and multiple further read-more links.

Cheers Rolf
(addicted to the Perl Programming Language :)
Wikisyntax for the Monastery

Replies are listed 'Best First'.
Re^8: How can I set a bit to 0 ?
by hippo (Bishop) on May 27, 2022 at 14:03 UTC
    you seem to miss that he's using constants

    You seem to assume that he's using constants ;-)

    Unfortunately, he hasn't provided the definitions of those labels, let alone an SSCCE, so it's all guesswork.


    🦛

      > You seem to assume that he's using constants

      Question: is there any other strict explanation for barewords as operands?

      I've seen this pattern so many times with modules exporting flags and IIRC even perldocs°, that this discussion is surprising me.

      Cheers Rolf
      (addicted to the Perl Programming Language :)
      Wikisyntax for the Monastery

      update

      °) see last paragraph in chmod

        You can also import the symbolic S_I* constants from the Fcntl module:

        use Fcntl qw( :mode ); chmod S_IRWXU|S_IRGRP|S_IXGRP|S_IROTH|S_IXOTH, @executables; # Identical to the chmod 0755 of the example above.
        Question: is there any other strict explanation for barewords as operands?

        Sure, any subs will do - they don't have to be constants:

        #!/usr/bin/env perl use strict; use warnings; sub upload () { rand 50 } sub getTicket () { rand 60 } sub downLoading () { rand 70 } sub printCLine { print shift } # Start of bartender1382 code my $stats = 0; $stats = upload | getTicket | downLoading; printCLine ($stats); # End of bartender1382 code

        🦛

Re^8: How can I set a bit to 0 ?
by syphilis (Archbishop) on May 27, 2022 at 14:55 UTC
    Now I'd be interested to know how I failed to answer exactly the question given in a concise way, especially given the level of the OP.

    I didn't say that you (or anyone else) had failed to answer the question.
    All I said was that I couldn't see how the answers given related to the question that was asked ... for the simple reason that I couldn't work out what the question actually was (owing to lack of details given).
    Sure, I know the OP wants to set bits in something - in a PV ? in an IV ? in an NV ? in some object (maybe Math::GMP or Bit::Vector) ?

    Everyone else seems to reckon they know, and if they were able to deduce that from the original post, then well done !!
    But I don't have that level of psychic acuity.

    Cheers,
    Rob
      bit operations happen normally on unsigned integers, I'd say in >90% of the cases (at least)

      And I've already shown two instances of perldocs demonstrating exactly that pattern.

      > in a PV ? in an IV ? in an NV ?

      I reckon IV is an integer value ... please explain the rest° in this context, my perlguts are aching ;-)

      And the OP will most probably only know "scalar".

      Cheers Rolf
      (addicted to the Perl Programming Language :)
      Wikisyntax for the Monastery

      °) OK looking up in "Advanced Perl Programming" (sic)

      > A scalar value (SV) contains the value of the scalar, a reference count, and a bitmask to describe the state of the scalar. The scalar may be an integer value ("IV"), a double ("NV"), a string ("PV" for pointer value),

      I can't see how this is relevant here.

      update

      I mean: If someone asks how best to hold a hammer, do you complain he didn't tell you which alloy the nails are made of and where the original ore was mined? Seriously?

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (5)
As of 2024-04-16 07:25 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found