{"id":71,"date":"2009-02-06T11:47:19","date_gmt":"2009-02-06T16:47:19","guid":{"rendered":"http:\/\/www.popmartian.com\/tipsntricks\/?p=71"},"modified":"2009-02-06T12:01:51","modified_gmt":"2009-02-06T17:01:51","slug":"perl-how-to-print-a-list-without-a-loop","status":"publish","type":"post","link":"https:\/\/www.popmartian.com\/tipsntricks\/2009\/02\/06\/perl-how-to-print-a-list-without-a-loop\/","title":{"rendered":"PERL How To Print A List Without A Loop"},"content":{"rendered":"<p>PERL has a built-in function called join() that will concatenate a list with a given string.  The official perldoc states:<\/p>\n<p><em><strong>join EXPR,LIST<\/strong><br \/>\nJoins the separate strings of LIST into a single string with fields separated by the value of EXPR, and returns that new string. Example:<\/em><br \/>\n<code>$rec = join(':', $login,$passwd,$uid,$gid,$gcos,$home,$shell);<\/code><\/p>\n<p>From the code example, you can make CSV output and all kinds of goodies, but what the doc misses and the example doesn&#8217;t show is that combining join() with a print statement makes writing lists to STDOUT or a file handle a snap.  This is where join() really shines.<\/p>\n<p>Example:<\/p>\n<p><em><strong>Code<\/strong><\/em><br \/>\n<code>@names = ('Mark', 'Jim', 'Bob','Mary','Steven','Gomer');<br \/>\nprint join(\"\\n\", @names);<\/code><\/p>\n<p><em><strong>Output<\/strong><br \/>\nMark<br \/>\nJim<br \/>\nBob<br \/>\nMary<br \/>\nSteven<br \/>\nGomer<\/em><\/p>\n<p>Note that this will NOT print a final or beginning string.  Join() concatenates the elements, meaning it puts the string value BETWEEN the list elements.<\/p>\n<blockquote><p>Did you find this post useful or have questions or comments?  Please let me know!<\/p><\/blockquote>\n","protected":false},"excerpt":{"rendered":"<p>PERL has a built-in function called join() that will concatenate a list with a given string. The official perldoc states: join EXPR,LIST Joins the separate strings of LIST into a single string with fields separated by the value of EXPR, &hellip; <a href=\"https:\/\/www.popmartian.com\/tipsntricks\/2009\/02\/06\/perl-how-to-print-a-list-without-a-loop\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3,12,9,8],"tags":[],"class_list":["post-71","post","type-post","status-publish","format-standard","hentry","category-how-to-do-stuff","category-perl","category-programming","category-software"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.popmartian.com\/tipsntricks\/wp-json\/wp\/v2\/posts\/71","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.popmartian.com\/tipsntricks\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.popmartian.com\/tipsntricks\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.popmartian.com\/tipsntricks\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.popmartian.com\/tipsntricks\/wp-json\/wp\/v2\/comments?post=71"}],"version-history":[{"count":9,"href":"https:\/\/www.popmartian.com\/tipsntricks\/wp-json\/wp\/v2\/posts\/71\/revisions"}],"predecessor-version":[{"id":81,"href":"https:\/\/www.popmartian.com\/tipsntricks\/wp-json\/wp\/v2\/posts\/71\/revisions\/81"}],"wp:attachment":[{"href":"https:\/\/www.popmartian.com\/tipsntricks\/wp-json\/wp\/v2\/media?parent=71"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.popmartian.com\/tipsntricks\/wp-json\/wp\/v2\/categories?post=71"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.popmartian.com\/tipsntricks\/wp-json\/wp\/v2\/tags?post=71"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}