School Assignment? Project Due Tomorrow? Chat LIVE With A Programming Expert!

Welcome to Dream.In.Code
Become an Expert!

Join 307,119 Programmers for FREE! Get instant access to thousands of experts, tutorials, code snippets, and more! There are 1,959 people online right now. Registration is fast and FREE... Join Now!




Perl storing records into array and accessing them! ERROR :-o

 

Perl storing records into array and accessing them! ERROR :-o, PLEASE HELP!

arun10427

24 Oct, 2009 - 12:20 PM
Post #1

New D.I.C Head
*

Joined: 24 Oct, 2009
Posts: 1

Hi all,

I am a perl newbie. I am using a perl code to read a column full of data from a DBF file from 1 field into an array. It contains dates in it. I need to traverse the records and check if the dates are consecutive. If the count of consecutive dates are less than 10, I will discard it. Array accessing is so confusing. I dont need exact code, But any direction would help

CODE
for(my $i=2;$i<table->last_record;$i++)
my @data = $table->get_record($i,"Date");




Now for example if my @data[1] consists of list of numbers, I need to find the diff between current record and prev record till it reaches the end of array.. Perl has such complex way of array accessing, I donno how to do $data[$i]-$data[$i-1]

This post has been edited by arun10427: 24 Oct, 2009 - 12:21 PM

User is offlineProfile CardPM
+Quote Post


brds

RE: Perl Storing Records Into Array And Accessing Them! ERROR :-o

28 Oct, 2009 - 09:14 AM
Post #2

D.I.C Regular
***

Joined: 22 Oct, 2008
Posts: 443



Thanked: 36 times
My Contributions
QUOTE(arun10427 @ 24 Oct, 2009 - 02:20 PM) *

Now for example if my @data[1] consists of list of numbers, I need to find the diff between current record and prev record till it reaches the end of array.. Perl has such complex way of array accessing, I donno how to do $data[$i]-$data[$i-1]


You just did it! mad.gif

CODE

my(@data, $diff, $i);

@data = (1, 5, 3, 8, 9, 4, 2, 6, 0, 7);

for($i = 0; $i < $#data; $i++) {
        $diff = $data[$i] - $data[$i + 1];
        print "$diff \n";
}

User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic

Time is now: 11/21/09 01:39PM

Live Help!

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter Fan Us On Facebook

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month