gman has asked for the wisdom of the Perl Monks concerning the following question:
Hello all,
I have a simple question regarding the behavior of split. Given a string following the pattern /w{2}.{4}/ I am getting an extra variable from split. I'm sure this is the correct behavior, I'm just not understanding why so can't correct it. see code:
#!/usr/bin/perl -w use strict; use Data::Dumper; my $string = "df5434vg7856fg3472sd1234jh45r5"; my @array = split(/(\w{2}.{4})/,$string); print Dumper(@array);
Output:
$VAR1 = ''; $VAR2 = 'df5434'; $VAR3 = ''; $VAR4 = 'vg7856'; $VAR5 = ''; $VAR6 = 'fg3472'; $VAR7 = ''; $VAR8 = 'sd1234'; $VAR9 = ''; $VAR10 = 'jh45r5';
Thanks in advance!
Thank You for the quick solution and explanation!
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: split() behavior
by BrowserUk (Patriarch) on Jan 20, 2011 at 04:40 UTC | |
|
Re: split() behavior
by PeterPeiGuo (Hermit) on Jan 20, 2011 at 04:34 UTC |