Re: grep help request
- From: "Paul Lalli" <mritty@xxxxxxxxx>
- Date: 28 Oct 2005 13:30:35 -0700
David Gilden wrote:
> I am stuck with this issue.
> How do get each substring (the names in this case) and then upper case them.
> This does not work just yet....
>
> Possible data:
> mike smith
> john h. hamilton
> g. bush
> hendric
>
> etc......
> ----
I'm curious as to what you believe each of these lines do...
> #!/usr/bin/perl
>
> $SendersName = " dave middlename gilden ";
> $SendersName =~ s/\s*(.+)\s*/$1/g;
Removing all spaces from the string. $SendersName is now, for example,
'johnh.hamilton'
> ($SendersName) = $SendersName =~ m/([\w\.-]{1,24}( [\w\.-]{1,24}){0,4})/;
matching between 1 and 5 instances of strings containing word
characters, periods, and dashes. Each instance separated by a space.
The entire sequence returned as the new $SendersName
> $SendersName =~ s/.+ (.+)? (.+){1,3}/\u$1 \u$2 \u$3/g;
Look for anything, a space, a possible anything, a space, and between
one and three anythings. Replace with a first-letter uppercased
version of the second string (which may not have existed), a
first-letter uppercased version of the last of the group of three
anythings, and a first-letter uppercased version of undefined.
What on earth is that trying to do?
> print "$SendersName\n";
#!/usr/bin/perl
use strict;
use warnings;
while (my $SendersName = <DATA>){
chomp $SendersName;
(my $upper_cased = $SendersName) =~ s/\b(\w)/\u$1/g;
print "$SendersName ==> $upper_cased\n";
}
__DATA__
mike smith
john h. hamilton
g. bush
hendric
Output:
mike smith ==> Mike Smith
john h. hamilton ==> John H. Hamilton
g. bush ==> G. Bush
hendric ==> Hendric
Paul Lalli
.
- Prev by Date: Re: problem using a module
- Next by Date: Re: <> tag in perl
- Previous by thread: <> tag in perl
- Next by thread: Re: grep help request
- Index(es):
Relevant Pages
|