Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re^3: The error says the value is uninitialized, but it works anyway

by karlgoethebier (Monsignor)
on Aug 18, 2019 at 20:38 UTC ( #11104659=note: print w/replies, xml ) Need Help??


in reply to Re^2: The error says the value is uninitialized, but it works anyway
in thread The error says the value is uninitialized, but it works anyway

"...We haven't learned "map" or "grep" yet..."

What does you discourage from reading the friendly manual and learning it by yourself?

Some sketch written in a hurry for your further inspiration:

#!/usr/bin/env perl use strict; use warnings; use Test::More; use Data::Dump; my @colors = qw(red green blue yellow pink purple brown); my @drop = qw(pink brown); my @expected = qw(red green blue yellow purple); my $regex = join "|", @drop; my @result = grep {!/$regex/} @colors; is($regex, q(pink|brown), q(Regex seems to be OK!)); is(@result, @expected, qq(Heureka!)); done_testing(); dd \@drop; dd $regex; dd \@colors; dd \@result; __END__

It's not carefully tested. And may be there is a better solution. Best regards, Karl

«The Crux of the Biscuit is the Apostrophe»

perl -MCrypt::CBC -E 'say Crypt::CBC->new(-key=>'kgb',-cipher=>"Blowfish")->decrypt_hex($ENV{KARL});'Help

Replies are listed 'Best First'.
Re^4: The error says the value is uninitialized, but it works anyway
by AnomalousMonk (Bishop) on Aug 18, 2019 at 21:22 UTC
    my $regex    = join "|", @drop;

    mizducky:   This technique has some gotchas associated with it. For a very good general discussion of the (update: very useful!) technique, see haukex's Building Regex Alternations Dynamically article.


    Give a man a fish:  <%-{-{-{-<

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (4)
As of 2019-09-22 08:01 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    The room is dark, and your next move is ...












    Results (273 votes). Check out past polls.

    Notices?