Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re: Matching a pattern which resides within round brackets

by jbl_bomin (Acolyte)
on Nov 27, 2008 at 16:58 UTC ( #726448=note: print w/ replies, xml ) Need Help??


in reply to Matching a pattern which resides within round brackets

FYI (just to bring this to a close, and for anyone else who may run into the problem)..

I've been able to resolve the this with the following code, which seems to give me the output I'm looking for:

#!/usr/bin/perl -w use strict; use Data::Dumper; my $data = "U|(Memory is incorrectly balanced between the NUMA "; $data .= "nodes of this system, which will lead to poor performance. +"; $data .= "See),_NUMA_CRIT_,;(/proc/vmware/NUMA/hardware),_NUMA_CRIT_"; $data .= ",__REFERAL__file:__SELF__;( for details on your current "; $data .= "memory configuration),_NUMA_CRIT_,;"; (my $m_type = $data) =~ s/^((?:U|M))\|.*$/$1/; (my $p_list = $data) =~ s/^(?:U|M)\|(.*)$/$1/; my @sub_p_tmp = split(/;/,$p_list); print "sub_p_tmp:\n"; print Dumper(@sub_p_tmp); my @args; for ( my $i = 0; $i <= $#sub_p_tmp; $i++ ) { $sub_p_tmp[$i] =~ s/,$//; if ( $sub_p_tmp[$i] =~ m/^\((.*)\),(.*),(.*)$/ ) { push @args, ($1, $2, $3); } elsif ( $sub_p_tmp[$i] =~ m/^\((.*)\),(.*)$/ ) { push @args, ($1, $2); } } #print "$m_type\n\n$p_list\n\n".Dumper(@sub_p_tmp)."\n"; print "\nArgs:\n"; print Dumper(@args)."\n";


Comment on Re: Matching a pattern which resides within round brackets
Download Code
Re^2: Matching a pattern which resides within round brackets
by TGI (Vicar) on Nov 28, 2008 at 20:09 UTC

    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

      Thanks TGI, I'll definitely play around with this!

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://726448]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (6)
As of 2014-08-21 23:15 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (144 votes), past polls