need a quick script

B

bob schmo

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

TIA.

Bob
 
G

Gunnar Hjalmarsson

bob said:
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.
 
M

Michele Dondi

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
 
G

grocery_stocker

How 'bout a bottle of champagne? ;-)


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.
 
G

Gunnar Hjalmarsson

grocery_stocker said:
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";
 
L

Lambik

Gunnar Hjalmarsson said:
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
 
G

Gunnar Hjalmarsson

Lambik said:
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
 
G

grocery_stocker

???

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";
 
T

Tad McClellan

grocery_stocker said:
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.
 
G

Gunnar Hjalmarsson

grocery_stocker said:
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";
 
J

Jürgen Exner

Petr said:
Hmm Gunnar, this is not programmer problem but national alphabet
problem. Many nations have 'Ch' as simple character. For example
Czech alphabet is A [...]
[...]
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
 
M

Michele Dondi

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
 
M

Michele Dondi

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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,202
Messages
2,571,057
Members
47,667
Latest member
DaniloB294

Latest Threads

Top