# 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'
In reply to Re^2: Sort hash with values
by AnomalousMonk
in thread Sort hash with values
by Rahul Gupta
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |