in reply to slurped scalar map
sub new_accessor { my $start = $_[0]; my $end = $_[1]; my $data_ref = \$_[2]; # Avoid making a copy. return sub { return substr($$data_ref, $start, $end-$start); }; } { my $data = ...; my $start1 = ...; # Calculate start from map. my $end1 = ...; # Calculate end from map. my $rec1 = new_accessor($start1, $end1, $data); print($rec1->(), "\n"); }
tie would allow you to do the same, but you'd use
print($rec1, "\n");
instead of
print($rec1->(), "\n");
Untested.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: slurped scalar map
by 0xbeef (Hermit) on Jun 20, 2006 at 15:13 UTC | |
by ikegami (Patriarch) on Jun 20, 2006 at 16:35 UTC | |
by BrowserUk (Patriarch) on Jun 20, 2006 at 18:23 UTC |