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: Regular Expressions: Re: [zohman] Need help with AutoComplete ARGV option: Edit Log



FishMonger
Veteran / Moderator

May 9, 2016, 8:17 AM


Views: 59092
Re: [zohman] Need help with AutoComplete ARGV option


Quote
if you going to direct me to 'use Getopt' please let me know how to do it because
i don't want to use switches (-/--)


Why not use switchs? It (Getopt::Lomg) would solve your problem without having to create you own custom "AutoComplete" sub.

Is this a homework assignment where your instructor has ruled out the use of switches?


Code
#!/usr/bin/perl 

use strict;
use warnings;
use Getopt::Long;
use Data::Dumper;

my $file;
my $length;
my $verbose;

GetOptions (
"length=i" => \$length, # numeric
"file=s" => \$file, # string
"verbose" => \$verbose) # flag
or die("Error in command line arguments\n");

print Dumper($file, $length, $verbose);



Quote
c:\test>Perl-1.pl
$VAR1 = undef;
$VAR2 = undef;
$VAR3 = undef;

c:\test>Perl-1.pl -fi test.txt
$VAR1 = 'test.txt';
$VAR2 = undef;
$VAR3 = undef;

c:\test>Perl-1.pl -len 25
$VAR1 = undef;
$VAR2 = 25;
$VAR3 = undef;

c:\test>Perl-1.pl -ver
$VAR1 = undef;
$VAR2 = undef;
$VAR3 = 1;

c:\test>Perl-1.pl -v -f test.txt -l 10
$VAR1 = 'test.txt';
$VAR2 = 10;
$VAR3 = 1;



(This post was edited by FishMonger on May 9, 2016, 8:22 AM)


Edit Log:
Post edited by FishMonger (Veteran) on May 9, 2016, 8:21 AM
Post edited by FishMonger (Veteran) on May 9, 2016, 8:22 AM


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

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