jayvillach has asked for the wisdom of the Perl Monks concerning the following question:

Hey Monks Hope you doing fine. My issue is, I have Barcode scanner, I have text to detect by the scanner. This project I am doing for tracking our library books when it is been lend to someone when they need. In order to track to whom I have lent it, I have made the program to scan Book ID. When we scan the book ID then a time loop starts, this time loop has been created so that if the person has multiple books then we scan the second, then again the time loop starts, then the third book, then when the time loop finish automatically it should update the details in our list. But it does not. It does update but we have to scan something after when the time loop finishes, I mean scan anything, any Barcode, then it happens. But I dont understand why it does not update automatically soon after I finish the flow and time loop ends. Any help would be appreciated. Thanks you in advance.

Replies are listed 'Best First'.
Re: Breaking issue
by Corion (Patriarch) on Jul 18, 2017 at 12:53 UTC

    Most likely, the error is in your loop or your loop condition.

    I imagine that your loop looks something like:

    my $user_id = <>; # the scanner sends keyboard input my $person_timeout = time() + 30; # 30 seconds until we consider the s +can done while( time < $person_timeout and my $book_id = <> ) { $person_timeout = time() + 30; # 30 seconds until we consider the +scan done print "Person $user_id has checked out book $book_id\n"; }

    In my toy example, the program will re-enter the loop and try to read from the scanner. Even if the timeout passes, it will still be waiting for the input.

    Without knowing more about your program, your loop and how things are structured, I can't really give more concrete advice. Maybe you can show us a short example that reproduces your problem. The example should not be longer than 30 lines.

      Hi Corion Thak you for the example and also for the quick response. Yes you are right the structure is more or less the same but here we have if instead of while, but can you guide me how I can make it so that the scanner wont wait for information and update it ?

Re: Breaking issue
by cavac (Prior) on Jul 19, 2017 at 11:28 UTC

    Not sure if i understand your problem completely, but i'd like to comment on a possible side-issue of your design. Does the time-limit thing even make sense to the user?

    Say your limit is 30 seconds. Then the user is forced to handle books quickly enough to be able to meet that limit. On the flip side, when the user wants to finish, they have to wait the 30 seconds twiddling their thumbs.

    Wouldn't it make more sense to have i "i am finished" barcode stuck to the place where the scanner is mounted, as well as one for "cancel my last scan" and "cancel the list" each?

    "For me, programming in Perl is like my cooking. The result may not always taste nice, but it's quick, painless and it get's food on the table."