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.

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];

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

Thanks for your helps....

10 Years
Discussion Span
Last Post by KevinADC

Your code is hard to understand. You appear to be checking for the existence of a hash key:

if(exists $name {$a}){

even though the syntax is a little messed up (a space between $name and {$a}) it probably still works.

but then you are using aray syntax when you try to delete later on, such as:

delete $name[$j];

square brackets [] are array indexing, curly brackets {} are hash keys. So I can't tell what it is you are actually trying to do by looking at your code. Are you removing something from an array or a hash?


Sorry for the late reply...

As regard as my question, I 've not any problem about deleting something in an array or a hash.

I just wonder how I can use exists function in an array??? (not in a hash.)

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.