vc_will_do has asked for the wisdom of the Perl Monks concerning the following question:
Hi monks,
Background
I have a set of values an array. Array can be
@names = qw(user_name house_name street_address phone_number date_of_birth);
I need to remove the "_" from all the values and need to have upper case for all words in each values.
The output I need is
User Name House Name Street Address Phone Number Date Of Birth
The Question
I tried to write something like
At the line $name =~ s/\_(\w)/\ uc($1)/g; Can I replace the "_" and next character with " " and return value of the function 'uc()', which takes $1 as parameter.foreach $name ( @names ){ $name = ucfirst($name); # made first letter $name =~ s/\_(\w)/\ uc($1)/g; # Here is the point. print "$name \n"; }
Update: Removed comas from the array as its a bug pointed out by pKai at Re: Interpolation inside regex
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Interpolation inside regex
by Corion (Patriarch) on Sep 07, 2007 at 08:43 UTC | |
by vc_will_do (Sexton) on Sep 07, 2007 at 08:49 UTC | |
|
Re: Interpolation inside regex
by johngg (Canon) on Sep 07, 2007 at 10:08 UTC | |
|
Re: Interpolation inside regex
by pKai (Priest) on Sep 07, 2007 at 11:38 UTC | |
by vc_will_do (Sexton) on Sep 07, 2007 at 11:56 UTC |