Is that your real program? You never open INFILE, so you never read anything from it, so you never add anything to @newseq. Use use strict; and use warnings;. You would have gotten
Name "main::INFILE" used only once: possible typo at a.pl line 18. readline() on unopened filehandle INFILE at a.pl line 18.
instead of having to waste your time waiting for a reply here.
Other problems:
for (my $i=0;$i<$#bin;$i++)
ends too soon. You want
for (my $i=0;$i<@bin;$i++)
or
for (my $i=0;$i<=$#bin;$i++)
Or even better,
for my $i (0..$#bin)
$run++ is executed too often. Change
if ($bin[$i]==1 && $bin[$i+1]==0)
to
elsif ($bin[$i]==1 && $bin[$i+1]==0)
What if the last one isn't followed by a zero?
elsif ($bin[$i]==1 && $bin[$i+1]==0)
should be
elsif ( $bin[$i]==1 && ($i==$#bin || $bin[$i+1]==0) )
What if you get a sequence of 16 ones?
You don't need %rules or @arg1.
$rules{$newseq[$_-1]}
is a weird way of saying
$results[$newseq[$_-1]]
The "1 .." (instead of "0 ..") and the "- 1" look very suspicious in the last loop. Can't say for sure without knowing what you want.
In reply to Re: length of 1's
by ikegami
in thread length of 1's
by coldy
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |