number check in perl


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting number check in perl
# 1  
Old 05-07-2009
number check in perl

Hi,,

Quote:
my $num = "1234567890";
if( $num =~ /\d{10}/ ) {
print "number is 10 dig\n";
}else {
print "Not a 10 dig numner\n";
}
this is returning true in all cases..( other than 10 dig number also)
what could be wrong??
# 2  
Old 05-07-2009
Quote:
Originally Posted by shellwell
Hi,,



this is returning true in all cases..( other than 10 dig number also)
what could be wrong??
Code:
Use:
if( $num =~ /^\d{10}$/ ) {

# 3  
Old 05-07-2009
Thanks redoubtable.
It worked. I hadn't thought about that.

Thanks again.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Programming

Perl: restrict perl from automaticaly creating a hash branches on check

My issue is that the perl script (as I have done it so far) created empty branches when I try to check some branches on existence. I am using multydimentional hashes: found it as the best way for information that I need to handle. Saing multidimentional I means hash of hashes ... So, I have ... (2 Replies)
Discussion started by: alex_5161
2 Replies

2. Shell Programming and Scripting

number of instance check

Hi, We are getting a curios result in one of AIX script. Its executed using !/bin/ksh . After following line we get result of 3 in in the variable instance_count. instance_count=`ps -ef | grep "script_check_instances.sh" | grep -v "grep" | wc -l` But once we do a "ps -aef | grep... (2 Replies)
Discussion started by: niba
2 Replies

3. Shell Programming and Scripting

Perl code to check date and check files in particular dir

Hi Experts, I am checking how to get day in Perl. If it is “Monday” I need to process…below is the pseudo code. Can you please prove the code for below condition. if (today=="Monday" ) { while (current_time LESS THAN 9:01 AM) ... (1 Reply)
Discussion started by: ajaypatil_am
1 Replies

4. Shell Programming and Scripting

Perl : print the sequence number without missing number

Dear Perl users, I need your help to solve my problem below. I want to print the sequence number without missing number within the range. E.g. my sequence number : 1 2 3 4 5 6 7 8 11 12 13 14 my desired output: 1 -8 , 11-14 my code below but still problem with the result: 1 - 14 1 -... (2 Replies)
Discussion started by: mandai
2 Replies

5. Shell Programming and Scripting

Check params for number

I have 2 and three params, both I should make sure thay numbers at one single line insted of checking for each one . Example I wroote the following way.. checking for 2 and three seperately but I shud be able to do it at on statement echo $2 | egrep '^+$' >/dev/null 2>&1 if ; then echo... (2 Replies)
Discussion started by: raopatwari
2 Replies

6. Shell Programming and Scripting

Check if the value is Number

Hi, I have a file with data as given $cat file1.txt 123 234 23e 234.456 234.876e 345.00 I am checking if the values are proper integers using the command. nawk -F'|' 'int($1)!=$1 {printf "Error in field 1|"$0"\n"}' file1.txt This is checking for only integers ( without... (10 Replies)
Discussion started by: ashwin3086
10 Replies

7. Shell Programming and Scripting

To check a word is number or not

Hi, I have one file like 00123. And this file name is generated as a sequence. So how can I confirm the generated file name is a number, not a special character or alphabets. Can anybody help me out. Thanks in advance. (3 Replies)
Discussion started by: Kattoor
3 Replies

8. Shell Programming and Scripting

How to check whether a string is number or not

Hi , I am facing a problem .. which looks simple... but took 2 days of mine.. even now it is not solved completely.. I have one variable..., want to know whether that variable contains number... canbe +ve or -ve ... Values +35 --- number -43 --- number 45A -- non number... (12 Replies)
Discussion started by: shihabvk
12 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. UNIX for Dummies Questions & Answers

Check if variable is a number

If I have a variable $X, how do I check it is a number? Many thanks. (2 Replies)
Discussion started by: handak9
2 Replies
Login or Register to Ask a Question