operations |
comment | "parent_author":"",<br>"parent_permlink":"utopian-io",<br>"author":"meblogger",<br>"permlink":"introduction-to-the-perl-language-issue-1",<br>"title":"Introduction to the Perl language,<br> Issue#1",<br>"body":"![perl.jpg (https:\/\/res.cloudinary.com\/hpiynhbhq\/image\/upload\/v1516429648\/vgvxk7hnpoeylsuadalh.jpg)\n[Image Source (https:\/\/walsoul.com\/index.php\/perl-programming-basic.html)\n#### `What Will I Learn?`\nIntroductory training support for programming with the Perl language. \n\n- Perl Language Introduction\n- PERL Overview\n- PERL Language Data types\n\n#### `Requirements`\nBasic Knowledge of programming and software concept.\n\n#### `Difficulty`\n- Basic\n\n\n#### `Tutorial Contents`\n_____________________________________\n##### `1 .INTRODUCTION`\n---------------------------------\n`A .What is Perl?`\n_____________________________\nP.E.R.L. means Practical Extraction and Report Language. What we could (try to) translate as \"practical language of extraction and editing\".\nCreated in 1986 by Larry Wall (System Engineer). Initially to manage a \"News\" system between two networks.\n\n`It is` :\n_________,<br>\n\u2022 A programming language\n\u2022 Free software (which can be obtained on the Internet in particular)\n\u2022 An interpreted language: \nno compilation\nslower than a compiled program\neach \"script\" requires the Perl interpreter on the machine to run.\n\n`Why Perl became popular`:\n________________________________,<br>\n\u2022 portability: Perl exists on most platforms today (Unix,<br> NT,<br> Windows,<br> Mac,<br>VMS,<br> Amiga,<br> Atari ...)\n\u2022 free: available on the Internet (as well as an impressive number of bookstores and utilities)\n\u2022 Simplicity: Some commands allow to do what a program of 500 lines in Cor in Pascal did.\n\u2022 robustness: No memory allocation to handle,<br> strings,<br> stacks,<br> variable names Unlimited ...\n\n`B. What use of Perl?`\n___________________________________________\n`Originally Perl was created for:`\n_______________________________________,<br>\n1) manipulate files (especially to manage several files at the same time),<br>\n2) manipulate texts (search,<br> substitution),<br>\n3) manipulate processes (especially through the network).\n\nPerl was mainly for the UNIX world\n\n`Why are you using Perl today?`\n____________________________________,<br>\n1) generate,<br> update,<br> analyze HTML files (especially for writing CGI),<br>\n2) \"universal\" access to databases,<br>\n3) file format conversion.\n\nPerl is no longer tied to the UNIX world\n\n`Perl is not made for:`\n_______________________________,<br>\n\u2022 write interactive interfaces (but there is now the Tk module,<br> which allows it,<br> on Unix or Windows),<br>\n\u2022 scientific computing (Perl is not compiled: performance problem if we want by example do multiplications of matrices,<br> but again there is the module PDL).\n\n`C . versions`\n------------------------------------------\n`Three main versions of Perl:`\n\u2022 Perl 4: The old version that did not integrate object programming (sometimes still used)\n\u2022 Perl 5.6: The old version\n\u2022 Perl 5.8: The new version that incorporates Unicode (international character encoding)\n\n_____________________________________\n##### `2 .PERL Overview`\n---------------------------------\n`Little polite program` -\n------------------------------,<br>\n```\n#!\/bin\/perl\nprint \"Bonjour\";\n```\n`Display the number of lines in a file:`\n------------------------------------------------,<br>\n```\n#! \/ Bin \/ perl\nopen (F,<br> '<myfile') || die \"Opening problem: $!\" ;\nmy $ i = 0;\nwhile (my $ line = <F>) \n$ I ++;\n \nclose F;\nprint \"Number of lines: $ i\";\n```\n\n`F` is a file descriptor,<br> which we can call as we want (the use is that we note the file descriptors in uppercase).`Each Perl statement ends with a semicolon`.\n\n_____________________________________\n##### `3 .PERL Data types`\n------------------------------------------\n`A. Constants`\n-------------------,<br>\n`1,<br> -12345,<br> 0.1415,<br> 1.6E16 (means 160,<br>000,<br>000,<br>000,<br>000,<br>000),<br> 'cherry',<br> 'a',<br>'the fruits of the palm are the dates'`\n\n`B. Scalars`\n-------------------,<br>\n`Scalars are preceded by the $ character` -\n```\n$ i = 0; $ c = 'a';\n$ my_fruit_prefere = 'kiwi';\n$ root__read_of_2 = 1.41421;\n$ string = '100 grams of $ my_fruit_prefere';\n=> '100 grams of $ my_fruit_prefere'\n$ string = \"100 grams of $ my_fruit_prefere\";\n=> '100 grams of kiwi'\n```\n`Caution: Do not put spaces in variable names. A name can be as long we want it in the latest version,<br>`\n\n`C. Table lists`\n---------------------,<br>\n`In Perl,<br> arrays can be used as sets or lists.`\nAlways preceded by the` \"@\"` character\n```\n@ digits = (1,<br>2,<br>3,<br>4,<br>5,<br>6,<br>7,<br>8,<br>9,<br>0);\n@fruits = ('almond',<br> 'strawberry',<br> 'cherry');\n@alphabet = ('a' .. 'z'); Both points mean \"so much to so much\"\n@a = ('a'); @nul = ();\n@cartes = ('01' .. '10',<br> 'Valet',<br> 'Lady',<br> 'King');\n```\n`we refer to an element of the table according to its index by:`\n```\n$ digits [1 (=> 2)\n$ fruits [0 (=> 'almond')\n```\n`NOTE: In Perl (as in C) arrays start at index 0`\n\n`You can assign a table to another table:`\n```\n@ch = @ digits;\n@alphanum = (@alphabet,<br> '_',<br> @ digits);\n## EQU1 ## ',<br>' 8 ',<br>' 9 ',<br>' 0 ')\n@ set = (@ digits,<br> 'date',<br> 'kiwi',<br> 12.45);\n```\n`Notes:`\nWe have a special scalar: $ # array that indicates the last array index (and therefore its size - 1): $ fruits [$ # fruits (=> 'cherry')\n`Ability to reference a part of a table`\n```\n@cards [6 .. $ # cards => ('07',<br> '08',<br> '09',<br> '10',<br> 'Valet',<br> 'Lady',<br> 'King')\n@fruits [0..1 => ('almond',<br> 'strawberry')\n```\n`D. Indexed (or associative) tables`\n---------------------------------------------,<br>\n`They are always preceded by the% character:`\n```\n% price = ('almond' => 30,<br> 'strawberry' => 9,<br> 'cherry' => 25);\n`or :`\n% price = (kernel => 30,<br> strawberry => 9,<br> cherry => 25);\n```\n`We then refer to an element of the array as:`\n```\n$ price 'cherry' (=> 25)\n`(or $ price cherry `\n`Examples:`\n% digit = ();\n$ digit 'a' = 1; => or $ digit a = 1;\nprint $ digit 'one' ;\n$ var = 'one'; print $ digit $ var ;\n```\n`E. Remarks`\n-------------------,<br>\n1 . `Perl5 allows combinations,<br> like a table of tables:`\n```\n% seasons = (\nApricot '=> [' been ' ,<br>\n'strawberry' => ['spring',<br> 'summer' ,<br>\n'apple' => ['autumn',<br> 'winter' ,<br>\n'orange' => ['winter' ,<br>\n'cherry' => ['spring' ,<br>\n'almond' => ['spring',<br> 'summer',<br> 'autumn',<br> 'winter' );\n`or`\n@departements = (\n['Ain',<br> 'Bourg-en-Bresse',<br> 'Rh\u00f4ne-Alpes' ,<br>\n['Aisne',<br> 'Laon',<br> 'Picardie' ,<br>\n['Yonne',<br> 'Auxerre',<br> 'Burgundy' );\n```\n2 . `No Booleans (as in C language)`\nWe use integers knowing that 0 is evaluated as false (in fact it is the chain of empty character) and 1 as true.\n```\nmy $ two_greater_what_un = (2> 1);\nif ($ two_more_large_one) \nprint \"Ok!\";\n \n```\n3 . `Two-dimensional tables`\n`Indexed tables can be used to simulate 2 (or n) dimensional tables:`\n```\n% table_multiplication = ('1,<br>1' => 1,<br> '1,<br>2' => 2,<br> ...,<br>\n'9.8' => 72,<br> '9.9' => 81);\n$ translation 'almond',<br> 'english' = 'almond';\n$ translation 'almond',<br> 'italian' = 'amoria';\n$ translation 'cherry',<br> 'english' = 'cherry';\nYou can also use Perl 5's table tables to do this:\n@table_multiplication = (\n[0,<br> 0,<br> 0,<br> 0,<br> 0,<br> 0,<br> 0,<br> 0,<br> 0,<br> 0 ,<br> # Multiplied by 0\n[0,<br> 1,<br> 2,<br> 3,<br> 4,<br> 5,<br> 6,<br> 7,<br> 8,<br> 9 ,<br> # Multiplied by 1\n[0,<br> 2,<br> 4,<br> 6,<br> 8,<br>10,<br>12,<br>14,<br>16,<br>18 ,<br> # Multiplied by 2\n...\n[0,<br> 9,<br>18,<br>27,<br>36,<br>45,<br>54,<br>63,<br>72,<br>81 ); # Multiplied by 9\n```\nWe will then refer to 2 * 6 by $ table_mult [6 [2 \n\n \n\n<br \/><hr\/><em>Posted on <a href=\"https:\/\/utopian.io\/utopian-io\/@meblogger\/introduction-to-the-perl-language-issue-1\">Utopian.io - Rewarding Open Source Contributors<\/a><\/em><hr\/>",<br>"json_metadata":" \"community\":\"utopian\",<br>\"app\":\"utopian\/1.0.0\",<br>\"format\":\"markdown\",<br>\"repository\"<br>\"id\":8183570,<br>\"name\":\"perl5\",<br>\"full_name\":\"Perl\/perl5\",<br>\"html_url\":\"https:\/\/github.com\/Perl\/perl5\",<br>\"fork\":false,<br>\"owner\"<br>\"login\":\"Perl\" ,<br>\"pullRequests\":[ ,<br>\"platform\":\"github\",<br>\"type\":\"tutorials\",<br>\"tags\":[\"utopian-io\",<br>\"utopian-io\",<br>\"tutorials\",<br>\"perl\" ,<br>\"users\":[\"fruits\",<br>\"alphabet\",<br>\"a\",<br>\"nul\",<br>\"cartes\",<br>\"ch\",<br>\"alphanum\",<br>\"cards\",<br>\"departements\",<br>\"table\" ,<br>\"links\":[\"https:\/\/res.cloudinary.com\/hpiynhbhq\/image\/upload\/v1516429648\/vgvxk7hnpoeylsuadalh.jpg\",<br>\"https:\/\/walsoul.com\/index.php\/perl-programming-basic.html\" ,<br>\"image\":[\"https:\/\/res.cloudinary.com\/hpiynhbhq\/image\/upload\/v1516429648\/vgvxk7hnpoeylsuadalh.jpg\" " | comment_options | "author":"meblogger", "permlink":"introduction-to-the-perl-language-issue-1", "max_accepted_payout":"1000000.000 SBD", "percent_steem_dollars":10000, "allow_votes":true, "allow_curation_rewards":true, "extensions":[[0, "beneficiaries":[ "account":"utopian.pay", "weight":2500 |
|