It's natural that you want to use uc like that.

First method - Call some methods on native types

You can use autobox for this in the following manner:

2 package MyArray; 3 use base qw(autobox); 4 sub uc { return map { uc } @{$_[0]}; }; 5 6 7 package MyString; 8 use base qw(autobox); 9 10 sub split { [ split $_[1], $_[0] ] ; }; 11 12 13 package main; 14 15 16 use autobox ARRAY => 'MyArray'; 17 use autobox STRING => 'MyString'; 18 use feature 'say'; 19 20 say "one:two:three:four"->split(':')->uc();

or shorter:

1 2 use feature 'say'; 3 use autobox ; 4 5 sub ARRAY::uc { return map { uc } @{$_[0]}; }; 6 sub SCALAR::split { [ split $_[1], $_[0] ] ; }; 7 8 9 say "one:two:three:four"->split(':')->uc();

Second method - Overriding the CORE method uc

This is simple , you just make up your own new method and you replace the one from CORE with your own in the BEGIN block

1 2 3 use feature 'say'; 4 5 sub new_uc { 6 @_ > 1 7 ? map { uc } @_ 8 : uc $_[0] ; 9 } 10 11 BEGIN { 12 *CORE::GLOBAL::uc = *new_uc; 13 } 14 15 say uc split(':',"one:two:three:four"); 16 17 my $w = uc "a"; 18 say $w;

By writing new_uc like that you assure that it will work as the old uc for scalars and in the new way for arrays

P.S. : There would be a third method .. to get into the Perl C sources in file pp.c at line 3620 and modify PP(pp_uc) so that it will behave as it should. Unfortunately that would require also reading av.c to understand how the arrays work , and reading or guessing what all of the macros do. Btw , has anyone else tried this before ? How in God's name do you start understanding those sources ?


In reply to Re: pipe one function output to another by spx2
in thread pipe one function output to another by bob_dobalina

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.