in reply to Re^2: How do I get an exclusion with grep?
in thread How do I get an exclusion with grep?
You've only provided snippets of code which has proven problematic. For instance, you have
my $root_link = base_path('link');
but don't show the &base_path code. Is it from a module? Did you write it?
You also have several lines of code like these:
my $magic = crossover_magic( big => ['Horror']); my $magic = crossover_magic( big => ['Westerns in Crisis']);
but don't show any context. Are those strings hard-coded as shown? They actually look like return values from textify(). It's also unclear what the comments about preferences mean; for example, what does "# I'd like to use the word 'Westerns' only" refer to? — why not just write 'Westerns' instead of 'Westerns in Crisis'?
And then there's the array @cross_files whose value you show as an arrayref. Next to it is textified which should probably be $textified if its value is also an arrayref.
The end result of this is a lot of guesswork and assumptions which are not helpful in providing you with a straightforward answer.
I put together an SSCCE to test all the possible things that I think you might be doing: it's in the spoiler below. The output is hundreds of lines long so I won't post it here: it should run without any problem with the OS and Perl version you indicated.
I couldn't replicate "Everything is getting right appended currently." as you stated in the OP. In fact, I got the expected output for everything except when filenames contained underscores.
Reviewing what I've provided may help you to solve your problem. If not, please write your own SSCCE and post it. Use only sufficient sample data to demonstrate the issue and do not include code that isn't relevant to the problem: it should only be enough to demonstrate whatever is going wrong.
Here's my SSCCE (in the spoiler):
#!/usr/bin/env perl use 5.028_001; use warnings; use Test::More; my @cross_files = @{_get_cross_files()}; my @expected_textified = @{_get_expected_textified()}; plan tests => @cross_files * 7; for (my $i = 0; $i <= $#cross_files; ++$i) { my $got_textified = textify($cross_files[$i]); is($got_textified, $expected_textified[$i], "Test '$cross_files[$i]' --> '$expected_textified[$i]'" ); { my $class = cutdown_crossover_magic($cross_files[$i]); is($class, 'svg_group right', "Test cross_file '$cross_files[$i]' with no 'big' key"); } { my $class = cutdown_crossover_magic($expected_textified[$i]); is($class, 'svg_group right', "Test expected_textified '$expected_textified[$i]' with no + 'big' key"); } { my $class = cutdown_crossover_magic($got_textified); is($class, 'svg_group right', "Test got_textified '$got_textified' with no 'big' key"); } { my $class = cutdown_crossover_magic($cross_files[$i], big => [$cross_files[$i]]) +; is($class, 'svg_group', "Test cross_file '$cross_files[$i]' using 'big' key"); } { my $class = cutdown_crossover_magic($expected_textified[$i], big => [$expected_textifie +d[$i]]); is($class, 'svg_group', "Test expected_textified '$expected_textified[$i]' using ' +big' key"); } { my $class = cutdown_crossover_magic($got_textified, big => [$got_textified]); is($class, 'svg_group', "Test got_textified '$got_textified' using 'big' key"); } } sub cutdown_crossover_magic { my ($cross_file, %opt) = @_; my $class = 'svg_group'; my @big_images = $opt{big} ? @{$opt{big}} : (); my $text = textify($cross_file); $class .= ' right' unless grep(/$text/i, @big_images); return $class; } sub _get_cross_files { [ 'key.svg', 'Spy_Machete.svg', 'Two_Half_Bang.svg', 'McHale_UNCLE_Smart.svg', 'Howling_Gremlins.svg', 'Dragnet.svg', 'View_Scream.svg', 'blank_spinoff.svg', 'Westphall.png', 'Westerns_in_Crisis.svg', 'Mary_Tyler_Moore.svg', 'Better_Fast.svg', 'Terminator_Abyss.svg', 'Frozen_Hatchet.svg', 'Babylon_5_Cases.svg', 'Columbo.svg', 'crossover_archive.zip', 'Burkes_Law.svg', 'temp.svg', 'Westphall.svg', 'Arriving_to_Westphall.svg', 'key-big.svg', 'Departing_from_Westphall.svg', 'MCU.svg', 'Horror.svg', 'Alices_Hazzard.svg' ]; } sub _get_expected_textified { [ 'key', 'Spy Machete', 'Two Half Bang', 'McHale UNCLE Smart', 'Howling Gremlins', 'Dragnet', 'View Scream', 'blank spinoff', 'Westphall', 'Westerns in Crisis', 'Mary Tyler Moore', 'Better Fast', 'Terminator Abyss', 'Frozen Hatchet', 'Babylon 5 Cases', 'Columbo', 'crossover archive', 'Burkes Law', 'temp', 'Westphall', 'Arriving to Westphall', 'key-big', 'Departing from Westphall', 'MCU', 'Horror', 'Alices Hazzard' ]; } # Exactly as posted EXCEPT both '$root_link' lines have been commented + out sub textify { my ($text, $opt) = @_; #my $root_link = base_path('link'); #$text =~ s/$root_link\///; # removes the $r +oot_link $text =~ s/_/ /g; # removes underso +res $text =~ s/ (Mr|Mrs|Ms|Dr) / $1. /g; # adds a period f +or Mr, Mrs, Ms, and Dr; I may need to add more $text =~ s/\s&\s/ & /g; # converts ' & ' +to & $text =~ s/\.{3}/…/g; # converts '...' +to … $text =~ s/(\w|\b|\s|^)'(\w|\b|\s|$)/$1ʼ$2/g; # converts "'" to + ʼ # The following takes out html tags unless I tell it not to $text =~ s/<.+?>//g unless ($opt->{'html'} && $opt->{'html'} + =~ /^[ytk1]/); # The following takes out parenthes unless I tell it not to $text =~ s/\s\(.*?\)$// unless ($opt->{'parens'} && $opt->{'parens' +} =~ /^[ytk1]/); # The following removes file extensions except .com, .net, and .org $text =~ s/\.\w{2,5}?$// unless $text =~ /\.(?:com|net|org)$/; # $text =~ s/(?<!\A)((?<! )\p{uppercase})/ $1/g; # from Kenosis, kcot +t, and tye on PerlMonks # I could not remember what the previous line was doing. return $text; }
— Ken
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: How do I get an exclusion with grep?
by Lady_Aleena (Priest) on Apr 27, 2020 at 13:07 UTC |