in reply to Declaring variables recursively

Yes, it's possible:

#!/usr/bin/perl my %variables = ( 'one' => 1, 'two' => 2 ); ${$_}=$variables{$_} for keys %variables; $\="\n"; $,=" : "; print $_, $$_ for keys %variables;
--------------
It's sad that a family can be torn apart by such a such a simple thing as a pack of wild dogs

Replies are listed 'Best First'.
Re^2: Declaring variables recursively
by sciarnold (Initiate) on Feb 25, 2005 at 15:26 UTC
    Thanks it works, but well.Now that I see that you are really monks in perl I will show my real problem. It is the following(besides that Im not good programming!!): I have a set of data like this: -90 120 -50 40 120 -180 -50 90 -90 45 ..., which are the (X,Y)coordinates of points in a 2d matrix. The thing is that I would like to sort this data in such a way that the order shows how close these points are from each other. The real objective behind it to make a contour plot from this points. So I have already the shape(points) in the 2d plot but now I want to connect them and have the contour. In fact I realised that regular programs draw lines between points in order of appeareance. So I got to the point of having to order them appropiately( or according to me by proximity). What do you suggest monks? -Arnold
      There are data structures well-suited to sorting two-dimensional points, and some have been implemented in perl. Check out Algorithm::QuadTree for example.

      For a contouring implementation PDL::Graphics::TriD::Contours might be worth a look.

      I'm not entirely positive I understand what you need here. You want the number sorted based on how close they are to... one another, or a central point on the grid? If you want to draw a line connecting them, it sounds like you need to start at one side, and go directly across the plane (left to right for simplicity sake). If that is the case you would want the list sorted based on the X cooridante in each pair. Beacuse these are pairs of numbers, it sounds like you should have an array of arrays (two dimensional array). To sort a two dimensional array based of the first of the two elements in the inner arrays:

      my(@sorted_array) = sort({$a->[0] <=> $b->[0]} @unsorted_array);

      See sort for details on using sort. See perlre for details on nested data structures.

      May the Force be with you
      I'm sure there's a module in CPAN that could help you do this. Try searching here.

      Or to go the stubborn route (or if this is homework ;) - I suggest looking into using nested datastructures such as arrays of arrays and so on, as suggested previously, which can be found here.
      --------------
      It's sad that a family can be torn apart by such a such a simple thing as a pack of wild dogs
        I found this module that is suposed to make "hashes" with duplicated keys... I think its CDB_File and related, but this is the "easy way", which nothing else work I can always use. I think I'll try the hard way, so i can learn something more for future problems with data manipulation, that for sure i'll have since Im a theoretian and work with simulations. Now I now in which direction to go(perhaps into more problems...Ha!!). Thanks again