Given the Perl array:
my @fruits = ('apple', 'pear', 'peach', 'orange', 'pineapple', 'persimmon');
-
What fruits would be found in the @pe array if we ran the following code:
my @pe = grep(/^pe/, @fruits);
A. pear, peach, persimmon
B. pear, pineapple, peach
C. apple, orange, pinable
D. All the fruits
E. None of the fruits -
If I wanted to inlude only ‘apple’ and ‘pineapple’ in a new array, what would be the simplest regular expression I could use in my grep?
A. my @apples = grep(/apple$/, @fruits);<br /> B. my @apples = grep(/^apple/, @fruits);<br /> C. my @apples = grep(/le$/, @fruits);<br /> D. my @apples = grep(/^le/, @fruits);<br /> E. my @apples = grep(/le/, @fruits);
Exercise 1.
Using the code below, and without using the ‘grep’ function, show how you’d get ‘apple’ and ‘pineapple’ into the @fruit_choice array. Make sure you replace ‘my_regex’ with a regular expression.
`my @fruits = (‘apple’, ‘pear’, ‘peach’, ‘orange’, ‘pineapple’, ‘persimmon’);
my @fruit_choice;
for my $fruit (@fruits)
{
if ($fruit =~ /my_regex/)
{</p>
}
}`