Bookmarks

Yahoo Gmail Google Facebook Delicious Twitter Reddit Stumpleupon Myspace Digg

Search queries

/proc/kallsyms format, sqldatasource dal, wwwxxxenden, convert raid5 to raid 10 mdadm, apache force chunked, nrao wwwxxx, xxxxxdup, procmail change subject header, wwwXxx not20, Wwwxxx.doks sas

Links

XODOX
Impressum

#1: Capitalizing Acronyms

Posted on 2011-09-08 17:58:09 by sono-io

I'm trying to capitalize 3 and 4 letter words that contain only =
vowels or consonants, but not both. The code I've come up with is not =
working correctly. Given the string 'The Kcl Group', it should return =
'The KCL Group' but it is also capitalizing the word 'THE'. What am I =
doing wrong?

Thanks,
Marc


use strict;
use warnings;

my $string =3D 'The Kcl Group';

my @words =3D split(/ /, $string);
my @new_words;
foreach my $word (@words) {
if ((length $word >=3D 3 and length $word <=3D 4) and ($word !~ =
m/[aeiouy]+/gi or $word !~ m/[bcdfghjklmnpqrstvwxz]+/gi)) {
$word =3D uc($word);
}
push @new_words, $word;
}
$string =3D "@new_words";

print $string . "\n";=

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

Report this message

#2: RE: Capitalizing Acronyms

Posted on 2011-09-08 18:17:33 by David.Wagner

>-----Original Message-----
>From: Marc [mailto:sono-io@fannullone.us]
>Sent: Thursday, September 08, 2011 9:58
>To: Perl Beginners
>Subject: Capitalizing Acronyms
>
>
> I'm trying to capitalize 3 and 4 letter words that contain only
>vowels or consonants, but not both. The code I've come up with is not
>working correctly. Given the string 'The Kcl Group', it should return =
'The
>KCL Group' but it is also capitalizing the word 'THE'. What am I doing
>wrong?
>
>Thanks,
>Marc
>
>
>use strict;
>use warnings;
>
>my $string =3D 'The Kcl Group';
>
>my @words =3D split(/ /, $string);
>my @new_words;
>foreach my $word (@words) {
> if ((length $word >=3D 3 and length $word <=3D 4) and ($word !~
>m/[aeiouy]+/gi or $word !~ m/[bcdfghjklmnpqrstvwxz]+/gi)) {

I changed the following:
($word !~ m/[aeiouy]+/gi or $word !~ m/[bcdfghjklmnpqrstvwxz]+/gi)
To
! ($word =3D~ m/^[aeiouy]+&/gi or $word =3D~ =
m/^[bcdfghjklmnpqrstvwxz]+&/gi)
This forces a start and end of on $word and I like the positive of if =
ONLY vowels plus Y or ONLY consonants. SO it is one way of doing it.

         If you have any questions and/or problems, =
please let me know.=20
        =A0Thanks.=20
=A0
Wags ;)=20
David R. Wagner=20
Senior Programmer Analyst=20
FedEx Services=20
1.719.484.2097 Tel=20
1.719.484.2419 Fax=20
1.408.623.5963 Cell
http://Fedex.com/us



> $word =3D uc($word);
> }
> push @new_words, $word;
>}
>$string =3D "@new_words";
>
>print $string . "\n";
>--
>To unsubscribe, e-mail: beginners-unsubscribe@perl.org
>For additional commands, e-mail: beginners-help@perl.org
>http://learn.perl.org/
>


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

Report this message

#3: Re: Capitalizing Acronyms

Posted on 2011-09-08 18:23:22 by Jim Gibson

On 9/8/11 Thu Sep 8, 2011 8:58 AM, "Marc" <sono-io@fannullone.us>
scribbled:

> I'm trying to capitalize 3 and 4 letter words that contain only vowels or
> consonants, but not both. The code I've come up with is not working
> correctly. Given the string 'The Kcl Group', it should return 'The KCL Group'
> but it is also capitalizing the word 'THE'. What am I doing wrong?

The regular expression m/[aeiouy]+/gi will match a string that contains one
or more vowels. Thus, the string 'The' matches and is capitalized because it
contains a vowel: 'e'.

If you want the regular expression to match only strings that consist
entirely of vowels, you need to anchor the pattern to the beginning and end
of the string:

