Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW

Re^2: Matching a pattern which resides within round brackets

by TGI (Parson)
on Nov 28, 2008 at 20:09 UTC ( #726660=note: print w/replies, xml ) Need Help??

in reply to Re: Matching a pattern which resides within round brackets
in thread Matching a pattern which resides within round brackets

Try this.

#!/usr/bin/perl -w use strict; use warnings; use Data::Dumper; my $data = join '', "U|(Memory is incorrectly balanced between the NUMA ", "nodes of this system, which will lead to poor performance. ", "See),_NUMA_CRIT_,;(/proc/vmware/NUMA/hardware),_NUMA_CRIT_", ",__REFERAL__file:__SELF__;( for details on your current ", "memory configuration),_NUMA_CRIT_,;"; print "DATA\n$data\n\n"; #(my $m_type = $data) =~ s/^((?:U|M))\|.*$/$1/; # gets U #(my $p_list = $data) =~ s/^(?:U|M)\|(.*)$/$1/; # gets U, i think thi +s is the reason you weren't getting anything # This approach does what I think you are trying for without as much w +ork for you or the computer. my ($m_type, $p_list) = split /\|/, $data, 2; my @sub_p_tmp = split /;/, $p_list; print "MTYPE: $m_type\n"; print "PLIST: $p_list\n"; my @args; # Try using # for my $p_tmp ( @sub_p_tmp ) # Instead of the c style for loop, unless you are processing HUGE arra +ys. for ( my $i = 0; $i <= $#sub_p_tmp; $i++ ) { print "$i: $sub_p_tmp[$i]\n"; # Here's your regex based method fixed to work # if ( $sub_p_tmp[$i] =~ m/^\(([^)]*)\),([^,]*),(.*)$/ ) # { # @args = ($1, $2, $3); # print "\nArgs:\n"; # print Dumper(\@args)."\n"; # } # Here's a split based approach. # in both approaches @args is overwritten each pass through the loop. my @temp = split /,/, $sub_p_tmp[$i]; if ( @temp ) { # Get rid of the extra parens. $temp[0] =~ s/^\(|\)$//g; # Overwriting the value of @args each time. # Do you mean # push @args, @temp[0..2]; # or # push @args, [ @temp[0..2]]; $temp[0] =~ s/^\(|\)$//g; @args = @temp[0..2]; print "\nArgs:\n"; print Dumper(\@args)."\n"; } }

TGI says moo

Replies are listed 'Best First'.
Re^3: Matching a pattern which resides within round brackets
by jbl_bomin (Acolyte) on Dec 04, 2008 at 15:42 UTC
    Thanks TGI, I'll definitely play around with this!

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://726660]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (4)
As of 2018-01-22 07:38 GMT
Find Nodes?
    Voting Booth?
    How did you see in the new year?

    Results (232 votes). Check out past polls.