open (INFILE, "$ARGV[1]") or die "$ARGV[1] cannot be openned : $!";
while ($source_file =~ /(\d)\s+(\d)\s+(\d)\s+(\w+)/)
Maybe (probably) in your head there's a connection between INFILE and $source_file, but not in your script. For Perl, they're unrelated…
if ($ARGV[0] eq "-a")
How do you know your $ARGV[0] really equals "-a"? What happens if it doesn't? I recommend to add an else block with a print "whatever\n", at least while you're still experimenting.
-
Many of the suggestions to your questions include using strict and warnings. Although this seems to impede or slowing down one's development, I recommend it, too:
-
Yes, the time it takes before your script "runs", will be longer
-
The time until your script works correctly, will be shorter
One of strict's messages is confusing for beginners: Global symbol "$x" requires explicit package name should read Do you really want "$x" to be a global symbol? Better declare it with my
If you are new to Perl, you might like diagnostics, which won't throw more errors, but messages that (hopefully) are more informative.
So, your script(s) should start with use strict;
use warnings;
use diagnostics;
-
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.
|