Doozer has asked for the wisdom of the Perl Monks concerning the following question:
Hi All.
I'm after some help on dealing with a valid number "0" as an input argument. I have a script which takes input arguments. One of the arguments relates to a USB audio input device number on a Raspberry Pi. The device numbers start from 0 and increment depending on how many of these devices are installed.
I know I can validate that the input argument was there via the following bit of code:
chomp(my $in1 = $ARGV[0] || ''); if (defined $in1) { #Validate; }
The problem I have is I also want to validate that the input is only a number. If I do regex pattern match validation against $in1 when it is "0", Perl gives me the uninitialized value error. I am aware that 0 translates to false.
How can I use "0" as a valid number? I have tried looking on Google for an answer but have been unsuccessful.
|
|---|