hchana has asked for the wisdom of the Perl Monks concerning the following question:
Hi, I'm trying open Text2.txt file and saving contents of each line into an array. I then wish to print each line of the array whilst keeping count of the array length. But this script is not working.? what am I doing wrong.? I am a complete novice, so please could I have simple to understand suggestions. thank you.
#!\usr\bin perl use warnings; use strict; use diagnostics; use feature 'say'; open(FILE, "Text2.txt") or die; my @lines; foreach (my $i = 0; $i < @lines; $i++) { say $lines[$i]; } Error message: Name "main::FILE" used only once: possible typo at open.pl line 9 (#1) (W once) Typographical errors often show up as unique variable nam +es. If you had a good reason for having a unique name, then just menti +on it again somehow to suppress the message. The our declaration is provided for this purpose. NOTE: This warning detects symbols that have been used only once s +o $c, @c, %c, *c, &c, sub c{}, c(), and c (the filehandle or format) are con +sidered the same; if a program uses $c only once but also uses any of the +others it will not trigger this warning.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: iterative foreach loop
by haukex (Archbishop) on Nov 14, 2017 at 10:28 UTC | |
by hchana (Acolyte) on Nov 14, 2017 at 11:23 UTC | |
by haukex (Archbishop) on Nov 14, 2017 at 11:29 UTC | |
by 1nickt (Canon) on Nov 14, 2017 at 13:56 UTC | |
|
Re: iterative foreach loop
by Laurent_R (Canon) on Nov 14, 2017 at 11:28 UTC | |
|
Re: iterative foreach loop
by thanos1983 (Parson) on Nov 14, 2017 at 11:38 UTC | |
|
Re: iterative foreach loop
by zarath (Beadle) on Nov 15, 2017 at 11:09 UTC | |
by hippo (Archbishop) on Nov 15, 2017 at 11:29 UTC | |
by zarath (Beadle) on Nov 15, 2017 at 11:38 UTC |