Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does this code do?

Tags:

grep

perl

This does what I would like it to

if (grep {/$dn/} @ad_sys) {
    $is_system = 1;
}

but this always returns 1.

if (grep $_ == $dn, @ad_sys) {
    $is_system = 1;
}

What does the second piece do?

like image 981
Sandra Schlichting Avatar asked Apr 17 '26 23:04

Sandra Schlichting


2 Answers

== is used for numeric comparison, if you need string comparison use eq.

like image 72
Matteo Riva Avatar answered Apr 20 '26 15:04

Matteo Riva


It filters those elements from the list @ad_sys that are numerically equal to $dn. Then, if the result is not empty, the condition is true and the if-block is entered.

like image 36
Ingo Avatar answered Apr 20 '26 15:04

Ingo



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!