Skip to content

Instantly share code, notes, and snippets.

@MelanieS
Created August 30, 2011 11:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MelanieS/1180678 to your computer and use it in GitHub Desktop.
Save MelanieS/1180678 to your computer and use it in GitHub Desktop.
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