#!/usr/bin/perl

#--Try rewriting this for Ruby
#--Need to download Perl intepreter to use

use CGI;

# Get the 'q' parameter out of the incoming Query String
my $cgi = new CGI();
my $q = $cgi->param('to');

# Our limited 'database' contains a few users
# with their username and full name
my @data = (
	{
		user => "amon",
		name => "N. Equalist"
	},
	{
		user => "android18",
		name => "Bad Ass"
	},
	{
		user => "ayeka",
		name => "Crown Princess of the Imperial Family of Jurai"
	},
	{
		user => "gaara",
		name => "Sandy"
	},
	{
		user => "goku",
		name => "Kakarot"
	},
	{
		user => "hiruma",
		name => "Yoichi Hiruma"
	},
	{
		user => "naruto",
		name => "The next Hokage"
	},
	{
		user => "rockLee",
		name => "Rock Lee"
	},
	{
		user => "ryoko",
		name => "Space Pirate Ryoko"
	},
	{
		user => "sakura",
		name => "S&S Forever"
	},
	{
		user => "sasuke",
		name => "Sasuke Uchiha"
	},
	{
		user => "vegeta",
		name => "Saiyan Prince"
	}
);

# Make sure that we print out the correct HTML header
print "Content-type: text/html\n\n";

# Now we "search" through the data
foreach my $row (@data) {

	# Looking for users that match our auto-complete search
	if ( $row->{user} =~ /$q/i || $row->{name} =~ /$q/i ){

		# If the user matches, print our the necessary HTML
		print qq~<li id="$row->{user}">
			<img src="icons/$row->{user}.png"/>
			<div>
				<span id="username">$row->{user}</span>
				<span id="fullname">$row->{name}</span>
			</div>
		</li>~;
	}
}