Perl Variable Check Script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Perl Variable Check Script
# 1  
Old 07-23-2010
Perl Variable Check Script

I am working on a perl script that is used to update a list of hosts to a certain file but I am having an issue when I try to perform a check to make sure the user enters valid information. The following is what I have currently written for the script:

Code:
IPINPUT:
print "Enter IP Address: ";
chomp($ipaddress=<STDIN>);

if($ipaddress !~ /\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}/) {
        print "Please enter a valid IP Address\n";
        goto IPINPUT;
}

This works for making sure the variable is in the proper format but I am having issues with making sure the user doesn't enter in anything over 255 for each of the spots. Any advise in editing this part of the code or adding another line that would perform this would be great. Thanks in advance for the help.
# 2  
Old 07-23-2010
This is a very generic thing which you can get data by googling.

Basically, you have to search for
Code:
validate IP address in perl

, or regex and something like that..


Update: Ok, here is the link finally: http://www.perlmonks.org/?node_id=615683

Last edited by thegeek; 07-23-2010 at 10:13 AM..
# 3  
Old 07-23-2010
Wow, thanks for the help. My searches failed me because I was making this more complex then it had to be. Sorry to waste your time.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Shell/perl script to check for files

Hi, I am trying to write a script for following scenario: I have a list of countries from where I receive files...eg. (Indonesia, Thailand, Australia...etc) For each country, I have a list of files that they send. IND -- a,b,c TH -- p,q,r AU -- x,y,z The path for these files could... (2 Replies)
Discussion started by: neil.k
2 Replies

2. Shell Programming and Scripting

Need a script to check if an argument is valid shell variable

I need a script that should print 'yes' if the argument is a valid shell variable name else 'No' if it is not a valid shell variable. A valid one begins with an alphabet or percentage (%) character and is followed by zero or more alphanumberic or percentage (%) characters. For example: $... (6 Replies)
Discussion started by: pingiliarjun
6 Replies

3. Shell Programming and Scripting

How to check if printer is out of paper using perl script ?

Hello, I need to chack if the printer is out of paper, and send message to operator. I need to do this from perl script. The printer have mechanism to check if it have paper. However, the cups does not report "printer out of paper" when I remove the paper, and try to print. Is there any... (1 Reply)
Discussion started by: +Yan
1 Replies

4. Shell Programming and Scripting

Perl script to check uname options

I am trying to read the /etc/security/limits.conf file to match with my specifications. Specification should match below : nofile=131072 noproc=131072 memlock=3500000 I have written a perl script to read the file: #!/usr/bin/perl $FILE1 = "/home/sriram/perl_scripts/limits.conf";... (2 Replies)
Discussion started by: sriram003
2 Replies

5. Shell Programming and Scripting

PERL : check + or - sign in a variable

I have a variable $max = -3; It can be $max = +3; I need to check if this variable is a positive/negative value. if its positive, should print "positive" if not "negative" How can this be done? Thanks in advance (2 Replies)
Discussion started by: irudayaraj
2 Replies

6. Shell Programming and Scripting

perl check email script not seeing attachment

The following script does pull the sender and Subject of the email but it is not seeing the attachment name. I know there is an attachment. I line in red SHOULD pull the filename out. this line is in the message: Content-Disposition: attachment; filename="Picture 243.jpg" ... (1 Reply)
Discussion started by: Ikon
1 Replies

7. Shell Programming and Scripting

Please check perl script

#!/usr/local/bin/perl #$path = perl; #use File::stat; use Time::localtime; sub ExampleFiles{ $today = time; $today -= $today % 86400; $return_value = 0; $mtime = (stat("$_")) || die "cannot stat file $!"; $size = (stat("$_")); # size in... (3 Replies)
Discussion started by: ellechim
3 Replies

8. Shell Programming and Scripting

perl script to check if empty files are created and delete them and run a shell script

I have a local linux machine in which the files are dumped by a remote ubuntu server. If the process in remote server has any problem then empty files are created in local machine. Is there any way using perl script to check if the empty files are being created and delete them and then run a shell... (2 Replies)
Discussion started by: hussa1n
2 Replies

9. Shell Programming and Scripting

Check if a variable is a number - perl

Logic of code if ( $var is a number ) { Do something } else { Do something else } My question is: How do I check if a variable is a number. All the reg ex that I came up with to match this is failing. Please help. (3 Replies)
Discussion started by: garric
3 Replies

10. Shell Programming and Scripting

Check if variable is set in script

I want to check to see if a variable is set - and if not set it to something ie. variable name test I want to check if $test is set then if there is nothing set against this currently - then set it to 0 Whats the best / shortest way of doing this in a script? (3 Replies)
Discussion started by: frustrated1
3 Replies
Login or Register to Ask a Question