Created
August 30, 2011 11:08
-
-
Save MelanieS/1180678 to your computer and use it in GitHub Desktop.
Playing with heredocs & conditionals in Perl
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/perl | |
use strict; | |
use warnings; | |
my $books = <<'END_OF_REPORT'; | |
1 The Well-Grounded Rubyist | |
2 Pragmatic Thinking & Learning | |
3 Programming Ruby 1.9 | |
4 Learning Perl | |
END_OF_REPORT | |
#I know I need a loop, just not there yet in my course | |
my ($line1, $line2, $line3, $line4) = split "\n", $books; | |
print "Here is a list of my programming books\n"; | |
my ($rank, $topic) = split " ", $line1, 2; | |
my $result = index ($topic, 'Ruby'); | |
if ($result != -1) #If string does not contain 'Ruby' index() will return -1 | |
{ | |
print "$rank $topic\n"; | |
} | |
($rank, $topic) = split " ", $line2, 2; | |
$result = index ($topic, 'Ruby'); | |
if ($result != -1) | |
{ | |
print "$rank $topic\n"; | |
} | |
($rank, $topic) = split " ", $line3, 2; | |
$result = index ($topic, 'Ruby'); | |
if ($result != -1) | |
{ | |
print "$rank $topic\n"; | |
} | |
($rank, $topic) = split " ", $line4, 2; | |
$result = index ($topic, 'Ruby'); | |
if ($result != -1) | |
{ | |
print "$rank $topic\n"; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment