| gif | history | intraday | java | news | objects | options | quote | soap | spots | tickers | weather | end of day | wddx |

Request:
 Chartdata
Sample Code:
 Coldfusion
 ASP
 JSP
 PHP
 Perl
 
Perl
The best examples of using WDDX with Perl are found at Codebits. We've modified one of their examples and combined it with a script using the LWP package (Lightweb web protocol - used to make server to server requests). We have not debugged this example, so if you find errors, email them immediately to FinWin Support.

Perl Example
 	#!/usr/bin/perl
	use WDDX;

	my(%pXML);
		 # Create a user agent object
         use LWP::UserAgent;
         $ua = new LWP::UserAgent;
         $ua->agent("AgentName/0.1 " . $ua->agent);

         # Create a request
         my $req = new HTTP::Request POST =>'http://www.finwin.com/processct/processchartdata.cfm';
         $req->content_type('application/x-www-form-urlencoded');
         $req->content('username=myusername&password=mypassword&id=1183&symbol=msft');

         # Pass request to the user agent and get a response back
         my $res = $ua->request($req);

         # Check the outcome of the response
         if ($res->is_success) {
             print $res->content;
         } else {
             print "Error retrieving content\n";}
To deserialize and output the WDDX packet found in the "$res" variable:
	
	$parser = new wddx();

	$parser->parsefile($res);
	
	$arrayRef = $parser->cfwddx('action' => 'wddx2perl'	);
	
	%hsh = %{@{$arrayRef}[0]};

	print "After the xml parsing:\n";
	
	# the hash (associative array) WDDXPROPERTIES has several values you can use.
	# They are RECORDCOUNT - number of records, FIELDCOUNT - number of columns, FIELDNAMES - the column names.
		
	print "Record Count = $hsh{'WDDXPROPERTIES'}{'RECORDCOUNT'}\n";
	print "Field Count  = $hsh{'WDDXPROPERTIES'}{'FIELDCOUNT'}\n";
	print "Field Names  = @{$hsh{'WDDXPROPERTIES'}{'FIELDNAMES'}}\n";
	print "The 2nd Field is named @{$hsh{'WDDXPROPERTIES'}{'FIELDNAMES'}}[1]\n\n";
	
	# to access the data, iterate through each row using the "RECORDCOUNT" 
	# Each column in the 
	
	for ($i = 0; $i < $hsh{'WDDXPROPERTIES'}{'RECORDCOUNT'}; $i++) 
	{
		for($ii = 0; $ii < $hsh{'WDDXPROPERTIES'}{'FIELDCOUNT'}; $ii++)
		{
			$thisfield	=  @{$hsh{'WDDXPROPERTIES'}{'FIELDNAMES'}}[$ii];
			
			print "\t $thisfield  IS  $hsh{$thisfield}[$i]\n";

		}
	}

	exit;


	

DTN Market Access
9110 West Dodge Road, Suite 200   Omaha, Nebraska 68114
Copyright 2010, All rights reserved