http://www.perlmonks.org?node_id=671697

barkingdoggy has asked for the wisdom of the Perl Monks concerning the following question:

I am trying to use Perl to extract fields in a csv file I exported from Excel...
#!/usr/bin/perl use strict; use warnings; our $list; our @clients; our $filedef1=$ARGV[0]; #name of client CSV file &read_clients (); # define regex components my $accode = qr(^"(.*)",.*,.*,.*,.*,.*,.*,.*,.*,.*,.*,.*,.*,.*,.*)x; my $name = qr(^.*,"(.*)",.*,.*,.*,.*,.*,.*,.*,.*,.*,.*,.*,.*,.*)x; # do regex matches print "Extractions:\n"; my @extractions = $list =~ m{(?: $name)}mxgc; print "$extractions[$_], " for 0.. $#extractions; print "End of Program!\n"; ##Beginning of subroutine for reading the document source file. sub read_clients { open FILEDEF1, "< $filedef1" or die "error reading $filedef1-$!"; while (<>) { push (@clients, <FILEDEF1>); } close FILEDEF1; $list = join(' ',@clients); print $list; } ##End of block for reading the document source file.
This code works like I want it to. When I substitute $accode for $name in the line my @extractions = $list =~ m{(?: $name)}mxgc; It only extracts the first record/line match for $accode, while I get every record/line match if I do a separate run and match for $name instead. In other words, I am not getting global, multiline matching on $accode while I am on $name. Any idea why? I want every record match for $accode.