Perl Getopt::Long question - stopping multiple args


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Perl Getopt::Long question - stopping multiple args
# 8  
Old 02-18-2010
I don't think so:
Code:
$ perl --version

This is perl, v5.8.8 built for i486-linux-gnu-thread-multi

Copyright 1987-2006, Larry Wall

Perl may be copied only under the terms of either the Artistic License or the
GNU General Public License, which may be found in the Perl 5 source kit.

Complete documentation for Perl, including FAQ lists, should be found on
this system using "man perl" or "perldoc perl".  If you have access to the
Internet, point your browser at http://www.perl.org/, the Perl Home Page.

$ perl test.pl --firstname John --surname Woo Wayne
firstname is set to  - John
surname is set to  - Woo Wayne

Getopt::Long is 2.35, you can check this in the headers of (probably) /usr/share/perl/5.8/Getopt/Long.pm
# 9  
Old 02-18-2010
I have a mixture of solaris 8 and 10. this is the module information of one of my more recent boxes


Code:
# cat /usr/perl5/5.8.4/lib/Getopt/Long.pm | more
# Getopt::Long.pm -- Universal options parsing

package Getopt::Long;

# RCS Status      : $Id: GetoptLong.pm,v 2.68 2003-09-23 15:24:53+02 jv Exp $
# Author          : Johan Vromans
# Created On      : Tue Sep 11 15:00:12 1990
# Last Modified By: Johan Vromans
# Last Modified On: Tue Sep 23 15:21:23 2003
# Update Count    : 1364
# Status          : Released

################ Copyright ################

# This program is Copyright 1990,2002 by Johan Vromans.
# This program is free software; you can redistribute it and/or
# modify it under the terms of the Perl Artistic License or the
# GNU General Public License as published by the Free Software
# Foundation; either version 2 of the License, or (at your option) any
# later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# If you do not have a copy of the GNU General Public License write to
# the Free Software Foundation, Inc., 675 Mass Ave, Cambridge,
# MA 02139, USA.

################ Module Preamble ################

use 5.004;

use strict;

use vars qw($VERSION);
$VERSION        =  2.34;


maybe they added this code in 2.35 ?
# 10  
Old 02-18-2010
Could be. Try fetching the current version from CPAN, and install it non-globally first. If everything works out, install it for the whole machine/all machines.
# 11  
Old 02-19-2010
in my environment I would have more chance of squeezing blood from a stone than getting the required signoff to update perl on all my systems Smilie

I may use the bash getopts_long by Stephane Chazelas as ive been working with this one for ages and i know how to get around the problem

thankyou for your help though Pludi (as always)

Last edited by rethink; 02-19-2010 at 09:53 AM..
# 12  
Old 02-19-2010
Well, if all else fails, ship the module as part of your script. Either in a file of its own, with a
Code:
use lib '.'; # Include current directory

or by simply appending it to the bottom of your script. Simple example:
Code:
#!/usr/bin/perl

use strict;
use warnings;

print "I'm the main script\n";
Foo::Bar();
Foo->new()->Bar();
print "I'm the main script again\n";

package Foo;

sub Bar {
    my ($self) = @_;
    if ( ref $self eq "Foo" ) {
        print "I'm Foo->Bar()\n";
    }
    else {
        print "I'm Foo::Bar()\n";
    }
}

sub new {
    my ($class) = @_;
    my $self = {};
    bless( $self, $class );
    return $self;
}
1;

Code:
$ perl pkg.pl
I'm the main script
I'm Foo::Bar()
I'm Foo->Bar()
I'm the main script again

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Question about getopts optional argument [args...]

There are many places where I can see the syntax description for optargs, which, usually boils down to this: getopts OPTSTRING VARNAME where: OPTSTRING tells getopts which options to expect and where to expect arguments VARNAME tells getopts which shell-variable to use for option reporting... (2 Replies)
Discussion started by: sharkura
2 Replies

2. Shell Programming and Scripting

Store args passed in array but not the first 2 args

Store args passed in array but not the first 2 args. # bash declare -a arr=("$@") s=$(IFS=, eval 'echo "${arr}"') echo "$s" output: sh array.sh 1 2 3 4 5 6 1,2,3,4,5,6 Desired output: sh array.sh 1 2 3 4 5 6 3,4,5,6 (2 Replies)
Discussion started by: iaav
2 Replies

3. Shell Programming and Scripting

Perl :: Getopt::Long in the program

While going through some of the perl script... I had found the below line.. use Getopt::Long; my $GetOptionsReturnCode = GetOptions ( '<>' => sub { push(@unknownArg, @_); }, 'h|help' => sub { &helpMessage(); exit 0; }, ); Could anyone please explain the above one ... (1 Reply)
Discussion started by: scriptscript
1 Replies

4. Programming

Perl Getopt::Long

Hi All I am using Getopt::Long in perl and i am trying to have it so if i dont supply a switch after the progname is will do a defult option i have the following GetOptions($OPT, 'debug|d', 'mail|m', ) or info(); i want it run the debug if it is not given a switch ... (1 Reply)
Discussion started by: ab52
1 Replies

5. Shell Programming and Scripting

using getopt for both short and long options

Hi , I am using getopt for both short and long options as below SHORTOPTS="a:c" LONGOPTS="alpha:,charlie" OPTS=$(getopt -o $SHORTOPTS --longoptions $LONGOPTS -n "$progname" -- "$@") eval set -- "$OPTS" while ; do case $1 in -a|--alpha) echo "-a or --alpha... (1 Reply)
Discussion started by: padmisri
1 Replies

6. Shell Programming and Scripting

using getopt for both short and long options

Hi , I am using getopt for both short and long options as below SHORTOPTS="a:c" LONGOPTS="alpha:,charlie" OPTS=$(getopt -o $SHORTOPTS --longoptions $LONGOPTS -n "$progname" -- "$@") eval set -- "$OPTS" while ; do case $1 in -a|--alpha) echo "-a or --alpha... (1 Reply)
Discussion started by: padmisri
1 Replies

7. Shell Programming and Scripting

using getopt for both short and long options

Hi , I am using getopt for both short and long options as below SHORTOPTS="a:c" LONGOPTS="alpha:,charlie" OPTS=$(getopt -o $SHORTOPTS --longoptions $LONGOPTS -n "$progname" -- "$@") eval set -- "$OPTS" while ; do case $1 in -a|--alpha) echo "-a or --alpha... (0 Replies)
Discussion started by: padmisri
0 Replies

8. Shell Programming and Scripting

getopt in perl

Hi, I have a perl script with two functions say func a and func b. sub a { ----------- --------- } sub b { --------- --------- } I want to use this function on command line as we can do in shell script using getopt. My motto here is to run the script like this ... (7 Replies)
Discussion started by: namishtiwari
7 Replies

9. AIX

Stopping multiple process on AIX

I'm trying to update a shared library (*.so) in our AIX machine. However, when I tried to delete the old *.so file, I get this error -> Cannot open or remove a file containing a running program. Based on the information I gather from the net, shared libraries are not unloaded (the file remains... (3 Replies)
Discussion started by: soulfactory2002
3 Replies

10. Programming

question about getopt()

I'm using getopt() to get command line options.One the optons accepts and argument.The argument is and offset.I was wondering how can I scecify that it's argument is of the type off_t.I've something like this "offset=(off_t)optarg" and it don't work. (1 Reply)
Discussion started by: angelfly
1 Replies
Login or Register to Ask a Question