Re: regexp puzzle

2014-03-08 Thread Bill McCormick
On 3/8/2014 12:05 AM, Bill McCormick wrote: I have the following string I want to extract from: my $str = "foo (3 bar): baz"; and I want to to extract to end up with $p1 = "foo"; $p2 = 3; $p3 = "baz"; the complication is that the \s(\d\s.+) is optional, so in then $p2 may not be set. getting

Re: regexp puzzle

2014-03-07 Thread Jim Gibson
On Mar 7, 2014, at 10:05 PM, Bill McCormick wrote: > I have the following string I want to extract from: > > my $str = "foo (3 bar): baz"; > > and I want to to extract to end up with > > $p1 = "foo"; > $p2 = 3; > $p3 = "baz"; > > the complication is that the \s(\d\s.+) is optional, so in the

Re: regexp puzzle

2014-03-07 Thread shawn wilson
On Mar 8, 2014 1:41 AM, "shawn wilson" wrote: > Oh and per optional, just do (?:\([0-9]+).*\)? You should probably use do my @match = $str =~ / ([^]+) (?:\([0-9]+).*\)? ([a-z]+)/; my ($a, $b, $c) = (scalar(@match) == 3 ? @match : $match[0], undef, $match[1]); > ([^]+) \(([0-9]+).*\) ([a-z]+) >

Re: regexp puzzle

2014-03-07 Thread Bill McCormick
On 3/8/2014 12:41 AM, shawn wilson wrote: my $str = "foo (3 bar): baz"; my $test = "foo (3 bar): baz"; my ($p1, $p2, $p3) = $test =~ /([^]+) \(([0-9]+).*\) ([a-z]+)/; print "p1=[$p1] p2=[$p2] p3=[$p3]\n"; Use of uninitialized value $p1 in concatenation (.) or string at ./lock_report.pl line 1

Re: regexp puzzle

2014-03-07 Thread shawn wilson
([^]+) \(([0-9]+).*\) ([a-z]+) On Mar 8, 2014 1:07 AM, "Bill McCormick" wrote: > I have the following string I want to extract from: > > my $str = "foo (3 bar): baz"; > > and I want to to extract to end up with > > $p1 = "foo"; > $p2 = 3; > $p3 = "baz"; > > the complication is that the \s(\d\s.+)