in reply to Comparing the first element of an array with an array

Apologies for this but i need this in an if statement so that if the URL already exists in the array then do something. The methods you have given me put the URL in another array which i dont really want and i dont think the statemnts you give me can be used in an if statement. Thanks for your patience
  • Comment on Re: Comparing the first element of an array with an array

Replies are listed 'Best First'.
Re^2: Comparing the first element of an array with an array
by jolande (Initiate) on Jul 29, 2005 at 01:39 UTC
    Grep returns the numer of items the code was true for when called in scalar context, so you can pretty much just use holli's code in an if statment
    if ((grep {$_ eq $links[0] } @visited_urls) > 0) { print "URL found\n"; } else { print "URL not found\n"; }