Joel wrote:
>
> If I was using one specific group of commands, Could I put them inside a
> variable, then just use the variable when I needed the commands instead of
> copying and pasting them?
>
> i.e.
> print "Hello world";
> if ($i == 50) {
>     goto MAIN;
>     }
> elsif ($t == 100) {
>     goto SECONDARY;
>     }
>
> as compared to
>
> $command =
> print "Hello world";
> if ($i == 50) {
>     goto MAIN;
>     }
> elsif ($t == 100) {
>     goto SECONDARY;
>     };

Hi Joel.

Both your question and your code suggest that you're not
thinking about your programming solution properly. I
don't think I've ever seen a Perl script that used 'goto'.
Not that is the Bad Thing that many people make out, it's
just usually a non-intuitive way of expressing a solution.
Also, what you describe is a subroutine, which is simply
a named piece of code. Have you come from programming BASIC
by any chance? In its earlier versions BASIC control flow
was entirely dependent on GOTO <line> and GOSUB <line>, as
it was based on the syntax of assembler languages.

I'd expect to do away with the labels and write something
like:

  sub command {

    print "Hello world";

    if ($i == 50) {
      :
    }
    elsif ($t == 100) {
      :
    }
  }

I hope this helps. It would be useful to tell us more about
what you're trying do do.

Rob

to do.



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to