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
        This construct pulls filenames from the @ARGV array, automatically.

        It also introduces some potential security risks if used wantonly, as described in Dangerous diamonds!. These risks are frequently acceptible, and I'm sure you're already aware of them, but I feel it's something worth mention for the benefit of others. :-)

        Update: thought it might be good to mention the original code uses two-arg open anyway, so switching to <> doesn't add any security risks that weren't already there.

        Another update: quick note about merlyn's reply. I wasn't really "that concerned", which is what I was trying to say when I wrote "these risks are frequently accept[a]ble." Maybe that wasn't very clear.