Please check code & logic

Discussion in 'Perl' started by Testor, Apr 18, 2004.

  1. Testor

    Testor Guest

    I am writing a simple perl script to learn in the process. The script
    is supposed to grab a receipt number from the query-string and write
    it into a file.

    To do that, here's what I did:

    $query = new CGI;

    $myreceipt = $query->param('bnkreceipt');

    open(DATABASE, ">>bnkrecpts.db") or die "Can't write open file.
    Reason: $!";
    seek(DATABASE,0,2);
    print DATABASE "$myreceipt\n";
    close(DATABASE);

    This works OK though not sure if it's the best way because I'm writing
    duplicate receipt numbers. I tried to use an if statement to make sure
    is the number exists in the file before writing it but I'm afraid I
    wasn't successful I did something like:

    open (THERECEIPT, "<bnkrecpts.db") or die "Can't open file. Because:
    $!";
    flock(THERECEIPT,2);
    $receiptnum = <THERECEIPT>;
    close (THERECEIPT);

    if ($receiptnum eq $myreceipt) {
    print something or whatever here...

    }

    As you can see since I'm still learning, my logic is out of no where
    here :)

    Comments on the above code will be appreciated.
     
    Testor, Apr 18, 2004
    #1
    1. Advertising

  2. Testor

    Testor Guest

    Re: writing duplicates in file

    I guess no one wants to comment on this.
     
    Testor, Apr 20, 2004
    #2
    1. Advertising

  3. Testor

    Joe Smith Guest

    Re: writing duplicates in file

    Testor wrote:

    > I guess no one wants to comment on this.


    1) You posted to comp.lang.perl instead of comp.lang.perl.misc; that's
    where the action is.
    2) A database that can hold only one number at a time is rather boring.
    It's better to use a real database with professional-grade record locking.

    -Joe
     
    Joe Smith, Apr 21, 2004
    #3
  4. Testor

    Testor Guest

    Re: writing duplicates in file

    Joe Smith <> wrote in message news:<j1phc.179243$K91.448230@attbi_s02>...
    > Testor wrote:
    >
    > > I guess no one wants to comment on this.

    >
    > 1) You posted to comp.lang.perl instead of comp.lang.perl.misc; that's
    > where the action is.
    > 2) A database that can hold only one number at a time is rather boring.
    > It's better to use a real database with professional-grade record locking.
    >
    > -Joe


    Joe,

    Thanks for the reply. I shall try to post to .misc as suggested. A
    database for holding one number is boring as you said, but I find it
    good for training since I'm not doing much just to get the idea.

    Once again, thanks for your reply.
     
    Testor, Apr 21, 2004
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. D. Shane Fowlkes
    Replies:
    3
    Views:
    336
    D. Shane Fowlkes
    Dec 10, 2003
  2. RSB

    CRC check logic/program

    RSB, Sep 29, 2004, in forum: Java
    Replies:
    2
    Views:
    2,598
    Michael Borgwardt
    Sep 30, 2004
  3. KK
    Replies:
    2
    Views:
    617
    Big Brian
    Oct 14, 2003
  4. Rich S.

    Logic check please

    Rich S., Sep 21, 2005, in forum: C++
    Replies:
    5
    Views:
    311
    Karl Heinz Buchegger
    Sep 22, 2005
  5. spike
    Replies:
    8
    Views:
    1,485
    Steve Holden
    Feb 9, 2010
Loading...

Share This Page