I recently needed to write some code to pull a single (and first) dn out of each line in an LDAP file. Each dn is contained between '<>' and always begins with capital CN=. I used:
#!/usr/bin/perl -w my @dn; open FILE, "crap" or die $!; while (<FILE>) { chomp $_; @dn = $_ =~ /(<CN=.*?>)/; print "$dn[0]\n"; } close (FILE);
This works great. The only part I'm not sure about is the parenthesis. If I remove them, then I just get in $dn[0] the value 1 which says that yes, the regex was present. By putting the parenthesis in, I instead get the actual match. Could someone give me an explanation for that please?
Thanks!
In reply to Understanding this regex by BradV
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |