Difference between revisions of "PERL"
imported>Byeongeun Lee (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,...") |
(No difference)
|
Revision as of 18:00, 17 June 2016
Basic of Perl
1) Variable
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.
Scalar ($)
Scalar variable stores a single (scalar) value. Perl scalar names are prefixed with a dollar sign ($), so for example, $x, $y, $z, $username,
and $url
are all examples of scalar variable names. A scalar can hold data of any type, be it a string, a number, or whatnot.
ex)
$name = "Byeongeun Lee";
Array (@)
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.
ex)
@Grades = ("A","B","C");
Hash (%)
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.
ex)
my %courses = ( "Cell bio" => "prof.P", "Micro" => "prof.M", );
Assignment study