clerew has asked for the wisdom of the Perl Monks concerning the following question:
I have a file with lines of the form
/dev/sda4 6 Fri Apr 12 04:30:02 2019 +0100 /dumpx/DUMP4X/var/level6/55 86.53 MBand I have another file with lines of the form
/dumpx/DUMP4X/var/level6/55and I would like to find (and remove) all the lines in the first file which contain the strings in the second file. Fortunately, I can assume that both files are sorted in the same order.
to find a single entry is simple:
if $line =~ m?/dumpx/DUMP4X/var/level6/55? then do somethingbut what I want to do is to read lines from the two files in a suitable loop, picking out the matches, so I need a $regexp variable
So I write
$regexp = "m?" . <STDIN> . "?";(the second file is actually coming from a pipe)
and then I test
if $line =~ $regexp ...and if it matches, then I do the necessary stuff, and fetch the next $line and obtain the next $regexp.
But the =~ operator has been cunningly designed so that does not work. Essentially, if the RHS of =~ is a variable (my $regexp), then there is a builtin assumption that it uses '/' delimiters which, for my case, are totally unsuitable.
So how do I do this job?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Regex variables with delimiters
by AnomalousMonk (Archbishop) on May 18, 2019 at 01:08 UTC | |
|
Re: Regex variables with delimiters
by AnomalousMonk (Archbishop) on May 18, 2019 at 01:26 UTC | |
by clerew (Novice) on May 19, 2019 at 15:11 UTC | |
by AnomalousMonk (Archbishop) on May 19, 2019 at 15:59 UTC | |
|
Re: Regex variables with delimiters
by johngg (Canon) on May 18, 2019 at 11:22 UTC | |
by AnomalousMonk (Archbishop) on May 18, 2019 at 14:52 UTC | |
|
Re: Regex variables with delimiters
by tybalt89 (Monsignor) on May 18, 2019 at 00:43 UTC | |
|
Re: Regex variables with delimiters
by hippo (Archbishop) on May 18, 2019 at 09:01 UTC | |
|
Re: Regex variables with delimiters
by jwkrahn (Abbot) on May 18, 2019 at 00:38 UTC | |
by AnomalousMonk (Archbishop) on May 18, 2019 at 01:31 UTC | |
|
Re: Regex variables with delimiters
by Jack_Langsdorf (Initiate) on May 19, 2019 at 17:58 UTC | |
by haukex (Archbishop) on May 19, 2019 at 18:43 UTC |