Open main menu

Biolecture.org β

Changes

PERL

1,890 bytes added, 18:00, 17 June 2016
Created page with "<p><span style="font-size:20px">Basic of Perl</span></p> <hr /> <p><span style="font-size:14px">1) <strong>Variable</strong></span></p> <p>Variable is a place to store a value,..."
<p><span style="font-size:20px">Basic of Perl</span></p>

<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>

<p><strong>Scalar ($)&nbsp;</strong></p>

<p>Scalar variable&nbsp;stores a single (scalar) value.&nbsp;Perl scalar names are prefixed with a dollar sign ($), so for example,&nbsp;<code>$x, $y, $z, $username,</code>&nbsp;and&nbsp;<code>$url</code>&nbsp;are all examples of scalar variable names.&nbsp;A scalar can hold data of any type, be it a string, a number, or whatnot.</p>

<p>ex)&nbsp;</p>

<pre>
$name = &quot;Byeongeun Lee&quot;;

</pre>

<p><strong>Array (@)</strong></p>

<p>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 (@).&nbsp;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&#39;re referring to a single element of an array, you prefix the name with a $ instead of the @. The $-sign again indicates that it&#39;s a single (scalar) value; the @-sign means you&#39;re talking about the entire array.</p>

<p>ex)</p>

<pre>
@Grades = (&quot;A&quot;,&quot;B&quot;,&quot;C&quot;);</pre>

<p>&nbsp;</p>

<p><strong>Hash (%)</strong></p>

<p>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.</p>

<p>ex)</p>

<pre>
my %courses = (
&quot;Cell bio&quot; =&gt; &quot;prof.P&quot;,
&quot;Micro&quot; =&gt; &quot;prof.M&quot;,
);</pre>

<p>&nbsp;</p>

<p><span style="font-size:20px">Assignment study</span></p>

<hr />
<p>&nbsp;</p>