I'm currently trying to learn PERL, and my instructor tasked me with the following and I'm kind of lost.
#!/usr/bin/perl
use strict;
use warnings;
# Grocery store inventory:
my $lines = <<'END_OF_REPORT';
0.95 300 White Peaches
1.45 120 California Avacados
5.50 10 Durian
0.40 700 Spartan Apples
END_OF_REPORT
my ($line1, $line2, $line3, $line4) = split "\n", $lines;
my ($cost, $quantity, $item) = split " ", $line1, 3;
my $a = index ($line1, "es" , 22 );
my $b = index ($line2, "es" , 28 );
my $c = index ($line3, "es" , 15 );
my $d = index ($line4, "es" , 23 );
print "$a\n";
print "$b\n";
print "$c\n";
print "$d\n";
The above shows
22
-1
-1
23
I'm supposed to search each line that is != 1 and print that line like such. Without using prior knowledge that $a and $d will work.
print "Total value of $item on hand = \$", $cost * $quantity, "\n";
Please help.
#!/usr/bin/perl
use strict;
use warnings;
# Grocery store inventory:
my $lines = <<'END_OF_REPORT';
0.95 300 White Peaches
1.45 120 California Avacados
5.50 10 Durian
0.40 700 Spartan Apples
END_OF_REPORT
my ($line1, $line2, $line3, $line4) = split "\n", $lines;
my ($cost, $quantity, $item) = split " ", $line1, 3;
my $a = index ($line1, "es" , 22 );
my $b = index ($line2, "es" , 28 );
my $c = index ($line3, "es" , 15 );
my $d = index ($line4, "es" , 23 );
print "$a\n";
print "$b\n";
print "$c\n";
print "$d\n";
The above shows
22
-1
-1
23
I'm supposed to search each line that is != 1 and print that line like such. Without using prior knowledge that $a and $d will work.
print "Total value of $item on hand = \$", $cost * $quantity, "\n";
Please help.