{"id":133,"date":"2010-08-02T21:28:40","date_gmt":"2010-08-02T21:28:40","guid":{"rendered":"http:\/\/soliloquyforthefallen.net\/blog\/?p=133"},"modified":"2015-03-05T07:18:15","modified_gmt":"2015-03-05T07:18:15","slug":"the-importance-of-coding-small","status":"publish","type":"post","link":"https:\/\/soliloquyforthefallen.net\/?p=133","title":{"rendered":"The importance of Coding Small"},"content":{"rendered":"<p>What does &#8220;Coding Small&#8221; mean?<\/p>\n<p>Simple.  It means code small.  A small bit of code is easier to debug then a large program.<\/p>\n<p>Take for instance my current Perl coding project.  I&#8217;m writing a script that will reside on my server and download a comic, and news headlines and then print it out at about 5 in the morning so everybody can have a bit of happiness, and find out what hell has broken loose in the world today.<\/p>\n<p>The comic I want to use is Sheldon.  Sometimes, however the creator doesn&#8217;t keep strictly to posting the link on his RSS feed.  So, I have to make sure that I grab that, or I will get a perl error later on.  How you ask?<\/p>\n<div style=\"width: 610px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/xkcd.com\/208\/\"><img decoding=\"async\" loading=\"lazy\" title=\"Stand Back\" src=\"http:\/\/soliloquyforthefallen.net\/images\/xkcd\/regular_expressions.png\" alt=\"Until tonight, this comic meant absoloutely nothing to me . . . .\" width=\"600\" height=\"607\" \/><\/a><p class=\"wp-caption-text\">Stand Back!<\/p><\/div>\n<p>Yes indeed.<\/p>\n<pre lang=\"PERL\" escaped=\"true\">use warnings; use strict;\nmy @file_contents;\n\nopen FILE, \"text.txt\" or die \"$!\"; #open with write rights\n@file_contents = &lt;FILE&gt;;\nclose FILE;\nforeach my $text (@file_contents){\n chomp $text;\n if ($text =~ m\/^Strip for \/){\n print $text;\n } else {\n print \"No goodness here (Text:$text) n\"\n }\n}\n<\/pre>\n<p>Pretty much what this snippet does is takes and loads the contents of the file into an array, with each line being an item in the array.\u00a0 It then stores one value of the array, chomps the newline character off of the end, and check if it starts with &#8220;Strip for&#8221;, case sensitively via a regular expression.\u00a0 If the value starts as wanted, then I&#8217;m good and it prints that line from the file.\u00a0 If\u00a0 the line does not start with &#8220;Strip for&#8221;, then it prints &#8220;No Goodness here&#8221; and what the line actually was.<\/p>\n<p>This can then be turned into a subroutine to use with perl.<\/p>\n<pre lang=\"PERL\" escaped=\"true\">use warnings; use strict;\nmy @file_contents;\n\nopen FILE, \"text.txt\" or die \"$!\"; #open with write rights\n@file_contents = &lt;FILE&gt;;\nclose FILE;\n\n&amp;reg_ex(@file_contents);\n\nsub reg_ex{\n foreach my $text (@file_contents){\n chomp $text;\n if ($text =~ m\/^Strip for \/){\n print $text;\n } else {\n print \"No goodness here (Text:$text) n\"\n }\n }\n}\n<\/pre>\n<p>Now, no matter how many different types of data I wanna shove at the array, I just call &amp;reg_ex(array of data), and it parse and prints.<\/p>\n<p>Why is this nice?\u00a0 Let say that I have a more complicated program.\u00a0 Now that I know that section of code works, I can paste that subroutine in, call when needed, and know that it works and is not affecting other parts of my program.\u00a0 Then I can work on debugging the rest of my crappy code.<\/p>\n<p>Lemme know what you think in the comments, and hopefully I&#8217;ll be posting more of this stuff as I go on . . . .<\/p>\n","protected":false},"excerpt":{"rendered":"<p>What does &#8220;Coding Small&#8221; mean? Simple. It means code small. A small bit of code is easier to debug then a large program. Take for instance my current Perl coding project. I&#8217;m writing a script that will reside on my server and download a comic, and news headlines and then print it out at about&#8230; <\/p>\n<div class=\"read-more navbutton\"><a href=\"https:\/\/soliloquyforthefallen.net\/?p=133\">Read More<i class=\"fa fa-angle-double-right\"><\/i><\/a><\/div>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[117],"tags":[],"_links":{"self":[{"href":"https:\/\/soliloquyforthefallen.net\/index.php?rest_route=\/wp\/v2\/posts\/133"}],"collection":[{"href":"https:\/\/soliloquyforthefallen.net\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/soliloquyforthefallen.net\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/soliloquyforthefallen.net\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/soliloquyforthefallen.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=133"}],"version-history":[{"count":1,"href":"https:\/\/soliloquyforthefallen.net\/index.php?rest_route=\/wp\/v2\/posts\/133\/revisions"}],"predecessor-version":[{"id":768,"href":"https:\/\/soliloquyforthefallen.net\/index.php?rest_route=\/wp\/v2\/posts\/133\/revisions\/768"}],"wp:attachment":[{"href":"https:\/\/soliloquyforthefallen.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=133"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/soliloquyforthefallen.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=133"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/soliloquyforthefallen.net\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=133"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}