in reply to Split Operation
I just taken your input as array and done the below program
use strict; use warnings; use Data::Dumper; my @test=qw( [ a b ] c d [ e [ f g h [ i j ] k l ] m n ] o p ); my ($append, $opencount, @temp, $closecount); foreach(@test){ if($_ eq '['){ ++$opencount; $append.=$_; next; } if($_ ne ']' && $opencount){ $append.=$_; print "----$append----\n"; next; } if($_ eq ']'){ --$opencount; $append.=$_; unless($opencount){ #print "------------=>$append<=---------------"; push @temp, $append; $append=undef;$closecount=0; $opencount=0; next; } next; } else{ #print "------------=>$_<=----------------"; push @temp, $_; } #print Dumper \@temp; } print Dumper \@temp;
|
|---|