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

When I do a tr///, for upper casing the present value of $_, it caps the whole line. What I need it to do is, cap to a certin point, like a period (.)
Does anyone have any clues. The help would be greatly appreciated.
Thanks
Bobby

Replies are listed 'Best First'.
Re: TRing part of a line
by Zaxo (Archbishop) on Sep 26, 2002 at 19:01 UTC
    substr( $_, 0, index( $_, '.')) =~ tr/a-z/A-Z/; or better,
    substr $_, 0, index( $_, '.'), uc( substr $_, 0, index( $_, '.'));

    After Compline,
    Zaxo

Re: TRing part of a line
by fglock (Vicar) on Sep 26, 2002 at 19:03 UTC

    Here it goes again:

    $_ ="abc.def"; s/(.*?\.)/\U$1/; print;

    output:

    ABC.def

    note: tr doesn't work well with international character sets - use \U or uc() instead.

Re: TRing part of a line
by sauoq (Abbot) on Sep 26, 2002 at 19:03 UTC

    Don't use tr///. Use s/// with a /e modifier and uc().

    perl -le '$_="cap this. not this."; s/([^.]*)/uc $1/e; print'
    -sauoq
    "My two cents aren't worth a dime.";
    
Re: TRing part of a line
by fglock (Vicar) on Sep 26, 2002 at 18:51 UTC

    This snippet works:

    $_ = "abcdef"; substr($_,0,3) =~ tr/a-z/A-Z/; print;

    output:

    ABCdef

    update: using $_ instead of $a

      I need to control where the period will show. Because the text is varied in length from one line to the next.
      Bobby