My output seems to be coming out in reverse order of how it is programmed. Can anyone tell me why? Also, when run it says scalar value @binary
1 better written as $binary
1, what does that mean?
I am running a piece of code which shows output:
Program ended successfully
In binary, that is 11111111
The code is:
#!C:\Perl\
use warnings;
use strict;
#binary.plx
print"Please enter an integer less than or equal to 256: ";
our $decimal = <STDIN>;
our @binary = ("0","1","2","3","4","5","6","7","8");
our $x = 0;
print"Checkpoint1\n";
if ($decimal == "256")
{
print "In binary, that is ";
while ($x < 8)
{
@binary[$x]=1;
print @binary[$x];
$x++;
}
die"\n\nProgram ended successfully";
}
elsif ($decimal < "256")
{
@binary[0] = 0;
}
# Nothing more needs to be done here.
elsif ($decimal >"256")
{
die"\nYou entered an invalid number!\n\n";
}
$decimal-=128;
print"\ndecimal is ",$decimal;
if ($decimal < "128")
{
@binary[1] = 0;
print"\nThe second digit ",@binary[1];
}
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.