in reply to Re^5: deleting a specific element from an array
in thread deleting a specific element from an array

Why, no - it doesn't.

ben@Tyr:~$ perl -wne'print length, ": $_" if /^(apple)$/' apple 6: apple

'$' in regular expressions matches before '\n'.


--
"Language shapes the way we think, and determines what we can think about."
-- B. L. Whorf

Replies are listed 'Best First'.
Re^7: deleting a specific element from an array
by ikegami (Patriarch) on Dec 03, 2008 at 18:22 UTC
    How does that contradict kyle? "apple\n" got matched even though it's not exactly "apple".

      I misunderstood kyle's "gets tossed" comment to mean "apple\n" will not be deleted if the regex is '^apple$'" - i.e., the deletion string will get tossed. From his comment and yours, it seems he meant it the other way - i.e., the content of "apple\n" "gets tossed" if the deletion string is "^apple$" - which is, of course, true. My mistake.


      --
      "Language shapes the way we think, and determines what we can think about."
      -- B. L. Whorf
Re^7: deleting a specific element from an array
by kyle (Abbot) on Dec 03, 2008 at 18:20 UTC

    I think your code actually proves my point, not yours.

    use Data::Dumper; my @array=('water','wine','applepie','beer','orange juice',"apple\n"); my @dels=('apple','orange'); my $dels = join '|', map quotemeta, @dels; @array = grep !/^($dels)$/, @array; print Dumper \@array; __END__ $VAR1 = [ 'water', 'wine', 'applepie', 'beer', 'orange juice' ];

    It removes both "apple" and "apple\n"—even though "apple\n" was not one of the @dels. If you change the $ to \z in the regular expression, the "apple\n" comes through (and "apple" is still removed).