Perl Utility Functions - Check integer, array item exists and more

Author: 
Hossain Md. Reza Khan
Functionality: 
These are some basic utility functions using perl.

Language: 
Perl
Source Code: 
# Utility Function
# Desc: To check if a value exists in the array of string elements.
# Param 1: value to check
# Param 2: array reference (where to check the value)
sub isExist($$) {
	my ($value, $array_ref) = @_;
	my $element;
	for $element (@{$array_ref}) {
		if($element eq $value){
			return 1;
		}
	}
	return 0;
} # end of function `isExist`
 
 
 
# Function Type: Utility
# Desc: Checks if passed parameter is a valid integer.
# Param 1: value to check
sub isValidID($){
	my $id = shift;
	if(defined $id && $id ne '')
	{
		if ($id =~ /^[1-9][0-9]*$/) {
	        return 1;
	    } else {
	        return 0;
	    }
	} else {
		return 0;
	}
} # end of isValidID()
© Hossain Khan - Some rights reserved.
Creative Commons License This site is licensed under a Creative Commons Attribution-Noncommercial 2.5 License.