|
|
nobull67@gmail.com wrote:
> Jay wrote:
>
> Your script seems to have nothing to do with that description.
>
> It's so far off I can't even imagine what you think it does.
>
>
> Consider using strict and warnings. It really will make life a _lot_
> less painful.
>
>
> scalar() in the above is redundant.
>
> What you believe is the purpose of the above statement? Nothing ever
> uses the value you've just put in $lines.
>
>
> Use the 3 arg open unless there's a reason not to.
>
> Do not quote varialbles for no reason.
>
> Consider putting the reason why you can't open in the error message.
>
> open (FILE, '<', $ARGV[0]) or die "Can't open $ARGV[0]: $!\n";
>
>
> There is no value in $line. Perl would have told you in so many ways if
> you'd allowed it. Remember what I said about pain. This is it.
>
> What does splitting lines have to do with your stated purpose?
>
>
> What is the purpose of %processes? You never use it again.
>
> What does counting occurances of distinct values in the first column
> have to do with your stated purpose?
>
>
> What do you suppose that does?
>
>
> What do you suppose that does?
Ok, so forget all that code then. Obviously I am so far off. Let's
focus on the original problem. I have to write a perl script for a
class which reads a file and prints its contents on screen and prefixes
each line with a line numbers. I know how to read the file and print
it properly, but how do I prefix each line with a line number?
#!/usr/bin/perl -w
open (FILE, "$ARGV[0]") or die "Can't open $ARGV[0]\n";
while ($lines = <FILE> ) {
print $lines;
}
close (FILE);
|
|