sub pars0r{
foreach my $volume (@raw_data) {
if ($volume =~ /$vol_to_parse/) {
my $counter++; # Create new $counter, set it to 1
if($counter <= 1){ # This will always be true
print "$vol_to_parse got got \n";
}
elsif ($counter > 1 ) { # Block will never be executed
next; # or break; ?
}
}
}
}
####
sub pars0r{
foreach my $volume (@raw_data) {
if ($volume =~ /$vol_to_parse/){
$counter++; # Set counter to one the first time
}
if ($counter <= 1){ # Changed ">= 1" to "<= 1"
# This block executes after the first match, and up to
# the next non-match, which is NOT what you want!
##
print "$vol_to_parse got got \n";
}
elsif( $counter > 1){
next;
}
}
}
####
sub pars0r{
my $b_got_match = 0; # Initialize boolean to FALSE
foreach my $volume (@raw_data) {
if ($volume =~ /$vol_to_parse/){
if (!$b_got_match) {
# Only print the match once, as $b_got_match gets
# set once we print it, and then this conditional
# will never again get executed.
##
print "$vol_to_parse got got\n";
$b_got_match = 1;
}
# We can still track the total number of matches
++$counter;
}
}
}