Controlling whether an element in an array or not

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • baron06
    New Member
    • May 2007
    • 6

    Controlling whether an element in an array or not

    Hi all;

    I have to control wheter a string is an array element or not.
    I tried to exists function but it didn't give me the desired output.

    Code:
    print "Which hotel do you want to remove from the list?\n";
    chomp($a = <STDIN>);
    
    if(exists $name {$a}){
    	foreach $record(@name){
    		if($record eq $a) {
    			delete $name[$j];
    			delete $rayt[$j];
    			delete $comf[$j];
    			delete $kitchen[$j];
    			delete $act[$j];
    		}
    		$j++;
    	}
    
    } else {
    	print "\nThe record couldn't find...\n";
    }
    When I try to remove a hotel name (which is already exist) from the array, it prints "The record couldn't find..."

    Note that "name" is an array such as @name = ("hilton","sher aton",...etc.);

    Thanks for your helps....
  • KevinADC
    Recognized Expert Specialist
    • Jan 2007
    • 4092

    #2
    You have this on another site where I have posted a reply.

    Comment

    Working...