On Thu, 8 Sep 2011 09:55:33 -0700
Marc <sono...@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-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to