Professional Web Applications Themes

How to add a sequential number to a form - PERL Miscellaneous

In article <bel3dj$g6i$1ftp.curtin.edu.au>, "gwmbox" <gregatworkNOSPAMPLEASEhotmail.com> wrote: > Hi > > I have a basic form mailer script but I want to add a number that increments > on each use of the form - like an ID for each request sent - how do I do > this - anyone got any code I can use to add this to a form script? guess noone else is gonna answer this, so here: #----------------------------------------------------------------------- sub getseqno { #----------------------------------------------------------------------- open (SEQNBR, "+>>/path/to/lastseqno") or die ("Can't open SEQNBR: $!"); # it's ours exclusively! flock (SEQNBR, 2); # ...rewind... seek (SEQNBR, 0, 0); # ...

  1. #1

    Default Re: How to add a sequential number to a form

    In article <bel3dj$g6i$1ftp.curtin.edu.au>,
    "gwmbox" <gregatworkNOSPAMPLEASEhotmail.com> wrote:
    > Hi
    >
    > I have a basic form mailer script but I want to add a number that increments
    > on each use of the form - like an ID for each request sent - how do I do
    > this - anyone got any code I can use to add this to a form script?
    guess noone else is gonna answer this, so here:

    #-----------------------------------------------------------------------
    sub getseqno {
    #-----------------------------------------------------------------------

    open (SEQNBR, "+>>/path/to/lastseqno") or die ("Can't open SEQNBR:
    $!");

    # it's ours exclusively!
    flock (SEQNBR, 2);

    # ...rewind...
    seek (SEQNBR, 0, 0);

    # get last number
    my $seqnbr = <SEQNBR>;

    # ...rewind...
    seek (SEQNBR, 0, 0);

    # ...clear the file...
    truncate (SEQNBR, 0);

    # ...and rewrite it, adding 1 to the sequence number
    $seqnbr++;
    print SEQNBR $seqnbr;

    # we're outa here! (note that perl's close also unlocks the file,
    # as does the ending of the program, so an explicit flock is n/n
    close (SEQNBR);

    return $seqnbr;

    }

    hope this helps...

    --
    Michael Budash
    Michael Budash Guest

  2. #2

    Default Re: How to add a sequential number to a form

    "gwmbox" <gregatworkNOSPAMPLEASEhotmail.com> wrote in message news:<bel3dj$g6i$1ftp.curtin.edu.au>...
    > Hi
    >
    > I have a basic form mailer script but I want to add a number that increments
    > on each use of the form - like an ID for each request sent - how do I do
    > this - anyone got any code I can use to add this to a form script?
    >
    > Thanks
    >
    > Greg
    uhhh...

    my $formSequence = 0;
    while (1)
    {$done = UseForm($formSequence);
    last if $done;
    $formSequence++;
    }

    Now, if you need to have the increment PERSIST, that is continue where
    you left off from the last run, you have a few options there. One is
    to tie the scalar. Another is to have it in a textfile and do a little
    error-checking on it. The nice part about the latter solution is that
    you can EDIT the file and change the value if you need to. Also tie
    actually creates 2 files, which seems like a lot of overhead to store
    one little old integer no?

    This might work:

    die "cannot open increment-value file, Land O Goshen!!\n $!" unless
    open I, "./increment.dat";

    my i = <I>;
    close I;

    # you may have to futz around a little with the EOL character, Ill
    leave that
    # as an exercise for the reader

    die "This does not seem to BE an increment file, what the HEY?\n"
    unless i == 1 && $i[0] =~ /^\d+$/;

    # OK we have our value..

    my $formSequence = $i[0];

    # use the rest of the code above

    Have a super weekend I know I will its NNW!!

    -Gx
    Sara Guest

Similar Threads

  1. Dynamic number of form elements
    By jbreslow in forum Macromedia ColdFusion
    Replies: 2
    Last Post: March 23rd, 11:38 PM
  2. Auto generate unique order number sequential
    By DutchCur in forum Macromedia ColdFusion
    Replies: 1
    Last Post: February 17th, 01:34 PM
  3. Replies: 0
    Last Post: August 7th, 07:05 PM
  4. row number on continuous form
    By Emidio in forum Microsoft Access
    Replies: 2
    Last Post: July 21st, 08:23 PM
  5. Sequential Number Generator
    By in forum Microsoft SQL / MS SQL Server
    Replies: 4
    Last Post: July 4th, 03:55 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139