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: Delete first line when blank

2014-03-07 Thread Janek Schleicher
Am 07.03.2014 22:58, schrieb s...@missionstclare.com: I have some text files from which I would like to remove the first line, but only if it's blank. Any hints? I tried a few things, but the results haven't quite been satisfactory. perl -pi -e '$_ = "" if ( $. == 1 && /^\n/);' filename on c

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.+)

regexp puzzle

2014-03-07 Thread Bill McCormick
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 close was my ($p1, $p3) = $str =~ /^(.+):

Re: Delete first line when blank

2014-03-07 Thread Jim Gibson
On Mar 7, 2014, at 1:58 PM, s...@missionstclare.com wrote: > I have some text files from which I would like to remove the first line, but > only if it's blank. Any hints? I tried a few things, but the results haven't > quite been satisfactory. You should be able to do that in just a few lines

Delete first line when blank

2014-03-07 Thread sb
I have some text files from which I would like to remove the first line, but only if it's blank. Any hints? I tried a few things, but the results haven't quite been satisfactory. Thanks! -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h