Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re: Bitwise & not working correctly in CGI script

by kennethk (Monsignor)
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 fluff.pl line 7 business_unit: D at fluff.pl line 7 business_unit: D at fluff.pl 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.


Comment on Re: Bitwise & not working correctly in CGI script
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (10)
As of 2014-07-10 10:27 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    When choosing user names for websites, I prefer to use:








    Results (206 votes), past polls