![]() |
|
Do you know where your variables are? | |
PerlMonks |
comment on |
( #3333=superdoc: print w/replies, xml ) | Need Help?? |
This code works like I want it to. It does? Really? OK. #!/usr/bin/perl use strict; use warnings; our $list; our @clients; our $filedef1=$ARGV[0]; #name of client CSV file Why are you declaring those variables here when you are only using them inside the read_clients() subroutine? &read_clients (); You shouldn't use & when calling subroutines, see perlsub for reasons why. # define regex components my $accode = qr(^"(.*)",.*,.*,.*,.*,.*,.*,.*,.*,.*,.*,.*,.*,.*,.*)x; my $name = qr(^.*,"(.*)",.*,.*,.*,.*,.*,.*,.*,.*,.*,.*,.*,.*,.*)x; Why include the empty fields after the captured field? # do regex matches print "Extractions:\n"; my @extractions = $list =~ m{(?: $name)}mxgc; Why are you using the /c option? It is only relevant if you are using the \G zero-width assertion in the pattern. 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 (<>) The special <> readline operator will treat @ARGV as a list of file names and open and read each line from all of those files. Since $filedef1 is the first element of @ARGV the file will be opened and the first line from that file will be read into the $_ variable. { push (@clients, <FILEDEF1>); You are pushing all the lines from the file onto the @clients array from inside the loop so you should have the number of lines times the file in the array. } close FILEDEF1; $list = join(' ',@clients); You are joining the lines together with a single space character. print $list; } ##End of block for reading the document source file. In reply to Re: Regexp mystery (to me)
by jwkrahn
|
|