sub pars0r{
foreach my $volume (@raw_data) {
if ($volume =~ /$vol_to_parse/) {
my $counter++;
if($counter <=1){
print "$vol_to_parse got got \n";
}
elsif (
$counter > 1 ) {
next; # or break; ?
}
}
}
}
####
#!/usr/bin/perl
#Libraries
use strict;
use warnings;
use Getopt::Long;
#Globals and default arguments
my $vol_to_parse = "john";
my $file_to_parse = "file1.txt";
my @raw_data;
my $counter=0;
#Main Program
process_args();
open_sesame();
pars0r();
#Subroutines
sub process_args{
GetOptions (
'v=s' => \$vol_to_parse,
'h=s' => \$file_to_parse,
) or die "syntax: $0 -v -h \n";
}
sub open_sesame{
open(DAT, "<", $file_to_parse) || die "Could not open file! ($!)\n +";
chomp(@raw_data = );
close(DAT);
}
sub pars0r{
foreach my $volume (@raw_data) {
if ($volume =~ /$vol_to_parse/){
$counter++;
}
if ($counter >=1){
print "$vol_to_parse got got \n";
}
elsif( $counter > 1){
next;
}
}
}
####
john got got
john got got
john got got
john got got
john got got
john got got