Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical

Re: Bitwise & not working correctly in CGI script

by kennethk (Abbot)
on Jun 13, 2012 at 15:30 UTC ( #975996=note: print w/replies, xml ) Need Help??

in reply to Bitwise & not working correctly in CGI script

I cannot not recover your issue. If I run the code provided (after adding use Carp 'cluck';, my $job_type = 65;, and a closing quote on your line 4, I get the output on STDERR:
business_unit: at line 7 business_unit: D at line 7 business_unit: D at line 7
I suspect your issue is that what you actually mean to have is something like
use strict; use Carp 'cluck'; my $job_type = 65; my %bj = (64,'D', 128,'A', 256,'H'); foreach my $flag (keys %bj) { if ($flag & $job_type) { my $bu = $bj{$flag}; cluck("business_unit: $bu"); } }

The difference here is that I am now only outputting when the if condition is true; your if applied only to the assignment, not the cluck.

Update: Jenda also has a plausible explanation, if Re: Bitwise & not working correctly in CGI script is correct. This makes sense if you are pulling the string out of $cgi->param, which contains only strings. You can numify the result using my $job_type = 0+ $cgi->param('job');, for whatever those variables are called locally.

#11929 First ask yourself `How would I do this without a computer?' Then have the computer do it the same way.

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (11)
As of 2016-10-25 13:55 GMT
Find Nodes?
    Voting Booth?
    How many different varieties (color, size, etc) of socks do you have in your sock drawer?

    Results (320 votes). Check out past polls.