when ((s/(\b[A-E]{3}\b)/XXX/g)) {@array[i,1] = $1}

Capture groups don't work the same way in  s/// substitution versus  m// matching:

c:\@Work\Perl>perl -wMstrict -le "my $s = 'xxx aBc yyy dE zzz'; print qq{\$s: '$s'}; ;; print qq{\$1: '$1'} if $s =~ s{ [AaBbCcDdEe]+ }{XXX}xmsg; print qq{\$s: '$s'}; " $s: 'xxx aBc yyy dE zzz' Use of uninitialized value $1 in concatenation (.) or string at -e lin +e 1. $1: '' $s: 'xxx XXX yyy XXX zzz'
Capture groups work in a potentially surprising way in  s/// substitution and  m// matching:
c:\@Work\Perl>perl -wMstrict -le "my $s = 'xxx aBc yyy dE zzz'; print qq{\$s: '$s'}; ;; print qq{\$1: '$1'} if $s =~ s{ ([AaBbCcDdEe]+) }{XXX}xmsg; print qq{\$s: '$s'}; " $s: 'xxx aBc yyy dE zzz' $1: 'dE' $s: 'xxx XXX yyy XXX zzz'
(note that only the last group matched is captured). Please see perlre, perlrequick, and perlretut.
Also: I don't think  @array[i,1] = $1 is going to work the way you think it will whatever the value of  $1 may be (but I'm not sure just what you expect from this expression). Please see Slices in perldata. (Update: Something like this works for hashes: see  $; in perlvar. There's a more complete discussion of this old trick somewhere, but I can't locate it right now — anyone know where it is? (Update: Anonymonk informs me this is Multi-dimensional array emulation in perldata. This section was apparently added with Perl version 5.16.0 or 5.16.1. I only had 5.14 available locally and so missed it.))


In reply to Re^3: CSV regex with hash/array program plan by AnomalousMonk
in thread CSV regex with hash/array program plan by campus1plb

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



  • 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:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.