Tie::CharArray

Tie::CharArray module can access Perl scalars as arrays of characters.
Download

Tie::CharArray Ranking & Summary

Advertisement

  • Rating:
  • License:
  • Perl Artistic License
  • Price:
  • FREE
  • Publisher Name:
  • Ilmari Karonen
  • Publisher web site:
  • http://search.cpan.org/~iltzu/Tie-CharArray-1.00/CharArray.pm

Tie::CharArray Tags


Tie::CharArray Description

Tie::CharArray module can access Perl scalars as arrays of characters. Tie::CharArray module can access Perl scalars as arrays of characters.SYNOPSIS use Tie::CharArray; my $foobar = 'a string'; tie my @foo, 'Tie::CharArray', $foobar; $foo = 'A'; # $foobar = 'A string' push @foo, '!'; # $foobar = 'A string!' print "@foon"; # prints: A s t r i n g ! tie my @bar, 'Tie::CharArray::Ord', $foobar; $bar--; # $foobar = '@ string!' pop @bar; # $foobar = '@ string' print "@barn"; # prints: 64 32 115 116 114 105 110 103Alternative interface functions use Tie::CharArray qw( chars codes ); my $foobar = 'another string'; my $chars = chars $foobar; # arrayref in scalar context push @$chars, '?'; # $foobar = 'another string?' $_ += 2 for codes $foobar; # tied array in list context # $foobar = 'cpqvjgt"uvtkpiA' my @array = chars $foobar; # WARNING: @array isn't tied!In low-level programming languages such as C, and to some extent Java, strings are not primitive data types but arrays of characters, which in turn are treated as integers. This closely matches the internal representation of strings in the memory.Perl, on the other hand, abstracts such internal details away behind the concept of scalars, which can be treated as either strings or numbers, and appear as primitive types to the programmer. This often better matches the way people think about the data, which facilitates programming by making common high-level manipulation tasks trivial.Sometimes, though, the low-level view is better suited for the task at hand. Perl does offer functions such as ord()/chr(), pack()/unpack() and substr() that can be used to solve such tasks with reasonable efficiency. For someone used to the direct access to the internal representation offered by other languages, however, these functions may feel awkward. While this is often only a symptom of thinking in un-Perlish terms, sometimes being able to manipulate strings as character arrays really does simplify the code, making the intent more obvious by eliminating syntactic clutter.This module provides a way to manipulate Perl strings through tied arrays. The operations are implemented in terms of the aforementioned string manipulation functions, but the programmer normally need not be aware of this. As Perl has no primitive character type, two alternative representations are provided:Requirements:· Perl Requirements: · Perl


Tie::CharArray Related Software