Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
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
Replies are listed 'Best First'.
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 cooling their heels in the Monastery: (8)
As of 2015-07-08 02:59 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (93 votes), past polls