http://qs1969.pair.com?node_id=11147461

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

I've got a number of perl scripts, that more or less use the same format as this, but this one script refuses to play nice.
#!/usr/bin/perl use Getopt::Std; my ($miscreants, $reason) = @ARGV; my %opts; getopts ('u', \%opts);
Amongst the inners of this script we have an  unless ($opts{'u'}) ... block that passes, it knows no -u was issued and works without error ./acl.pl 1.2.3.4

Then where I need it to, ./acl.pl -u 1.2.3.4 if ($opts{'u'}) ...

upon executing it errors-u must be IP or IP/CIDR which is the print statement for what happens when it doesnt get the ARGV[0] aka miscreants as numerical

It seems it is seeing -u as ARGV[0] , verified by checking what miscreants returns.

Other scripts happily ignore the switches and use the ARGV[0] for their purposes, and they also work still with or without switches, eg: an addhost script that may have options like -n or -d or neither, then domain = ARGV[0], the same type of thing I'm trying here, it works, it knows -n and -d are switches if used or if not used, it knows ARGV[0] is the non switched argument given, for the life of me I can not figure why this darn script does not.

I thought if perl didnt recognise the -u as a switch, it would pass it through to argv[0] like it is doing here, but as you from my opening lines, its very clearly defined, those lines are copy and paste, and are identical to the scripts that do work.

I've triple checked the spelling and syntax (perl -c scriptname passes as syntax OK)

snip... This is perl 5, version 34, subversion 0 (v5.34.0) built for x86_64-linux-thread-multi Anyone see what might be wrong? Thanks