tag:blogger.com,1999:blog-6603440187887047162.post8349888412378181710..comments2023-06-16T07:54:41.787-04:00Comments on Detroit Dave's Raves: Using Perl for NSLOOKUP from logfiles (Part 1)DetroitDavehttp://www.blogger.com/profile/00384772147714696312noreply@blogger.comBlogger2125tag:blogger.com,1999:blog-6603440187887047162.post-3504324363000066142012-06-17T18:08:18.230-04:002012-06-17T18:08:18.230-04:00Thank you very much for the comment. I appreciate ...Thank you very much for the comment. I appreciate it when others take the time to read and comment on what I have written.<br />You are partially correct in that I could use the caret. My focus was intentionally on 'containing' and not starting. I am going to take this response as more of a 'teaching' thing for those who don't know Perl regex's well (and I admit to being one of them). So...<br />For those who don't know, in Perl, the '=~' means 'containing' and the 'next' (without anything else) means to go to the next iteration of the for loop. So, if the script comes upon a line containing 192.168 anywhere in the line, it will skip the remainder of that iteration of the for loop and go to the next one, which in this case it will start to process the next line. <br />Additionally, using 'm/^sometext/' means match only lines beginning with 'sometext.' If you place the caret between the 's' and the 'o', then it will match any line where there is at least one 'o' follwing an 's'. In short, the caret used without the brackets is normally for testing against a specific place in the string. <br />To negate with the caret you would in most cases use a hard bracket with a character class, such as: [^abc]. This says 'NOT a, b, or c' in the string. So, I could have changed the if statement and used something like m/[^1][^9][^2]\.[^1][^6][8]/ to do what you are suggesting. However, I found what I used to be a little cleaner and easier to understand. <br />Basically, there are a number of different ways that I could have done this but I chose the way that I felt would be the most accurate. By looking to see if the string DID contain '192.168', and then moving 'next' if it did, I am ONLY skipping lines that contain that value and NOT skipping lines that contained other similar values. I also didn't want to limit it to only being at the start of the line, in the event that the output file it reads from may have some errors. <br />You DID cause me to realize that I need to do something better in case the address has 192.168 starting in the second or third octect, which I think was the exact point you were trying to make. This is exactly why I like comments that challenge me, so Thank You very much!!! :)<br />DWDetroitDavehttps://www.blogger.com/profile/00384772147714696312noreply@blogger.comtag:blogger.com,1999:blog-6603440187887047162.post-73674469210999554532012-06-17T16:40:26.326-04:002012-06-17T16:40:26.326-04:00Dude, you might want to use a caret at the start o...Dude, you might want to use a caret at the start of your regexs (e.g. m/^192/) so that you only grab the addresses starting with 192 rather than containing 192.Anonymousnoreply@blogger.com