Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Author separation

by Shaveta_Chawla (Sexton)
on Jun 07, 2012 at 07:41 UTC ( #974896=perlquestion: print w/replies, xml ) Need Help??
Shaveta_Chawla has asked for the wisdom of the Perl Monks concerning the following question:

Hi, i have a string $author = "Cheng, Liying, Fox, Janna., and Zheng, Ying. ";
i want o/p like
$author = "Liying Cheng, Janna. Fox, Ying. Zheng ";
please guide!!

Replies are listed 'Best First'.
Re: Author separation
by kcott (Chancellor) on Jun 07, 2012 at 08:08 UTC
Re: Author separation
by DrHyde (Prior) on Jun 07, 2012 at 09:49 UTC
    That's easy.
    if($author eq "Cheng, Liying, Fox, Janna., and Zheng, Ying. ") { $author = "Liying Cheng, Janna. Fox, Ying. Zheng "; }
    If you want something that works in the general case, then I suggest that you start by showing us what you've tried.
      I have used this code:
      $author = "Cheng, Liying, Fox, Janna., Zheng, Ying."; @author = split(',' , $author); $length = scalar(@author); $l = 0; $j = 1; for($i=0; $i<$length/2 ; $i++) { $author1[$i]= "$author[$j] $author[$l]"; $l = $l+2; $j = $j+2; } $author = join (',' , @author1); print "$author\n\n";
      but this is not feasible
Re: Author separation
by cdarke (Prior) on Jun 07, 2012 at 13:05 UTC
    Many ways of doing this, here is mine:
    use strict; use warnings; my $author = "Cheng, Liying, Fox, Janna., and Zheng, Ying. "; $author =~ s/\.| and| //g; my %hash = split (',', $author); my @authors; for my $key (sort keys %hash) { push @authors,"$hash{$key} $key"; } $author = join(',', @authors); print "$author\n";
    Gives:
    Liying Cheng,Janna Fox,Ying Zheng
Re: Author separation
by Shaveta_Chawla (Sexton) on Jun 07, 2012 at 11:05 UTC
    This code can also be used::
    $author = "$author,"; $author =~ s/(.*?),(.*?),/$2 $1,/g;

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://974896]
Approved by betterworld
help
Chatterbox?
[shmem]: LanX: now I have to find a succinct transformation FOOL => MONK
[LanX]: yeah but Marto already proposed a new "Lex Sun-D" ...
[karlgoethebier]: the word really exists: http://www. urbandictionary. com/define.php? term=fool
[shmem]: ...possibly involving RTFM
[karlgoethebier]: big surprise!
[Eily]: LanX I try to avoid answering, but I did feel that this one post was going into much detail to prove a false claim (that SHA-1 is secure, I was just wrong about how insecure it is)
[LanX]: ironically...
[LanX]: yeah whatever ... I'm in the favorable condition to already autohiding him ... how can I judge the poor FOOLs who still see his contributions xD
[Eily]: he's been pretty saavy about threads that were implictly about him in the past. I think he might have deliberatly avoiding mentioning it for some reason (he got tired?)
[Eily]: he did mention one of his propositions: basically make it possible to ignore downvotes, by separating them more from the upvotes

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (8)
As of 2017-07-24 17:21 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    I came, I saw, I ...
























    Results (356 votes). Check out past polls.