X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=perl-module%2FExamples.pod;h=cb286ca19c12dbef9c6966888f4555d05da49c26;hb=HEAD;hp=fc3f016777dee06431fbb53a9dfaac40f74a269b;hpb=77612c9127e474daf7f06ba4dce7935b8eaf4052;p=pspp-builds.git diff --git a/perl-module/Examples.pod b/perl-module/Examples.pod index fc3f0167..cb286ca1 100644 --- a/perl-module/Examples.pod +++ b/perl-module/Examples.pod @@ -102,4 +102,45 @@ that it be correctly represented by pspp. $sysfile->close(); +=head2 Reading data + +Data can be read from a system file or other source: + + use PSPP; + + my $sf = PSPP::Reader->open ("foo.sav"); + + my $dict = $sf->get_dict (); + + +Once opened, the dictionary can be used like any other. + + for ($v = 0 ; $v < $dict->get_var_cnt() ; $v++) + { + my $var = $dict->get_var ($v); + + # Print the variables + my $name = $var->get_name (); + my $label = $var->get_label (); + print "Var: $name, Label: $label\n"; + + # Retrieve and print the value labels + my $vl = $var->get_value_labels (); + print "$_: $vl->{$_}\n" for keys %$vl; + } + + +Reading of data must be done sequentially using the C method. + + while (my $c = $sf->get_next_case () ) + { + my $v; + for ($v = 0; $v < $dict->get_var_cnt(); $v++) + { + print "val$v: @$c[$v] "; + } + print "\n"; + } + + =cut \ No newline at end of file