I thought this would be a no-brainer. I've been using a command line version of this code explicitly entering the values to get the proper number to put into the debug_level value in nagios.cfg: perl -e 'printf("%d\n", 16|8);'.
I got tired of typing it, so I wrote what i thought was a simple script:
#!/usr/bin/perl
use strict;
use warnings;
# a simple script to produce the 'or' number required for the debug_le
+vel setting
# in nagios.cfg
my $or;
for my $x (@ARGV){
$or |= $x ;
}
printf("%d\n", $or);
exit;
The results were NOT what I expected. I'd have been happier if they returned '42' instead of '96', but '24' is what is supposed to come out. Here's me running it in the debugger:
perl -d or 16 8
Loading DB routines from perl5db.pl version 1.37
Editor support available.
Enter h or 'h h' for help, or 'man perldebug' for more help.
main::(or:9): my $or;
DB<53> n
main::(or:10): for my $x (@ARGV){
DB<53> n
main::(or:11): $or |= $x ;
DB<53> x $or, $x
0 undef
1 16
DB<54> x $or|$x
0 16
DB<55> n
main::(or:11): $or |= $x ;
DB<55> x $or, $x
0 16
1 8
DB<56> x $or|$x
0 96
DB<57> x 16|8
0 24
DB<58> n
main::(or:14): printf("%d\n", $or);
DB<58> n
96
main::(or:16): exit;
It's mystified the other perl programmer at my office as well. What's going on here?
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
|
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.