Curiosity killed the cat (meow)

I found the null strings, which come from the undefined captures ($2 is not found, and undefined) and I guess $_ gets set to a null string if it is equated to an undefined capture?...

#!/usr/bin/perl -w use strict; my $str = '129-129A & B-131 NORTH AV'; print "\nDon't check for undefined matches\n"; while ($str =~ m[(.*?)(?:\s*([&/+-])\s*|\s+)]g){ print "\$1='$1'\t\t\$2='$2'\n"; } print "\nCheck for undefined matches\n"; while ($str =~ m[(.*?)(?:\s*([&/+-])\s*|\s+)]g) { my $one = "undef"; my $two = "undef"; $one = $1 if defined $1; $two = $2 if defined $2; print "\$1='$one'\t\t\$2='$two'\n"; } print "\nPseudo Split\n"; my @b = ($str =~ m[(.*?)(?:\s*([&/+-])\s*|\s+)]g,$'); foreach (@b) { $_="undef" unless defined $_; print "'$_',\n"; }
Result (NB: Active state does not give me the warning messages, although I get them on Solaris)
Don't check for undefined matches $1='129' $2='-' $1='129A' $2='&' $1='B' $2='-' Use of uninitialized value in concatenation (.) or string at test.pl l +ine 8. $1='131' $2='' Use of uninitialized value in concatenation (.) or string at test.pl l +ine 8. $1='NORTH' $2='' Check for undefined matches $1='129' $2='-' $1='129A' $2='&' $1='B' $2='-' $1='131' $2='undef' $1='NORTH' $2='undef' Pseudo Split '129', '-', '129A', '&', 'B', '-', '131', 'undef', 'NORTH', 'undef', 'AV',
UPDATE: I was actually trying to comment on Brower UK's post, but slipped up. Oh well

In reply to Re^5: split and capture some of the separators by Sandy
in thread split and capture some of the separators by shemp

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.