1. We have moved from vBulletin to XenForo and you are viewing the site in the middle of the move. Though the functional aspect of everything is working fine, we are still working on other changes including the new design on Xenforo.
    Dismiss Notice

need help with a function in a perl file

Discussion in 'Perl' started by topsy99, Jan 9, 2011.

  1. topsy99

    topsy99 New Member

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

    chorny New Member

    Do you have problems with Perl or with algorithm?
     
  3. topsy99

    topsy99 New Member

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

    chorny New Member

    Yes, I'll need both of then, possibly with explanation of algorithms if comments are missing.
     
  5. topsy99

    topsy99 New Member

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

    topsy99 New Member

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

    topsy99 New Member

    chorny can i email the perl program to you it is a bit long for the post but is only about 80 lines.
    regards
     
  8. topsy99

    topsy99 New Member

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

    topsy99 New Member

    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 "$_ ";
      }
     }
     
    Last edited by a moderator: Apr 9, 2011
  10. topsy99

    topsy99 New Member

    sent file in a attachments but dont know where it went.
     
  11. topsy99

    topsy99 New Member

    the perl file is posted as an attachment name freddy.txt. hope it helps.
     

    Attached Files:

  12. topsy99

    topsy99 New Member

    have resolved this issue thanks for your interest.
     

Share This Page