Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses

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]
[marto]: Eily, there's actually a lot of good discussion on the topic in the HN link choroba posted
[marto]: sorry for the late response, busy busy :/
[Corion]: I think you need to load Readline in the debugger, but I don't know how
[Corion]: Yay, invitation for a team-building workshop, with a team of 100 people :-/
[Eily]: marto after an additional read I started to see the light actually. And choroba's link was helpful as well :)
[Corion]: I'll send my colleague who doesn't yet know the people there, and I'll do production duty instead.

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (15)
As of 2017-07-26 15:03 GMT
Find Nodes?
    Voting Booth?
    I came, I saw, I ...

    Results (396 votes). Check out past polls.