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

Re^3: Regex to match range of characters broken by dashes

by Cristoforo (Curate)
on Jul 18, 2016 at 01:26 UTC ( [id://1167937]=note: print w/replies, xml ) Need Help??


in reply to Re^2: Regex to match range of characters broken by dashes
in thread Regex to match range of characters broken by dashes

Thanks for pointing out points in my solution that can be stated cleaner.

This is a bug that was corrected in Perl version 5.18 IIRC. With this correction, lexical variables always work as expected in "(?{ code })" and "(??{ code })" regex constructs.

I wasn't aware of that bug. And your local our $q = $s - 1; fixes that.

it can all be written normally, given that the s/// match regex is, by default, re-compiled on each s/// execution

That is a nice solution! The (??{. . .}) construct wasn't necessary.

Replies are listed 'Best First'.
Re^4: Regex to match range of characters broken by dashes
by AnomalousMonk (Archbishop) on Jul 18, 2016 at 04:07 UTC
    ... local our $q = $s - 1; fixes [the lexical bug].

    It can even be fixed a bit more cleanly, and also fold in the added  s/// fixup at the end (still runs under 5.8.9):

    c:\@Work\Perl\monks\Q.and>perl -wMstrict -le "my @stops = (2,6); ;; my $tag = '___'; ;; for (qw(ATCGGATCTGGC A-C-G--CTGGC)) { my $seq = $_; printf qq{'$seq' -> }; $seq =~ s{ ((?: [TAGC] [^TAGC]*){$_} [TAGC]) [^TACG]* }{$1$tag}xms for map $_-1, @stops; print qq{'$seq'}; } " 'ATCGGATCTGGC' -> 'AT___CGGA___TCTGGC' 'A-C-G--CTGGC' -> 'A-C___G--CTG___GC'


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

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others chilling in the Monastery: (5)
As of 2024-04-25 16:53 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found