Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Using a calculation to place locations

by Hasharray (Novice)
on May 07, 2013 at 13:45 UTC ( #1032485=perlquestion: print w/ replies, xml ) Need Help??
Hasharray has asked for the wisdom of the Perl Monks concerning the following question:

Good Day all. I am stuck with something. I am writing perl code that creates an XML file with alot of information. The one thing I need to do is to join points with a line, the XML code has an X and Y axle with which you just specify x=10 and y=11, this will create the point for location one. As this is completely dynamic, I do not want to hardcode the locations and instead want to create a has table or perhaps just a calculation to work out the next location. In other words I want to say
$X_initial = "80"; $Y_initial = "80";
So the first location for the first link will be at x80 and y80 but the following location should automatically use 80*2 and 80. In other words x160 and y80 and then the next 80 and 80*2 (x80 and y160) So the hash table should refer to using each only once and once it ahs reached the limit of the html display which could be 1138x638 it should create a new page and start from x80y80 again. here is an example of the how I write the XML using XML::Writer $writer->startTag("button", "name" => "foreshore", "label" => "Foreshore", "x" => "580", "y" => "528", "action" => "Active Zone"filter" => ", "target" => "_blank", "w" => "15", "h" => "15", "flash" => "false", "color" => "blue", "type" => "rounded"; So in essence I would like to replace the hardcoded "580" and "528" with the key that will auto select a location, but not reuse it. I hope it makes some sense.

Comment on Using a calculation to place locations
Select or Download Code
Re: Using a calculation to place locations
by kcott (Abbot) on May 07, 2013 at 14:16 UTC

    G'day Hasharray,

    Welcome to the monastery.

    This technique appears to do what you want.

    $ perl -Mstrict -Mwarnings -e ' my $X_initial = "80"; my $Y_initial = "80"; my $MAX_X = 240; my ($cur_x, $cur_y) = ($X_initial, $Y_initial); for (0 .. 20) { if ($cur_x > $MAX_X) { $cur_x = $X_initial; $cur_y += $Y_initial; print "\n"; } print " \t$_:$cur_x/$cur_y"; $cur_x += $X_initial; } print "\n"; ' 0:80/80 1:160/80 2:240/80 3:80/160 4:160/160 5:240/160 6:80/240 7:160/240 8:240/240 9:80/320 10:160/320 11:240/320 12:80/400 13:160/400 14:240/400 15:80/480 16:160/480 17:240/480 18:80/560 19:160/560 20:240/560

    I'll leave you to translate that into your XML-populating code.

    -- Ken

      Dude! You rock! Thanks a mill, really appreciate it!

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1032485]
Front-paged by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (8)
As of 2014-07-28 05:12 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (186 votes), past polls