in reply to length of 1's
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.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: length of 1's
by coldy (Scribe) on Apr 27, 2009 at 04:51 UTC | |
by ikegami (Patriarch) on Apr 27, 2009 at 05:07 UTC | |
by coldy (Scribe) on Apr 27, 2009 at 05:27 UTC | |
by ikegami (Patriarch) on Apr 27, 2009 at 05:30 UTC | |
by coldy (Scribe) on Apr 27, 2009 at 05:42 UTC | |
by coldy (Scribe) on Apr 27, 2009 at 05:09 UTC | |
by ikegami (Patriarch) on Apr 27, 2009 at 05:13 UTC |