Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Is it possible to include GetOpt flags in $0

by c (Hermit)
on Oct 24, 2002 at 13:40 UTC ( #207699=perlquestion: print w/replies, xml ) Need Help??

c has asked for the wisdom of the Perl Monks concerning the following question:

I guess the title for the post says it all, but to restate... Is there an internal perl variable that holds not just the command line used when calling the current script, but also all parameters with it? For example
./scriptname --flag

The $0 value is './scriptname', however I am looking for a variable that will return './scriptname --flag'.

Thanks! -c

Replies are listed 'Best First'.
Re: Is it possible to include GetOpt flags in $0
by robartes (Priest) on Oct 24, 2002 at 13:46 UTC
    Just use @ARGV:
    use strict; my @commandline=@ARGV; unshift @commandline, $0;

    CU
    Robartes-

Re: Is it possible to include GetOpt flags in $0
by sch (Pilgrim) on Oct 24, 2002 at 14:03 UTC

    How about:

    $var = join / /, @ARGV;

    But today you took me walking, Through a land that we have lost,
    While our children sit at websites, With no access to the cost

Re: Is it possible to include GetOpt flags in $0
by Jenda (Abbot) on Oct 24, 2002 at 15:44 UTC

    If you happen to use Windows you may get the raw commandline with

    use Win32::API; my $GetCommandLine = Win32::API->new('kernel32', 'GetCommandLine', [ ] + , 'P' ); $cmdline = $GetCommandLine->Call();

    In other case you will probably want something like:

    BEGIN { @ORIGINAL_ARGV = @ARGV }; use GetOpt::Long ... ...

    I don't think you should add the options to $0 itself, but I guess you may if you want to.

    HTH, Jenda

Re: Is it possible to include GetOpt flags in $0
by roik (Scribe) on Oct 24, 2002 at 13:54 UTC
    In Perl the parameters are passed in a special list called @ARGV.
    An example of accessing them is:
    my $variable1 = $ARGV[0]; my $variable2 = $ARGV[1]; # etc..
      Update - having noticed that c is an Abbot I expect (s)he knows this and is after something more esoteric! No patronisation intended!

        Someone can become a Saint without knowing diddly squat about Perl. All it takes is some clever replies that draw upvotes and time. Do not assume that simply because someone has moved up the "ranks" here that they are Perl experts.

        Update: Reworded... Must not have had enough caffeine in my blood system yet.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://207699]
Approved by robartes
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (7)
As of 2021-06-15 14:03 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    What does the "s" stand for in "perls"? (Whence perls)












    Results (72 votes). Check out past polls.

    Notices?