5 our $VERSION = '0.7.0';
9 PSPP - Perl extension to PSPP
17 PSPP:: provides an interface to the libraries used by pspp to create
27 XSLoader::load('PSPP', $VERSION);
31 =head1 PROGRAMMER'S INTERFACE
33 The subroutines in this package return zero or unref on error.
34 When errors occur, a string describing the error is written
42 use constant { SYSMIS => -(POSIX::DBL_MAX),
43 PERL_EPOCH => 12219379200 # Number of seconds between
45 # and 14th October 1582
54 =head2 PSPP::Dict::new
56 Creates a new dictionary. This returned dictionary will be empty.
57 Returns undef on failure.
59 =head3 set_documents ($string)
61 Sets the documents (comments) to C<string>.
63 =head3 add_document ($string)
65 Appends C<string> to the documents.
67 =head3 clear_documents ()
69 Removes all documents.
71 =head3 set_weight ($var)
73 Sets the weighting variable to C<var>.
80 my $self = _dict_new ();
81 bless ($self, $class);
91 Contains constants used to denote variable format types.
92 The identifiers are the same as those used in pspp to denote formats.
93 For example C<PSPP::Fmt::F> defines floating point format, and
94 C<PSPP::Fmt::A> denotes string format.
98 # These must correspond to the values in src/data/format.h
144 =head3 new ($dict, $name, %input_fmt)
146 Creates and returns a new variable in the dictionary C<dict>. The
147 new variable will have the name C<name>.
148 The input format is set by the C<input_fmt> parameter
150 By default, the write and print formats are the same as the input format.
151 The write and print formats may be changed (See L</set_write_format>),
152 L</set_print_format>). The input format may not be changed after
153 the variable has been created.
154 If the variable cannot be created, undef is returned.
164 my $self = _dict_create_var ($dict, $name, \%format);
167 bless ($self, $class);
174 =head3 set_label ($label)
176 Sets the variable label to C<label>.
183 =head3 set_write_format (%fmt)
185 Sets the write format to C<fmt>. <fmt> is a hash containing the keys:
191 A constant denoting the format type. See L</PSPP::Fmt>.
195 An integer denoting the number of decimal places for the format.
199 An integer denoting the number of width of the format.
203 On error the subroutine returns zero.
211 _set_write_format ($var, \%format);
216 =head3 set_print_format (%fmt)
218 Sets the print format to C<fmt>.
219 On error the subroutine returns zero.
227 _set_print_format ($var, \%format);
232 =head3 set_output_format (%fmt)
234 Sets the write and print formats to C<fmt>. This is the same as
235 calling set_write_format followed by set_print_format.
236 On error the subroutine returns zero.
241 sub set_output_format
245 _set_output_format ($var, \%format);
250 =head3 clear_value_labels ()
252 Removes all value labels from the variable.
259 =head3 add_value_label ($key, $label)
261 Adds the value label C<label> to the variable for the value C<key>.
262 On error the subroutine returns zero.
264 =head3 add_value_labels (@array)
275 while ( @li = each %values )
277 if ( $var->add_value_label ($li[0], "$li[1]") )
288 =head3 set_value_labels ($key, $value)
290 C<Set_value_labels> is identical to calling L</clear_value_labels>
291 followed by L</add_value_labels>.
292 On error the subroutine returns zero.
300 $self->clear_value_labels () ;
301 $self->add_value_labels (%labels);
306 =head3 set_missing_values ($val1 [, $val2[, $val3] ])
308 Sets the missing values for the variable.
309 No more than three missing values may be specified.
314 package PSPP::Sysfile;
320 =head3 new ($filename, $dict [,%opts])
322 Creates a new system file from the dictionary C<dict>. The file will
323 be written to the file called C<filename>.
324 C<opt>, if specified, is a hash containing optional parameters for the
325 system file. Currently, the only supported parameter is
326 C<compress>. If C<compress> is non zero, then the system file written
327 will be in the compressed format.
328 On error, undef is returned.
331 =head3 append_case (@case)
333 Appends a case to the system file.
334 C<Case> is an array of scalars, each of which are the values of
335 the variables in the dictionary corresponding to the system file.
336 The special value C<PSPP::SYSMIS> may be used to indicate that a value
338 If the array contains less elements than variables in the dictionary,
339 remaining values will be set to system missing.
346 my $filename = shift;
350 my $self = _create_sysfile ($filename, $dict, $opts);
354 bless ($self, $class);
363 Closes the system file.
365 This subroutine closes the system file and flushes it to disk. No
366 further cases may be written once the file has been closed.
367 The system file will be automatically closed when it goes out of scope.
379 John Darrington, E<lt>john@darrington.wattle.id.auE<gt>
381 =head1 COPYRIGHT AND LICENSE
383 Copyright (C) 2007 by Free Software Foundation
385 This program is free software; you can redistribute it and/or
386 modify it under the terms of the GNU General Public License as
387 published by the Free Software Foundation; either version 2 of the
388 License, or (at your option) any later version.
390 This program is distributed in the hope that it will be useful, but
391 WITHOUT ANY WARRANTY; without even the implied warranty of
392 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
393 General Public License for more details.
395 You should have received a copy of the GNU General Public License
396 along with this program; if not, write to the Free Software
397 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA