in reply to Using @ARGV
You have several problems. You are supplying two arguments on the command line so the size of @ARGV is going to be 2.
You would be better off checking to see if @ARGV contains anything and continuing from there.
You are opening the file handle FILE, then reading from STDIN, so you probably are not getting what you expect.
You should never use the captured variables from a regex without checking to see if the match succeded.
use warnings; #<-- also a good idea, especially if you are just starti +ng perl programming use strict; die "Specify a file path\n" unless @ARGV; open my $fh, shift or die "Cannot open file: $!\n"; while (<$fh>) { if (/(\S+)\s+\S+\s+(\S+)\s+(.*)/){ #testing regex and tags print "$1, $2, $3\n"; #testing printing } } close $fh; print "Done!\n";
Then leave 'open' out of the command line.
myperlscript.pl "C:/path/to/file/on_windows_pc/file.txt"
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Using @ARGV
by Joost (Canon) on Dec 03, 2005 at 18:29 UTC | |
by merlyn (Sage) on Dec 03, 2005 at 18:50 UTC | |
by revdiablo (Prior) on Dec 03, 2005 at 21:50 UTC | |
by merlyn (Sage) on Dec 04, 2005 at 01:36 UTC | |
by Joost (Canon) on Dec 04, 2005 at 03:56 UTC |