Prev: Converting HTML to PDF with Webkit
Next: FAQ 8.46 What's the difference between require and use?
From: Peng Yu on 11 Jun 2010 23:57 After I did a regex match, I want to figure out what the line number is after the match in (). Is there an easy way to do it? $string =~ /xxxx(somepattern)yyyy/;
From: Dr.Ruud on 12 Jun 2010 00:00 Peng Yu wrote: > After I did a regex match, I want to figure out what the line number > is after the match in (). Is there an easy way to do it? > > $string =~ /xxxx(somepattern)yyyy/; Do you mean that your $string contains multiple lines? Otherwise see $. in perlvar, as you have been told before. -- Ruud
From: Peng Yu on 12 Jun 2010 00:13 On Jun 11, 11:00 pm, "Dr.Ruud" <rvtol+use...(a)xs4all.nl> wrote: > Peng Yu wrote: > > After I did a regex match, I want to figure out what the line number > > is after the match in (). Is there an easy way to do it? > > > $string =~ /xxxx(somepattern)yyyy/; > > Do you mean that your $string contains multiple lines? Yes. $string contains multiple lines.
From: Dr.Ruud on 12 Jun 2010 00:38 Peng Yu wrote: > On Jun 11, 11:00 pm, "Dr.Ruud" <rvtol+use...(a)xs4all.nl> wrote: >> Peng Yu wrote: >>> After I did a regex match, I want to figure out what the line number >>> is after the match in (). Is there an easy way to do it? >>> $string =~ /xxxx(somepattern)yyyy/; >> >> Do you mean that your $string contains multiple lines? > > Yes. $string contains multiple lines. So how did they end up there, did you slurp a file into it? If so, then why not just process the file line-by-line? You can still use a while-loop on the $string, for example: my $n = 0; while ( my ($line) = $string =~ /.*/g ) { ++$n; print "$n ($1)\n" if $line =~ /xxxx(somepattern)yyyy/; } -- Ruud
From: Tad McClellan on 12 Jun 2010 00:58 Peng Yu <pengyu.ut(a)gmail.com> wrote: > After I did a regex match, I want to figure out what the line number > is after the match in (). Is there an easy way to do it? > > $string =~ /xxxx(somepattern)yyyy/; ---------------- #!/usr/bin/perl use warnings; use strict; my $string = 'xxxxxxxsomepatternyyyyyyy'; print __LINE__, "\n" if $string =~ /xxxx(somepattern)yyyy/; ---------------- -- Tad McClellan email: perl -le "print scalar reverse qq/moc.liamg\100cm.j.dat/" The above message is a Usenet post. I don't recall having given anyone permission to use it on a Web site.
|
Next
|
Last
Pages: 1 2 Prev: Converting HTML to PDF with Webkit Next: FAQ 8.46 What's the difference between require and use? |