Perl : split the string from last occurrence .

Posted by kiruthika on Stack Overflow See other posts from Stack Overflow or by kiruthika
Published on 2010-03-18T10:27:36Z Indexed on 2010/03/18 10:41 UTC
Read the original article Hit count: 386

Filed under:
|

Hi All,

my $str="1:2:3:4:5";
my ($a,$b)=split(':',$str,2);

In the above code I have used limit as 2 ,so $a will contain 1 and remaining elements will be in $b. Like this I want the last element should be in one variable and the elements prior to the last element should be in another variable.

Example

$str = "1:2:3:4:5" ; 
# $a should have "1:2:3:4"  and $b should have "5" 
$str =  "2:3:4:5:3:2:5:5:3:2" 
# $a should have "2:3:4:5:3:2:5:5:3" and $b should have "2"

© Stack Overflow or respective owner

Related posts about perl

Related posts about split