in reply to Re^2: Working through it...
in thread Working through it...

Using the @ was causing errors for me

Right. Array elements and hash values can only be scalars. What do you expect $currVar[$arrayKey[$i]] to contain?

But i'm trying to learn HOW to do this at the same time.

I've been writing Perl 5 professionally since 1998. I probably could write robust XML parsers in multiple languages, but I never do because it's really not worth the time getting things right. I'm sure I'd learn a few things doing it even with my experience, but that's not worth it either, because parsing XML is tricky.

You're just learning how to use arrays and hashes in Perl. You've already spent several days getting this far; expect to spend at least that long figuring out robust parsing of the XML you've shown. Your reach exceeds your grasp, which is not a bad thing, but you've chosen a particularly pernicious task to learn.

I don't mean to discourage you from learning. Certainly you have a lot to admire in sticking with this task—but what you'll learn by using a module in this case is very much more valuable right now at your level of Perl understanding than all the work necessary to make a robust XML parser.

Improve your skills with Modern Perl: the free book.

Replies are listed 'Best First'.
Re^4: Working through it...
by Inexistence (Acolyte) on Sep 11, 2011 at 21:14 UTC

    Peace and love :)

    Quote "You're just learning how to use arrays and hashes in Perl. You've already spent several days getting this far; expect to spend at least that long figuring out robust parsing of the XML you've shown. Your reach exceeds your grasp, which is not a bad thing, but you've chosen a particularly pernicious task to learn"

    I know i'm hitting my head against a wall... But if I don't, i'll put the books away and start playing WoW again :P I've got some recommended books to read, that aren't beginner, but intermediate. I'll spend days or months till I start hammering out working code. I love coding, or even the attempt. When I eventually manage to hammer out something working, something 'signature me', I smile inside :) I was just hired into an internet company, with hours that will allow me to code a lot and still earn enough to live, plus they're giving me a new laptop :) (Obviously i'm not coding for them though)

Re^4: Working through it...
by Inexistence (Acolyte) on Sep 11, 2011 at 22:35 UTC
    What do you expect $currVar[$arrayKey[$i]] to contain?

    I'm not sure how to explain it in perl terms, but i'll try. I'm trying to self reference the variable to a different depth within itself

    @myarray=(); $currVar=\$myarray; $currVar=\$currVar[TableDepth1name]; $currVar=\$currVar[TableDepth2name];

    Thus, $currVar should equal the value of

    $myarray[TableDepth1name][TableDepth2name]

    I've managed to build it, even Dumper it and it shows up correctly, but the data is always missing

      @myarray=();

      You should probably use my @myarray; instead.

      $currVar=\$myarray;

      $myarray has nothing to do with @myarray.

      $currVar=\$currVar[TableDepth1name];

      You're taking a reference to the value stored in the array at that position. Because you're trying to build an array of arrays, the value stored in the array at that position is itself an array reference.

      $currVar=\$currVar[TableDepth2name];

      ... and this is where things go really weird, because you're trying to treat a reference to an array reference as an array, and then take a reference to whatever Perl happens to autovivify at that position.

      If you want the value in $myarray[TableDepth1name][TableDepth2name], write:

      my $value = $myarray[TableDepth1name][TableDepth2name];

      It's that easy if TableDepth1name and TableDepth2name are constants or functions which return valid indexes for the array of arrays reachable through $myarray. My guess is that they're not, and that you're not using strict and warnings, and Perl's doing its best to try to guess what you mean.

      As I've mentioned before, you really need to get the hang of nested data structures before you go any further, because this is not the sort of thing that anyone can just throw together random syntactic elements and get the right results. It's one of the weirdest corners of Perl 5 and it takes some practice, but it has a logic and a consistency despite its quirks.

      Improve your skills with Modern Perl: the free book.

        Thank-you for the info, mucho appreciated. I sorta figured out the reference to reference thing from the code errors I've fumbled my way into having it nearly functional after plenty more hours :) As much as i've hated strict, i'm using it now. So many more errors of course, but in the end it must be the better way to do it (versus as you said, perl guessing what to do) Thank-you again :) Cheers!
        There isn't in existence