Victor.H
Victor.H

Reputation: 157

How to make a column value as an number range for smartmatch

I have the txt file with the column value look like

85806534..85893402
49011742..49029143
114352846..114428174

I want to do the smartmatch. I put thses values into @array[0]

if ($line ~~$array[0]){do something here}

How can I make $array[0] as a number range?

if I split by .. then put the values into array [0] and array [1]

if ($line ~~[$array[0]..$array[1]){....}

this perl code is working for me.

Upvotes: 0

Views: 71

Answers (1)

ikegami
ikegami

Reputation: 385887

$line ~~ [ do { my ($min, $max) = split(/\.\./, $array[0]); $min..$max } ]

The inefficiencies here are insane. Why do you want to create arrays with 10s of thousands of elements just to smartmatch? Even if smartmatch wasn't still flagged as experimental after all these years for being broken, you should be using the following instead:

my ($min, $max) = split(/\.\./, $array[0]);
$line >= $min && $line <= $max

Upvotes: 4

Related Questions