nkpgmartin has asked for the wisdom of the Perl Monks concerning the following question:

I'd like to do something like:
($mon, $tue, $wed, $thu, $fri, $sat, $sun) = split (/ /); $alldays = lc($mon $tue $wed $thu $fri $sat $sun); print "$alldays\n";
but it doesn't work. How can I change multiple strings to lower case at once?

Replies are listed 'Best First'.
Re: lower case multiple strings
by lemming (Priest) on Sep 27, 2001 at 23:51 UTC
    Why don't you just lowercase $_?
    lc; ($mon, $tue, $wed, $thu, $fri, $sat, $sun) = split (/ /); #if you stil +l need this
    mon-sun will all be lowercased, if you still want to you can just have $alldays = lc;. That is if your intent is to have the original string lowercased.
Re: lower case multiple strings
by arturo (Vicar) on Sep 27, 2001 at 23:58 UTC

    you want to process a number of things? Think foreach or map. You want to turn a bunch of things into a string with a common delimiter? Think join.

    But I'm not sure what you want to do: it looks like you start out with a (possibly mixed-case) string in $_ and want an all lower-case *string* ($alldays is a scalar) out, in which case

    $alldays = lc $_;
    oughta do you.

    But supposing you want that array for whatever reason: my $alldays = join " ", map { lc $_ } ($mon, $tue, $wed, $thu, $fri, $sat, $sun);

    the map lowercases each of the elements of the array, and the join puts a space in between each member of that array.

    perl -e 'print "How sweet does a rose smell? "; chomp ($n = <STDIN>); +$rose = "smells sweet to degree $n"; *other_name = *rose; print "$oth +er_name\n"'
Re: lower case multiple strings
by suaveant (Parson) on Sep 27, 2001 at 23:51 UTC
    yes... but this would be MUCH more straightforward...
    ($mon, $tue, $wed, $thu, $fri, $sat, $sun) = split " ", lc($_); $alldays = "$mon $tue $wed $thu $fri $sat $sun"; # Edit doh... forgot +to remove lc and () print "$alldays\n";
    or even
    $alldays = lc($_);
    the way you have it

    but to do multiple I would put them in a hash or array and do something similar to...

    @days = split (/ /); $alldays = join ' ', map { lc $_ } @days;
    or use a for loop... there are many things you can do

                    - Ant
                    - Some of my best work - Fish Dinner

Re: lower case multiple strings
by nkpgmartin (Sexton) on Sep 28, 2001 at 19:10 UTC
    my split statement actually goes more like this:
    ($s1, $s2, $s3, $mon, ... , $sun) = split (/ /);
    so $_ puts in too much information. I tried something like:
    ($s1,$s2, $s3, $mon, $tue, $wed, $thu, $fri, $sat, $sun) = split (/ /) +; $alldays = ($mon, $tue, $wed, $thu, $fri, $sat, $sun); $alldays2 = lc($alldays); print "$alldays2\n";
    which I think is quite long-winded but for some reason my output is just $fri.

      You might want to look at the join function

      join EXPR,LIST
      Joins the separate strings of LIST into a single string with fields separated by the value of EXPR, and returns that new string. Example:

      $rec = join(':', $login,$passwd,$uid,$gid,$gcos,$home,$shell);
      Beware that unlike "split", "join" doesn't take a pattern as its first argument. Compare the split entry elsewhere in this document.