in reply to Re: Are strings lists of characters?
in thread Are strings lists of characters?
Example:package StringArray; require Tie::Array; use base 'Tie::Array'; sub TIEARRAY { bless $_[1], $_[0] } sub FETCH { substr(${$_[0]}, $_[1], 1) } sub STORE { substr(${$_[0]}, $_[1], 1) = $_[2] } sub FETCHSIZE { length(${$_[0]}) } sub STORESIZE { $$self = substr(${$_[0]}, 0, $_[1]) } sub DELETE { substr(${$_[0]}, $_[1], 1) = '' } 1;
#!perl -w use StringArray; use strict; my $test = "Hello dolly"; my @testa; tie @testa, 'StringArray', \$test; print "\$#testa = $#testa\n"; print "testa[1] = $testa[1]\n"; $testa[1] = 'b'; print "testa[1] = $testa[1]\n"; map {$_ = uc $_} @testa; print "after map: test = $test\n"; delete $testa[1]; print "after delete: test = $test\n"; push @testa, "C"; print "after push: test = $test\n";
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: Are strings lists of characters?
by Aristotle (Chancellor) on Oct 29, 2002 at 22:52 UTC |