#!/usr/bin/perl use strict; use warnings; use IO::All; use v5.16; ############## ## 03/14/19 ## Exercise reads from file, then lets user interactively submit matching search criteria die "Please provide a file to process!\n" unless (defined $ARGV[0]); my @lines = io($ARGV[0])->chomp->slurp; # Chomp as you slurp while (1) { print 'Please enter a pattern: '; chomp(my $pattern = ); last if $pattern =~ /\A\s*\Z/; my @matches = eval { grep /$pattern/, @lines; }; ## end of eval if ($@) { print "Error: $@"; } else { my $count = @matches; print "There were $count matching strings:\n", map "$_\n", @matches; } print "\n"; }