Changes
PERL
,no edit summary
<hr />
<p><span style="font-size:14px">1) <strong>Variable</strong></span></p>
<p>Variable is a place to store a value, so we can refer to it or manipulate it throughout program. Perl has three types of variables; scalars, arrays and hases.</p>
</pre>
<p><span style="font-size:14px"><strong>Array (@)</strong></span></p>
<p><span style="font-size:14px">An array stores a list of values. While a scalar variable can only store one value, an array can store many. Perl array names are prefixed with an at-sign (@). In Perl, array indices start with 0, so to refer to the first element of the array @colors, you use $colors[0]. Note that when you're referring to a single element of an array, you prefix the name with a $ instead of the @. The $-sign again indicates that it's a single (scalar) value; the @-sign means you're talking about the entire array.</span></p>
<p>ex)</p>
<p> </p>
<p><span style="font-size:14px"><strong>Hash (%)</strong></span></p>
<p><span style="font-size:14px">A hash is a special kind of array - an associative array, or paired group of elements. Perl hash names are prefixed with a percent sign (%), and consist of pairs of elements - a key and a data value.</span></p>
<p>ex)</p>
);</pre>
<p>2) <strong>Function</strong></p> <p>Functions are blocks of codes that are given names so that we can use them as needed. Functions help to organize code into pieces that are easy to understand and work with. They help to build program step by step, testing the code along the way.</p> <p><span style="font-size:14px">2<strong>substr( ) </strong>Function</strongspan></p> <p><span style="font-size:14px">The <code>substr()</code> function is used to return a substring from the expression supplied as its first argument. </span><code>substr()</code> has a variable number of arguments, it can be told to start at an offset from either end of the expression, so it can supply a replacement string so that it replaces part of the expression as well as returning it, and it can be assigned to.</p> <p>substr( ) have three parameters; ( character, offset : location from "0", length of character which will be extracted ). And it is also possible to add fourth parameter, the character which wants to exchage with. </p> <p>ex1) </p> <pre>my $str = "The black cat climbed the green tree"; say substr $str, 4, 5; # black</pre> <p>ex2)</p> <pre>my $z = substr $str, 14, 7, "jumped from"; say $z; # climbed say $str; # The black cat jumped from the green tree</pre>
<p> </p>