Been on this for a week now. Not able to make an if condition to work in perl. Not sure where I am going wrong.
#!/usr/bin/perl
use strict;
use warnings;
local $/ = undef;
my $data = <DATA>;
$data =~ s/(\s+)/ /gi;
$data =~ s/\[|\]//gi;
while ($data =~ /:(?<end>\d+) (?<notneeded>- [a-z0-9\-']+) (?<needed>[a-z0-9\-']+?) (?<start>\d+)(?=:)/ig) {
if (($+{start} - $+{end}) == 0) {
$data =~ s/:(?<end>\d+) (?<notneeded>- [a-z0-9\-']+) (?<needed>[a-z0-9\-']+?) (?<start>\d+)(?=:)/:$+{end} $+{needed} $+{start}/i;
print "\nFull match: '" . "$&" . "'\n";
print "\nStart: '" . "$+{start}" . "'\n";
print "\nEnd: '" . "$+{end}" . "'\n";
print "\nDiff: '" . ($+{start} - $+{end}) . "'\n";
}
}
#print "$data\n\n";
__DATA__
lorem [1170:1540]
ipsum [1540:2040]
dolor [2040:2350]
sit [2350:2510]
amet [2510:2670]
consectetur [2670:3130]
adipiscing [3130:3240]
elit [3240:3470]
quisque [3550:4070]
egestas [4070:4290]
magna [4290:4570]
sit [4620:4650]
amet [4780:5390]
molestie [5480:6660]
imperdiet [6660:6890]
- velit
lectus [6920:6950]
egestas [7130:7530]
enim [7570:7830]
non [7830:8160]
ornare [8160:8260]
eros [8260:8600]
- neque
non [8600:8890]
risus [9120:9450]
aenean [9450:9570]
venenatis [9570:9820]
- hendrerit
- urna
- nec
- bibendum
nunc [11210:11380]
lobortis [11380:11470]
in [11470:11710]
in [11780:11810]
facilisis [12960:13340]
urna [13340:13460]
in [13460:13920]
neque [14070:14630]
bibendum [14630:14930]
lobortis [14930:15250]
- maecenas
- efficitur
- fermentum
eros [17060:17450]
malesuada [17450:17760]
posuere [17760:17810]
nisi [18050:18080]
- tristique
- sit
If I change the if conditional statement from above to any of the below variations, it still seems not to be working.
if ($+{start} == $+{end})
if (($+{start} - $+{end}) eq 0)
if ("$+{start}" eq "$+{end})")
The desired output is only the second match, which is ":8600 - neque non 8600"
Aucun commentaire:
Enregistrer un commentaire