Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
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. 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.


In reply to Re: Regexp mystery (to me) by jwkrahn
in thread Regexp mystery (to me) by barkingdoggy

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (2)
As of 2022-05-29 02:32 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Do you prefer to work remotely?



    Results (101 votes). Check out past polls.

    Notices?