Perl coding. please help

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Peyman
    New Member
    • Sep 2008
    • 1

    Perl coding. please help

    Hello perl programmers. i have the following code in one of my scripts.
    i dont have any idea about what does most of the code do. i will put some notes regarding which parts i dont undrestand. could anybody please explain in details ???

    almost 3 parts of this code which are the most important parts are not undrestood. thnx in advance


    Code:
    @a=();
    $advert=0;
    open(che,"namess/list.txt");
    while (<che>) {
    @a=();
    $advstr="";
    
    
    ###### what is being splite ?#####
    @a = split(//,$_);
    
    
    foreach $let (@a) {
    if ($let eq "l" || $let eq "i" || $let eq "1") {
    
    #### what does the following mean ? please in details specially [\\W_]  #####
    $advstr .= "*[il1|!]+[\\W_]"; 
    #########################################
    
    } elsif ($let eq "o" || $let eq "0") {
    $advstr .= "*[o0]+[\\W_]";
    } elsif ($let eq "a" || $let eq "@") {
    $advstr .= "*[a@]+[\\W_]";
    } else {
    $advstr .= "\*$let\+[\\W_]";
       }
     }
    
    
    
    ######### im asking alot but these lines are not undrestood ####
    $advstr =~ s/\+\[\\W\_\]\*\s+\+\[\\W\_\]$//ig;
    $advstr =~ s/^\*//ig;
    $advstr =~ s/\./\\\./ig;
    $advstr =~ s/\@/\\\@/ig;
    $advstr =~ s/\$/\\\$/ig;
    $advstr =~ s/\-/\\\-/ig;
    ############################################
    
    
    if ($IN{'msg'} =~ /$advstr/ig){
    $advert++;
    
    } 
    }
    close(che);
  • Icecrack
    Recognized Expert New Member
    • Sep 2008
    • 174

    #2
    For:

    Code:
    ######### im asking alot but these lines are not undrestood ####
    $advstr =~ s/\+\[\\W\_\]\*\s+\+\[\\W\_\]$//ig;
    $advstr =~ s/^\*//ig;
    $advstr =~ s/\./\\\./ig;
    $advstr =~ s/\@/\\\@/ig;
    $advstr =~ s/\$/\\\$/ig;
    $advstr =~ s/\-/\\\-/ig;
    ############################################
    Look Up Perl Regular Expressions Tutorial in your favorite search engine.

    For your information this part is canceling perl's special characters, and cleaning up text.

    But for a better understanding follow my advice on Reg Exp.

    Ice

    Comment

    • KevinADC
      Recognized Expert Specialist
      • Jan 2007
      • 4092

      #3
      i have the following code in one of my scripts.
      If its your script, why don't you understand the code? Didn't you write it?

      Comment

      • numberwhun
        Recognized Expert Moderator Specialist
        • May 2007
        • 3467

        #4
        I agree with Kevin, if you don't understand those regex's, then you didn't write this code.

        Comment

        Working...