CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
Search Posts SEARCH
Who's Online WHO'S
Log in LOG

Home: Perl Programming Help: Beginner:
Need simple one-liner for "if not in array"



Oct 21, 2001, 2:38 PM

Post #1 of 2 (413 views)
Need simple one-liner for "if not in array" Can't Post

For the life of me I can't figure out how to do this.

I have a string value that I want to check if it does not exist in a array. Short of running through the entire array one cell at a time, is there a way to code: "IF ($X DOES NOT EXIST IN @Y) "?

The comparison should be a exact match.


Sean Shrum


Oct 21, 2001, 2:59 PM

Post #2 of 2 (411 views)
Re: Need simple one-liner for "if not in array" [In reply to] Can't Post

try using the grep function.

$Z = grep(/^$X$/, @Y);
if ($Z < '1') {print "does not exist"} else{print "$Z times";}

I Hope this helps...

perl programmers don't die.. they just start writing a new script.


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives