{"id":18,"date":"2004-03-12T19:28:24","date_gmt":"2004-03-12T17:28:24","guid":{"rendered":"http:\/\/frenchfragfactory.net\/ozh\/archives\/2004\/03\/12\/fake-perl-shell\/"},"modified":"2007-04-22T11:28:33","modified_gmt":"2007-04-22T09:28:33","slug":"fake-perl-shell","status":"publish","type":"post","link":"https:\/\/planetozh.com\/blog\/2004\/03\/fake-perl-shell\/","title":{"rendered":"Fake perl shell"},"content":{"rendered":"<p>This script emulates a (really ugly) perl shell within your bash (or wathever) session. I like it to quickly test a few regexps or a function.<br \/>\n<!--more--><\/p>\n<div class=\"igsh-code-box\" id=\"ig-sh-1\"><pre class=\"language-perl line-numbers\" data-no-optimize=\"1\" data-cfasync=\"false\"><code class=\"language-perl\">#!\/usr\/bin\/perl -wn\r\n\r\n# the -n switch gives us a loop around the script. the BEGIN block is\r\n# only executed once. it sets up our prompt and turns off the signals\r\n# that could interrupt the script\r\n\r\nBEGIN {\r\n# turn off control keys\r\n    $SIG{$_} = &#039;IGNORE&#039; for keys %SIG;   \r\n# let the user know how to get off this crazy thing.\r\n    print &quot;\\n\\tType\\e[1m exit\\e[0m when you are ready to stop.\\n&quot;;\r\n\r\n    $history = 1;\r\n    sub prompt {\r\n        print &quot;\\n&quot;, $ENV{USER}, &#039;@perl-shell[&#039;, $history++, &#039;]&gt;&#039;;\r\n    }\r\n    prompt;\r\n}\r\n# the body is executed over and over (each time &lt;&gt; is given). all we\r\n# do is eval the body, and voila, perl-shell behavior\r\n\r\neval;\r\n$@ and warn $@;  # give perl errors back to the user\r\n\r\nprompt;                # print a fresh prompt with updated history\r\n\r\nEND { print &quot;\\n\\t\\tBye!\\n\\n&quot; }<\/code><\/pre><\/div>\n","protected":false},"excerpt":{"rendered":"<p>Light (and ugly) perl shell<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[2,3,9],"class_list":["post-18","post","type-post","status-publish","format-standard","hentry","tag-code","tag-linux","tag-perl"],"_links":{"self":[{"href":"https:\/\/planetozh.com\/blog\/wp-json\/wp\/v2\/posts\/18","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/planetozh.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/planetozh.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/planetozh.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/planetozh.com\/blog\/wp-json\/wp\/v2\/comments?post=18"}],"version-history":[{"count":0,"href":"https:\/\/planetozh.com\/blog\/wp-json\/wp\/v2\/posts\/18\/revisions"}],"wp:attachment":[{"href":"https:\/\/planetozh.com\/blog\/wp-json\/wp\/v2\/media?parent=18"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/planetozh.com\/blog\/wp-json\/wp\/v2\/categories?post=18"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/planetozh.com\/blog\/wp-json\/wp\/v2\/tags?post=18"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}