in reply to How can I create a procedure
First, you do realize that the syntax if ($_ =~ C B A R) { ... } is unlikely to even compile for you¹, right?
The way you create functions (procedures/methods/subroutines, pick your terminology) is with the sub keyword.
Arguments to a sub are passed via the special array variable named @_.sub my_sub { print "I'm a sub!\n"; }
The way we call those subs is simply by invoking their name. If you didn't declare them before you invoke them, you must supply parens. Generally speaking, parens are a good idea anyway.sub my_sub_with_args { my @args = @_; print "I'm in a sub that was called with these args: @args\n"; }
This is perhaps the most basic of basic introductions. For more information, read perldoc persub. One thing you should know right off the bat though... don't use "prototypes" until you really understand them. (And don't think that you really understand them until you read Tom Christiansen's article about them.my_sub(); my_sub_with_arguments("some", "arguments");
1.Unless you have some whacky packages and methods names, anyway.
-sauoq "My two cents aren't worth a dime.";
|
|---|