CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Intermediate:
Using GetOpts on something other than @ARGV

 



bkreitman
New User

Mar 4, 2003, 9:45 AM

Post #1 of 3 (474 views)
Using GetOpts on something other than @ARGV Can't Post

Can the GetOpts family of commands be used on something other than @ARGV?

The GetOpts command(s) are pretty useful, and wanted to know if I could use a different array with the command. Otherwise, you can corrupt the original @ARGV and reissue the command.


davorg
Thaumaturge / Moderator

Mar 5, 2003, 1:50 AM

Post #2 of 3 (468 views)
Re: [bkreitman] Using GetOpts on something other than @ARGV [In reply to] Can't Post

The Getopts functions only work on @ARGV because that's where the command line options are held.

I haven't tried it, but it should be possible to set @ARGV to some other value and then use the functions. You can use "local" and a naked block to prevent @ARGV becoming corrupted.

Code
{ 
local @ARGV;
@ARGV = @some_other_data;

getopts("...");
}
# @ARGV now has its original value.


--
Dave Cross, Perl Hacker, Trainer and Writer
http://www.dave.org.uk/
Get more help at Perl Monks


bkreitman
New User

Mar 5, 2003, 7:37 AM

Post #3 of 3 (464 views)
Re: [davorg] Using GetOpts on something other than @ARGV [In reply to] Can't Post

Thank you for your quick reply. Your solution works wonderfully (perl 5.8), and is just what I needed for my project.

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives