(sorry if there is a duplication, I tried posting this with  my
newsgroup client and it has never showed up)

I need three versions of a string ($city)
(In case EAST BANK is entered)

(1) capitol first (cowboy case)                            East Bank
(2) Any spaces present changed to undersccore   East_Bank
(3) Any spaces present changed to plus sign        East+Bank

#!/usr/local/bin/perl -w
use strict;

print "\nEnter the city name: ? ";
chomp(my $city = <STDIN>);

# make sure that it is capitol first (cowboy case) ie East Bank
$city =~   s/(\w+)/\u\L$1/g;

my $cityUnderscore = $city;
$cityUnderscore =~ tr / /_/;

my $cityPlus = $city;
$cityPlus =~ tr / /+/;
print "$city\n";
print  "$cityUnderscore\n";
print  "$cityPlus\n";

Is there a simple one line way to initialize each of the last two
extra strings and then change spaces to the correct _ / +

Instead of doing it in two lines as I have here?

thanks


-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to