Hello Monks,
At first here is part of my code:
&pytaj(); if ($question1 eq '') { print "Nie wybrales zadnej opcji \n"; print "Zamykam.... \n"; sleep(5); exit(); } elsif ($question1 eq "1") { &backup(); } elsif ($question1 eq "2") { &restore(); } elsif ($question1 eq "3") { &testowanie(); } elsif ($question1 eq "4") { &full(); } elsif ($question1 eq "5") { &shared(); } elsif ($question1 eq "6") { &archive(); } elsif ($question1 eq "0") { print "Ok wiec koniec pracy. Zamykam.... \n"; sleep(5); exit(); } sub pytaj { print "*************** \n\n"; print "Narzedzie do wykonywania operacji na bazach danych i plikach SM +/PCB klientow CORE \n"; print "Jesli nie jestes pewien co robisz, do czego sa te opcje to lepi +ej nie rob nic! \n"; print "Wybierz zadanie do wykonania: \n\n"; print "[1] utworz backup bazy do pliku gbk \n"; print "[2] odtworz baze ze wskazanego pliku gbk \n"; print "[3] przetestuj wskazana baze danych \n"; print "[4] wykonaj kompletna procedure backupu - backup, odtworzenie i + testowanie \n"; print "[5] zarchiwizuj katalog Shared do zip \n"; print "[6] spakuj podana baze do pliku zip \n"; print "[0] Nie rob nic i wyjdz \n\n"; print "Plik do przetworzenia podawaj jako pelna sciezke do pliku! \n\n +"; print "Podaj numer czynnosci do wykonania: "; chomp( $question1 = <STDIN> ); return $question1; }
TODO - script prints to STDOUT list of options, user select one, subroutine is executed.
At end of subroutine e.g.
sub shared { $sharedarchname = "shared-$day.zip" ; chdir($shared); $object2 = Archive::Zip->new(); $object2->addTree("$shared"); my $target; print "Do jakiego katalogu zapisac paczke [Jesli nie podasz b +edzie w $kopietar] : "; chomp( $target = <STDIN> ); $target = $kopietar if $target eq ''; if ($object2->writeToFileNamed("$target$sharedarchname") != 0) { print "Blad pakowania Shared! $! \n"; print "Automatyczne wyjscie za 10s..."; sleep(10); exit(); } else { print "Shared poprawnie zarchiwizowane. Zapisano w $target$sharedarchn +ame \n"; } &pytaj(); }
I want back to options menu so I`ve inserted &pytaj(); and menu is printed and waits for selection but when I type selection number and press enter the script ends but should go back to beginning.
I think there should be some simple method to go back to top of script - the $question1 should be returned to top and whole script should be executable once again. Finally it should be executable unless error breaks execution of any of subroutine (this is done by die where sub should break) or 0 - quit will be selected.
GOTO 10 didn`t work ;))
Idea - is there an option to end all of subroutines with back to beginning of the script? If I cut out sub pytaj to beginning of the script it will be correctly executed, $question1 reply launches correct subroutine but only one thing needed is to back after end of sub to beginning of script.

In reply to How to escape from sub to beginning of script? by Mery84

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.