I am trying to exclude certain items with grep, however, my exclusion is not working.

Here is the snippet I am working on where I do not want the string  right appended if the word in the $text appears in one of the items in the list. Everything is getting  right appended currently.

my @big_images = $opt{big} ? @{$opt{big}} : (); for my $cross_file (@cross_files) { my $text = textify($cross_file); my $class = 'svg_group'; $class .= ' right' unless grep(/$text/i, @big_images); }

So, if I use it like the following, I do not want right appended to $class if Smart is in $text.

my $magic = crossover_magic( big => ['Smart'] );

Update: I found that $text needs to be an exact match. I would prefer not having to use exact matches. I added case insensitivity to it also.

Here is the whole subroutine if there is something in there that might be affecting things that I am not seeing.

sub crossover_magic { my %opt = @_; our $magic; my $open_directory = file_directory('Fandom/Crossovers', 'imagesd'); my $link_directory = file_directory('Fandom/Crossovers', 'images'); my @cross_files = file_list($open_directory); my @big_images = $opt{big} ? @{$opt{big}} : (); for my $cross_file (@cross_files) { my $link = "$link_directory/$cross_file"; my $text = textify($cross_file); my $class = 'svg_group'; $class .= ' right' unless grep(/$text/i, @big_images); my $title = "$text chart"; $magic->{$text} = sub { figure(6, sub { line(7, anchor( '', { 'href' => $link, 'target' => 'new' })); line(7, object( '', { 'data' => $link, 'type' => 'image/svg+xm +l'})); }, { 'class' => "$class", 'title' => $title }); }; } my $series = series('data', 'me'); my $series_list = movie_option('series'); for my $item (sort keys %$series_list) { my $magic_search; my $magic_text; if ($series->{$item}) { for my $program (@{$series->{$item}->{programs}}) { my $magic_key = $item eq $program ? "$program-single" : $pr +ogram; $magic_text = textify($program); $magic_search = searchify($item, [$program]); $magic->{$magic_key} = qq(A<I<$magic_text>|href="../../Movies/ +Movies_by_series.pl?series=$magic_search">); } } $magic_text = $item eq 'Scorpion' ? '&#60;/Scorpion&#62;' : $item eq 'EUReKA' ? 'EURSUP<e>KA' : textify($item); $magic_search = searchify($item); $magic->{$item} = qq(A<I<$magic_text>|href="../../Movies/Movies_by +_series.pl?series=$magic_search">); } return $magic; }

My OS is Debian 10 (Buster); my perl version is 5.28.1.

No matter how hysterical I get, my problems are not time sensitive. So, relax, have a cookie, and a very nice day!
Lady Aleena

In reply to How do I get an exclusion with grep? by Lady_Aleena

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.