m/^[aeiouy]+$/i

The 'g' modifier is not needed, as you are only attempting to match the
entire string, not repetitive substrings within the string.

A similar change should be made to the consonant regular expression.

>
> use strict;
> use warnings;
>
> my $string = 'The Kcl Group';
>
> my @words = split(/ /, $string);
> my @new_words;
> foreach my $word (@words) {
> if ((length $word >= 3 and length $word <= 4) and ($word !~ m/[aeiouy]+/gi or
> $word !~ m/[bcdfghjklmnpqrstvwxz]+/gi)) {
> $word = uc($word);
> }
> push @new_words, $word;
> }
> $string = "@new_words";
>
> print $string . "\n";



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

Report this message

#4: Re: Capitalizing Acronyms

Posted on 2011-09-08 18:38:13 by Shlomi Fish

Hi Marc,

On Thu, 8 Sep 2011 08:58:09 -0700
Marc <sono-io@fannullone.us> wrote:

> I'm trying to capitalize 3 and 4 letter words that contain only vowels o=
r consonants, but not both. The code I've come up with is not working corr=
ectly. Given the string 'The Kcl Group', it should return 'The KCL Group' =
but it is also capitalizing the word 'THE'. What am I doing wrong?
>=20
> Thanks,
> Marc
>=20
>=20
> use strict;
> use warnings;
>=20
> my $string =3D 'The Kcl Group';
>=20
> my @words =3D split(/ /, $string);
> my @new_words;
> foreach my $word (@words) {
> if ((length $word >=3D 3 and length $word <=3D 4) and ($word !~ m/[aeiou=
y]+/gi or $word !~ m/[bcdfghjklmnpqrstvwxz]+/gi)) {

The problem here that /g confuses Perl and puts it in the \G anchor mode.
Removing both /g fixes the problem. Some other notes:

1. You don't really need to say [...]+ inside the regex. [....] here would =
be
enough.

2. You map opt to use perldoc -f map instead of foreach here.

3. Since the foreach aliases the variable you can modify the array inplace.

Regards,

Shlomi Fish=20


--=20
------------------------------------------------------------ -----
Shlomi Fish http://www.shlomifish.org/
UNIX Fortune Cookies - http://www.shlomifish.org/humour/fortunes/

Learn Perl from âÂ=9CLearning Perl in 24 Minutes Unleashed, in a Nutshe=
ll for=20
Dummies.âÂ=9D
âÂ=94 based on Shlomi Fish and f00li5h on #perl

Please reply to list if it's a mailing list post - http://shlom.in/reply .

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

Report this message

#5: Re: Capitalizing Acronyms

Posted on 2011-09-08 18:38:41 by sono-io

Jim and David,

> m/^[aeiouy]+$/i

I tried your suggestions but it still gives the same result:

my $string =3D 'Off The Menu';

my @words =3D split(/ /, $string);
my @new_words;
foreach my $word (@words) {
if ((length $word >=3D 3 and length $word <=3D =
4) and ! ($word =3D~ m/^[aeiouy]+$/i or $word =3D~ =
m/^[bcdfghjklmnpqrstvwxz]+$/i)) {
$word =3D uc($word);
}
push @new_words, $word;
}
$string =3D "@new_words";

print $string . "\n";

gives me "OFF THE MENU".=

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

Report this message

#6: Re: Capitalizing Acronyms

Posted on 2011-09-08 18:48:13 by timothy adigun

--0016e65ae5249f796a04ac70d3b7
Content-Type: text/plain; charset=ISO-8859-1

Hi Marc,
Please check >>> <<<< comment in your code below:
use strict;
use warnings;

my $string = 'The Kcl Group';

my @words = split(/ /, $string);
my @new_words;
foreach my $word (@words) {

>>> if ((length $word >= 3 and length $word <= 4) and ($word !~
m/[aeiouy]+/gi or $word !~ m/[bcdfghjklmnpqrstvwxz]+/gi)) { <<<<<<

====> remove the "g" from /gi <<<< =====you will get what you want!
$word = uc($word);
}
push @new_words, $word;
}
$string = "@new_words";

print $string . "\n";

--0016e65ae5249f796a04ac70d3b7--

Report this message

#7: Re: Capitalizing Acronyms

Posted on 2011-09-08 18:55:33 by sono-io

Hi Shlomi,

> The problem here that /g confuses Perl and puts it in the \G anchor =
mode.
> Removing both /g fixes the problem. Some other notes:
>=20
> 1. You don't really need to say [...]+ inside the regex. [....] here =
would be
> enough.

Unfortunately, removing the /g and the + doesn't help. (Updated =
code below.)

> 2. You may opt to use perldoc -f map instead of foreach here.

I don't fully understand map yet. =3D:\ That's why I'm using =
foreach.

> 3. Since the foreach aliases the variable, you can modify the array =
in-place.

Sorry, but you've lost me here. Could you give an example?

Thanks,
Marc


my $string =3D 'Off The Menu';

my @words =3D split(/ /, $string);
my @new_words;
foreach my $word (@words) {
if ((length $word >=3D 3 and length $word <=3D 4) and ! ($word =
=3D~ m/^[aeiouy]$/i or $word =3D~ m/^[bcdfghjklmnpqrstvwxz]$/i)) {
$word =3D uc($word);
}
push @new_words, $word;
}
$string =3D "@new_words";

print $string . "\n";


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

Report this message

#8: Re: Capitalizing Acronyms

Posted on 2011-09-08 18:57:30 by Jim Gibson

On 9/8/11 Thu Sep 8, 2011 9:38 AM, "Marc" <sono-io@fannullone.us>
scribbled:

> Jim and David,
>
>> m/^[aeiouy]+$/i
>
> I tried your suggestions but it still gives the same result:
>
> my $string = 'Off The Menu';
>
> my @words = split(/ /, $string);
> my @new_words;
> foreach my $word (@words) {
> if ((length $word >= 3 and length $word <= 4) and ! ($word =~ m/^[aeiouy]+$/i
> or $word =~ m/^[bcdfghjklmnpqrstvwxz]+$/i)) {
> $word = uc($word);
> }
> push @new_words, $word;
> }
> $string = "@new_words";
>
> print $string . "\n";
>
> gives me "OFF THE MENU".

Then the problem probably lies with the complex logical expression, which is
too complicated for me to parse easily.

You can use the substitution operator s/// to match and modify strings in
one step. Note also that the only number <= 3 and >= 4 at the same time is
3!

So try this:

use strict;
my $string = 'Off The aei xxx aeiou bcdfg Menu';
my @words = split(/ /, $string);
my @new_words;
foreach my $word (@words) {
if( length $word == 3 ) {
$word =~ s/^([aeiouy]+)/uc $1/ie;
$word =~ s/^([bcdfghjklmnpqrstvwxz]+)$/uc $1/ie;
}
push @new_words, $word;
}
$string = "@new_words";
print $string . "\n";

.... which gives on my system:

Off The AEI XXX aeiou bcdfg Menu




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

Report this message

#9: Re: Capitalizing Acronyms

Posted on 2011-09-08 19:03:04 by Brandon McCaig

On Thu, Sep 8, 2011 at 11:58 AM, Marc <sono-io@fannullone.us> wrote:
> I'm trying to capitalize 3 and 4 letter words that contain
> only vowels or consonants, but not both. àThe code I've come
> up with is not working correctly. àGiven the string
> 'The Kcl Group', it should return 'The KCL Group' but it is
> also capitalizing the word 'THE'. àWhat am I doing wrong?
*snip*
> my @words =3D split(/ /, $string);
> my @new_words;
> foreach my $word (@words) {
> à à à àif ((length $word >=3D 3 and length $word <=3D=
4) and ($word !~ m/[aeiouy]+/gi or $word !~ m/[bcdfghjklmnpqrstvwxz]+/gi))=
{
> à à à à à à à à$word =3D uc($word=
);
> à à à à}
> à à à àpush @new_words, $word;
> }
> $string =3D "@new_words";

Hmmm, couldn't you just use a s/// operator for this?

#!/usr/bin/perl

while(my $original =3D <DATA>)
{
chomp $original;
(my $modified =3D $original) =3D~
s/\b([aeiouy]{3,4}|[bcdfghjklmnpqrstvwxz]{3,4})\b/uc($1)/egi ;
print "$original -> $modified\n";
}

__DATA__
The Kcl Group
Off The Menu



Output:

The Kcl Group -> The KCL Group
Off The Menu -> Off The Menu



--=20
Brandon McCaig <http://www.bamccaig.com/> <bamccaig@gmail.com>
V zrna gur orfg jvgu jung V fnl. Vg qbrfa'g nyjnlf fbhaq gung jnl.
Castopulence Software <http://www.castopulence.org/> <bamccaig@castopulence=
..org>

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

Report this message

#10: Re: Capitalizing Acronyms

Posted on 2011-09-08 19:06:29 by Uri Guttman

>>>>> ""D" == "Wagner, David <--- Sr Programmer Analyst --- CFS" <david.wagner@fedex.com>> writes:

"D> ! ($word =~ m/^[aeiouy]+&/gi or $word =~ m/^[bcdfghjklmnpqrstvwxz]+&/gi)

"D> This forces a start and end of on $word and I like the positive of
if ONLY vowels plus Y or ONLY consonants. SO it is one way of doing
it.

i think you mean $ and not & in those regexes. & has no meaning in a
regex.

also the /g is useless there since you aren't matching the same text in
scalar context in a loop (each match is against a new word).

uri

--
Uri Guttman -- uri AT perlhunter DOT com --- http://www.perlhunter.com --
------------ Perl Developer Recruiting and Placement Services -------------
----- Perl Code Review, Architecture, Development, Training, Support -------

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

Report this message

#11: Re: Capitalizing Acronyms

Posted on 2011-09-08 19:09:25 by Uri Guttman

>>>>> "M" == Marc <sono-io@fannullone.us> writes:

M> Jim and David,
>> m/^[aeiouy]+$/i

M> I tried your suggestions but it still gives the same result:

M> my $string = 'Off The Menu';

M> my @words = split(/ /, $string);
M> my @new_words;
M> foreach my $word (@words) {
M> if ((length $word >= 3 and length $word <= 4) and ! ($word =~ m/^[aeiouy]+$/i or $word =~ m/^[bcdfghjklmnpqrstvwxz]+$/i)) {

your boolean logic is wrong. you want to get rid of the ! in there. you
upper case if the word size is right AND it has all vowels or all
consonants. your negation makes it do this for regular words (mixed
vowel/consonant) of the right size

uri


--
Uri Guttman -- uri AT perlhunter DOT com --- http://www.perlhunter.com --
------------ Perl Developer Recruiting and Placement Services -------------
----- Perl Code Review, Architecture, Development, Training, Support -------

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

Report this message

#12: Re: Capitalizing Acronyms

Posted on 2011-09-08 19:13:35 by Rob Dixon

On 08/09/2011 16:58, Marc wrote:
> use strict;
> use warnings;
>
> my $string = 'The Kcl Group';
>
> my @words = split(/ /, $string);
> my @new_words;
> foreach my $word (@words) {
> if ((length $word>= 3 and length $word<= 4) and ($word !~ m/[aeiouy]+/gi or $word !~ m/[bcdfghjklmnpqrstvwxz]+/gi)) {
> $word = uc($word);
> }
> push @new_words, $word;
> }
> $string = "@new_words";
>
> print $string . "\n";

Hi Marc

The program below will do what you requested.

Cheers,

Rob


use strict;
use warnings;

my $string = 'The Kcl Group';

$string =~ s/\b([aeiouy]{3,4}|[^aeiouy]{3,4})\b/\U$1/ig;

print $string, "\n";

**OUTPUT**

The KCL Group



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

Report this message

#13: Re: Capitalizing Acronyms

Posted on 2011-09-08 19:15:15 by Shlomi Fish

On Thu, 8 Sep 2011 09:55:33 -0700
Marc <sono-io@fannullone.us> wrote:

> Hi Shlomi,
>
> > The problem here that /g confuses Perl and puts it in the \G anchor mode.
> > Removing both /g fixes the problem. Some other notes:
> >
> > 1. You don't really need to say [...]+ inside the regex. [....] here would be
> > enough.
>
> Unfortunately, removing the /g and the + doesn't help. (Updated code below.)
>

Well you removed the /g and the +, but also made other changes such as add ^ and
$ and change the conditional logic.

> > 2. You may opt to use perldoc -f map instead of foreach here.
>
> I don't fully understand map yet. =:\ That's why I'm using foreach.
>

OK, map is a powerful tool once you learn it.

> > 3. Since the foreach aliases the variable, you can modify the array in-place.
>
> Sorry, but you've lost me here. Could you give an example?
>

This code:

[CODE]
#!/usr/bin/perl

use strict;
use warnings;

my @words = ("One", "Two", "Three", "four");
foreach my $word (@words)
{
$word = uc($word);
}

print join(",", @words), "\n";
[/CODE]

prints "ONE,TWO,THREE,FOUR".

Regards,

Shlomi Fish

> Thanks,
> Marc
>
>
> my $string = 'Off The Menu';
>
> my @words = split(/ /, $string);
> my @new_words;
> foreach my $word (@words) {
> if ((length $word >= 3 and length $word <= 4) and ! ($word =~ m/^[aeiouy]$/i or $word =~ m/^[bcdfghjklmnpqrstvwxz]$/i)) {
> $word = uc($word);
> }
> push @new_words, $word;
> }
> $string = "@new_words";
>
> print $string . "\n";
>
>



--
------------------------------------------------------------ -----
Shlomi Fish http://www.shlomifish.org/
UNIX Fortune Cookies - http://www.shlomifish.org/humour/fortunes/

The X in XSLT stands for eXtermination.

Please reply to list if it's a mailing list post - http://shlom.in/reply .

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

Report this message

#14: Re: Capitalizing Acronyms

Posted on 2011-09-08 19:47:21 by sono-io

On Sep 8, 2011, at 10:13 AM, Rob Dixon wrote:

> $string =3D~ s/\b([aeiouy]{3,4}|[^aeiouy]{3,4})\b/\U$1/ig;

Thanks to everyone who responded. I was trying to be concise =
but I went about it the wrong way and ended up creating more work for =
myself. I like the above code as it allows me to use the original =
string without having to split it and create new arrays just for this =
one feature, and it's simpler than I had hoped for. Most importantly, I =
understand it! =3D;)

Thanks again,
Marc=

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

Report this message

#15: Re: Capitalizing Acronyms

Posted on 2011-10-07 01:05:00 by sono-io

On Sep 8, 2011, at 10:13 AM, Rob Dixon wrote:

> my $string =3D 'The Kcl Group';
>=20
> $string =3D~ s/\b([aeiouy]{3,4}|[^aeiouy]{3,4})\b/\U$1/ig;
>=20
> print $string, "\n";

I'd like to revisit this, if I could. I've modified the above =
regex so as not to capitalize ordinal numbers, however I've noticed that =
it produces incorrect output if the word has an apostrophe. Given:

my $string =3D "rex's chicken on 51st st. at lkj";
$string =3D~ s/\b([aeiouy]{3,4}|[^aeiouy0123456789]{3,4})\b/uc($1)/eg;

the output is:
Rex'S Chicken on 51st ST. at LKJ

It should be:
Rex's Chicken on 51st St. at LKJ

I Googled and tried everything I'd found, but I can't fix it. =
Again, that line should capitalize 3 and 4 letter words that have either =
all vowels or all capitals. The code I found below works great for =
capitalization except for that one regex which throws a wrench into it.

Thanks,
Marc

-----------

# http://daringfireball.net/2008/08/title_case_update

use strict;
use warnings;
use utf8;
use open qw( :encoding(UTF-8) :std );


my @small_words =3D qw( (?<!q&)a an and as at(?!&t) but by en for if in =
of on or the to v[.]? via vs[.]? );
my $small_re =3D join '|', @small_words;

my $apos =3D qr/ (?: ['â≢] [[:lower:]]* )? /x;

my $string =3D "rex's chicken on 51st st at lkj";

$string =3D~
s{
\b (_*) (?:
( [-_[:alpha:]]+ [@.:/] [-_[:alpha:]@.:/]+ $apos =
) # URL, domain, or email
|
( (?i: $small_re ) $apos ) =
# or small word (case-insensitive)
|
( [[:alpha:]] [[:lower:]'â≢(=
)\[\]{}]* $apos ) # or word w/o internal caps
|
( [[:alpha:]] [[:alpha:]'â≢(=
)\[\]{}]* $apos ) # or some other word
) (_*) \b
}{
$1 . (
defined $2 ? $2 # preserve URL, domain, or =
email
: defined $3 ? "\L$3" # lowercase small word
: defined $4 ? "\u\L$4" # capitalize word w/o internal =
caps
: $5 # preserve other kinds of word
) . $6
}exgo;

$string =3D~
# exceptions for small words: capitalize at start and end of =
title
s{
( \A [[:punct:]]* # start of title...
| [:.;?!][ ]+ # or of subsentence...
| [ ]['"ââ¬ÃÂââ¬ÃÂ(\[][ =
]* ) # or of inserted subphrase...
( $small_re ) \b # ... followed by small word
}{
$1\u\L$2
}xigo;

$string =3D~
s{
\b ( $small_re ) # small word...
(?=3D [[:punct:]]* \Z # ... at the end of the =
title...
| ['"ââ䢉â¬Ã=9D)\]] =
[ ] ) # ... or of an inserted subphrase?
}{
\u\L$1
}xigo;

$string =3D~ s/\b([aeiouy]{3,4}|[^aeiouy0123456789]{3,4})\b/uc($1)/eg;

print "$string \n";
print "$string \n";


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

Report this message

#16: Re: Capitalizing Acronyms

Posted on 2011-10-07 01:44:02 by Jim Gibson

On 10/6/11 Thu Oct 6, 2011 4:05 PM, "Marc" <sono-io@fannullone.us>
scribbled:

> On Sep 8, 2011, at 10:13 AM, Rob Dixon wrote:
>
>> my $string = 'The Kcl Group';
>>
>> $string =~ s/\b([aeiouy]{3,4}|[^aeiouy]{3,4})\b/\U$1/ig;
>>
>> print $string, "\n";
>
> I'd like to revisit this, if I could. I've modified the above regex so as not
> to capitalize ordinal numbers, however I've noticed that it produces incorrect
> output if the word has an apostrophe. Given:
>
> my $string = "rex's chicken on 51st st. at lkj";
> $string =~ s/\b([aeiouy]{3,4}|[^aeiouy0123456789]{3,4})\b/uc($1)/eg;
>
> the output is:
> Rex'S Chicken on 51st ST. at LKJ

That is not what I get after cutting-and-pasting the above two lines into a
Perl program. I get:

rex'S chicken on 51st ST. at LKJ

>
> It should be:
> Rex's Chicken on 51st St. at LKJ

Why are Rex and Chicken capitalized here? They are not 3-4 letters strings
consisting solely of vowels or consonants.

>
> I Googled and tried everything I'd found, but I can't fix it. Again, that
> line should capitalize 3 and 4 letter words that have either all vowels or all
> capitals.

I think you mean "all vowels or all consonants" (not capitals).

> The code I found below works great for capitalization except for
> that one regex which throws a wrench into it.

I am ignoring and deleting the complete program, as your problem seems to be
with the regex.

The problem is that the character class [^aeiouy0123456789] includes
everything not listed, which includes all punctuation characters such as '''
and '.' (and also upper-case letters). Thus, 'st.' is matched by
[^aeiouy0123456789]{3,4} and gets upper-cased.

You should go back to your original character class of
[bcdfghjklmnpqrstvwxz], which can be shortened somewhat as
[bcdfghj-np-tvwxz].



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

Report this message

#17: Re: Capitalizing Acronyms

Posted on 2011-10-07 02:38:22 by sono-io

On Oct 6, 2011, at 4:44 PM, Jim Gibson wrote:

> You should go back to your original character class of =
[bcdfghjklmnpqrstvwxz]

Making this change fixed the "Rex'S" problem, but it didn't =
capitalize LKJ because the rest of the code had capitalized the acronym =
as Lkj. So I changed that line to:
$string =3D~ =
s~\b([aeiouyAEIOUY]{3,4}|[bcdfghjklmnpqrstvwxzBCDFGHJKLMNPQR STVWXZ]{3,4})\=
b~uc$1~eg;

and now it works, even though it's a mile long. ;) Thanks for helping =
me to think about it differently.

Marc=

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

Report this message

#18: Re: Capitalizing Acronyms

Posted on 2011-10-07 10:50:08 by Igor Dovgiy

--0016e6de14d5492c9e04aeb18792
Content-Type: text/plain; charset=ISO-8859-1

You know, it shouldn't be mile long. )

$string =~ s! \b (?=[a-z]{3,4}) ([aeiouy]{3,4}|[^aeiouy]{3,4}) \b !\U$1!igx;

-- iD

2011/10/7 Marc <sono-io@fannullone.us>

> On Oct 6, 2011, at 4:44 PM, Jim Gibson wrote:
>
> > You should go back to your original character class of
> [bcdfghjklmnpqrstvwxz]
>
> Making this change fixed the "Rex'S" problem, but it didn't
> capitalize LKJ because the rest of the code had capitalized the acronym as
> Lkj. So I changed that line to:
> $string =~
> s~\b([aeiouyAEIOUY]{3,4}|[bcdfghjklmnpqrstvwxzBCDFGHJKLMNPQR STVWXZ]{3,4})\b~uc$1~eg;
>
> and now it works, even though it's a mile long. ;) Thanks for helping me
> to think about it differently.
>
> Marc
> --
> To unsubscribe, e-mail: beginners-unsubscribe@perl.org
> For additional commands, e-mail: beginners-help@perl.org
> http://learn.perl.org/
>
>
>

--0016e6de14d5492c9e04aeb18792--

Report this message

#19: Re: Capitalizing Acronyms

Posted on 2011-10-07 17:07:13 by Rob Dixon

On 07/10/2011 01:38, Marc wrote:
> On Oct 6, 2011, at 4:44 PM, Jim Gibson wrote:
>
>> You should go back to your original character class of [bcdfghjklmnpqrstvwxz]
>
> Making this change fixed the "Rex'S" problem, but it didn't capitalize LKJ because the rest of the code had capitalized the acronym as Lkj. So I changed that line to:
> $string =~ s~\b([aeiouyAEIOUY]{3,4}|[bcdfghjklmnpqrstvwxzBCDFGHJKLMNPQR STVWXZ]{3,4})\b~uc$1~eg;
>
> and now it works, even though it's a mile long. ;) Thanks for helping me to think about it differently.
>
> Marc

Just add the /i modifer (as you had originally) and there is no need to
list both the upper and lower case alphabetics.

Also, it is far better to use the standard delimiters for s/// and m//
unless you are dealing with string with a lot of slashes in them

Capturing parenthese should be avoided unless the are needed

And there is no need for an executable substituion string when \U will
do the upper casing for you:

$string =~ s/\b(?:[aeiouy]{3,4}|[bcdfghjklmnpqrstvwxz]{3,4})\b/\U$1/gi;

HTH,

Rob

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

Report this message

#20: Re: Capitalizing Acronyms

Posted on 2011-10-07 18:25:38 by sono-io

On Oct 7, 2011, at 8:07 AM, Rob Dixon wrote:

> Just add the /i modifer (as you had originally) and there is no need =
to list both the upper and lower case alphabetics.

Of course. Err... :\

> Capturing parenthese should be avoided unless the are needed

This I don't understand. Since we're using $1 we need them, no?

> $string =3D~ =
s/\b(?:[aeiouy]{3,4}|[bcdfghjklmnpqrstvwxz]{3,4})\b/\U$1/gi;

This gave me an error of "use of uninitialized value $1 in uc". =
Removing the non-capturing code works though;

$string =3D~ s/\b([aeiouy]{3,4}|[bcdfghjklmnpqrstvwxz]{3,4})\b/\U$1/ig;

This now allows me to step it down to {2,4} without capitalizing =
the 'st' in 51st.

Thanks again,
Marc=

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

Report this message

#21: Re: Capitalizing Acronyms

Posted on 2011-10-07 21:36:31 by Rob Dixon

On 07/10/2011 17:25, Marc wrote:
> On Oct 7, 2011, at 8:07 AM, Rob Dixon wrote:
>
>> Capturing parenthese should be avoided unless the are needed
>
> This I don't understand. Since we're using $1 we need them, no?
>
>> $string =~ s/\b(?:[aeiouy]{3,4}|[bcdfghjklmnpqrstvwxz]{3,4})\b/\U$1/gi;
>
> This gave me an error of "use of uninitialized value $1 in uc".
> Removing the non-capturing code works though;

Yes, of course you are right. A lapse on my part.

Rob

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

Report this message