Not that Perl would be lacking string manipulation facilities, but this new feature proposal for (allegedly) perl5.10 simply cries for rubyisms::String:
use autobox SCALAR => 'rubyisms::String';
print " bla "->strip;
my $foo = "bAR";
$foo->capitalizeI;
print $foo;
Due to different lexer rules in Ruby I had to find a different nomenclature for string.strip! so I chose $string->stripI with 'I' being mnemonic for 'in-place' while maintaining some visual similarity to '!'.
So far done are capitalize, capitalizeI, strip, stripI and center. This will take another couple of days since it's being done in XS. After that I can finally run some benchmarks and see whether the XS approach makes up for some of the performance hits introduced by autobox (which I haven't yet benchmarked, either, so they might not even be severe at all).
For those being adventurous enough (and curious about how it feels like to have everything act like an object), grab perl5.8.1-RC4 and autobox from the CPAN, apply the patch, compile and have FUNNNNNN!
See CPAN (Score:3, Interesting)
Rather than using method vs methodI, I chose to use context to determine whether or not the receiver was modified, which seemed more Perlish.
Reply to This
Re:See CPAN (Score:2, Insightful)
string.strip!.capitalize!in Ruby (that is, willstringbe capitalized and stripped in-place? If so, can this be done with autobox at all?)The main problem here is to determine whether something feels Perlish or not: Perl so far had no primitive objects and subsequentl
Scalar::Properties does some of that (Score:1)
Seems to do some of what you propose.
ObPlug.
Marcel
Re:Scalar::Properties does some of that (Score:1)
autoboxon the other hand wont ever bless something. It invokes the method directly on the primitives (and thus wont suffer from the slowdown caused by blessed referents). Btw, it is lexically scoped, so it can be turned on and off selectively for blocks.Secondly,
Scalar::Propertiescomes with its own methods whereauModule name (Score:2, Insightful)
Re:Module name (Score:1)
rubyisms::Stringvery much either...I chose it because of Simon Cozen'srubyismsmodule.Hmmh, is there a rule that lexically scoped module usage has to relate to pragmata? I just implemented the import() and unimport() semantics that allow
use String::Ruby;
print "foo"->center(10);
{