Note that there are some explanatory texts on larger screens.

plurals
  1. POI can't seem to dereference an array correctly
    primarykey
    data
    text
    <p>I'm not very adept at Perl, but I need to be able to do a sort on a multi-dimension array. I've been playing with some test code to try and get a better grasp on the concept, and I think I'm getting close, but I can't find the magic combination.</p> <p>What I can't seem to do is dereference my arrays and get them to print correctly. I can seem to get just about everything in the world I need to know about these refrences except for the values in the arrays being referenced.</p> <p>I'm getting my data from a tab-delimited flat file, so in my sample code, I'm mimicking that by creating multiple arrays via splits and then pushing them in to a single array. In practice, I'll be looping through the file, splitting on the tabs and pushing them in to the array as I go.</p> <p>If there is a better way of going about this, I'm all ears. Each line in the flat file is a single record. I need to first sort by a date to get the oldest records to the top, and then do a secondary sort to group records by acct number. I've looked at several examples online, but not found anything that seems to work with the data I need to mimick.</p> <pre><code>my @s1 = split(/:/, 'X:Y:Z'); my @s2 = split(/:/, 'A:B:C'); my @s3 = split(/:/, 'Q:L:P:0'); my @s4 = split(/:/, 'U:E:G'); my @array = (); push(@array, \@s1); push(@array, \@s2); push(@array, \@s3); push(@array, \@s4); print "@array\n"; my @sorted = sort { $a-&gt;[0] cmp $b-&gt;[0] } @array; print "\n"; foreach $thingy (@sorted) { print @thingy . "\n"; #result: number 0 print $thingy . "\n"; #result: reference #print ${$thingy} . "\n"; #result: 'Not a scalar reference' error print ${@thingy} . "\n"; #result: file name (???) print @{$thingy} . "\n"; #result: length of the array referenced } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload