need a quick script

Discussion in 'Perl Misc' started by bob schmo, May 6, 2007.

  1. bob schmo

    bob schmo Guest

    Does anyone have a script lying around that will take firstname lastname
    and create first initial lastname: Bob Schmo --> BSchmo

    TIA.

    Bob
     
    bob schmo, May 6, 2007
    #1
    1. Advertising

  2. bob schmo wrote:
    > Does anyone have a script lying around that will take firstname lastname
    > and create first initial lastname: Bob Schmo --> BSchmo


    Probably not. That task is so easy to accomplish that it's unlikely that
    somebody would bother to save a script. You'd better write some code.

    --
    Gunnar Hjalmarsson
    Email: http://www.gunnar.cc/cgi-bin/contact.pl
     
    Gunnar Hjalmarsson, May 6, 2007
    #2
    1. Advertising

  3. On Sun, 06 May 2007 02:27:27 GMT, bob schmo <> wrote:

    >Subject: need a quick script


    How 'bout a bottle of champagne? ;-)

    >Does anyone have a script lying around that will take firstname lastname
    >and create first initial lastname: Bob Schmo --> BSchmo


    Nope. I doubt anyone has. It's so easy to write one in a few seconds
    that there's no reason one should have a similar thing "lying around".


    Michele
    --
    {$_=pack'B8'x25,unpack'A8'x32,$a^=sub{pop^pop}->(map substr
    (($a||=join'',map--$|x$_,(unpack'w',unpack'u','G^<R<Y]*YB='
    ..'KYU;*EVH[.FHF2W+#"\Z*5TI/ER<Z`S(G.DZZ9OX0Z')=~/./g)x2,$_,
    256),7,249);s/[^\w,]/ /g;$ \=/^J/?$/:"\r";print,redo}#JAPH,
     
    Michele Dondi, May 6, 2007
    #3
  4. On May 6, 3:40 am, Michele Dondi <> wrote:
    > On Sun, 06 May 2007 02:27:27 GMT, bob schmo <> wrote:
    > >Subject: need a quick script

    >
    > How 'bout a bottle of champagne? ;-)
    >
    > >Does anyone have a script lying around that will take firstname lastname
    > >and create first initial lastname: Bob Schmo --> BSchmo

    >
    > Nope. I doubt anyone has. It's so easy to write one in a few seconds
    > that there's no reason one should have a similar thing "lying around".
    >


    I just tried the doing it now. I took me exactly 17 minutes. The thing
    that slowed me up was if I had the input of say

    Chad Altenburg

    I needed to figure out how to store the name the characters 'C' 'h'
    'a' 'd' in one array and 'Chad' 'Altenburg' in another array. All
    this was due to the fact that I have a poor grasp over regex.
     
    grocery_stocker, May 6, 2007
    #4
  5. grocery_stocker wrote:
    > I just tried the doing it now. I took me exactly 17 minutes. The thing
    > that slowed me up was if I had the input of say
    >
    > Chad Altenburg
    >
    > I needed to figure out how to store the name the characters 'C' 'h'
    > 'a' 'd' in one array and 'Chad' 'Altenburg' in another array. All
    > this was due to the fact that I have a poor grasp over regex.


    ???

    sub nameconvert {
    my ($first, $last) = split ' ', shift;
    substr($first, 0, 1) . $last
    }

    print nameconvert('Chad Altenburg'), "\n";

    --
    Gunnar Hjalmarsson
    Email: http://www.gunnar.cc/cgi-bin/contact.pl
     
    Gunnar Hjalmarsson, May 6, 2007
    #5
  6. bob schmo

    Lambik Guest

    "Gunnar Hjalmarsson" <> wrote in message
    news:...
    > grocery_stocker wrote:
    > sub nameconvert {
    > my ($first, $last) = split ' ', shift;
    > substr($first, 0, 1) . $last
    > }
    >
    > print nameconvert('Chad Altenburg'), "\n";
    >


    Such a hopeless question and i still learned something. I would have done:

    return substr($first, 0, 1) . $last

    Didn't know the return was optional
     
    Lambik, May 6, 2007
    #6
  7. Lambik wrote:
    > "Gunnar Hjalmarsson" <> wrote in message
    > news:...
    >>
    >>sub nameconvert {
    >> my ($first, $last) = split ' ', shift;
    >> substr($first, 0, 1) . $last
    >>}
    >>
    >>print nameconvert('Chad Altenburg'), "\n";

    >
    > Such a hopeless question and i still learned something. I would have done:
    >
    > return substr($first, 0, 1) . $last
    >
    > Didn't know the return was optional


    It's optional when I want a sub return the value of the last evaluated
    expression.

    perldoc -f return

    --
    Gunnar Hjalmarsson
    Email: http://www.gunnar.cc/cgi-bin/contact.pl
     
    Gunnar Hjalmarsson, May 6, 2007
    #7
  8. On May 6, 9:36 am, Gunnar Hjalmarsson <> wrote:
    > grocery_stocker wrote:
    > > I just tried the doing it now. I took me exactly 17 minutes. The thing
    > > that slowed me up was if I had the input of say

    >
    > > Chad Altenburg

    >
    > > I needed to figure out how to store the name the characters 'C' 'h'
    > > 'a' 'd' in one array and 'Chad' 'Altenburg' in another array. All
    > > this was due to the fact that I have a poor grasp over regex.

    >
    > ???
    >
    > sub nameconvert {
    > my ($first, $last) = split ' ', shift;
    > substr($first, 0, 1) . $last
    > }
    >
    > print nameconvert('Chad Altenburg'), "\n";
    >
    > --


    Here is perl code I wrote this morning

    #!/usr/bin/perl -w

    my $line=<stdin>;

    $line =~ s/^\s+//;
    @full_name = split(/\W/, $line);

    @first_name = split(//,$line);

    print "$first_name[0].$full_name[1]\n";
     
    grocery_stocker, May 6, 2007
    #8
  9. grocery_stocker <> wrote:
    > On May 6, 3:40 am, Michele Dondi <> wrote:
    >> On Sun, 06 May 2007 02:27:27 GMT, bob schmo <> wrote:
    >> >Subject: need a quick script

    >>
    >> How 'bout a bottle of champagne? ;-)
    >>
    >> >Does anyone have a script lying around that will take firstname lastname
    >> >and create first initial lastname: Bob Schmo --> BSchmo

    >>
    >> Nope. I doubt anyone has. It's so easy to write one in a few seconds
    >> that there's no reason one should have a similar thing "lying around".
    >>

    >
    > I just tried the doing it now. I took me exactly 17 minutes.



    Yikes!


    > The thing
    > that slowed me up was if I had the input of say
    >
    > Chad Altenburg
    >
    > I needed to figure out how to store the name the characters 'C' 'h'

    ^^^^^^^^^^^
    > 'a' 'd' in one array and 'Chad' 'Altenburg' in another array.



    No you didn't.

    perl -le '$_=q(Chad Altenburg); s/^(.)\S+\s+/$1/; print'


    > All
    > this was due to the fact that I have a poor grasp over regex.



    Right.


    --
    Tad McClellan SGML consulting
    Perl programming
    Fort Worth, Texas
     
    Tad McClellan, May 6, 2007
    #9
  10. grocery_stocker wrote:
    > On May 6, 9:36 am, Gunnar Hjalmarsson <> wrote:
    >>
    >> sub nameconvert {
    >> my ($first, $last) = split ' ', shift;
    >> substr($first, 0, 1) . $last
    >> }
    >>
    >> print nameconvert('Chad Altenburg'), "\n";

    >
    > Here is perl code I wrote this morning
    >
    > #!/usr/bin/perl -w


    use strict;

    missing.

    > my $line=<stdin>;
    >
    > $line =~ s/^\s+//;
    > @full_name = split(/\W/, $line);


    What if $line contains non-ASCII characters? Those two lines can be
    replaced with

    my @full_name = split ' ', $line;

    See "perldoc -f split"

    > @first_name = split(//,$line);


    No need to create that array. Just use substr() to grasp the first
    character of the first name.

    > print "$first_name[0].$full_name[1]\n";


    --
    Gunnar Hjalmarsson
    Email: http://www.gunnar.cc/cgi-bin/contact.pl
     
    Gunnar Hjalmarsson, May 6, 2007
    #10
  11. Petr Vileta wrote:
    > Hmm Gunnar, this is not programmer problem but national alphabet
    > problem. Many nations have 'Ch' as simple character. For example
    > Czech alphabet is A

    [...]
    > C

    [...]
    > H
    > CH
    > As I know the similar problem is in Spanish and some other languages.
    > The Spanish first name Chita sound as english wroted Khyta, then miss
    > Chita Castro must be transformed to ChCastro, not to CCastro.


    This alphabet has single 'C' and 'H' as individual characters, too. How do
    you -as a human(!)- know, if the first is supposed to be 'C' or 'Ch'?

    jue
     
    Jürgen Exner, May 7, 2007
    #11
  12. On Sun, 6 May 2007 19:51:50 +0200, "Lambik" <> wrote:

    >Such a hopeless question and i still learned something. I would have done:
    >
    >return substr($first, 0, 1) . $last
    >
    >Didn't know the return was optional


    It's not optional, it's implicit. I like to rely on this. Somebody
    else prefer to be explicit. Some like to be explicit *if* there are
    explicity early return()s anyway. That sounds sensible, indeed.


    Michele
    --
    {$_=pack'B8'x25,unpack'A8'x32,$a^=sub{pop^pop}->(map substr
    (($a||=join'',map--$|x$_,(unpack'w',unpack'u','G^<R<Y]*YB='
    ..'KYU;*EVH[.FHF2W+#"\Z*5TI/ER<Z`S(G.DZZ9OX0Z')=~/./g)x2,$_,
    256),7,249);s/[^\w,]/ /g;$ \=/^J/?$/:"\r";print,redo}#JAPH,
     
    Michele Dondi, May 11, 2007
    #12
  13. On Tue, 8 May 2007 02:43:13 +0200, "Petr Vileta"
    <> wrote:

    >> This alphabet has single 'C' and 'H' as individual characters, too. How do
    >> you -as a human(!)- know, if the first is supposed to be 'C' or 'Ch'?
    >>

    >In the Czech language it is very simple. If I found 'C' followed by 'H' or
    >'h' then this MUST be 'CH' (or 'Ch'). In other language I don't know.


    But isn't it represented with a single gliph, then?


    Michele
    --
    {$_=pack'B8'x25,unpack'A8'x32,$a^=sub{pop^pop}->(map substr
    (($a||=join'',map--$|x$_,(unpack'w',unpack'u','G^<R<Y]*YB='
    ..'KYU;*EVH[.FHF2W+#"\Z*5TI/ER<Z`S(G.DZZ9OX0Z')=~/./g)x2,$_,
    256),7,249);s/[^\w,]/ /g;$ \=/^J/?$/:"\r";print,redo}#JAPH,
     
    Michele Dondi, May 11, 2007
    #13
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. jack
    Replies:
    1
    Views:
    912
  2. TN Bella
    Replies:
    1
    Views:
    2,489
    Edward
    Jun 18, 2004
  3. =?Utf-8?B?RGF2aWQgVGhpZWxlbg==?=

    Quick Starts - <script> vs code behind

    =?Utf-8?B?RGF2aWQgVGhpZWxlbg==?=, Jan 30, 2006, in forum: ASP .Net
    Replies:
    5
    Views:
    381
    HongQuan Wu[MSFT]
    Feb 2, 2006
  4. JKop
    Replies:
    11
    Views:
    915
  5. Jose  Reckoner
    Replies:
    1
    Views:
    555
Loading...

Share This Page