=-= Mode #lecture +m by Ch4r Ch4r ok, let's start with some code: Ch4r #!/usr/bin/perl Ch4r print "Hello, world!\n"; Ch4r the above is the infamous 'hello world' script Ch4r it prints the text 'hello, world' to standard output (the screen) Ch4r the first line is for UNIX systems - it tells the shell where the perl interpreter is located on the system Ch4r this line will be ignored by Windows though Ch4r the second line includes a call to the print() function Ch4r before, we can completely understand that though, we need to understand what a function, aka a subroutine, is |<-- Moddy has left irc.binaryuniverse.net (Ping timeout: 181 seconds) Ch4r a function is one or more lines of code that have a specific purpose and are given a name Ch4r the print() function comes with the perl interpreter, and its purpose is to print text to standard output Ch4r as we can see here, the text printed to standard output is "Hello, world!\n" =-= Mode #lecture -m by Ch4r Ch4r questions so far? mu-tiger what's "n"? qwertydawom no, you can keep it up Ch4r I'll get to that in a minute, mu mu-tiger k Ch4r well, ok =-= Mode #lecture +m by Ch4r Ch4r the only part of this that isn't obvious is the "\n", heh Ch4r \n is what is called an escape sequence, and is used to print 'special' characters Ch4r \n is the newline character Ch4r there are other 'escape characters', such as \t, which is a tab, and \a, which is a bell =-= Mode #lecture -m by Ch4r Ch4r clear? mu-tiger bell? Ch4r it makes a small noice Ch4r noise* qwertydawom =ding mu-tiger k qwertydawom :) Ch4r yeah Ch4r :P Ozzy cool Ch4r ok, moving on =-= Mode #lecture +m by Ch4r Ch4r *looks through notes* Ch4r oh, and one more thing regarding the code Ch4r you can see that the line that prints a string, or text, to standard output ends with a semicolon; Ch4r all statements in Perl should be terminated with a semicolon Ch4r right, moving on to the next code sample Ch4r Code: Ch4r #!/usr/bin/env perl Ch4r # The infamous 'hello, world' script... Ch4r print "Hello".", wor"; # print part of the phrase Ch4r print("ld","!\n"); # print the other part Ch4r this is a slightly more complex version of the previous script, ,but it does *exactly* the same thing Ch4r this is a slightly more complex version of the previous script, ,but it does *exactly* the same thing Ch4r the first line is still the location of the Perl interpreter on *nix systems. The difference is that using #!/usr/bin/env perl instead of #usr/bin/perl is more portable - it tells the system to find the perl interpreter, wherever it is within the path. Ch4r whereas using the line #!/usr/bin/perl states to use the Perl interpreter within the dir /usr/bin =-= Mode #lecture -m by Ch4r Ch4r Qs? qwertydawom yeah qwertydawom yeah Ch4r ok..? qwertydawom to concatenate strings qwertydawom do we have to use "." or "," ? Ch4r hm? Ch4r I'll get to that in a moment ;) qwertydawom ok :) Ch4r ok..? qwertydawom to concatenate strings qwertydawom do we have to use "." or "," ? Ch4r hm? Ch4r I'll get to that in a moment ;) qwertydawom ok :) Ch4r right. Anyone else? Ch4r ok Ch4r moving on -->| Peradox (~Peradox@adsl-67-124-248-105.dsl.snfc21.pacbell.net) has joined #lecture =-= Mode #lecture +m by Ch4r Ch4r hey Peradox Ch4r anyway, moving on :P Ch4r the second line of the code is what is referred to as a comment. Comments are like a coder's "notes-to-self", and are completely ignored by the perl interpreter Ch4r in Perl, lines are made comments by beginning the line with a #. The space from the # until the end of the line is ignored by perl Ch4r the third line of the code includes a call to print() Ch4r this time however, tell it to print: Ch4r "hello".", wor" Ch4r so you might be wondering - wtf is that dot? Ch4r the dot is the concatenation operator. It's used to join two strings together in perl Ch4r so in this example, "Hello" and ", wor" are joined together resulting in the string "Hello, wor" Ch4r the next line is *another* call to print() as you can see. This time print is told to print ("ld","!\n") Ch4r first off, what's up with the parentheses? Ch4r the answer is that the argument(s) passed to print, the string(s) you want print to, erm, print, can be enclosed within parentheses Ch4r then parentheses are, though, completely optional Ch4r next question - Ch4r what's up with the comma Ch4r it turns out that we can actually tell print to print more than one string. If we want print to print two strings, we pass the to the print function separated by a comma Ch4r in this case, the two strings are "ld" and "!\n", which are the characters 'ld!' and a newline =-= Mode #lecture -m by Ch4r Ch4r questions? mu-tiger lemme scroll =/ Ch4r am I going too fast? :\ Peradox no Peradox fine Ch4r ok mu-tiger what's "ld?" qwertydawom worLD ;) mu-tiger =/ Ch4r "ld" is one of the strings to be printed by print() mu-tiger this is over my fucking head Peradox lol dude, it's just stdio Ch4r what else don't you understand? I can probably explain it more thoroughly Ch4r Peradox, you're a bit more experienced than some of the other people in here ;) mu-tiger i mean, maybe i better stick to the first way Peradox oh, sorry mu-tiger i don't understand what concentrators are and why if Ch4r ok, mu-tiger it's more complicated you don't just do it the easier way, or i guess me, at least to learn Ch4r concatenating is simply joining two strings together into one string mu-tiger ok mu-tiger but why print "hello world" in all those pieces? qwertydawom lol Ch4r haha, no reason qwertydawom that's an example mu-tiger instead of a nice smooth "hello world?" Ch4r it's just to illustrate some new concepts of perl mu-tiger so i shouldn't worry about it for now? mu-tiger for myself? Ch4r right mu-tiger ok mu-tiger sorry Ch4r lol Ch4r np Ch4r any more questions? Ch4r well, ok =-= Mode #lecture +m by Ch4r Ch4r next up is the concept of variables Ch4r first, some more code though: Ch4r #!/usr/bin/env perl Ch4r $variable = "hi"; Ch4r print $variable, " there\n"; Ch4r the first line should be pretty clear by now -->| yosyp_ (~yosyp@pool-70-108-80-79.res.east.verizon.net) has joined #lecture Ch4r the second requires some explanation though... simply put, we assign the variable '$variable' the value "hi" Ch4r so wtf are variables, you're probably wondering. Ch4r Variables allow us to represent strings, numbers, or other pieces of data with one single word. Ch4r in this case, the name $variable now holds the value "hi" Ch4r we can now use the name $variable anywhere we could use the word "hi". For instance: Ch4r print $variable; Ch4r would print "hi" to standard output Ch4r $variable . " more text"; Ch4r that would result in the string "hi more text" Ch4r because we're simply concatenation $variable, or "hi", with " more text" -->| CreepyNodque (~nova@L0153P03.dipool.highway.telekom.at) has joined #lecture Ch4r getting back to the code, the next line prints "hi there\n" Ch4r why? Ch4r because we're passing two arguments, or strings to be printed, to print() Ch4r the first is $variable, which contains the text "hi" Ch4r the second is " there\n", which contains 'there' and a newline. The result is that the two strings are printed in the order they appear, and "hi there" + a newline is printed to standard output =-= Mode #lecture -m by Ch4r Ch4r questions? Ch4r oh, and hey creepy, hey yosyp ;) mu-tiger nope :D yosyp_ hi Ch4r yosyp_ nice lexture Ch4r thanks Ch4r any more questions? yosyp_ are you gonna go on further/ Ch4r yeah Peradox lol yosyp_ go ahead Ch4r ok Known Networks ChatZilla error Connected Networks URL irc://foo/bar Not Connected Lag URL irc://irc.binaryuniverse.net/lecture Mode +nt Users 8, 0@, 0%, 0+ Topic BU/HL Lectures || Next lecture is TODAY at 10 PM GMT +0 URL irc://foo/bar Connected via URL irc://foo/bar Connected to File Progress #lecture Ch4r concatenating is simply joining two strings together into one string mu-tiger ok mu-tiger but why print "hello world" in all those pieces? qwertydawom lol Ch4r haha, no reason qwertydawom that's an example mu-tiger instead of a nice smooth "hello world?" Ch4r it's just to illustrate some new concepts of perl mu-tiger so i shouldn't worry about it for now? mu-tiger for myself? Ch4r right mu-tiger ok mu-tiger sorry Ch4r lol Ch4r np Ch4r any more questions? Ch4r well, ok =-= Mode #lecture +m by Ch4r Ch4r next up is the concept of variables Ch4r first, some more code though: Ch4r #!/usr/bin/env perl Ch4r $variable = "hi"; Ch4r print $variable, " there\n"; Ch4r the first line should be pretty clear by now -->| yosyp_ (~yosyp@pool-70-108-80-79.res.east.verizon.net) has joined #lecture Ch4r the second requires some explanation though... simply put, we assign the variable '$variable' the value "hi" Ch4r so wtf are variables, you're probably wondering. Ch4r Variables allow us to represent strings, numbers, or other pieces of data with one single word. Ch4r in this case, the name $variable now holds the value "hi" Ch4r we can now use the name $variable anywhere we could use the word "hi". For instance: Ch4r print $variable; Ch4r would print "hi" to standard output Ch4r $variable . " more text"; Ch4r that would result in the string "hi more text" Ch4r because we're simply concatenation $variable, or "hi", with " more text" -->| CreepyNodque (~nova@L0153P03.dipool.highway.telekom.at) has joined #lecture Ch4r getting back to the code, the next line prints "hi there\n" Ch4r why? Ch4r because we're passing two arguments, or strings to be printed, to print() Ch4r the first is $variable, which contains the text "hi" Ch4r the second is " there\n", which contains 'there' and a newline. The result is that the two strings are printed in the order they appear, and "hi there" + a newline is printed to standard output =-= Mode #lecture -m by Ch4r Ch4r questions? Ch4r oh, and hey creepy, hey yosyp ;) mu-tiger nope :D yosyp_ hi Ch4r yosyp_ nice lexture Ch4r thanks Ch4r any more questions? yosyp_ are you gonna go on further/ Ch4r yeah Peradox lol yosyp_ go ahead Ch4r ok =-= Mode #lecture +m by Ch4r =-= Mode #lecture -m by Ch4r Ch4r yes, dlab? dlab why are you using env for perl? Peradox to make the code portable Ch4r as I said, it's more portable than using a specific path to use #/usr/bin/env perl Peradox he uses a nice little unbix trick dlab aah mu-tiger :) Ch4r because then it finds Perl whertever it is within the path Ch4r any more questions? dlab but then /bin/sh -c 'perl' would work as well dlab although, env is a lot less overhead mu-tiger what's "sh"? Peradox a shell dlab mu-tiger: Its a shell mu-tiger thought so mu-tiger ty dlab that's off topic dlab sorry, continue Ch4r Ch4r dlab, well, I'll have to look into using /bin/sh -c 'perl' :P Ch4r ok, thanks. Np =-= Mode #lecture +m by Ch4r Ch4r we can even assign a variable to a variable. Ch4r For instance: Ch4r $anothervar = $variable; Ch4r $anothervar sitll holds the value "hi" Ch4r now, moving on to receiving input Ch4r take a look at this code: Ch4r #!/usr/bin/env perl Ch4r print "Enter a string: "; Ch4r chomp($a = ); Ch4r print "\"$a\" <-- that's what you said\n"; Ch4r the first line shoudl be familiar by now Ch4r the second line should too. It just prints "Enter a string " to standard output Ch4r the third line is what's new Ch4r before we get into what chomp() is, let's analyze $a = Ch4r represents standard input. Knowing this, we can tell that the variable $a is assigned the value , which is actually whatever the user enters into standard input Ch4r chomp() is the second function I'm going to tell you about today Ch4r it simply removes the newline from the end of a string (if there is one) Ch4r the reason we need to do this is because the input is terminated with a newline, and we might not necessarily want that newline later on. For instance, it could result in unpredictable or unwanted results when we use concatenation Ch4r the last line, print "\"a\" <-- that's what you said\n"; prints whatever the user entered and then "<-- that's what you said" Ch4r "\"$a\"* Ch4r not "\"a\" Ch4r fucking typo Ch4r erm Ch4r anyway Ch4r so you're probably wondering -what's with the \"? Ch4r well, we need a way to represent a " character in a string contained within " " without terminating the string too early Ch4r \" is used to represent " within a double-quoted string Ch4r we could've just used single-quotes, that probably would have been better and easier, but this looks cooler and allows me to introduce more info in my lecture. =-= Mode #lecture -m by Ch4r Ch4r questions? Peradox i'm not sure if everyone is familiar with procedural programming, so laet me make this clear: chomp($a = ); is the same as $a = ; chomp($a); mu-tiger \'== in double quotes? Peradox \ is the escape character Ch4r mu-tiger, hmm? mu-tiger the what to achieve double quotes? Peradox it's used for non printable ASCII characters Peradox and double quotes so you do not confuse the interpreter mu-tiger ok Ch4r ok, now you lost me... :P dlab in perl, double quotes mean to interpret the line. If a character is preceded with a backslash, then it is interpreted by perl mu-tiger :D mu-tiger gotcha mu-tiger ty xD Ch4r alright.. dlab like \n gets replaced with a newline, \r gets replaced with a carriage-return mu-tiger yeah dlab \0600 gets replaced with the octal value of 600 :/ dlab etc.. mu-tiger :| Peradox heh mu-tiger go on charlie Ch4r ok Ch4r lol Peradox wait till you get to 0x32 mu-tiger hush mu-tiger :( =-= Mode #lecture +m by Ch4r Ch4r ok. The last Q and A session (for want of a better term) brings up another topic I haven't introduced yet - single quotes vs. double quotes Ch4r there is one very important difference between single and double quotes, and that is: Ch4r when you double-quote a string, any variables in the string are replaced with their values. For instance, print "$a" prints whatever $a contains. When you single-quote a string, however, all characters are interpreted literally. This means that print '$a' prints the text $a and NOT the value $a contains. Similarly, print '\n' does NOT print a newline; it prints the two characters \ and n |<-- Peradox has left irc.binaryuniverse.net (Client Quit) Ch4r bye pera Ch4r ok, next Ch4r check out this code: Ch4r #!/usr/bin/env perl Ch4r $a = 4 + 8; Ch4r $b = $a * 2; Ch4r $c = $b / $a; Ch4r $d = $c * $c * $c % 3; Ch4r print '$d: ', "$d\n"; Ch4r $a = 10 - 3 * 7; Ch4r $b = (10 - 3) * 7; Ch4r print "\$a = $a | \$b = $b\n"; Ch4r by this time the first line should seem like an old friend (Btw, the first line's called the 'shebang' or 'hash bang' line) -->| Peradox (~Peradox@adsl-67-124-248-105.dsl.snfc21.pacbell.net) has joined #lecture Ch4r the second line $a = 4 + 8; assignes $a the value of 12, because 12 is, afterall, 4 + 8 Ch4r the third line, $b = $a * 2; assigns $b the value 24. Why? Because the * operator multiplies its operands together and returns the result. In this case, 12 is multipliued by 2, which equals 24. Ch4r the next line, $c = $b / $a; divides $b by $a and then assigns the result to $c. In this case, 24 divided by 12 equals 2, so $c = 2; Ch4r the next line multiples 2 times 2 times 2, which equals 8, divides it by 3 and assigns the remainder, 2, to $d Ch4r then, the following is printed. '$d: ',"$d\n"; this prints the characters '$d: ' to standard output and then the value that $d contains along with a newline =-= Mode #lecture -m by Ch4r Ch4r questions so far? mu-tiger nope :) Ch4r ok, cool. Anyone else Ch4r ?* dlab hmm Ozzy no, but i g2g. Looking forward to the log Ch4r laters Ozzy mu-tiger bye ox Ozzy bye! Ch4r dlab, ...? mu-tiger oz* |<-- Ozzy has left irc.binaryuniverse.net ("Toodaloo") dlab maybe you should introduce the perl order of precidence Ch4r yeah, that's next mu-tiger :) Ch4r as you would see if you looked at the code :P dlab ok :) Ch4r ok, moving on then =-= Mode #lecture +m by Ch4r Ch4r order of precendence determines which part of a mathematical expression in Perl is evaluated first. Take the next line: Ch4r $a = 10 - 3 * 7; Multiplication and division are evaluated before addition and subtraction, so 3 * 7 is evaluated first, which equals 21. Then the subtraction is evaluated, so 21 is subtracted from 10 and the result is assigned to $a. Ch4r But what if we wanted the subtraction to be evaluated version, so that first 3 was subtracted from 10 and then the result was multipled by 7? Ch4r well, it actually isn't very hard. We simply place parentheses around the part we want evaluated first, which is 10 - 3. so (10 - 3) * 7 is the same as 7 * 7 Ch4r because first 3 is subtracted from 10 and then the result is multiplied by 7 Ch4r and then the result is printed =-= Mode #lecture -m by Ch4r Ch4r questions? mu-tiger just like simple algebra mu-tiger no Ch4r yep Ch4r ok Ch4r no more? =-= Mode #lecture +m by Ch4r =-= Mode #lecture -m by Ch4r Ch4r err Ch4r I think that's it :P dlab haha Ch4r no qwertydawom what about modulo? Ch4r it isn't Ch4r hold on dlab there are things like quotes and commas in there as well dlab .. and modulo Ch4r I already described that, didn't I? Ch4r yeah Ch4r scroll up ;) dlab like a comma has the lowest precidence, etc.. mu-tiger char mu-tiger restate it for me? Ch4r mu-tiger, yes? Ch4r #!/usr/bin/env perl Ch4r $a = 4 + 8; Ch4r $b = $a * 2; Ch4r $c = $b / $a; Ch4r $d = $c * $c * $c % 3; Ch4r print '$d: ', "$d\n"; Ch4r $a = 10 - 3 * 7; Ch4r $b = (10 - 3) * 7; mu-tiger oh yeah Ch4r print "\$a = $a | \$b = $b\n"; mu-tiger sorry Ch4r whoops Ch4r shit Ch4r sorry Ch4r didn't mean to paste the whole thing Ch4r hm? mu-tiger no nothing mu-tiger my bad mu-tiger ty Ch4r ok Ch4r np Ch4r well, let's move on to conditionals then? Peradox w00t qwertydawom you haven't said if % was to be evaluated first dlab modulo should have the same precidence as division/multiplcation, no? Peradox yes Ch4r yeah qwertydawom ok Ch4r sorry Ch4r right, done? dlab .. yeah Ch4r well, with questions i mean Peradox yup mu-tiger yes Ch4r ok =-= Mode #lecture +m by Ch4r Ch4r here's some more code for you: Ch4r #!/usr/bin/env perl Ch4r if (8 > 4) { Ch4r print "Eight is greater than four!\n"; Ch4r } Ch4r if (5 < 6 && 7 <= 3) { Ch4r print "Condition was true.\n"; Ch4r } Ch4r else { Ch4r print "Condition was false - else block executed.\n"; Ch4r } Ch4r this code introduces some new concepts Ch4r starting at the second line -->| chedder (1000@S01060000e88e954d.vc.shawcable.net) has joined #lecture Ch4r lines 2 through 4 contain an if conditional statement Ch4r so how do we use the if? Ch4r if takes a condition that is specified between parentheses and checks whether or not it's true. If it is, the code between the curly braces {} is executed (aka, the block of the statement) Ch4r in this case, if checks whether 8 > 4, whether eight is greater than four. It is, so the print statement between the braces, print "Either is grater than four!\n"; is executed =-= Mode #lecture -m by Ch4r Ch4r questions? dlab yeah Ch4r ok...? dlab what about the precidence of boolean operators? Peradox explain about how expression evaluate mu-tiger mu-tiger like where he has the "}" is that written on a new line like he just did it? Peradox if($a) Peradox for example Ch4r Peradox, what? dlab well.. 0 is usually false, and nonzero is true in C Ch4r yeah Ch4r oh, that's what you mean? :P dlab perl supports true booleans though, so.. dlab not sure Peradox well Ch4r mu-tiger, what were you saying? dlab prolly eveluates the same mu-tiger i thought this was a beginner lecture :| Peradox you need to show that you can evlaute dlab evaluates* Peradox 1 && 0 Ch4r ok, one person at a time please Peradox and ! || 0 Peradox and so on dlab yeah Ch4r I'll get to ||, 7&, etc in a min Ch4r please don't get ahead of me :) dlab haha Peradox k dlab alright qwertydawom :) mu-tiger can i have like mu-tiger 2 minutes to go do soemthing and try to work this out a sec, too? mu-tiger and here's what i asked mu-tiger mu-tiger like where he has the "}" is that written on a new line like he just did it? Ch4r what exactly are you trying to ask? :/ qwertydawom it's a syntax.. Ch4r the } doesn't necessarily have to be written on a line by itself Ch4r we could've put it on the same line as the print statement chedder damn i wish i could be a ninja chedder damn i wish i could be a ninja qwertydawom if stuff { blib } else {bla} mu-tiger when you were showing us Ch4r if (8 > 4) { mu-tiger Ch4r print "Eight is greater than four!\n"; mu-tiger Ch4r } dlab ... mu needs another client mu-tiger that last bracket dlab anyway.. mu-tiger is on another line? mu-tiger just like that? chedder the last bracket dosent matter dlab doesn't matter if it is Ch4r it doesn't have to be on another line chedder it dosent matter mu chedder it has to be there mu-tiger ok chedder but what line its on mu-tiger brb Ch4r chedder, it doesn't actually have to be there in this instance ;) dlab actually, you don't even need the brackets since Ch4r executed a single statement Ch4r I know chedder well, it techniqly dosent have to be there anyways chedder :P dlab perl is a free-form language Ch4r mu-tiger, tell me when you're back. we'll wait for you chedder licks dlab chedder you back now? dlab you can have the bracket 6 lines down if you wish chedder im back on slackware, for some reason chedder lol dlab chedder: No dlab still in oregon Ch4r please don't go off topic, ched chedder :( chedder oh chedder sorry Ch4r Ch4r do that in #hackerlounge or #binaryuniverse Ch4r np mu-tiger k Ch4r ok, moving on again =-= Mode #lecture +m by Ch4r Ch4r mu-tiger mu-tiger like where he has the "}" is that written on a new line like he just did it? Ch4r wtf Ch4r no mu-tiger lol === #lecture The channel demigods have stolen your voice Ch4r hold on, I'm going to paste the code again Ch4r #!/usr/bin/env perl Ch4r if (8 > 4) { Ch4r print "Eight is greater than four!\n"; Ch4r } Ch4r if (5 < 6 && 7 <= 3) { Ch4r print "Condition was true.\n"; Ch4r } Ch4r else { Ch4r print "Condition was false - else block executed.\n"; Ch4r } Ch4r right. Ch4r so, we aren't limited to checking whether one number is greater than the other with if statements Ch4r the > (greater than) operator is only one of many we can use Ch4r some more are: Ch4r < - less than Ch4r > - greater than Ch4r <= - less than or equal to Ch4r == - equal to Ch4r >= - greater than or equal to Ch4r != - not equal to Ch4r eq - equal to FOR STRINGS Ch4r ne - not equal to FOR STRINGS Ch4r && - and Ch4r || - or Ch4r for instance, Ch4r if (5 != 4) evaluates to be true Ch4r if ( 5 <= 2) does not Ch4r the last two operators on that list, && and || require a further explanation though Ch4r it turns out that we can specify more than one condition for an if statement Ch4r for instance, the second if statement in our code reads: Ch4r Ch4r if (5 < 6 && 7 <= 3) { Ch4r Ch4r print "Condition was true.\n"; Ch4r Ch4r } Ch4r for the expression to evaluate to be true and for the print "Condition was true.\n" to be executed, both of the conditions 5 < 6 and 7 <= 3 must be true Ch4r the && operator simply means that both conditions specified must be true for the expression as a whole to be true Ch4r we can use it with more than two expressions though. For example: Ch4r if (5 != 7 && 2 <= 2 && 99 > 7 && 2 == 2) { ... } Ch4r the above condition will only be true if 5 is not 7 and 2 is less than or equal to 2 and 99 is greater than 7 and 2 is 2. =-= Mode #lecture -m by Ch4r Ch4r questions? dlab what about boolean OR? Ch4r yeah, I'll get to that dlab or is that next? >_> Ch4r yes dlab my bad Ch4r lol, np dlab shuts up Ch4r haha mu-tiger wait a sec charlie Ch4r ok chedder pokes #lecture Ch4r gives chedder his final warning about going off topic and then pokes #lecture. mu-tiger ok go on mu-tiger sorry Ch4r ok, np =-= Mode #lecture +m by Ch4r Ch4r ok, next up, logical OR. Ch4r locgical or is similar to logical and, &&, which I just introduced. The main difference is that if either of its operands is true, the statement as a whole is true. Eg: Ch4r if (5 > 3 || 9 < 3) { ... } Ch4r even though nine is certainly not less than three, the statement is still true as a whole. Why? Because 5 is greater than three, and if either of the operands (statements it is used with) is true, the expression as a whole is true. Ch4r logical ORs and logical ANDs can be used in a single expression as well. For instance: Ch4r if (5 < 7 || 6 == 6 && 2 > 3) { ... } Ch4r however, the question of precedence arises once more Ch4r to acheive the desired results, you may need to enclose part of the expression within parentheses to make sure it's evaluated first. =-= Mode #lecture -m by Ch4r Ch4r questions? dlab what about conditionals? :) mu-tiger :| Ch4r dlab, hm? Ch4r mu-tiger, hmm? dlab $meh = ($poo == 1) ? 1 : 2; Ch4r oh, and one more note. Do NOT confuse bitwise and logical and/or operators with one another. They're a bit different. mu-tiger bitwis? dlab Ch4r: Indeed. :) mu-tiger wtf? mu-tiger cries Ch4r dlab, oh. I'm not planning on including the ? : notation Ch4r mu-tiger, what's wrong? dlab mu-tiger: That will prolly come later mu-tiger nothing cept i'm so lost mu-tiger i'll try to sort it all later Ch4r well Ch4r now's the time for questions lecture DLAB! [INFO] No such nick/channel Ch4r don't be afraid to ask, even if it sounds stupid mu-tiger well it's just i'm vague on a lot mu-tiger i'll have to look at it in parts later and ask mu-tiger go on, pls Ch4r ok =-= Mode #lecture +m by Ch4r Ch4r pardon me, but I'm going to need to paste the code again ^_^ Ch4r #!/usr/bin/env perl Ch4r if (8 > 4) { Ch4r print "Eight is greater than four!\n"; Ch4r } Ch4r if (5 < 6 && 7 <= 3) { Ch4r print "Condition was true.\n"; Ch4r } Ch4r else { Ch4r print "Condition was false - else block executed.\n"; Ch4r } Ch4r ok, next up is the else { ... } statement. Ch4r else statements are used along with if statements. If the condition specified in the parentheses of the if(){} statement is true, the body of the if statement is executed. We already know this. However, what if it's false? Well, if the if statement is alone, we just go on to the next code. If however, the if statement contains a corresponding else block, the else block is executed. Ch4r for instance, take a look at the following code: Ch4r if (5 == 6) { Ch4r # do something Ch4r } Ch4r else { Ch4r # do something else Ch4r } |<-- qwertydawom has left irc.binaryuniverse.net (Client Quit) Ch4r well, it turns out that 5 does NOT equal six, so the if statement is not executed. However, the if statement has an else statement right after it, so the else statement is executed. in this case, the else statement is simply a comment, # do something else, though. =-= Mode #lecture -m by Ch4r Ch4r questions? Ch4r ok then Ch4r dlab ? dlab end? Ch4r yeah dlab what about elif? mu-tiger what's an example of the "else? mu-tiger " mu-tiger dlab it ws a beginner lecture!!! Ch4r mu-tiger, I thought I just gave an example. But here's another :P mu-tiger jumps up and down Ch4r haha dlab if($input eq "hi") { print "Hello"; } else { print "Bye"; } Ch4r yeah Ch4r :) mu-tiger good mu-tiger awesome mu-tiger you're redeemed, dlab Ch4r haha mu-tiger hehe dlab o_O mu-tiger ty Ch4r dlab, I'll introduce elif next lecture maybe mu-tiger well you confused me dlab alright mu-tiger asking all that stuff about booleans and stuff dlab because its an important conditional mu-tiger well i'm new and dumb Ch4r important? dlab esp. since switch() only accepts ints :/ Ch4r yeah Ch4r true Peradox now how about loops?? Ch4r next lecture Peradox ahh