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