<?xml version="1.0" encoding="windows-1252"?>
<node id="975996" title="Re: Bitwise &amp; not working correctly in CGI script" created="2012-06-13 11:30:52" updated="2012-06-13 11:30:52">
<type id="11">
note</type>
<author id="712372">
kennethk</author>
<data>
<field name="doctext">
I cannot not recover your issue.  If I run the code provided (after adding &lt;c&gt;use Carp 'cluck';&lt;/c&gt;, &lt;c&gt;my $job_type = 65;&lt;/c&gt;, and a closing quote on your line 4, I get the output on STDERR:
&lt;c&gt;business_unit:  at fluff.pl line 7
business_unit: D at fluff.pl line 7
business_unit: D at fluff.pl line 7&lt;/c&gt;
I suspect your issue is that what you actually mean to have is something like
&lt;c&gt;use strict;
use Carp 'cluck';

my $job_type = 65;
my %bj = (64,'D', 128,'A', 256,'H');
foreach my $flag (keys %bj) {
    if ($flag &amp; $job_type) {
        my $bu = $bj{$flag};
        cluck("business_unit: $bu");
    }
}&lt;/c&gt;
&lt;p&gt;The difference here is that I am now only outputting when the if condition is true; your &lt;c&gt;if&lt;/c&gt; applied only to the assignment, not the &lt;c&gt;cluck&lt;/c&gt;.
&lt;p&gt;&lt;b&gt;Update&lt;/b&gt;: [Jenda] also has a plausible explanation, if [id://975999] is correct.  This makes sense if you are pulling the string out of &lt;c&gt;$cgi-&gt;param&lt;/c&gt;, which contains only strings.  You can numify the result using &lt;c&gt;my $job_type = 0+ $cgi-&gt;param('job');&lt;/c&gt;, for whatever those variables are called locally.
&lt;!-- Node text goes above. Div tags should contain sig only --&gt;
&lt;div class="pmsig"&gt;&lt;div class="pmsig-712372"&gt;
&lt;hr /&gt;
&lt;p&gt;#11929 First ask yourself `How would I do this without a computer?'  Then have the computer do it the same way.&lt;/p&gt;
&lt;/div&gt;&lt;/div&gt;</field>
<field name="root_node">
975971</field>
<field name="parent_node">
975971</field>
</data>
</node>
