#!/usr/bin/perl -- use strict; use warnings; my $data = "Region Item volume Month"; my @da = split /\s+/, $data; for my $daix ( 0 .. $#da ){ $_ = $da[$daix]; /volume/ and print "volume $daix\n"; /Item/ and print "Item $daix\n"; /(volume|Item)/ and print "$1 $daix\n"; } __END__
#!/usr/bin/perl -- use strict; use warnings; my $data = "Region Item volume Month"; my @da = split /\s+/, $data; my $daix = 0; for( @da ){ /volume/ and print "volume $daix\n"; /Item/ and print "Item $daix\n"; /(volume|Item)/ and print "$1 $daix\n"; $daix++; } __END__
#!/usr/bin/perl -- use strict; use warnings; use 5.012; my $data = "Region Item volume Month"; my @da = split /\s+/, $data; while( my($daix, $_) = each @da ){ /volume/ and print "volume $daix\n"; /Item/ and print "Item $daix\n"; /(volume|Item)/ and print "$1 $daix\n"; } __END__
In reply to Re^2: finding the field number of a matching pattern in perl
by Anonymous Monk
in thread finding the field number of a matching pattern in perl
by Thomas Kennll
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |