Re: grep help request



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

.



Relevant Pages

  • Re: grep help request
    ... > g. bush ... Mike Smith ... John H. Hamilton ...
    (perl.beginners)
  • Re: US politics has shifted....
    ... >>>We have leftists in this newsgroup triumphantly announcing that Bush ... >>>had to give in to John McCain's provision to prohibit torture. ... >>>2) when pressed about using torture in desperate situations, McCain ... up mercury pollution from power plants. ...
    (alt.politics.bush)
  • Bush Family Involvement in Nazi Industry: Check Out Dave Emorys Interview with John Buchanan
    ... family's involvement with Nazi industry. ... the program sets forth John Buchanan's harrowing ... John's uncovering of the fact that Prescott Bush, ...
    (sci.med.diseases.lyme)
  • Re: Bush Is Crap Said This MP
    ... I have no regrets about making public John Prescott's private thoughts ... should never have made public the fact that Mr Prescott said Mr Bush ... the core dispute in the Middle East: ...
    (alt.religion.islam)
  • Re: Villains Rocky should have fought?
    ... John Wilkes Booth ... where Republicans cannot interfere with a Woman's Right to Choose ... Bush because he is a crony of Halliburton and big business interests & ... Halliburton and big business interests & we hate George W. Bush & ...
    (rec.sport.pro-wrestling)