Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Not errors but possible bugs

by raptor (Sexton)
on Jan 31, 2001 at 22:02 UTC ( [id://55512]=perlquestion: print w/replies, xml ) Need Help??

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

thanx :") Ok.. the problem I had before a couple of days.. It wasn't possible to do ..
goto LINE ....blah .... LINE: use Module;
But this worked :
goto LINE ....blah .... LINE: print; use Module;
:"(... Yes I needed to use goto..:"), may be NOP will be good candidat for here :") (after the specs for the task changed I've not used goto anymore :")) The other problem :
SWITCH: { if (..cond1..) {... last SWITCH}; if (..cond2..) { ... grab one row fetchrow_hashref ..populate field names.. do {..code last if blah; ...code... } while (condX); last SWITCH }; if (..cond3..) {... last SWITCH}; }
DIDN'T worked..(yes in the docs is stated that I can't exit do{}, but this is a do{}while() :")) So I needed to do this :
SWITCH: { if (..cond1..) {... last SWITCH}; if (..cond2..) { ... grab one row fetchrow_hashref ..populate field names.. { do {..code last if blah; } } while (condX); last SWITCH }; if (..cond3..) {... last SWITCH}; }
DO YOU see second braces.. PERL5.6 (Win98/ActiveState) OK...both problem are overcomed easly but ...!!! thanx for the attention

Replies are listed 'Best First'.
Re: Not errors but possible bugs
by chipmunk (Parson) on Jan 31, 2001 at 22:19 UTC
    Neither of these are actual bugs in Perl, although the behavior can be counter-intuitive.

    use is a compile-time directive. It has no meaning at runtime, so you cannot assign it a label. If you want to conditionally load a module at runtime, you should use require and import.

    A do BLOCK with a while after it is still just a do BLOCK. Remember that while as a statement modifier was added later; do BLOCK while EXPR is just another use of while as a statement modifier and has no extra meaning in Perl.

Re: Not errors but possible bugs
by extremely (Priest) on Jan 31, 2001 at 23:45 UTC
    You can do the following for the first goto question:
    #... goto LABEL; #... LABEL:; #A plain ; is basically the NOP you are looking for. use Module;

    For the second case, do you actually need the do{}while(); form? That syntax guarantees that the code in the do{} runs once at the price you discovered. If running the code zero times would be ok or if prior code ensures that the while condition is always true for one iteration, just use the while(){} form.

    --
    $you = new YOU;
    honk() if $you->love(perl)

Re: Not errors but possible bugs
by Fastolfe (Vicar) on Feb 01, 2001 at 04:13 UTC
    A do { ... } while ( ... ) construct is not the same thing as a while loop. In fact, they're not even considered loop blocks in Perl, so things like next or last are invalid there. Consider re-writing your construct to use a real while ( ... ) { ... } block. The documentation for do is not explicit in this regard, but consider do/while and do/until to be "do" blocks, not a real loop, and then the documentation makes sense and you can see that these are forbidden operations.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://55512]
Approved by root
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chanting in the Monastery: (3)
As of 2024-04-25 06:50 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found