in reply to Perl 'grammar'

I would tend to use substr rather than reverse to abbreviate the first name in this case:
#!/usr/bin/env perl use warnings; use strict; while (<DATA>) { my ($last, $first) = split /,/; $last =~ s/\s+//; $first =~ s/\s+//; print substr($first, 0, 1), $last, "\n"; } __DATA__ Smith, John Bar, Foo

Prints out:

JSmith FBar

Replies are listed 'Best First'.
Re^2: Perl 'grammar'
by johngg (Canon) on Jan 10, 2008 at 14:47 UTC
    Why not let the split regex do some of the work of removing spaces?

    my ( $last, $first ) = split m{\s*,\s*};

    Cheers,

    JohnGG