Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Can someone help me to explain the code below

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

Hi guys, i have a sample of code in here. can someone please explain to me what does this line below does... (($this_mail) = ($this_in =~ /(.*)/gio)); you may refer to the complete source code i have attached below Thanks in advanced...It's really urgent...can someone please help me!!!!
#!/usr/bin/perl # create compare output file for CoIn use Net::LDAP; use Net::LDAP::Util qw(ldap_error_name ldap_error_text); use Encode; $DEBUG = 2; $BASEDIR = "/log/sad/info/net/"; $INFILE = "$BASEDIR/test-contacts.dat"; $INFILE = "$BASEDIR/test.dat"; $NOW = `date +%Y%m%d`; chop ($NOW); $LOGFILE = "$BASEDIR/DP-contacts-$NOW.txt"; $ldapopts_host = "edsldap.dhl.com:389"; $ldapopts_root = "ou=users,o=dhl.com"; &Main; sub Main { $conn_in = Net::LDAP->new($ldapopts_host); die("server failed $ldapopts_host") unless $conn_in; $mesg = $conn_in->bind(dn => $ldapopts_bind,password => $ldapopts_ps +wd); &Debug( 1, "Connected to destination : $ldapopts_host\t$NOW" ); open( IN, "$INFILE" ); while( $this_in = <IN> ) { (($this_mail) = ($this_in =~ /(.*)/gio)); $this_user = $conn_in->search(base => $ldapopts_root, scope => "su +b", filter => "(|(mail=$this_mail)(mailAlternateAddress=$this_mail))" +, attr s => ['uid','mail','mailalternateaddress','cn','ou']); &Debug( 3, "Search:(|(mail=$this_mail)(mailAlternateAddress=$this_ +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( 1, "$entry_ou|$entry_uid|$entry_mail|$my_alt_all|$entr +y_cn"); } } else { &Debug( 2, "NOT FOUND: $this_mail"); } } $conn_in->unbind if $conn_in; close(IN); } #***************************** # Handle DEBUG #***************************** sub Debug { local( $level, $message ) = @_; if( $DEBUG >= $level ) { if( open( DB, ">> $LOGFILE" ) ) { print DB "\t" x ( $level - 1 ), $message, "\n"; print "\t" x ( $level - 1 ), $message, "\n"; close( DB ); }; }; };

Comment on Can someone help me to explain the code below
Download Code
Re: explain code
by toolic (Chancellor) on Aug 03, 2010 at 19:21 UTC
    Great. You added code tags, but please do not start a new thread.

    See my other suggestions in: Re: explain code

Re: Can someone help me to explain the code below
by Anonymous Monk on Aug 03, 2010 at 19:30 UTC
Re: Can someone help me to explain the code below
by Anonymous Monk on Aug 03, 2010 at 19:59 UTC
    (($this_mail) = ($this_in =~ /(.*)/gio));

    That simply matches everything in $this_in and assigns it to $this_mail. More concisely:

    $this_mail = $this_in;
      thank for your reply.... i have one more question for you...what about this line buddy... ($this_in =~ /(.*)/gio)
      . does not match then newline character. So it's more like:
      $this_mail = $this_in; chomp $this_mail;
        ($this_mail) and ($this_in) are variable isn't it? but than i didn't see it has been defined in the code? how does it possible? what does the /gio means? , whats the function? ($this_mail) = ($this_in =~ /(.*)/gio)

      When running under -T it will also make an untainted copy of the contents of $this_in in $this_mail (presuming $this_in was from a tainted source)</nit>

      $ perl -MScalar::Util=tainted -lT -e '($o)=$ENV{PWD}=~/(.*)/gio;print +tainted( $_ ) for ( $o, $ENV{PWD} )' 0 1

      (Not that that's the case here, but saying it's just a copy assignment isn't universally true . . .)

      Update: And before someone else outpedants me, as toolic points out above that should really be "... an untainted copy up to the first newline of the contents ..." :)

      The cake is a lie.
      The cake is a lie.
      The cake is a lie.

        Well, true, but <nit>
        We're untainting only to the extent that we're performing a function that Perl (uncritically) reads as untainting... but without any substantive untainting...

        In other words, <c>(($this_mail) = ($this_in =~ /(.*)/gio));<c> passes the entire tainted input without any attempt to cull out unacceptable content.

        </nit> (or is it merely a nit?)

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (6)
As of 2014-07-23 03:58 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (133 votes), past polls