i do not understand the foreach loop..can anyone explain to me what is it doing?
#!/usr/bin/perl -w print "Your binary input please =>"; $bin = <STDIN>; #read in user input chomp $bin; # use of array to store $bin and split it @digits = reverse(split('',$bin)); #reverse and split $bin, then assig +n to an array $result = 0; foreach $pos (0..$#digits) { $result += $digits[$pos] * 2 ** $pos; } print $result;
In reply to binary converter by perlnoobz
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |