Perl Parsing Argument


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Perl Parsing Argument
# 1  
Old 05-16-2009
Perl Parsing Argument

i wanna passing an argument which read in a file or a set of files if the files are given in the command line, otherwise use STDIN if no file argument.
i got something like that, but it is not really working.
so can anyone help me? which one is better to use for and how? Use perl.

Thank you

Code:
use Getopt()::Long;
GetOptions( "file=s" => \$file );


Code:
$str = @ARGV ? $ARGV[0] : <STDIN>
chomp ($str = <STDIN>);

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

parsing argument in perl

in bash: LIST=`cat $1` for i in $LIST do ... done how will i do this in perl ? $1 is my first arguement. I'm a newbie in perl and will appreciate much your help guys ... (4 Replies)
Discussion started by: linuxgeek
4 Replies

2. Shell Programming and Scripting

Question about argument parsing in scripts

Hello all, I am relatively new to linux and bash scripting. I have what seems to be a simple question but I'm having trouble finding the answer. The question is what is the difference between the variables $@ and $*. I've seen them both used in the same context, and I've tried a number of... (4 Replies)
Discussion started by: nicthu
4 Replies

3. Shell Programming and Scripting

How to use perl to run bash with argument?

Hi All, I want to run a bash script using perl. But they are in the different dir. #! /usr/bin/perl -w use strict; my $root=`pwd`; chomp($root); my $cmd=".$root/testdir/ft_623.sh 3 4 5 6 7"; print $cmd; my @line=`$cmd`; foreach (@line){ print $_; } ft_623.sh (0 Replies)
Discussion started by: Damon sine
0 Replies

4. Shell Programming and Scripting

PERL need help splitting argument

If i have a script name.pl I run it like name.pl -v file.txt -t ext2 -u user -j how can I edit the array @ARGV so when my script calls $ARGV = -v file.txt $ARGV = -j (2 Replies)
Discussion started by: 3junior
2 Replies

5. Shell Programming and Scripting

Perl parsing compared to Ksh parsing

#! /usr/local/bin/perl -w $ip = "$ARGV"; $rw = "$ARGV"; $snmpg = "/usr/local/bin/snmpbulkget -v2c -Cn1 -Cn2 -Os -c $rw"; $snmpw = "/usr/local/bin/snmpwalk -Os -c $rw"; $syst=`$snmpg $ip system sysName sysObjectID`; sysDescr.0 = STRING: Cisco Internetwork Operating System Software... (1 Reply)
Discussion started by: popeye
1 Replies

6. Shell Programming and Scripting

problem with spaces and argument parsing

public class HelloWorld { public static void main(String args) { System.out.println("Welcome, master"); } } and I compiled using javac HelloWorld.java ] Suppose that I execute the following command directly from the shell: java -XX:OnError="gdb - %p" HelloWorld Then it works... (8 Replies)
Discussion started by: fabulous2
8 Replies

7. Shell Programming and Scripting

not null cheking of an argument in perl

Hi, I have to check whether an argument say $ARGV is not null in an if operator. Please let me know the operator. It would be great if you write a psuedo code. Thanks in advance Ammu (4 Replies)
Discussion started by: ammu
4 Replies

8. Shell Programming and Scripting

argument parsing...

Hi all, Iam a beginer in shell scripting. i need a script that can parse the arguments and store them in variables. ex: ./myScript -v v1 -h v2 -c v3...... can someone suggest me...? tnx in adv. (1 Reply)
Discussion started by: midhun_u
1 Replies

9. UNIX for Dummies Questions & Answers

command line argument parsing

how to parse the command line argument to look for '@' sign and the following with '.'. In my shell script one of the argument passed is email address. I want to parse this email address to look for correct format. rmjoe123@hotmail.com has '@' sign and followed by a '.' to be more... (1 Reply)
Discussion started by: rmjoe
1 Replies

10. Shell Programming and Scripting

