Skip to content

Instantly share code, notes, and snippets.

@kamipo
Created March 12, 2010 13:59
Show Gist options
  • Save kamipo/330317 to your computer and use it in GitHub Desktop.
Save kamipo/330317 to your computer and use it in GitHub Desktop.
#!/usr/bin/perl
package string;
use overload '""' => sub { ${$_[0]} };
sub __ : method : lvalue { substr(${$_[0]}, $_[1], $_[2]) }
package main;
use Data::Dump qw/dump/;
sub p { print dump(@_), "\n" }
sub _ { local $_ = $_[0]; bless \$_, 'string' }
p "practice 1";
$se = _"google";
p $se_ar = [$se, $se];
$se = _"yahoo";
p $se_ar;
p "practice 2";
$se = _"google";
p $se_ar = [$se, $se];
(__$se(0, 6)) = _"yahoo";
p $se_ar;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment