Slash Boxes
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

use Perl Log In

Log In

[ Create a new account ]

Ovid (2709)

  (email not shown publicly)
AOL IM: ovidperl (Add Buddy, Send Message)

Stuff with the Perl Foundation. A couple of patches in the Perl core. A few CPAN modules. That about sums it up.

Journal of Ovid (2709)

Sunday January 11, 2009
07:09 PM

Implementing .trim in Perl 6

[ #38261 ]

Today I really started to dig into Perl 6 and PIR. With some excellent IRC handholding from moritz++, I submitted a patch with the following code:

.sub 'trim' :method :multi(_)
    .local string s
    .local int start, end, temp, len
    .local int not_whitespace
    s = self
    start = 0
    end = length s
    if end == 0 goto donetail
    not_whitespace = is_cclass 32, s, start
    unless not_whitespace goto done
    inc start
    goto loop
    temp = end
    dec temp
    not_whitespace = is_cclass 32, s, temp
    unless not_whitespace goto donetail
    end = temp
    goto tail
    len = end - start
    s = substr s, start, len

It has some problems with the confusing double-negative and the magic number, but I've asked about this on the list. Aside from tests, documentation and some sample Perl 6 code (in Pugs), this will be my first "real" patch to Perl 6. I expect it won't get accepted as this is my first stab at it, but it made me feel good to finally get in and see what's going on.

The biggest obstacle? Remembering that this is high-level assembler and combining multiple statements doesn't work.

Update: Ah, sheesh. The 'not_whitepace' should be 'is_whitespace'. Patch resent.

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
More | Login | Reply
Loading... please wait.