rspishock has asked for the wisdom of the Perl Monks concerning the following question:
I come seeking the wisdom of the all knowledgeable monks.
I'm working on a script that passes user input into a subroutine and compares the value to a regex for compliance. Below is a couple snippets of code to show what I'm doing. The variable names in the hash have been changed and do not reflect what I am using in my actual script.
use strict; use warnings; use diagnostics; my ($input, $value) my %vlan = ( "vlan1" => "", "vlan2" => "", "vlan3" => "", "vlan4" => "", ); sub verification { print "Entering the subroutine\n"; #added for debugging purposes print "$value"; #added for debugging purposes if ($value =~ m{(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\. (25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\. (25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\. (25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\/ (2[0-4]?$)}x) { %vlan{$value}=$input; } else { print "\t\tInvlaid response. Please try again.\n"; #enter return } print "Exiting the subroutine.\n"; #added for debugging purposes } ---lines omitted--- print "Enter IP address in x.x.x.x/x format\n"; foreach $_(keys %vlan) { print "\t$_: "; chomp ($input = <STDIN>); $input = $value; #call subroutine to check user input verification($value) }
I'm having a problem with passing $value into the subroutine. When I test my script, I get the Entering the subroutine message followed by an error stating that I am using an undefined value, and the the closing Exiting the subroutine message.
Can someone please point me in the direction how I can pass this value to my subroutine for verification?
Thanks for all of your help.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Passing a scalar to a subroutine
by moritz (Cardinal) on Feb 01, 2012 at 12:52 UTC | |
by rspishock (Monk) on Feb 01, 2012 at 13:03 UTC | |
Re: Passing a scalar to a subroutine
by Anonymous Monk on Feb 02, 2012 at 15:22 UTC |