Sponsored Content
Top Forums Shell Programming and Scripting Check if a variable is a number - perl Post 302159169 by ghostdog74 on Thursday 17th of January 2008 06:43:24 AM
Old 01-17-2008
if you have Posix module
Code:
use POSIX;
@test = qw(zzz 456 vc32 xyz! 12.34);

foreach (@test) {
    print "$_ is digits\n" if isdigit $_;
    print "$_ is alpha\n" if isalpha $_;
}

 

10 More Discussions You Might Find Interesting

1. 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

2. UNIX for Dummies Questions & Answers

check whether variable number or string

I am passing an argument to a file and i wanna check whether the argument is a number or string ? how can i do this? (4 Replies)
Discussion started by: rolex.mp
4 Replies

3. Shell Programming and Scripting

number check in perl

Hi,, this is returning true in all cases..( other than 10 dig number also) what could be wrong?? (2 Replies)
Discussion started by: shellwell
2 Replies

4. Shell Programming and Scripting

Number lines of file and assign variable to each number

I have a file with a list of config files numbered on the lefthand side 1-300. I need to have bash read each lines number and assign it to a variable so it can be chosen by the user called by the script later. Ex. 1 some data 2 something else 3 more stuff which number do you... (1 Reply)
Discussion started by: glev2005
1 Replies

5. Shell Programming and Scripting

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: IPINPUT: print "Enter IP Address: ";... (2 Replies)
Discussion started by: Takau
2 Replies

6. Shell Programming and Scripting

Check if a variable ends in a particular number

Hi guys, I am working on a server where there are many users. The user names end in a 1 or a 2. I want to write a bash script that will say which users are in which group and was wondering if I could get some help. The only part I am unsure of is how to check if it ends in the number. Here's... (2 Replies)
Discussion started by: wua05
2 Replies

7. Shell Programming and Scripting

number of fields in a text file as a variable - perl

I am looking for perl code to get following o/p. If a line has more than 7 fields then value in field 7 onwards is BHA_GRP1, BHA_GRP2, BHA_GRP3, BHA_GRP4 etc. Here is example of what I am trying to achieve. INPUT File: VAH NIC_TYPE CONFIG SIZE_GB PILO KOM BHA_GRP1 BHA_GRP2 BHA_GRP3...... 2... (1 Reply)
Discussion started by: dynamax
1 Replies

8. 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

9. 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

10. 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
CTYPE(3)						   BSD Library Functions Manual 						  CTYPE(3)

NAME
isalpha, isupper, islower, isdigit, isxdigit, isalnum, isspace, ispunct, isprint, isgraph, iscntrl, isblank, toupper, tolower, -- character classification and mapping functions LIBRARY
Standard C Library (libc, -lc) SYNOPSIS
#include <ctype.h> isalpha(int c); isupper(int c); islower(int c); isdigit(int c); isxdigit(int c); isalnum(int c); isspace(int c); ispunct(int c); isprint(int c); isgraph(int c); iscntrl(int c); isblank(int c); toupper(int c); tolower(int c); DESCRIPTION
The above functions perform character tests and conversions on the integer c. See the specific manual pages for information about the test or conversion performed by each function. EXAMPLES
To print an upper-case version of a string to stdout, the following code can be used: const char *s = "xyz"; while (*s != '') { putchar(toupper((int)(unsigned char)*s)); s++; } SEE ALSO
isalnum(3), isalpha(3), isblank(3), iscntrl(3), isdigit(3), isgraph(3), islower(3), isprint(3), ispunct(3), isspace(3), isupper(3), isxdigit(3), tolower(3), toupper(3), ascii(7) STANDARDS
These functions, with the exception of isblank(), conform to ANSI X3.159-1989 (``ANSI C89''). All described functions, including isblank(), also conform to IEEE Std 1003.1-2001 (``POSIX.1''). CAVEATS
The first argument of these functions is of type int, but only a very restricted subset of values are actually valid. The argument must either be the value of the macro EOF (which has a negative value), or must be a non-negative value within the range representable as unsigned char. Passing invalid values leads to undefined behavior. Values of type int that were returned by getc(3), fgetc(3), and similar functions or macros are already in the correct range, and may be safely passed to these ctype functions without any casts. Values of type char or signed char must first be cast to unsigned char, to ensure that the values are within the correct range. The result should then be cast to int to avoid warnings from some compilers. Casting a negative-valued char or signed char directly to int will produce a negative-valued int, which will be outside the range of allowed values (unless it happens to be equal to EOF, but even that would not give the desired result). BSD
May 6, 2010 BSD
All times are GMT -4. The time now is 11:11 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy