develooper Front page | perl.perl5.porters | Postings from October 2003

Re: [perl #24176] inconsistent m/.../g behaviour

Thread Previous
From:
Yitzchak Scott-Thoennes
Date:
October 12, 2003 20:56
Subject:
Re: [perl #24176] inconsistent m/.../g behaviour
Message ID:
20031013035548.GA3604@efn.org
On Sat, Oct 11, 2003 at 08:41:30AM +0100, Graham Barr <gbarr@pobox.com> wrote:
> On 9 Oct 2003, at 19:38, Jonathan Eisler (via RT) wrote:
> >my $text = "Foo\nBar\n";
> >while ( my ( $name ) = ( $text =~ /(\w+)/g ) ) { print $name, "\n" }
> >
> >The above script goes into an infinite loop, printing "Foo\n" to stdout
> >over and over.
> 
> Correct. the ()  puts the m//g into a list context.

Just to clarify, it is the () around $name that puts the match in a
list context, by being the right side of a list assignment.  The
parens around the =~ operation do nothing.

(I do intend to get back to my //r patch some day, that would allow

while ( defined ( my $name = ( $text =~ /\w+/rg ) ) )

to work.  Real life has just seriously intervened for a while.)

Thread Previous


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About