Harry Putnam wrote:
Why is it that the first two splits do not produce any elements?
Because: perldoc -f split split /PATTERN/,EXPR,LIMIT split /PATTERN/,EXPR split /PATTERN/ split Splits the string EXPR into a list of strings and returns that list. By default, empty leading fields are preserved, and empty trailing ones are deleted. (If all fields are empty, they are considered to be trailing.) If you want to retain the empty trailing fields then use the LIMIT argument.
#!/usr/local/bin/perl use strict; use warnings; my $var = 100421; my @elems1 = split(/\d/,$var); my @elems2 = split(/./,$var); my @elems3 = split(//,$var);
Change those to: my @elems1 = split( /\d/, $var, -1 ); my @elems2 = split( /./, $var, -1 ); my @elems3 = split( //, $var, -1 ); John -- The programmer is fighting against the two most destructive forces in the universe: entropy and human stupidity. -- Damian Conway -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/