Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re: Swap Input lines

by trizen (Friar)
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
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?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (3)
As of 2014-09-18 04:59 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (108 votes), past polls