Login Register


[TUT] Perl Basic's Using Arrays. Name Holder [Beginner LVL 4] filter_list
Author
Message
[TUT] Perl Basic's Using Arrays. Name Holder [Beginner LVL 4] #1
Hello and welcome to another Perl tutorial. In this tutorial we will be covering the basic's of arrays. An array is similar to a Variable in the way it is declared by a symbol @, Except an array can hold multiple value's. So let's begin our basic arrays tutorial.

code:
Code:
print"\n\n-- # p-teo arrays # --"; print"\n>>"; @names = ("james", "anna", "elis", "peter", "adam", "john", "elvis", "danny", "wayne", "javier", "sam", "harry", "ray", "chris", "ashley", "electra", "frodo"); my $input = <STDIN>; if ($input eq "names") { print"@names"; } else { print"Invalid command"; }


Explained.

Code:
print"\n\n-- # p-teo arrays # --"; print"\n>>";
Very simple, print's the line of text in the quotation marks.

Code:
@names = ("james", "anna", "elis", "peter", "adam", "john", "elvis", "danny", "wayne", "javier", "sam", "harry", "ray", "chris", "ashley", "electra", "frodo");
This is the array, it is declared by putting "@" at the beginning of the assigned word, the following items are the bit's of data it is holding.

Code:
my $input = <STDIN>;
As explained in another tutorial, this is just to allow user input when the program is running.

Code:
if ($input eq "names") { print"@names"; } else { print"Invalid command"; }
This is the if statement, it just says if the input equals "names" then it prints the content's of the array, in this case all of the names. If it doesn't equal names then it prints the text "Invalid Command".


Thanks for reading my tutorial, hope you found this useful, feel free to look at my other tutorials and have a nice day.
[Image: 6caf54.gif]

Reply





Messages In This Thread
[TUT] Perl Basic's Using Arrays. Name Holder [Beginner LVL 4] - by FrostByte_mybb_import5923 - 05-10-2011, 09:59 PM



Users browsing this thread: