in reply to Braino - why is this not working?

The short answer would be to use the uniq function provided by List::MoreUtils.

What you have here seems incredibly complicated. Compare with the function I've just mentioned:

sub uniq (@) { my %h; map { $h{$_}++ == 0 ? $_ : () } @_; }

-- Ken

Replies are listed 'Best First'.
Re^2: Braino - why is this not working?
by perl-diddler (Chaplain) on Oct 19, 2010 at 01:04 UTC
    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?)...:-)

      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