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.
That may confuse the /m option on regular expressions? That means that every line except the first will have a space at the beginning.
print $list;
} ##End of block for reading the document source file.
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
|
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.