Wednesday, April 13, 2011

spliting limit in perl with example

my $string = "Group: ALL:ALL:Good";
my @str    = split(/:/, $string, 2);

print $str[0],"\n";
print $str[1];

#Group
# ALL:ALL:Good


use strict;
use warnings;

my $x = "object1:object2:object3:rest of the line with a : character";
my @x = split (":", $x, 3);
foreach my $s (@x) {
        print "$s\n";
}

No comments: