in reply to What is the purpose of subroutine parameters?
The reason you use sub-routines(also known as functions) is to avoid typing code over and over again. This way, if you have to perform a specific operation over and over again on constantly changing data, you can simply send the data to the subroutine, it will do the operation on it, and return the result to you.#!/usr/bin/perl -w use strict; my $first_number=5; my $second_number=1; my $result=Add($first_number,$second_number); print"And the result is $result.\n"; sub Add{ my($x,$y)=shift; my $result=$x+$y; return $result; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Use of perl
by Anonymous Monk on Sep 17, 2001 at 09:39 UTC |