shell script argument parsing

how to parse the command line argument to look for '@' sign and the following with '.'. In my shell script one of the argument passed is email address. I want to parse this email address to look for correct format. rmjoe123@hotmail.com has '@' sign and followed by a '.' to be more... (1 Reply)
Discussion started by: rmjoe
1 Replies
Login or Register to Ask a Question
HasVersion(3)						User Contributed Perl Documentation					     HasVersion(3)

NAME
Test::HasVersion - Check Perl modules have version numbers SYNOPSIS
"Test::HasVersion" lets you check a Perl module has a version number in a "Test::Simple" fashion. use Test::HasVersion tests => 1; pm_version_ok("M.pm", "Valid version"); Module authors can include the following in a t/has_version.t file and let "Test::HasVersion" find and check all installable PM files in a distribution. use Test::More; eval "use Test::HasVersion"; plan skip_all => 'Test::HasVersion required for testing for version numbers' if $@; all_pm_version_ok(); DESCRIPTION
Do you wanna check that every one of your Perl modules in a distribution has a version number? You wanna make sure you don't forget the brand new modules you just added? Well, that's the module you have been looking for. Use it! Do you wanna check someone else's distribution to make sure the author have not commited the sin of leaving Perl modules without a version that can be used to tell if you have this or that feature? "Test::HasVersion" is also for you, nasty little fellow. There's a script test_version which is installed with this distribution. You may invoke it from within the root directory of a distribution you just unpacked, and it will check every .pm file in the directory and under lib/ (if any). $ test_version You may also provide directories and files as arguments. $ test_version *.pm lib/ inc/ $ test_version . (Be warned that many Perl modules in a t/ directory do not receive versions because they are not used outside the distribution.) Ok. That's not a very useful module by now. But it will be. Wait for the upcoming releases. FUNCTIONS PRIVATE _pm_version $v = _pm_version($pm); Parses a PM file and return what it thinks is $VERSION in this file. (Actually implemented with "use ExtUtils::MakeMaker; MM->parse_version($file)".) $pm is the filename (eg., lib/Data/Dumper.pm). pm_version_ok pm_version_ok('Module.pm'); pm_version_ok('M.pm', 'Has valid version'); Checks to see if the given file has a valid version. Actually a valid version number is defined and not equal to 'undef' (the string) which is return by "_pm_version" if a version cannot be determined. all_pm_version_ok all_pm_version_ok(); all_pm_version_ok(@PM_FILES); Checks every given file and .pm files found under given directories to see if they provide valid version numbers. If no argument is given, it defaults to check every file *.pm in the current directory and recurses under the lib/ directory (if it exists). If no test plan was setted, "Test::HasVersion" will set one after computing the number of files to be tested. Otherwise, the plan is left untouched. PRIVATE _list_pm_files @pm_files = _list_pm_files(@dirs); Returns all PM files under the given directories. all_pm_files @files = all_pm_files() @files = all_pm_files(@files_and_dirs); Implements finding the Perl modules according to the semantics of the previous function "all_pm_version_ok". USAGE
Other usage patterns besides the ones given in the synopsis. use Test::More tests => $num_tests; use Test::HasVersion; pm_version_ok($file1); pm_version_ok($file2); Obviously, you can't plan twice. use Test::More; use Test::HasVersion; plan tests => $num_tests; pm_version_ok($file); "plan" comes from "Test::More". use Test::More; use Test::HasVersion; plan 'no_plan'; pm_version_ok($file); "no_plan" is ok either. SEE ALSO
Test::Version Please reports bugs via CPAN RT, http://rt.cpan.org/NoAuth/Bugs.html?Dist=Test-HasVersion AUTHOR
A. R. Ferreira, <ferreira@cpan.org> COPYRIGHT AND LICENSE
Copyright (C) 2006 by A. R. Ferreira This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself. perl v5.16.3 2006-10-07 HasVersion(3)