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

Hi all

Is there a workaround for this. I am trying to decode a logic in the else block and if it passes then i dont want it exit out of the loop but go to Line 12. Is there a workaround for this?

Please let me know .. I have attached the code below

Krishnar

1: while (<READ_FILE>) { 2: if ($cur_code == $area_code) { 3: //Some logic here 4: } 5: else{ 6: $cur_code = $area_code; 7: if($first_time == 1){ 8: $first_time = 0; 9: last ; 10: } 11: } 12: print "Hello"; 13: }

Edited 2004-08-18 by mirod: added <code> and <p> tags

Replies are listed 'Best First'.
Re: Question about last statement
by ccn (Vicar) on Aug 18, 2004 at 18:30 UTC

    while (<READ_FILE>) { if ($cur_code == $area_code) { //Some logic here } else{ $cur_code = $area_code; if($first_time == 1){ $first_time = 0; next; # not last } } } continue { print "Hello"; }

    perldoc -f continue, perldoc perlsyn

•Re: Question about last statement
by merlyn (Sage) on Aug 18, 2004 at 18:54 UTC
Re: Question about last statement
by ikegami (Patriarch) on Aug 18, 2004 at 18:23 UTC

    Get rid of line 9 (last;), and you'll get just that. (Update:) If you need to do something when it's not the first time, add an else:

    while (<READ_FILE>) { if ($cur_code == $area_code) { //Some logic here } else { $cur_code = $area_code; if ($first_time == 1) { $first_time = 0; } else { //Some logic here } } print "Hello"; }

    (I reformatted your code to a style with which I am more familiar so I could read it more easily. Don't take it personally.)

Re: Question about last statement
by shemp (Deacon) on Aug 18, 2004 at 19:26 UTC
    Use CODE tags. It's nearly impossible to decipher unindented code!

    ...brings back nightmares of a former co-worker whose indentation can only be described as Random