perlMunger has asked for the wisdom of the Perl Monks concerning the following question:
I have a delima that I'm trying to solve, but can't seem find the answer. Maybe someone has already solved this before.
My delima is: I'm trying to push a string onto an array only if it doesn't already exist in the array. I know that I could probably use a hash instead, but don't want to use a hash (key = value), since the string is just a directory path that I'm storing for future use.
some code that I've tried:
returns a warning/error: Argument "$directory/$entry" isn't numeric in exists at scriptname line #.push(@mounts, "$directory/$entry") unless (exists($mounts["$directory/ +$entry"]));
returns the same warning/error.push(@mounts, "$directory/$entry") if (!(exists($mounts["$directory/$ +entry"])));
What, if any, is the syntax for testing if a string already exists in the @array, before pushing it onto the @array?
TIA
Mitch
|
|---|