Gossamer Forum
Home : General : Perl Programming :

grep and $_ question

Quote Reply
grep and $_ question
can you please explain what the line:
if (grep {$_ eq $name} @players) {
in the code below does? what is $_ in this context? thanks!

Code:
my (@players,$pEmail,@sent_to,$user_sent,$name,@signed_up,@not_signed_up);
# my ($to,$reply_to,$returnpath,$cc,$bcc,$found,$subscriber);
my ($found,$subscriber);
$reply_to = $in{'email'};
$returnpath = $admin_email;

@players = split (/\|/, $rec{'Players'});

my (%sav) = %in;
&switch_to_members;
undef %in;
$in{'Member'} = 'Yes';
$in{'sb1'} = '1';
my ($status2, @hits2) = &query2("view");
%in = %sav;
if($status2 eq 'ok') {
my ($numhits2) = ($#hits2+1) / ($#db2_cols+1);
for (0 .. $numhits2 - 1) {
$email_msg = $orig_msg; # 05/10/2022
$email_msg .= $rec{'DayOfWeek'} . " " . $date . "~"; # 06/30/2022
$email_msg .= $rec{'Title'} . "~~";
$found = 0; # 06/03/2022
$subscriber = ''; # 07/22/2022
%rec2 = &array_to_hash2($_, @hits2);
if (($rec2{'Email'} ne $default_email) && ($rec2{'Email'} =~ /.+\@.+\..+/)) { # valid email
$name = $rec2{'Userid'};
$to = $rec2{'Email'};
if ($rec2{'Subscriptions'} =~ /EventNotifications/) { # 07/22/2022
$subscriber = 'Subscriber';
}
if (grep {$_ eq $name} @players) {
$found = 1;
$subject = "Signup Confirmation Notice";
$email_msg .= qq|~You are signed up to play $rec{'DayOfWeek'} $date. ~~
Online signups are now closed. Please call the pro shop if you need to cancel.|;
$email_msg .= '~~' . $players; # 06/02/2022
#push (@signed_up,$to); # collect the email addresses
push (@signed_up,$rec2{'Userid'} . " " . $rec2{'Firstname'} . " " . $rec2{'Lastname'} . " " . $to . " " . $subscriber );
}
else {
$subject = "Online Signups Closed";
$email_msg .= qq|~You are NOT signed up to play $rec{'DayOfWeek'} $date. ~
Online signups are now closed. Please call the pro shop to sign up.|;
#push (@not_signed_up,$to); # collect the email addresses
push (@not_signed_up,$rec2{'Userid'} . " " . $rec2{'Firstname'} . " " . $rec2{'Lastname'} . " " . $to . " " . $subscriber);
}

Subject Author Views Date
Thread grep and $_ question delicia 3618 Aug 10, 2022, 4:42 PM
Thread Re: [delicia] grep and $_ question
Andy 3556 Aug 11, 2022, 11:49 PM
Thread Re: [Andy] grep and $_ question
delicia 3553 Aug 12, 2022, 6:51 AM
Thread Re: [delicia] grep and $_ question
Andy 3547 Aug 12, 2022, 6:57 AM
Thread Re: [Andy] grep and $_ question
delicia 3543 Aug 12, 2022, 9:42 AM
Post Re: [delicia] grep and $_ question
Andy 3498 Aug 14, 2022, 11:09 PM