Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Playing with heredocs & conditionals in Perl
#!/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