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