Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

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

by stephen (Priest)
on Mar 16, 2001 at 01:34 UTC ( #64792=note: print w/ replies, xml ) Need Help??


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

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


Comment on Re: Why does this core? or How am I being a bonehead
Download Code
Re: Re: Why does this core? or How am I being a bonehead
by SparkeyG (Curate) on Mar 16, 2001 at 01:46 UTC
    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

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (3)
As of 2015-07-03 23:26 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (57 votes), past polls