Try changing your code to this:
sub main {
open my $file, '<', 'thefile.txt' or die;
while(<$file>){
chomp;
print "$_\n" if /\!/;
}
}
Question
#!/usr/bin/perl
use strict;
use warnings;
main(@ARGV);
sub main
{
open(FH,"<", 'thefile.txt') or die;
my $filTMP=undef;
while(<FH>){
chomp();
$filTMP=<FH>;
if( $filTMP=~ /\!/){ # extracting all exclamation marks.
print $filTMP;
}
}
}
The problem with my newbie code is that the first matching word in the list is diplayed, but after that the angry red text "unitialized value $filetmp in patten match (m//)" shows up. As far as I can see the $filTMP is initialized. Help is needed :).
Solution
Try changing your code to this:
sub main {
open my $file, '<', 'thefile.txt' or die;
while(<$file>){
chomp;
print "$_\n" if /\!/;
}
}