Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

What is this line doing in the perl script?

by anakin30 (Acolyte)
on Aug 25, 2010 at 07:42 UTC ( #857101=perlquestion: print w/ replies, xml ) Need Help??
anakin30 has asked for the wisdom of the Perl Monks concerning the following question:

hie there

can someone help me

i have this line as input file

CN=L.Yakin@postdirekt.de,CN=ExternalContacts,DC=dhl,DC=com

whats is this line doing with the input above

(($this_mail) = ($this_in =~ /CN=(.*),CN=ExternalContacts/gio));

This is the line in input file

CN=L.Yakin@postdirekt.de,CN=ExternalContacts,DC=dhl,DC=com

This is the perl script if you need to refer

open( IN, "$INFILE" ); while( $this_in = <IN> ) { if ($this_in =~ /^dn: /gio) { (($this_mail) = ($this_in =~ /CN=(.*),CN=ExternalContacts/gio)); $this_user = $conn_in->search(base => $ldapopts_root, scope => " +sub", filter => "(|(mail=$this_mail)(mailAlternateAddress=$this_mail) +)", attrs => ['uid','mail','mailalternateaddress','cn','ou']); &Debug( 3, "Search:(|(mail=$this_mail)(mailAlternateAddress=$thi +s_mail))"); if ($this_user->entries) { foreach $my_entry ($this_user->entries) { $entry_uid = $my_entry->get_value('uid'); $entry_mail = $my_entry->get_value('mail'); @all_alts = $my_entry->get_value('mailalternateaddress'); $my_alt_all = ""; foreach $entry_alt (@all_alts) { $my_alt_all .= $entry_alt; $my_alt_all .= ","; } chop($my_alt_all); $entry_cn = $my_entry->get_value('cn'); $entry_ou = $my_entry->get_value('ou'); &Debug( 3, "$entry_ou|$entry_uid|$entry_mail|$my_alt_all|$en +try_cn"); } } elsif ($this_in =~ /deutschepost/gio) { chop($this_in); &Debug( 2, "$this_in"); &Debug( 2, "changetype: delete\n"); } else { (($this_mail1) = ($this_mail =~ /\@(.*)/gio)); &Debug( 1, "$this_mail1"); } } }

Comment on What is this line doing in the perl script?
Download Code
Re: What is this line doing in the perl script?
by Corion (Pope) on Aug 25, 2010 at 07:48 UTC

    You haven't told us what part of the line you have problems understanding.

    You can learn what the line is doing from perlre about the /g flag, and from perlsyn about what the assignment does.

    Maybe it helps you to look at this example:

    use strict; use Data::Dumper; my @list = ("abcdef" = /(.)./g); print Dumper \@list; (my ($first)) = @list; print "$first\n"; # in one step (my $first) = ("abcdef" = /(.)./g);
      You are missing the tilde in the match.
      Should've been:
      use strict; use Data::Dumper; my @list = ("abcdef" =~ /(.)./g); print Dumper \@list; (my ($first)) = @list; print "$first\n"; # in one step (my $first) = ("abcdef" =~ /(.)./g);

      print+qq(\L@{[ref\&@]}@{['@'x7^'!#2/"!4']});
Re: What is this line doing in the perl script?
by Ratazong (Prior) on Aug 25, 2010 at 07:54 UTC
                 whats is this line doing with the input above
    (($this_mail) = ($this_in =~ /CN=(.*),CN=ExternalContacts/ +gio));

    Why don't you check yourself? Just add a

    print ">>>$this_mail<<<\n";
    directly after your line. Then you'll see. The >>><<< are just visual delimiters - they help you to spot if your variable has some leading or trailing blanks.

    If you have trouble understanding regexes, try this web-resource.

    Or read some of the docs in this collection of planetscape

    HTH, Rata
Re: What is this line doing in the perl script?
by Utilitarian (Vicar) on Aug 25, 2010 at 12:19 UTC
    The line uses a regular expression to capture the canonical name of the object under CN=ExternalContacts in the object name ($this_in) and saves it to $this_mail.
    It works as follows:
    ($this_mail) # puts the value in a list context so that values capture +d by the regex are saved in the list (only the first match will be sa +ved as there is only one variable available) = $this_in =~ # apply a regular expression to $this_in /CN=(.*),CN=ExternalContacts/ # capture the +bit in brackets gio; #apply glob +ally (g), case insensitively (i) and only compile once (o)
    print "Good ",qw(night morning afternoon evening)[(localtime)[2]/6]," fellow monks."

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://857101]
Approved by moritz
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (7)
As of 2014-11-23 05:05 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My preferred Perl binaries come from:














    Results (128 votes), past polls