Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?

Why does this core? or How am I being a bonehead

by SparkeyG (Curate)
on Mar 15, 2001 at 22:43 UTC ( [id://64747]=perlquestion: print w/replies, xml ) Need Help??

SparkeyG has asked for the wisdom of the Perl Monks concerning the following question:

This is completly humbling, but I haven't a clue why this is droping core.
@dataArr is 4 by x array, while @line is an array with the return of a Date::Manip::ParseRecur. What I want to do is take the 3rd element of the current line, parse it through ParseRecur, then create a larger array, one line for each date returned in @date. This is for easier sorting later in the program.
for (my $count=0; $count <= $#dataArr; $count++) { my (@date) = &ParseRecur($dataArr[$count][3], $base, $start, $stop +); foreach my $line (@date) { $bigArr[0 .. 2] = $dataArr[$count][0 .. 2]; $bigArr[3] = $line; $bigArr[4] = $dataArr[$count][4]; } }
I'll also be gratefull for a more elegant approach to my problem if one exsists.
Perl Bonehead

Replies are listed 'Best First'.
Re: Why does this core? or How am I being a bonehead
by stephen (Priest) on Mar 16, 2001 at 01:34 UTC
    Here's an attempt at a more elegant approach. I can't test it without sample data.
    foreach my $record ( @dataArr ) { my (@date) = &ParseRecur($record->[3], $base, $start, $stop); foreach my $line (@date) { @bigArr = ( @$record[0, 1, 2], $line, @$record[4] ); } }
    You might want to put it into a subroutine, and have it return @bigArr... not sure where that's being dealt with...


      Brother Stephan,

      Your solution in much more elegant than mine, and it works on my data-set.
      The one thing that I'd left out was that @bigArr will be a list-of-lists. The following references to $place, a temp var, and making the assignment into a anon array fixes that problem.

      my $place=0; foreach my $record ( @dataArr ) { my (@date) = &ParseRecur($record->[3], $base, $start, $stop); foreach my $line (@date) { $bigArr[$place] = [ @$record[0, 1, 2], $line, @$record[4] ]; $place++; } }


        Brother SparkeyG...

        How about this? (Minor change)

        my @bigArr = (); foreach my $record ( @dataArr ) { foreach my $line ( &ParseRecur($record->[3], $base, $start, $stop) + ) { push(@bigArr, [ @$record[0, 1, 2], $line, @$record[4] ]); } }
        As a general principle: using counting variables like $place can increase program complexity unnecessarily... if you're building a list it's best to use push.

        In the same spirit, I eliminated @date, since it's only used in one place.


Re: Why does this core? or How am I being a bonehead
by McD (Chaplain) on Mar 16, 2001 at 00:35 UTC
    I think I'm stumped too, but I'll offer this: the range operator in the second subscript makes me nervous:

    $bigArr[0 .. 2] = $dataArr[$count][0 .. 2];

    I'm not sure what context that gets evaulated in, but what you want is a list, I believe. If it's getting scalar by mistake, that could be trouble.

    So I'd try either wrapping it in parens, or explicitly using a list:

    $bigArr[0 .. 2] = $dataArr[$count][(0 .. 2)];


    $bigArr[0 .. 2] = $dataArr[$count][0,1,2];

    ...and see if that helped.


Re: Why does this core? or How am I being a bonehead
by enoch (Chaplain) on Mar 15, 2001 at 22:52 UTC
    The line:
    $bigArr[3] = $line;
    Doesn't do anything if the variable $line is supposed to be an array like you stated.
    Is this a typo, or is this causing your error?

      Sorry, typo
      $line is just a tmp var that holds one entry from @date. @data is an array that holds the return of ParseRecur.
      Bonehead Perl Programmer
        Oh, yea. I see that now, I just got confused there.
(tye)Re: Why does this core? or How am I being a bonehead
by tye (Sage) on Mar 18, 2001 at 14:03 UTC

    BTW, if this actually causes Perl to dump core, then there is a bug in Perl and it might be a good idea for you to report it (via the perlbug script which is included with Perl).

            - tye (but my friends call me "Tye")

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://64747]
Approved by root
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others admiring the Monastery: (4)
As of 2024-04-22 04:19 GMT
Find Nodes?
    Voting Booth?

    No recent polls found