in reply to Creating an image map using Perl code

This seems to work, although of course I have no idea what's in your data:
#!/usr/bin/perl my @x_points = ( 100, 200 ); my @y_points = ( 100, 200 ); my @radiuses = ( 50, 50 ); my @websites = qw( http://www.yahoo.com http://www.google.com ); print q( <IMG SRC="figure.gif" USEMAP="#mymap" width="400" height="400"> <MAP NAME="mymap"> ); for ( my $i = 0 ; $i < @x_points ; $i++ ) { print qq(<AREA SHAPE="circle" COORDS="$x_points[$i],$y_points[$i],$radiuses[$i]" HREF="$websites[$i]"> ); } print q(</MAP>);
This produces two circular links, centres at 100,100 and 200,200, with radius 50. Very roughly, something like this:
###################################################### # # # # # ###### # # ## ## # # # # # # # # <-yahoo # # # # # # ## ## # # ###### # # ###### # # ## ## # # # # # # # # <- google # # # # # # ## ## # # ###### # # # # # # # # # # # # # # # # # # # # # ######################################################
But what your code is crying out for is a nice little AoH containing all the data in a much better structure. Exercise for the reader etc.


($_='kkvvttuu bbooppuuiiffss qqffssmm iibbddllffss')
=~y~b-v~a-z~s; print

Replies are listed 'Best First'.
Re^2: Creating an image map using Perl code
by lampros21_7 (Scribe) on Apr 06, 2006 at 09:27 UTC
    Right, i have ran Cody Pendant's algorithm and it works. My algorithm has similar data but it gives the same errors:
    #!/usr/bin/perl use warnings; use strict; use DBIx::Simple; my $db = DBIx::Simple->connect('dbi:SQLite:dbname=mydatabase.db') or die DBIx::Simple->error; open (X_POINTS,"x_points.txt") || die "couldn't open the file!"; open (Y_POINTS,"y_points.txt") || die "couldn't open the file!"; # Insert all the x points in an array my @x_points = <X_POINTS>; # Insert all the y points in an array my @y_points = <Y_POINTS>; close(X_POINTS); close(Y_POINTS); print @x_points; print @y_points; my @webpages; my $webpage_no = 500; for (my $count=0; $count <= $webpage_no; $count++) { $webpages[$count] = $db->query("SELECT webpage FROM webpages_dat +a WHERE id = '$count'")->list; } print @webpages; print q(<IMG SRC="figure.gif" USEMAP="#mymap"> <MAP NAME="mymap"> ) for (my $secondcount=0; $secondcount <= $webpage_no; $secondcount++) +{ print qq(<AREA SHAPE=circle COORDS="$x_points[$secondcount],$y_po +ints[$secondcount],1" HREF="$webpages[$secondcount]">); } print q(</MAP>); ******************************************
    This is the complete code. The print statements work for the coordinates and the webpages so that's fine. The errors are:

    syntax error at image_map_gui.pl line 49, near "0;"

    syntax error at image_map_gui.pl line 49, near "++) "

    Execution of image_map_gui.pl aborted due to compilation errors. Can't really understand what's the problem here. If i comment out the JavaScript and the for loop bit it works fine but if i add those it gives the errors. Any ideas? thanks for your help

      You're missing a semicolon after your first print q(...) statement.
        Sorry, another silly mistake... Thanks for pointing that out.

        Now, is there a way to run this script? I have tried running it and then opening my picture from a browser but it doesn't work. I have also looked around and couldn't find anywhere that said how. Does anyone know?thanks