#!/usr/bin/perl # # Name : Matthew Reeves # # Converts a binary number to decimel # #use diagnostics; use warnings; use strict; #use feature ":5.10"; #prompt user for binary number to be converted, chomp $input print "\nPlease enter a binary number: "; chomp(my $input = <>); #declares and sets initial values for variables my $tmp = ""; my $count = 0; my $decimel = 0; my $binary = $input; #loop to process binary-decimel conversion. Chops off digits #from input from right to left, checks if digit is 1 or not, #and if it is, raises 2 to the appropriate power based on the #value of $count, and adds result to current value for $decimel #then increments $count. Loop runs until $binary = empty string. while ($binary ne "") { $tmp = chop $binary; if ($tmp == 1) { $decimel+=2**$count; } $count++; } #prints original value, and converted value to screen print "$input is $decimel in decimel.\n\n"; #I see now why you said arrays would be overkill for this assignment, #the array implementation I coded first was way more complex that this.