Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"

Re: Swap Input lines

by trizen (Hermit)
on Apr 19, 2012 at 09:31 UTC ( #965898=note: print w/ replies, xml ) Need Help??

in reply to Swap Input lines

$output_line = "$3$2$1" if $input_line =~ /^([a-z][a-z\s]*[a-z])(\W+)(\d[\d-]*\d)$/i;
It accepts input like this:
Mary Smith = 345-78-9090 Joseph Alioto 976-83-1234
and the output will be:
345-78-9090 = Mary Smith 976-83-1234 Joseph Alioto

Comment on Re: Swap Input lines
Select or Download Code
Replies are listed 'Best First'.
Re^2: Swap Input lines
by brx (Pilgrim) on Apr 19, 2012 at 10:09 UTC
    This is a detail, but this regex  /^([a-z][a-z\s]*[a-z])(\W+)(\d[\d-]*\d)$/i is too specific.
    Input file contains lines with "x=y" format, so we must only search for "=" -- see jwkrahn's contribution: Re: Swap Input lines.
    Here some examples where this regex doesn't match:
    Jean-Paul Goude = 22-22 Marcel Duchamp = One-Two-Two Victoire Passage = 118_218 Philip K. Dick = 123-456
      You are right. I misunderstood the OPs problem.
Re^2: Swap Input lines
by JavaFan (Canon) on Apr 19, 2012 at 10:22 UTC
    So, you're swapping around pieces of the input, even on lines that do not contain a =? And on the other hand, you don't swap around input on lines that do contain a =, but don't match a regexp you distilled from looking at two examples? Yet, you still allow many other lines that aren't either the first, or the second example.

    That's an, uhm, "interesting" way of answering the question. I wonder whether it's helpful.

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (5)
As of 2015-11-28 04:17 GMT
Find Nodes?
    Voting Booth?

    What would be the most significant thing to happen if a rope (or wire) tied the Earth and the Moon together?

    Results (737 votes), past polls