Create a gist now

Instantly share code, notes, and snippets.

Playing with heredocs & conditionals in Perl
#!/usr/bin/perl
use strict;
use warnings;
my $books = <<'END_OF_REPORT';
4 Ruby
1 Python
1 Perl
2 HTML/CSS
END_OF_REPORT
#I know I need a loop, just not there yet in my course
my ($line1, $line2, $line3, $line4) = split "\n", $books;
my ($quantity, $topic) = split " ", $line1;
if ($quantity == 1)
{
print "I have $quantity $topic book\n";
}
else
{
print "I have $quantity $topic books\n";
}
($quantity, $topic) = split " ", $line2;
if ($quantity == 1)
{
print "I have $quantity $topic book\n";
}
else
{
print "I have $quantity $topic books\n";
}
($quantity, $topic) = split " ", $line3;
if ($quantity == 1)
{
print "I have $quantity $topic book\n";
}
else
{
print "I have $quantity $topic books\n";
}
($quantity, $topic) = split " ", $line4;
if ($quantity == 1)
{
print "I have $quantity $topic book\n";
}
else
{
print "I have $quantity $topic books\n";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment