Gossamer Forum
Home : General : Perl Programming :

Re: [delicia] grep and $_ question

Quote Reply
Re: [delicia] grep and $_ question In reply to
Hi,

It should all be indented if you did it right :) (which it isn't). Could be your code isn't indented in Notepad?

Anyway, to answer your question:

Code:
if (grep {$_ eq $name} @players) {

this is basically looking at each value of @players, and checking if the value matched $name. Its a shorthand way of doing something like:

Code:
foreach (@players) {
if ($_ eq $name) {
print "its a match!"
}
}

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Subject Author Views Date
Thread grep and $_ question delicia 3792 Aug 10, 2022, 4:42 PM
Thread Re: [delicia] grep and $_ question
Andy 3724 Aug 11, 2022, 11:49 PM
Thread Re: [Andy] grep and $_ question
delicia 3720 Aug 12, 2022, 6:51 AM
Thread Re: [delicia] grep and $_ question
Andy 3714 Aug 12, 2022, 6:57 AM
Thread Re: [Andy] grep and $_ question
delicia 3710 Aug 12, 2022, 9:42 AM
Post Re: [delicia] grep and $_ question
Andy 3664 Aug 14, 2022, 11:09 PM