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

Author separation

by Shaveta_Chawla (Sexton)
on Jun 07, 2012 at 07:41 UTC ( [id://974896]=perlquestion: print w/replies, xml ) Need Help??

Shaveta_Chawla has asked for the wisdom of the Perl Monks concerning the following question:

This node falls below the community's threshold of quality. You may see it by logging in.

Replies are listed 'Best First'.
Re: Author separation
by kcott (Archbishop) 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
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://974896]
Approved by betterworld
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chanting in the Monastery: (9)
As of 2024-03-28 14:46 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found