Hi All,
I have a piece of code which reads as shown below:
unless (open(IN, "in.txt")) {
die("Cannot open input file \n");
}
binmode(IN);
unless (open(OUT, "+>output.txt")) {
die("Cannot open input file input.txt\n");
}
%structure = ( 1 => "A", 2 => "B", 3 => "C",
);
@keys = keys %structure;
%table = ( A => 4, B => 8, C => 32,
);
$j=0;
print("ENTER THE SEQUENCE between[1-3]:\n");
$seq = <STDIN>;
chop($seq);
@seq = split(/ +/, $seq);
$seq_len = @seq;
$input = <IN>;
@input = split(/ +/, $input);
$new = join ("", @input);
for($i=0; $i<$seq_len; $i++) {
$read1[$i] = $table{$structure{$seq[$j]}};
syswrite (OUT, $new, $read1[$i]);
print OUT ("\n");
$j++;
}
In the above code, i m trying to read the input in bytes and display them in
another output file. The reading is done in different sizes (4 or 8 or
32bytes), as per the sequence specifed by the User. The input file with
filehandle IN contains data as shown below:
F1 2F 8A 02 05 09 00 00 00 04 2B 48 00 00 00 68
When i use syswrite function, i face the following problem
syswrite (OUT, $new, 4); => Writes 4 bytes properly
syswrite (OUT, $new, $val); (where $val =4;) => Writes 4 bytes properly
syswrite (OUT, $new, $read1[$i]); => This does not work. It displays all the
bytes together, without seperators(new line). I dont know the reason.
Can anyone please guide me in this?
Thanks and Regards,
Dharshana