in reply to Re: Braino - why is this not working?
in thread Braino - why is this not working?

I agree, that's an alternate way to do this, but I don't see why the /^$_$/ which successively holds lines from the source, would come up 'true' on the second pass, when the lines don't match.

Yeah, your example would circumvent the problem what 3-4 people haven't seen so far, but that just makes me wonder why its so hard to see what is going wrong. Something this simple couldn't be a perl bug, it's trivial code, so why is it so hard to see what's broken? GRRR....*knocking head against the wall*...(when I stop it will feel good?)...:-)

  • Comment on Re^2: Braino - why is this not working?

Replies are listed 'Best First'.
Re^3: Braino - why is this not working?
by kcott (Archbishop) on Oct 19, 2010 at 17:04 UTC

    Between the time I logged off yesterday and logged back in today, the discussion has extended considerably and you appear to have your answer.

    In general, I tend to use a lexical variable in for loops and the block form of map, grep and similar constructs.

    for my $list_element (@list) { # use $list_element here } map { ... } @list; grep { ... } @list; sort { ... } @list;

    (for and foreach are synonymous, in case you didn't know)

    This generally avoids any confusion over what $_ refers to.

    Perl 5.10 introduced a new lexically scoped $_ (that's in addition to the current globally scoped $_) so there's even more chance of confusion.

    Hoping your head isn't hurting too much and the wall doesn't need fixing. :-)

    -- Ken