1Char(3)               User Contributed Perl Documentation              Char(3)
2
3
4

NAME

6       PDL::Char -- PDL subclass which allows reading and writing of
7       fixed-length character strings as byte PDLs
8

SYNOPSIS

10        use PDL;
11        use PDL::Char;
12
13        my $pchar = PDL::Char->new( [['abc', 'def', 'ghi'],['jkl', 'mno', 'pqr']] );
14
15        $pchar->setstr(1,0,'foo');
16
17        print $pchar; # 'string' bound to "", perl stringify function
18        # Prints:
19        # [
20        #  ['abc' 'foo' 'ghi']
21        #  ['jkl' 'mno' 'pqr']
22        # ]
23
24        print $pchar->atstr(2,0);
25        # Prints:
26        # ghi
27

DESCRIPTION

29       This subclass of PDL allows one to manipulate PDLs of 'byte' type as if
30       they were made of fixed length strings, not just numbers.
31
32       This type of behavior is useful when you want to work with charactar
33       grids.  The indexing is done on a string level and not a character
34       level for the 'setstr' and 'atstr' commands.
35
36       This module is in particular useful for writing NetCDF files that
37       include character data using the PDL::NetCDF module.
38

FUNCTIONS

40       new
41
42       Function to create a byte PDL from a string, list of strings, list of
43       list of strings, etc.
44
45        # create a new PDL::Char from a perl array of strings
46        $strpdl = PDL::Char->new( ['abc', 'def', 'ghij'] );
47
48        # Convert a PDL of type 'byte' to a PDL::Char
49        $strpdl1 = PDL::Char->new (sequence (byte, 4, 5)+99);
50
51        $pdlchar3d = PDL::Char->new([['abc','def','ghi'],['jkl', 'mno', 'pqr']]);
52
53       string
54
55       Function to print a character PDL (created by 'char') in a pretty for‐
56       mat.
57
58        $char = PDL::Char->new( [['abc', 'def', 'ghi'], ['jkl', 'mno', 'pqr']] );
59        print $char; # 'string' bound to "", perl stringify function
60        # Prints:
61        # [
62        #  ['abc' 'def' 'ghi']
63        #  ['jkl' 'mno' 'pqr']
64        # ]
65
66        # 'string' is overloaded to the "" operator, so:
67        # print $char;
68        # should have the same effect.
69
70       setstr
71
72       Function to set one string value in a character PDL.  The input posi‐
73       tion is the position of the string, not a character in the string.  The
74       first dimension is assumed to be the length of the string.
75
76       The input string will be null-padded if the string is shorter than the
77       first dimension of the PDL.  It will be truncated if it is longer.
78
79        $char = PDL::Char->new( [['abc', 'def', 'ghi'], ['jkl', 'mno', 'pqr']] );
80        $char->setstr(0,1, 'foobar');
81        print $char; # 'string' bound to "", perl stringify function
82        # Prints:
83        # [
84        #  ['abc' 'def' 'ghi']
85        #  ['foo' 'mno' 'pqr']
86        # ]
87        $char->setstr(2,1, 'f');
88        print $char; # 'string' bound to "", perl stringify function
89        # Prints:
90        # [
91        #  ['abc' 'def' 'ghi']
92        #  ['foo' 'mno' 'f']      -> note that this 'f' is stored "f\0\0"
93        # ]
94
95       atstr
96
97       Function to fetch one string value from a PDL::Char type PDL, given a
98       position within the PDL.  The input position of the string, not a char‐
99       acter in the string.  The length of the input string is the implied
100       first dimension.
101
102        $char = PDL::Char->new( [['abc', 'def', 'ghi'], ['jkl', 'mno', 'pqr']] );
103        print $char->atstr(0,1);
104        # Prints:
105        # jkl
106
107
108
109perl v5.8.8                       2002-05-21                           Char(3)
Impressum