in reply to Converting percentage into number

#!/usr/bin/perl use strict; use warnings; while (<DATA>) { s|(\d+\.\d+)%|$1/100|eg; print; } __DATA__ ENSP00000233379 1058 30 1206 1298 96.1% 13 + 96524483 96533474 8992

Depending on your data, you may need to adjust the regex that matches the percentages.

--
<http://dave.org.uk>

"The first rule of Perl club is you do not talk about Perl club."
-- Chip Salzenberg

Replies are listed 'Best First'.
Re^2: Converting percentage into number
by johngg (Canon) on Jan 10, 2007 at 13:59 UTC
    I'm all for using alternative regular expression delimiters from the slash (/) (especially when matching paths). I do think the pipe symbol (|) is potentially confusing though as, at first glance, my eye sees the alternation metacharacter, not a delimiter. Perhaps it's just me.

    Cheers,

    JohnGG

      It's just you. :-p

      I moderately often use alternative delimiters, and when I do I very often choose the pipe symbol - it stands out nicely in the line noise that regexen generally devolve into (even when using /x). Alternatively I use ! for similar reasons, but generally only if I anticipate requiring alternation in the regex.

      And no, I've not been bitten during maintenance by that choice. ;)


      DWIM is Perl's answer to Gödel
        The pipe symbol is not such a problem with m|some pattern| as the pipes are at either end but when substituting like s|old|new| it's the one in middle that causes the double-take. Like you I've not been bitten by it but it does cause me that moment of hesitation.

        I used to use pipe symbols a lot but I find that I am wearing out the curly brace keys as I tend towards m{...} and s{...}{...} these days. It might have something to do with my addiction to quoting constructs. :)

        Cheers,

        JohnGG