Good that you are using strict and warnings, but you have to end
the expressions with a semicolon.
use strict;
use warnings;
...
Doing this will allow you to get information on problems in your
code. You have a syntax error for the
while line and a
missing curly brace in the last line.
I'm fairly sure you are missing the purpose of this assignment,
though. The only way it makes sense to me is for you to write
four separate pieces of logic, each printing the numbers
successfully. The only code you have close to doing this so far is
part of one line.
print 2*$_, "\n", foreach (1..20);
This could be rewritten if you want as follows, but note you are
still missing zero in the printout.
for ( 1..20 ) {
print 2*$_, "\n";
}
I suggest you read the documentation carefully for
while, until, for, and do in perlsyn and try some examples
from there to see how you can write similar code which does what you want. Just having monks here give you working code will not have long-term value for you, but learning how to read documentation and produce working code yourself will be of great value.
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.