Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > Data Dumper guidance

Reply
Thread Tools

Data Dumper guidance

 
 
Kasp
Guest
Posts: n/a
 
      11-13-2003
Hi Everyone,

Need some help in Data:umper.
What I want to do is sort this array (@arr) based on the first element of
the sub-arrays.
So I want finally is @sarr = ([3,2], [5,0], [6,3]);

Here is the code:
use Data:umper;
my @arr = ([5,0], [3,2], [6,3]);
print Data:umper->Dump(\@arr);
my @sarr = sort { $a <=> $b} @arr;
print Data:umper->Dump(\@sarr);

TIA
--



 
Reply With Quote
 
 
 
 
Andreas Kahari
Guest
Posts: n/a
 
      11-13-2003
In article <bova38$1j5p2l$(E-Mail Removed)-berlin.de>, Kasp wrote:
> Hi Everyone,
>
> Need some help in Data:umper.
> What I want to do is sort this array (@arr) based on the first element of
> the sub-arrays.
> So I want finally is @sarr = ([3,2], [5,0], [6,3]);



So, really this has nothing to do with Data:umper, but with
sorting.


> Here is the code:
> use Data:umper;
> my @arr = ([5,0], [3,2], [6,3]);
> print Data:umper->Dump(\@arr);
> my @sarr = sort { $a <=> $b} @arr;


That will sort on the array references in @arr.

You want this:
my @sarr = sort { $a->[0] <=> $b->[0]} @arr;



--
Andreas Kähäri
 
Reply With Quote
 
 
 
 
Kasp
Guest
Posts: n/a
 
      11-13-2003
> You want this:
> my @sarr = sort { $a->[0] <=> $b->[0]} @arr;


Thanks Andreas.

--



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Data::Dumper for Java? Sam Java 4 02-11-2011 06:59 PM
eval of Data::Dumper output not same as original data structure himanshu.garg@gmail.com Perl Misc 4 08-01-2007 01:49 PM
Installation of Data::Dumper Eric Perl 0 06-09-2005 02:25 PM
Data::Dumper and XML::Simple in Java rc Java 3 08-16-2004 09:51 AM
Data::Dumper How to quote keys while dumping kamal Perl 0 08-12-2003 05:23 AM



Advertisments