Session Start: Tue Mar 27 10:26:38 2001 *** Now talking in #topniche *** Topic is 'Week 6 Perl/CGI Class Tech Chat - This week, Intro to CGI.pm' *** Set by FurBall on Tue Mar 20 12:37:15 -HelpBot- Welcome to Topniche IRC Webmaster Chat. Webmasters only please! -HelpBot- Our url: http://www.weboverdrive.com/ *** TDavid is now known as TD-lunch *** FurBall has joined #topniche *** HelpBot sets mode: +o FurBall *** FurBall changes topic to ' :Week 7 Perl/CGI Class Tech Chat - This week, regular expressions' Hey TD *** TD-lunch is now known as TDavid hello :) Hey there... hmmm we'll give them a few :) NP.. :) *** Itchy has joined #topniche Hey there itchy! Hello :o) school today? Hey TD... Do me a favor please if you would... Could you try posting to the message board. Yup! here? Or you too itchy. Yup! whats up? which board I mean? Could you try posting a message at the perl message board? www.webmastermatrix.com/tech/perl/msgboard/ Specifically week 7. it's there :o) on the phone, furball You had no problems at all? Ok.. Then it's me. Good. :) NP TD... nope with a potential guest for this friday :)) Ahh.. GOOD! :) what time school today ? About 5 minutes. :o) *** FurBall has quit IRC (QUIT: User exited) *** FurBall has joined #topniche Growl.... *** HelpBot sets mode: +o FurBall *** FurBall has quit IRC (QUIT: User exited) *** FurBall has joined #topniche Ok... Umm.. Are we ready? ;) *** HelpBot sets mode: +o FurBall *** FurBall sets mode: +v Itchy where is everyone ? *** FurBall sets mode: +v TDavid They're not here... ;) eheh and I'm 2 weeks behind now Ahh.. This is a good time for catchup then... :) Do you have any questions? lots hehe not sure yet Before I get into regular expressions that is. regular what ?? hehe We can turn this into a one on one for you... IE if you want to cover previous weeks, that's fine... just like lat time i learn lots yup Ok... :) Shoot with your first question then... :) ok I never got the url one to work right but looking at whta beth put on the board i see i don't need to make the arrys a link first there is a code for making what ever that arry selection a link Ok... What was the problem you were having? I made all the urls a link inside the array I see that... Ahh.. I see what you did. You should have had two arrays. One for the actual links themselves and then another one for the descriptions. ok didn't do a description one then Yup... print "$url
"; this is what i missed too was doing this code then this way i skip making the $url a link in side the Array right ? Yup But you would have to assign a value to $url before you printed it. so then we have to make so that what ever link it picks it will pick the right description too? Yup... That's easy... ;) ok thats the ? from me then how ? Just make sure that the descriptions match to the URL.. IE if $url[3] = "http://www.yahoo.com" then make sure that $description[3] = "Yahoo" Then later, assuming $index = 3, if you do this: Print "$description[$index]
"; It will print out the url for yahoo and then the description for yahoo. so then the link would be the description then or all of it ? Just the description. ok Does that answer your question? yup I see now how to get it and will built a new page after today Ok! now forms :o) Next question. :) Shoot. :) I'm just reading the assignment now :o) OK... :) anything thats a little trivcky that i might ned to look out for? Nope... nice spelling today :o) :) Are you familiar with forms? no problem to make forms work all stright forward stuff then? Yup... A bit been looking at html forms for submitting to tgps lots And since you've already kinda started to get into cgi.pm... a bit yup :o) The format that I use is different than what you use... I personally like the object method better BUT... Both work! which is shorter to write ? Probably the function method. thats the one for me then hehe but why do you like the object one? what makes you like it better ? The downside of the function method (and if you're not using something like mod_perl then it's OK) is that it uses a little bit more memory. AAAA that would make a differnece on a bit script running then right? bit = big Yes! The other difference is that I'm more "object oriented" in my thinking... Next question? =~ /([\w-.]+\@[\w-.]+)/) whats that stuf hehe OK... This is a regular expression. :) looks like fun :) ALL a regular expression is is a way to "search" through a string. It's also VERY handy for testing strings to see if they match a certain value. just checking what ever some one puts in to a form text area to make sure it's in the right format IE if you want to make sure that a URL starts out with http://www. A regular expression is the way to go. That too! The simplest regular expression is this: .* Now, what does that mean? :) The . Matches any SINGLE character and the * means that we want to match 0 or more single characters. TO test a string, you have to use the =~ operator. IE $url =~ /http:\/\/www/ (The \/ escapes the / so that we match a literal / rather than telling it to end the search) All of the stuff between the two /'s is your regular expression and is what you're searching for. so =~ tests to make sure there is a http://www there Yup... and the \is stoping the script from ending and making it go forward looking for more stuf Nope.. The \ is used to "escape" the next character. so it doesn't read the next charater then kinda like it's not there There are some "special" characters that if you wanted to match them (such as the .) you have to use the \ to tell perl to match it as a period. ok The next important concept to understand is ranges. For example, if you wanted to match any urls that started with http://www.f through http://www.j you would use a range. Like this: /http:\/\/www\.[f-j]/ The [f-j] is a range. With me so far? yup well i think so :o) Ok.. Now with ranges, you can do neat things. :) like.....hehe For example, let's say we wanted to match f through j, p, and u through z. Here's that range: [f-jpu-z] The f-j matches anything startign with f through j, the p matches anything starting with p, and the u-z matchs anythign starting u through z. so you could use that on a link list that rotates then making it look for the right letter every ay Right! cool Now, let's go back to the regular expression you posted and see how much we understand now. =~ /([\w-.]+\@[\w-.]+)/) Ok.. We know what the =~ / does. We also know what the [] do. What does the \@ do? yikes, i'm back! looks in a array for the info ? Nope... What does a \ do again? its being skipped Escaped... Not skipped... ;) looking for the @ sign i nthe e-mail addy Right! Ok.. So all we have left is the () and the \w and the +. the inside of () is what is being looked at The plus is a special form the the *. It says rather than matching ZERO or more occcurences, it says we want to match ONE or more. (nope... We'll get the the () in a sec. :)) ok it's what they call greedy hehe :) Yup.. :) The () are used to group expressions... For example, say you wanted to match one or more occurences of the string abcd in a string. The regular expression for that would be /(abcd)+/ IE it applies the + to the expression abcd. If you wrote it as /abcd+/, then it would match a string of abc followed by one or more d's. Make sense so far? so abcd and abcdd are the same or abcddddddd yuppers Using the second expression.. Yes... ok making some sence then hehe But NOT using the first expression... IE /(abcd)+/ Well.. Actually, that's not true. :0 Both regular expressions would match abcd and abcdd yup it would match in the first one any combination of abcd would match as long as they were in that order Right... :) so dabc is different SO... ALL we have left is the \w. BINGO! ok next hehe aabbcccddddd matches Now for a curve... Ready? :) :O) \w and it's friends are what we call character classes. freinds ? Basically, they are shortcuts for HUGE ranges.. For example, \d is the same as the range [0-9]. IE it matches a single digit. In this case, \w matches an upper or lowercase letter, a digit, or the underscore symbol. written long like this [(a-zA-z|0-9|_)] There's about 6 or 8 \ combos for character classes... Actually, no.. ;) It would be this: [a-zA-Z0-9_] that's right no pipes necessary unless no brackets And no parens either.. :) Right! hehe :) you know what I meant :) Does the \w make sense Itchy? (yes TD, I did. LOL) sorry bout that itchy is ok and yup reading a bit on that too in week the point is if you didn't use shortcuts then the code would be VERY confusing to look at er, the regexp that is Right! OK... So let's look at that regular expression again: =~ /([\w-.]+\@[\w-.]+)/) What does the [\w-.]+ do? there has to be a upper oe lower case letter od number aor digit there it must START with that Yes... And whatelse? then looks for a @ sign with the + think of how an email address is structured ... it will help you No... abc@123.com The + says we want to match one or more of the PREVIOUS expressions... IE in this case the [\w-.] expression. its_my_emailaddy@anydomain.com What does the \@ do? makes sure that @ is there yup looks to make sure it's in the string Ok.. Final question. Do we need the () in the expression? yes Why? we just talked about that What is it doing? or else it looks for something else grouping the expresa. yup, it groups the expression But it's grouping the entire expression... (As an aside, if we were doing a search and replace with this, then yes, there would be a good reason for the () :) ) So if it's grouping the entire expression...do we really need the () after all? I'm not sure but i want to say no we don't need them there You are right... But do you know why? furball can ya give me a call when we're done here mon? (sure can!) Let me put it this way... What's the difference between =~ /([\w-.]+\@[\w-.]+)/) And =~ /[\w-.]+\@[\w-.]+/ ? If any? P.S. The final ) is just a typo... aaaaaaaaa' Yes? ..../>>>>>>/ works like (........) Bingo! :) lost the ? because the first letter was a / Remember, the regular expression is what is between the two /'s. must be a mirc thing yup OOHH... ;) Ok.. Ok.. That does it for regular expressions... ;) you can also use the m#expressionhere# cool I sure like these tuesday class's hehe if furball didn't mention that already :) No I didn't... :) nope you didn't hehe' OK... Then we are done... :) yup, itchy, people don't know what they are missing by not coming here :) a couple hundred dollars per hour worth of information for free! :)) fur sore I know hgow are the friday class's :) I moved so been out of touch for a bit Hey TD, what's your number again? (Don't feel like wandering to the website. :)) lol shame on ya, i want to show you my real time chat interface! http://www.tdscripts.com/contact.html try it Oh wait... :) Ok... thank you for coming itchy :)) you bet see you's on friday fur sore Oh.. OK.. :) Great! See ya there Itchy! *** Itchy has left #topniche Ring ring. :) Session Close: Tue Mar 27 13:23:48 2001