Monday, July 18, 2011

redo keyword perl

redo keyword:
The redo keyword causes Perl to restart the current Statement block.It does not either intialize or increment or decrement.It is
usually used in case of the statements where the input is from another file or from the keyboard.


Content of the Perl file:

{
print ("what is your name? " );
$name=;
chop($name);
content of the perl file:
if ( ! length($name)) {
print ("Zero length name please try a valid name");
redo;
}
print ("Thank you ".uc($name)."\n");

}

OUTPUT:

G:\perl_programs>perl perl_redo.pl
what is your name? karthik
Thank you KARTHIK

G:\perl_programs>perl perl_redo.pl
what is your name?
Zero length name please try a valid namewhat is your name?
Zero length name please try a valid namewhat is your name? kkkk
Thank you KKKK

G:\perl_programs>
As you may see when you give no name it restarts the block to ask the name again.

No comments:

Post a Comment