"Jeff 'japhy' Pinyan" <[EMAIL PROTECTED]> writes:
> On Sep 6, Harry Putnam said:
>
>>IMPORTANT: I don't want techniques involving call back (remembered)
>>operators and parens, I know how to piece those together for simple
>>things like the file below.
>
> Is there a reason for that limitation?
On Sep 6, Harry Putnam said:
>IMPORTANT: I don't want techniques involving call back (remembered)
>operators and parens, I know how to piece those together for simple
>things like the file below.
Is there a reason for that limitation? Oh well. Anyway, here's a good
approach:
while () {
Oops - teaches me not to test my solution :). Both suffer from not
adding a newline to the last element of the join. You could stick a
newline at the end, but doing so naively will generate a number of empty
lines. The simplest thing is probably:
while(<>) {
print join("", map { "$_ l
George Schlossnagle <[EMAIL PROTECTED]> writes:
> while(<>) {
> print join("\n", map { "$_ lineno $." } /(string)/g);
> }
George, I haven't gotten good results with either of the pieces of
code you posted. This one gives me.
string lineno 1
string lineno 1string lineno 2
I can fix
while(<>) {
print join("\n", map { "$_ lineno $." } /(string)/g);
}
On Friday, September 6, 2002, at 10:32 PM, Harry Putnam wrote:
> Tinkering with some of the suggestions here, I was looking for a way
> to get the line number in there. Thought maybe I could just
> con
Tinkering with some of the suggestions here, I was looking for a way
to get the line number in there. Thought maybe I could just
concatenate it in there:
With this test file:
string strung strang string other junk
blabbitty string other junk
while(<>){
push @array,$_ =~ /(string)/g . "
Timothy Johnson <[EMAIL PROTECTED]> writes:
> You mean something like this?
>
> while(){
> push @matches,$_ =~ /(silly)/;
> }
>
> foreach(@matches){
> print $_."\n";
> }
Bingo... but this looks like it might be a sort of default
callback or remembered item inside parens.
Is it?
Anyway
david <[EMAIL PROTECTED]> writes:
> you are probably looking for the $& variable:
>
> open(FILE,'file') || die $!;
> while(){
> print $&,"\n" if(/silly/);
> }
> close(FILE);
>
cool, a whole different way to do it thanks
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional co
or
while() {
/(myregex)/ && print "$1\n";
}
or if you are concerned about multiple matches in a line
while() {
print join("\n", /(myregex)/g);
}
if there are worries about
Timothy Johnson wrote:
>You mean something like this?
>
>while(){
> push @matches,$_ =~ /(silly)/;
>}
>
>foreac
you are probably looking for the $& variable:
open(FILE,'file') || die $!;
while(){
print $&,"\n" if(/silly/);
}
close(FILE);
__END__
you probably want to check out $`(pre match) and $'(post match) as well.
note the $&, $` and $' are kind of expensive and you usually can do the
above w
You mean something like this?
while(){
push @matches,$_ =~ /(silly)/;
}
foreach(@matches){
print $_."\n";
}
-Original Message-
From: Harry Putnam [mailto:[EMAIL PROTECTED]]
Sent: Friday, September 06, 2002 4:18 PM
To: [EMAIL PROTECTED]
Subject: print only what a regex actuall
11 matches
Mail list logo