Yes, BASIC is the only programming I have ever done. All I can really remember was PRINT, GOTO, and a variety of line numbers. I'm trying to write a text adventure (Don't look at me like that, Perl is a general purpose language!). I'm getting tired of writing large chunks of code that I reuse the basic structure of and wouldn't mind an easier solution. I'll go look up subroutines, allthough GOTO does just fine for me.
----- Original Message ----- From: "Rob Dixon" <[EMAIL PROTECTED]> To: <[EMAIL PROTECTED]> Sent: Thursday, February 19, 2004 8:36 AM Subject: Re: Could I put commands in a variable > 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> > > > -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>