Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re^2: Suggestions to make this code more Perlish

by hazylife (Monk)
on Mar 31, 2014 at 10:50 UTC ( [id://1080382]=note: print w/replies, xml ) Need Help??


in reply to Re: Suggestions to make this code more Perlish
in thread Suggestions to make this code more Perlish

Ken, your original solution handles lines like this properly:
Bangladesh,"Claire, Laura, Phillip, Pascale",70016,"5,6,7,8"
whereas s/$re,/$+{field}\037/g will never dequote the last field.

One other minor observation: \037 is an atom, so no brackets are needed in s/[\037]+$//;

Replies are listed 'Best First'.
Re^3: Suggestions to make this code more Perlish
by kcott (Archbishop) on Mar 31, 2014 at 13:00 UTC

    Thanks for taking the time to study my code and provide feedback.

    "your original solution handles lines like this properly:

        Bangladesh,"Claire, Laura, Phillip, Pascale",70016,"5,6,7,8"

    whereas s/$re,/$+{field}\037/g will never dequote the last field."

    I made reference to the fact that we're dealing with "very specific input" in "Re^4: Suggestions to make this code more Perlish". I also alluded to the fact that different code would be required if the input changed.

    You're correct in saying that it "will never dequote the last field"; however, the last field (in this "very specific input") is an unquoted integer, so no dequoting is required.

    "One other minor observation: \037 is an atom, ..."

    Yes, that's how I used \037 (along with \036 and \012) in:

    $ perl -pe 'y/\036\037/\012|/' pm_1080161_output.tff
    "... so no brackets are needed in s/[\037]+$//;"

    The use of brackets here was a conscious decision to make it more obvious what the '+' quantifier referred to.

    You're correct in saying that 's/\037+$//' would have worked as well as 's/[\037]+$//'.

    -- Ken

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others admiring the Monastery: (4)
As of 2024-03-29 00:31 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found