Hi Can someone help me to figure out why i am not gettiong the right output. on the screen it prints fine but not in the file
Thanks
######################################################
#!/usr/local/bin/perl
open(DAT, "datafile.txt") ||die("Could not open file!");
open(FILE, ">output.txt") || die("Could not open file!");
@read_data=<DAT>;
foreach $variable(@read_data)
{
# print "$variable\n";
binary_2_decimal($variable);
}
sub binary_2_decimal{
my $int = shift;
## constant = 10000000000000000000000000000000
my $and = 0x80000000;
## for each bit
for(1..32){
## if the bit is set, print 1
if( $int & $and ){
print "1";
}
## if the bit is not set, print 0
else{
print "0";
}
## shift the constant using right shift
$and = $and >> 1;
}
print "\n";
print FILE "$and\n";
}
close(DAT);
close(FILE);
####################################################
Thanks
######################################################
#!/usr/local/bin/perl
open(DAT, "datafile.txt") ||die("Could not open file!");
open(FILE, ">output.txt") || die("Could not open file!");
@read_data=<DAT>;
foreach $variable(@read_data)
{
# print "$variable\n";
binary_2_decimal($variable);
}
sub binary_2_decimal{
my $int = shift;
## constant = 10000000000000000000000000000000
my $and = 0x80000000;
## for each bit
for(1..32){
## if the bit is set, print 1
if( $int & $and ){
print "1";
}
## if the bit is not set, print 0
else{
print "0";
}
## shift the constant using right shift
$and = $and >> 1;
}
print "\n";
print FILE "$and\n";
}
close(DAT);
close(FILE);
####################################################