in reply to dereference array

timestamps is a hash containing at least one element that is an array reference. The array reference contains 5 elements containing array references. That is a horrible way to describe the structure so lets look at some code ways of dealing with it

use strict; use warnings; my %timestamps = ( x => [ ['2013-08-18T20:43:40Z'], ['2013-08-18T20:43:12Z'], ] ); my $page = 'x'; my @edits = @{$timestamps{$page}}; for my $stamps (@edits) { for my $stamp (@$stamps) { print "a: $stamp\n"; } } print "b: $edits[0][0]\n"; print "b: $edits[1][0]\n"; print "c: $timestamps{x}[0][0]\n"; print "c: $timestamps{x}[1][0]\n";

Prints:

a: 2013-08-18T20:43:40Z a: 2013-08-18T20:43:12Z b: 2013-08-18T20:43:40Z b: 2013-08-18T20:43:12Z c: 2013-08-18T20:43:40Z c: 2013-08-18T20:43:12Z

I've only populated two of the time stamps, but that should serve to see how things hand together. Note the {} to access the hash elements and the [] to access the array elements, and that you can concatenate them as you like for whatever structure you have.

True laziness is hard work

Replies are listed 'Best First'.
Re^2: dereference array
by natxo (Scribe) on Dec 03, 2013 at 13:50 UTC
    I absolutely agree with you that this is a horrible way to get the structure.

    The original problem was getting the recent changes from a mediawiki site. I use the excellent mod:MediaWiki::Bot module to retrieve the info using the Mediawiki API.

    What you get is then an array of hashes with this structure:

    $VAR50 = { 'revid' => 174, 'ns' => 0, 'comment' => '', 'timestamp' => '2013-04-01T12:30:28Z', 'user' => 'user', 'title' => 'page title', 'type' => 'edit', 'pageid' => 50, 'old_revid' => 173, 'rcid' => 180 };
    But I then need to put it all together per user: pages edited, number of edits, etc. It would be much easier if I had database access but that is a no-no Thanks for taking the time to look into this.

      Have you looked at DBD::SQLite? It's completely stand alone - just install the module and you've got the whole thing. Maybe the advice in Yes, even you can use CPAN may help too?

      True laziness is hard work
        That is something I had not thought of, self contained sql. Nice, I'll look into it.