Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery

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

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 all is quiet...

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (8)
As of 2018-06-21 12:58 GMT
Find Nodes?
    Voting Booth?
    Should cpanminus be part of the standard Perl release?

    Results (118 votes). Check out past polls.