[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

web service for .sav file translation

From: Ben Pfaff
Subject: web service for .sav file translation
Date: Sun, 01 Feb 2009 22:10:54 -0800
User-agent: Gnus/5.11 (Gnus v5.11) Emacs/22.2 (gnu/linux)

I've noticed that a lot of users want to use PSPP just to
translate .sav files into other formats, because they don't have
SPSS available.  But sometimes it's hard for them to install PSPP
to do that.  So I've been working a little bit on a PSPP-based
web service that can do that without having to install any
special software.

Here is an alpha version:

It is pretty featureless, but it does work.

What do you think of this idea?

The code is simple:

#! /usr/bin/perl

use strict;
use warnings;

use CGI;
use PSPP;
use Digest::MD5;

$CGI::POST_MAX = 10 * 1024 * 1024;  # max 10 MB posts

my $q = new CGI;

if ($q->param('file')) {
    my $temp = $q->upload ('file');

    my $ctx = Digest::MD5->new;
    $ctx->addfile ($temp);
    my $digest = $ctx->hexdigest;
    my $file = "/home/www-pspp/input/$digest.sav";

    seek ($temp, 0, 0);
    open (FILE, '>', $file);
    my $s;
    while (sysread ($temp, $s, 4096)) {
        syswrite (FILE, $s);
    close FILE;

    my $reader = PSPP::Reader->open ($file);
    my $dict = $reader->get_dict ();
    print "Content-type: text/plain\r\n\r\n";
    while (my @case = $reader->get_next_case ()) {
        my @values;
        for (my $i = 0; $i < $dict->get_var_cnt (); $i++) {
            push (@values, PSPP::format_value ($case[$i], $dict->get_var ($i)));
        print join (',', @values), "\n";

Ben Pfaff

reply via email to

[Prev in Thread] Current Thread [Next in Thread]