joaming has asked for the wisdom of the Perl Monks concerning the following question:
Hi, I am new to Perl, learning how to parse a linux log file. So, I grep sth from the log, serving as input to m parse script and print the result to a proper format.
[linux host] $ grep "Something" sample.log | perl myParser.pl my $line; foreach $line (<>) { ... }
This works fine, but I would like to supply more parameter to my perl script to determine the format style, eg.
will print the result vertically,$ grep "Something" sample.log | perl myParser.pl VERTICAL
will print the result in columnized format.$ grep "Something" sample.log | perl myParser.pl COLUMN
I tried to capture it by $ARGV[0], $ARGV1, but still failed. Please kindly help
More, i did a simple test
#!/usr/bin/perl use strict; my $param0 = $ARGV[0]; my $line; print "\nFirst Arguement is : $param0"; foreach $line (<>) { ... }
$ grep "Name=" sample.log | perl SimpleTest.pl VERTICAL
Can't open VERTICAL: No such file or directory at SimpleTest.pl line 1 +1. First Arguement is : VERTICAL
Then , it just stopped and not execute the foreach loop
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: More Arguments
by Athanasius (Archbishop) on Sep 05, 2015 at 04:31 UTC | |
by joaming (Novice) on Sep 05, 2015 at 05:27 UTC | |
|
Re: More Arguments
by choroba (Cardinal) on Sep 05, 2015 at 07:18 UTC | |
|
Re: More Arguments
by stevieb (Canon) on Sep 05, 2015 at 03:37 UTC | |
by joaming (Novice) on Sep 05, 2015 at 04:06 UTC | |
|
Re: More Arguments
by parv (Parson) on Sep 05, 2015 at 03:35 UTC | |
|
Re: More Arguments
by QuillMeantTen (Friar) on Sep 06, 2015 at 14:12 UTC |