Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re^2: Changing the order of elements in the variable

by bimleshsharma (Beadle)
on May 30, 2012 at 11:01 UTC ( #973259=note: print w/ replies, xml ) Need Help??


in reply to Re: Changing the order of elements in the variable
in thread Changing the order of elements in the variable

That's fantastic.. But one comma (,) is missed- it seems.

$author =~ s/([^,;]+),([^,;]+)/$2, $1/g;


Comment on Re^2: Changing the order of elements in the variable
Download Code
Re^3: Changing the order of elements in the variable
by kcott (Abbot) on May 30, 2012 at 11:30 UTC

    You can check this sort of thing on the commandline: usually advisable if you're going to tell someone they got something wrong.

    Shaveta_Chawla wants: "... "Smith, Kristen A." should change to "Kristen A. Smith".".

    moritz' solution does this:

    $ perl -Mstrict -Mwarnings -E 'my $author = q{Smith, Kristen A.}; $aut +hor =~ s/([^,;]+),([^,;]+)/$2 $1/g; say $author' Kristen A. Smith

    Your correction does not do this:

    $ perl -Mstrict -Mwarnings -E 'my $author = q{Smith, Kristen A.}; $aut +hor =~ s/([^,;]+),([^,;]+)/$2, $1/g; say $author' Kristen A., Smith

    -- Ken

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (4)
As of 2014-12-22 06:29 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (111 votes), past polls