in reply to Re: Sort hash with values
in thread Sort hash with values
# SPLIT THE IP-ADDRESSES INTO FOUR =STRINGS= BY # THE PERIOD CHARACTER. my ($a1, $a2, $a3, $a4) = split('.', @$a);
The split built-in function does not use single-quotes around a /PATTERN/ argument to 'meta-quote' the argument: the '.' in the above really is trying to split on "any character except newline". Use '\.' to split on a literal period.
>perl -wMstrict -le "my $s = 'a.bb.ccc.d'; ;; my @ra = split '.', $s; print 'naked dot'; printf qq{ '$_'} for @ra; print '@ra elements: ', scalar @ra; ;; @ra = split '\.', $s; print 'escaped dot'; printf qq{ '$_'} for @ra; " naked dot @ra elements: 0 escaped dot 'a' 'bb' 'ccc' 'd'
|
---|
Replies are listed 'Best First'. | |
---|---|
A reply falls below the community's threshold of quality. You may see it by logging in. |
In Section
Seekers of Perl Wisdom