There's more than one way to do things | |
PerlMonks |
Operate with bitsby syedasadali95 (Acolyte) |
on Mar 11, 2020 at 07:06 UTC ( [id://11114115]=perlquestion: print w/replies, xml ) | Need Help?? |
syedasadali95 has asked for the wisdom of the Perl Monks concerning the following question: Hi Monks, I am trying to read a file from my perl script and decide something based on the 6th bit of my address pattern which I read from the file. For example I have a file which has the following lines: 43307205 (26224) chn:req mon:orig cmd:SDP_CMD_RDBLKL tag:0x3bb504dd addr:0x1009dc0 qospri:0 len:0xf qosfw:0 vc:4 unit:0x0 thrd:15 chain:0 io:0 blklvl:0 noalloc:0 43331070 (26239) chn:req mon:orig cmd:SDP_CMD_WRSIZEDFULL tag:0x3bb508e1 addr:0xcf09dc0 qospri:0 len:0xf qosfw:0 vc:4 unit:0x0 thrd:14 chain:0 io:0 blklvl:0 noalloc:0 I want to do the following 1. Read the input file 2. Open two output files (Out1 & Out2) 3. Grep the address value from the input file (addr:0xcf09dc0) 4. If 6th bit of addr field is zero (addr[ 6 ]=0) then print the entire line to Out1 file/ If 6th bit is one (addr[ 6 ]=1) then print the entire line to Out2 file ############ Code starts #############
######## Code ends ######### From the above code, instead of checking for SDP_CMD_RDBLKL and SDP_CMD_WRSIZEDFULL, I need to check if addr[ 6 ] = 0/1 Please suggest any way to operate on bit positions in perl.
Back to
Seekers of Perl Wisdom
|
|