Avatar of ventumsolve
ventumsolveFlag for Denmark

asked on 

advise on data-structure

I have to assign coordinates (right,left,top,bottom) to a number of objects residing in a 8 x 4 grid. First I wanted to create objects with get and set methods but cant find a way to name the objects the way I want to. I'm looping through the grid in two nested for-loops and wanted to create an object with the counter as an extension:
$asset_$counter = Asset->new();
That doesn't work because the variable-name is an address returned by the constructor.
So is this still the right way - OO? Would like that because it's handy. Or should I do something else .. e.g. creating a hash where each key points to an array of my values?

Perl

Avatar of undefined
Last Comment
ventumsolve
ASKER CERTIFIED SOLUTION
Avatar of Kim Ryan
Kim Ryan
Flag of Australia image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of ventumsolve
ventumsolve
Flag of Denmark image

ASKER

I'll give your idea  a closer look. Have found a way though to name my objects;
${asset.$counter} = Asset->new();
Avatar of Kim Ryan
Kim Ryan
Flag of Australia image

Yes that's good, I knew there was a way to get varaible  variable names. My though was that having a lot of objects a1, a2, a3 etc is a bit redundant as the properties are so limited, just cordinates. With the data strucutre you just have a list of points which is easy to access and expand.
SOLUTION
Avatar of Adam314
Adam314

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
Avatar of ventumsolve
ventumsolve
Flag of Denmark image

ASKER

I should have mentioned that the assets stored in the grid might span over several rows and/or columns (but always coherent). And assets might have common boundary so they might share a xy-coordinate that should be (top,bottom) for the one but (0,0) for the other. That's why the oo-idea struck me as an appropriate datastructure. Furthermore each asset has other attributes besides from the coordinates that has to be accessed on different occassions.
This is by the way a script that should build an xml-file for InDesign and the grid-parser that I'm working on should build an image-tag and a story-tag for each asset.
Since you both opt for the array-array-solution I'll give that a go today to see if I can make it work.
Avatar of Kim Ryan
Kim Ryan
Flag of Australia image

If you use an array of hashes, your hash can have as many properties as you want

$asset>{'left'} = 1;
$asset->{'top'} = 12;
$asset->{'prop_1'} = 'x';
etc  just add keys as you need them
SOLUTION
Avatar of David_Botham
David_Botham
Flag of United States of America image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
Avatar of ventumsolve
ventumsolve
Flag of Denmark image

ASKER

Thanx, went for the hash-way but nice to know what best-practice on OO-perl would be.
Perl
Perl

Perl is a high-level, general-purpose, interpreted, dynamic programming languages with over 25 years of development. Perl 5 runs on over 100 platforms from portables to mainframes and is suitable for both rapid prototyping and large-scale development projects. Perl gained widespread popularity as a Common Gateway Interface (CGI) scripting language, in part due to its regular expression and string parsing abilities. In addition to CGI, Perl is used for graphics programming, system administration, network programming, finance, bioinformatics, and other applications.

26K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo