Help for this page

Select Code to Download


  1. or download this
    s/(old)/preserve_case("new", $1)/ieg;
    
    ...
      my $mask = $from & (' ' x length($from));
      return uc($to) | $mask;
    }
    
  2. or download this
    # requires $" hasn't been altered
    #       123456789_123456789_12345678 = 28
    sub pc {uc$_[0]|$_[1]&$"x length pop}
    
  3. or download this
    sub preserve_case {
      my ($to, $from) = @_;
    ...
      my $mask = join '', map /\w/ ? $_ & ' ' : "\0", split //, $from;
      return uc($to) | $mask;
    }
    
  4. or download this
    (my $mask = $from) =~ s/(\w)|./ $1 ? $1 & ' ' : "\0" /egs;
    
  5. or download this
    # requires $" hasn't been altered
    #       123456789_123456789_123456789_123456789_123456789_ = 50
    sub pc {(my$x=pop)=~s/(\w)|./$1?$1&' ':"\0"/egs;uc$_[0]|$x}
    
  6. or download this
    sub preserve_case {
      my ($to, $from) = @_;
    ...
    
      return uc($to) | $mask;
    }
    
  7. or download this
    sub preserve_case {
      my ($to, $from) = @_;
    ...
    
      return uc($to) | ($from ^ uc $from);
    }