Iterate over matches with foreach and $_ and nested foreach : Loop « Regular Expression « Perl






Iterate over matches with foreach and $_ and nested foreach

   


#!/usr/bin/perl

use warnings;
use strict;

my $text = "one, two, three, four";

foreach ($text =~ /\b(\w+)\b/g) {
    print "outer: got: $_, matched: $&, extracted: $1 \n";
    foreach (/(\w)/g) {
        print "\tinner: got: $_, matched $&, extracted $1 \n";
    }
}

   
    
    
  








Related examples in the same category

1.Iterate over matches with foreach and $_ and nested while loop
2.Iterate over matches with while and $1
3.Zero width loop
4.A program that loops using a pattern.