in reply to Strip first name from string

The trouble with this sort of problem statement is that it is subject to all kinds of counter-exemplification: so, what about a name like "G. Gordon Liddy Sr., PhD"?

Replies are listed 'Best First'.
Re^2: Strip first name from string
by htmanning (Friar) on Jan 29, 2014 at 01:15 UTC
    Exactly. I don't know how to handle that, but I did do this and it worked okay:
    @contactname = split(' ',$contact); $firstname = $contactname[0]; $lastname = $contactname[1]; $showcontactname = "Mr. $lastname";
Re^2: Strip first name from string
by 2teez (Vicar) on Jan 29, 2014 at 07:58 UTC

    While I agree with your statement that ..The trouble with this sort of problem statement is that it is subject to all kinds of counter-exemplification I will want to second toolic mention of Lingua::EN::NameParse.

    And for a one off name like you mentioned one could do this:

    print sprintf 'Mr. %3$s' => split/ / => "G. Gordon Liddy Sr., PhD"; #M +r. Liddy

    If you tell me, I'll forget.
    If you show me, I'll remember.
    if you involve me, I'll understand.
    --- Author unknown to me

      While I understand what the fat commas are doing in there (I think), it's more perplexing why you used print sprintf instead of just printf. What am I missing here?

        FWIW , usually, when one goes the more verbose route in posts, its to help the noobs, for example
        my $foo = sprintf ...; print "$foo\n";

        So  print sprintf ...

        Its kinda like using qq{} and q{} for oneliners --- makes the readers life more copy/paste and less editing :)

        Just my impression

        hi hippo,
        ..it's more perplexing why you used print sprintf instead of just printf. What am I missing here?..

        Apart from printf doc. stating that printf and print sprintf(FORMAT, LIST) are equivalent. Atleast it's obvious from the usage of sprintf that one wants a formatted string.

        If you tell me, I'll forget.
        If you show me, I'll remember.
        if you involve me, I'll understand.
        --- Author unknown to me