By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,712 Members | 1,958 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,712 IT Pros & Developers. It's quick & easy.

Perl coding. please help

P: 1
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


Expand|Select|Wrap|Line Numbers
  1. @a=();
  2. $advert=0;
  3. open(che,"namess/list.txt");
  4. while (<che>) {
  5. @a=();
  6. $advstr="";
  7.  
  8.  
  9. ###### what is being splite ?#####
  10. @a = split(//,$_);
  11.  
  12.  
  13. foreach $let (@a) {
  14. if ($let eq "l" || $let eq "i" || $let eq "1") {
  15.  
  16. #### what does the following mean ? please in details specially [\\W_]  #####
  17. $advstr .= "*[il1|!]+[\\W_]"; 
  18. #########################################
  19.  
  20. } elsif ($let eq "o" || $let eq "0") {
  21. $advstr .= "*[o0]+[\\W_]";
  22. } elsif ($let eq "a" || $let eq "@") {
  23. $advstr .= "*[a@]+[\\W_]";
  24. } else {
  25. $advstr .= "\*$let\+[\\W_]";
  26.    }
  27.  }
  28.  
  29.  
  30.  
  31. ######### im asking alot but these lines are not undrestood ####
  32. $advstr =~ s/\+\[\\W\_\]\*\s+\+\[\\W\_\]$//ig;
  33. $advstr =~ s/^\*//ig;
  34. $advstr =~ s/\./\\\./ig;
  35. $advstr =~ s/\@/\\\@/ig;
  36. $advstr =~ s/\$/\\\$/ig;
  37. $advstr =~ s/\-/\\\-/ig;
  38. ############################################
  39.  
  40.  
  41. if ($IN{'msg'} =~ /$advstr/ig){
  42. $advert++;
  43.  
  44. }
  45. close(che);
  46.  
Sep 21 '08 #1
Share this Question
Share on Google+
3 Replies


Icecrack
Expert 100+
P: 174
For:

Expand|Select|Wrap|Line Numbers
  1. ######### im asking alot but these lines are not undrestood ####
  2. $advstr =~ s/\+\[\\W\_\]\*\s+\+\[\\W\_\]$//ig;
  3. $advstr =~ s/^\*//ig;
  4. $advstr =~ s/\./\\\./ig;
  5. $advstr =~ s/\@/\\\@/ig;
  6. $advstr =~ s/\$/\\\$/ig;
  7. $advstr =~ s/\-/\\\-/ig;
  8. ############################################
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
Sep 22 '08 #2

KevinADC
Expert 2.5K+
P: 4,059
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?
Sep 22 '08 #3

numberwhun
Expert Mod 2.5K+
P: 3,503
I agree with Kevin, if you don't understand those regex's, then you didn't write this code.
Sep 22 '08 #4

Post your reply

Sign in to post your reply or Sign up for a free account.