From the course: Perl 5 Essential Training
Unlock the full course today
Join today to access over 22,400 courses taught by industry experts or purchase this course individually.
Loops and conditionals - Perl Tutorial
From the course: Perl 5 Essential Training
Loops and conditionals
- [Voiceover] In this lesson, I'll give you a very brief overview of conditionals and loops in Perl. This is actually a big subject, and it's an area where Perl is far more flexible than many other languages. It will be covered in more detail later in the course. Here I have a working copy of countlines2.pl from Chapter 2 of the exercise files. In this version of countlines, we'll read the file one line at a time, so we're no longer reading the entire file into memory at once. This allows us to count much larger files. Of course, we're just still counting our little 50 line linesfiles.txt file. Here in line six, you'll notice that I use IO::File; This reads in the IO File module. This is an object-oriented file-handling library. In line 11, we created an object using this library, and the object interface is stored in the $fh scalar variable. Line 12 is a simple conditional. It tests if the $fh variable is false, which would indicate that the object construction failed. The block…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.