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

Good Morning all
How can run under a loop for checking into array, then out put only display one time only?
foreach my $j(1,2){ if (!exists(${"Name_$j"})) { print <<END_OF_HTML; <font color="#000000" size="-1" face=arial,sans-serif>$showname</font> +<br> END_OF_HTML } }

Replies are listed 'Best First'.
Re: display one time only
by rje (Deacon) on Jan 10, 2002 at 21:19 UTC
    If I understand you correctly, then I think all you need to do is use the keyword last:

    foreach my $j (1,2) { if ( !exists( ${"Name_$j"} )) { # # print your stuff here # last; } }
    "last" tells perl to immediately exit the loop.

    rje

Re: display one time only
by blakem (Monsignor) on Jan 11, 2002 at 00:24 UTC
    The answer you're looking for has already been given. However your conditional looks incorrect to me...
    !exists(${"Name_$j"})
    You should read the documentation for exists which explains what exists is expecting better than I can...
    Perhaps you meant:
    !exists($Name{$j})
    or even:
    !exists($hash{"Name_$j"})

    -Blake