Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

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

by SparkeyG (Curate)
on Mar 15, 2001 at 22:43 UTC ( #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.
--SparkeyG
Perl Bonehead

Comment on Why does this core? or How am I being a bonehead
Select or Download Code
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?

    Jeremy
      Sorry, typo
      $line is just a tmp var that holds one entry from @date. @data is an array that holds the return of ParseRecur.
      --SparkeyG
      Bonehead Perl Programmer
        Oh, yea. I see that now, I just got confused there.
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)];

    or

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

    ...and see if that helped.

    Peace,
    -McD

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...

    stephen

      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++; } }

      --SparkeyG

        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] ]); } }
        <PEDANTIC>
        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.
        </PEDANTIC>

        stephen

(tye)Re: Why does this core? or How am I being a bonehead
by tye (Cardinal) 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?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (12)
As of 2014-09-17 09:11 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (70 votes), past polls