Go4Expert

Go4Expert (http://www.go4expert.com/)
-   Perl (http://www.go4expert.com/forums/perl/)
-   -   need help with a function in a perl file (http://www.go4expert.com/forums/help-function-perl-file-t24452/)

topsy99 9Jan2011 12:00

need help with a function in a perl file
 
I use a perl program to carry out functions and need a function added to the program.

this function is to add up numbers on each pass when a selected search is reached. is there any one that can help.
i can paste the program .

chorny 28Jan2011 17:26

Re: need help with a function in a perl file
 
Do you have problems with Perl or with algorithm?

topsy99 3Apr2011 15:44

Re: need help with a function in a perl file
 
I have a perl program that i need a function added to . it was written by my son-in-law and now needs an additional function. i have not been able to get the function added.
i have been using gw-basic to carry out the task manually but this is laborious and my hands dont type as well these days.
the perl program does a search of htm files and prints and saves results. i need it to do a tally during the passing through the data and storing the outcome into the txt file outcome. i can provide / past both gwbasic function and the perl file if it would help.
(i'm sure it would help)
sorry i missed your reply to my query. hope you are still there.

chorny 4Apr2011 05:38

Re: need help with a function in a perl file
 
Yes, I'll need both of then, possibly with explanation of algorithms if comments are missing.

topsy99 4Apr2011 05:43

Re: need help with a function in a perl file
 
10 input "filename";me$
20 dim x$(3900),a$(4900)
30 input "search name or XXX to end";s$
40 r(i)=0
50 if s$="XXX" then END
60 open "i",#1,me$
70 if eof(1) then 230
80 input#1,a$(i)
90 q=q+1
100 if left$(a$(i),len(s$)) <> s$ then 220
110 print a$(i),q
120 x$= right$(a$(i),1)
130 j=val(x$)
140 y$=right$(a$(i),2)
145 e=e+1
150 z=val(y$)
160 if z>0 then z=9-z
170 j=9-j
180 if j = 9 then j = 0
190 r(i) = r(i) +j+z
200 print r(i),e
210 n = n+1
220 goto 70
230 close#1
235 e = 0
240 goto 30

topsy99 4Apr2011 05:53

Re: need help with a function in a perl file
 
that was the gw basic algorithm it inputs data from horse.dat under a$(i) and at the end of the name is a number for each name appearance it adds the numbers by subtracting from 9 e.g. where the name ends with 5 it subtracts 9-5 which is 4 this is stored in another variable and the final total is printed at the end after the horse name. there is also a test for a value at the 2nd last character in the name if there is an a on the end. e.g. )7a is tested for a value at the second last character.
sample data "pepinello(good)(1200)(belmont)27-09-98)7" other sample
"naughty boy(2150)(good)(oakbank)13-03-10)7a"

i will post part of the perl file in another post.

topsy99 4Apr2011 05:56

Re: need help with a function in a perl file
 
chorny can i email the perl program to you it is a bit long for the post but is only about 80 lines.
regards

topsy99 7Apr2011 18:19

Re: need help with a function in a perl file
 
chorny can you send me advice if you need perl program emailed. or should i post it.
it seems a little large to post.

or can post it in parts.

topsy99 9Apr2011 15:43

Re: need help with a function in a perl file
 
this is part of the perl file.

Code:

#!/usr/bin/perl
# Fred's Race Query
# For each html file, extract race info and horse names,
# then print entries from Horse.dat that match the horses
# TODO
# only print races with one or more of Fred's horses in
# find out why it is so slow, and speed it up
$horsefile = "Horse.dat";
print "Reading Fred's horse data.\n";
open HORSES, "<$horsefile" || die "Cannot open $horsefile\n";
@horses = <HORSES>;  # Is this memory gluttony or what?
print "Studying Fred's horse data.\n";
study @horses;  # optimises data for searching
$raceinfo = 0;  # used to pick out race number etc.
$laststart = 0;  # set to 1 when looking for last start info
$foundmatch = 0;

while (<>) {
 # the info about the race is from the beginning of the body
 # till the time hh:mm. We detect this below by looking for ":".
 # NOTE: it is important that this comes first as later blocks
 # remove the tag we are searching for here.
 if ( grep /<body/, $_ ) {
  $raceinfo = 1;
  print "\n";
 }
 # print race information
 if ( $raceinfo ) {
  chomp;  # remove newline
  # The <hr> is the line on the page where the race info ends
  if ( grep /<hr>/, $_ ) {
  $raceinfo = 0;
  print "\n\n";
  }
  s/<br>/ /g;  # turn a break tag into a space
  s/<[^>]*>//g;  # remove html tags
  unless ( $_ eq "" ) { # print it unless it's blank
                        print "$_ ";
  }
 }


topsy99 9Apr2011 15:49

Re: need help with a function in a perl file
 
sent file in a attachments but dont know where it went.


All times are GMT +5.5. The time now is 03:39.