use strict; use CGI; use WDDX; use Data::Dumper; my $q = new CGI; my $wddx = new WDDX; # get params my $report = $q->param('report'); # send request to josh's data service my $hashref = getData($report); #print Dumper($hashref); #print "\n\n"; my $type_sub = sub { my( $name, $row, $mode ) = @_; #print "$name--$row--$mode\n"; #$name =~ /wind/ and return "number"; }; my $wddx_obj = $wddx->hash2wddx( $hashref, $type_sub ); $WDDX::INDENT = " "; print $wddx->serialize( $wddx_obj ); exit; sub getData { # here's where we'll get various query params for ea report my $report = shift; # dummy value # return a hash w data structure my $data; open (FH,"/home/httpd/html/newdev2/wddx/ib_basics.txt") or die("Couldn't open: $!"); while () { if ($_ =~ /^"\@QUERY:(.*)"/) { my $query = $1; my $i = 0; my @keys = (); while () { last if /^"\@ENDQUERY"/; $_ =~ s/\r\n//; $_ =~ s/\"//g; # get the keys push(@keys,split(",",$_)) unless $i ne 0; # reset @values and get 'em my @values = (); push(@values,split(",",$_)) unless $i eq 0; # fill da hashes for(my $k = 0; $k <= $#keys; $k++) { $data->{$query}->{"r$i"}->{$keys[$k]} = $values[$k] unless $values[$k] eq ""; } # increment the row $i++ } } } close FH; return $data; } #### Unable to create object of type WDDX::3: Can't locate object method "new" via package "WDDX::3" (perhaps you forgot to load "WDDX::3"?) at (eval 4) line 1. at text2wddx.cgi line 42 #### #$name =~ /wind/ and return "number"; #### ### from sub hash2wddx my $var = eval "WDDX::\u$type->new( \$val )" or croak "Unable to create object of type WDDX::\u$type: " . _shift_blame( $@ ); $new_hash->{$name} = $var; next; ## sub continues #### Using perl 5.6.1 unless otherwise noted. Apache 1.3.27 unless otherwise noted. Redhat 7.1 unless otherwise noted.