in reply to Re^4: split and capture some of the separators
in thread split and capture some of the separators
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?...
Result (NB: Active state does not give me the warning messages, although I get them on Solaris)#!/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"; }
UPDATE: I was actually trying to comment on Brower UK's post, but slipped up. Oh wellDon'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',
|
|---|