Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re^2: How do I get an exclusion with grep?

by Lady_Aleena (Curate)
on Apr 27, 2020 at 07:17 UTC ( #11116110=note: print w/replies, xml ) Need Help??


in reply to Re: How do I get an exclusion with grep?
in thread How do I get an exclusion with grep?

The only thing I left out of the big block of code with the crossover_magic is the "heading" of the module. So, here is the contents of @cross_files and the results of textify on them side-by-side. textify is at the bottom of this post. Also, if you need any other subroutines, let me know.

@cross_filestextified
[ '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' ];
[ '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' ];

I am using this in scripts, so no -- options. Here is how crossover_magic is being used in the scripts.

my $magic = crossover_magic(); # no big svgs here, s +o no $opt{big} # The rest have only one that should NOT have ' right' appended to $cl +ass my $magic = crossover_magic( big => ['Horror']); my $magic = crossover_magic( big => ['Westerns in Crisis']); # I'd lik +e to use the word 'Westerns' only my $magic = crossover_magic( big => ['McHale UNCLE Smart']); # I'd lik +e to use ONE word only # All svgs with Westphall in the name are big, so again no ' right' my $magic = crossover_magic( big => ['Westphall']); my $magic = crossover_magic( big => ['Arriving to Westphall']); # I prefer my $magic = crossover_magic( big => ['Westphall']); my $magic = crossover_magic( big => ['Departing from Westphall']); # I prefer my $magic = crossover_magic( big => ['Westphall']);

Here is textify for you to peruse. It looks messy, but regexen are never pretty for me at least.

sub textify { my ($text, $opt) = @_; my $root_link = base_path('link'); $text =~ s/$root_link\///; # removes the $ro +ot_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/ &amp; /g; # converts ' & ' +to &amp; $text =~ s/\.{3}/&#8230;/g; # converts '...' +to &#8230; $text =~ s/(\w|\b|\s|^)'(\w|\b|\s|$)/$1&#700;$2/g; # converts "'" to + &#700; # 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; }

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

Replies are listed 'Best First'.
Re^3: How do I get an exclusion with grep?
by kcott (Bishop) on Apr 27, 2020 at 10:15 UTC

    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):

    — Ken

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://11116110]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (4)
As of 2020-09-28 23:08 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    If at first I donít succeed, I Ö










    Results (144 votes). Check out past polls.

    Notices?