<?xml version='1.0'?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:georss="http://www.georss.org/georss" xmlns:atom="http://www.w3.org/2005/Atom" >
<channel>
	<title><![CDATA[BOL: Run bash script in Perl program !]]></title>
	<link>https://bioinformaticsonline.com/blog/view/42921/run-bash-script-in-perl-program?</link>
	<atom:link href="https://bioinformaticsonline.com/blog/view/42921/run-bash-script-in-perl-program?" rel="self" type="application/rss+xml" />
	<description><![CDATA[]]></description>
	
	<item>
	<guid isPermaLink="true">https://bioinformaticsonline.com/blog/view/42921/run-bash-script-in-perl-program</guid>
	<pubDate>Sat, 27 Feb 2021 01:42:23 -0600</pubDate>
	<link>https://bioinformaticsonline.com/blog/view/42921/run-bash-script-in-perl-program</link>
	<title><![CDATA[Run bash script in Perl program !]]></title>
	<description><![CDATA[<p>BioPerl is a compilation of Perl modules that can be used to build bioinformatics-related Perl scripts. It is used, for example, in the development of source codes, standalone software/tools, and algorithms in bioinformatics programmes. Different modules are easy to instal and include, making it easier to perform different functions. Despite the fact that Python is commonly favoured over Perl, some bioinformatics software, such as the standalone version of 'alienomics', is written in Perl. Often it's a major problem for beginners to execute certain Unix/shell commands in Perl script, so it's hard to determine which feature is unique to a situation.</p><div style="background-color: white;">Perl provides various features and operators for the execution of external commands (described as follows), which are unique in their own way.</div><div style="background-color: white;">&nbsp;</div><div style="background-color: white;">They vary slightly from one another, making it difficult for Perl beginners to choose between them.</div><div style="background-color: white;">&nbsp;</div><div style="background-color: white;"><strong>1. IPC::Open2</strong></div><p>More at https://bioinformaticsonline.com/snippets/view/42919/perl-ipcopen2-module</p><p><strong>2. exec&rdquo;&rdquo;</strong></p><p><em>&nbsp;syntax:&nbsp;</em><code>exec "command";</code></p><div style="background-color: #edfbff;">It's a Perl function (perlfunc) that executes a command but never returns, similar to a function's return statement.</div><div style="background-color: white;">While running the command, it keeps processing the script and does not wait until it finishes first, returns false when the command is not found, but never returns true.</div><p><strong>3. Backticks &ldquo; or qx//</strong></p><p><em>syntax:&nbsp;</em><code>`command`;</code></p><p><em>syntax:&nbsp;</em><code>qx/command/;</code></p><div style="background-color: white;">It's a Perl operator (perlop) that executes a command and then resumes the Perl script once the command has ended, but the return value is the command's STDOUT.</div><p><strong>4. IPC::Open3</strong></p><p><em>syntax:&nbsp;</em><code>$output =&nbsp;open3(\*CHLD_IN, \*CHLD_OUT, \*CHLD_ERR,&nbsp;'command arg1 arg2', 'optarg',...);</code></p><p style="text-align: justify;"><code></code>It is very similar to <code>IPC::Open2</code> with the capability to capture all three file handles of the process, i.e., STDIN, STDOUT, and STDERR. It can also be used with or without the shell. You can read about it more in the documentation: <a href="https://perldoc.perl.org/IPC/Open3.html" target="_blank">IPC::Open3</a>.</p><p><code>$output = open3(my $o ut,&nbsp;my $in, 'command arg1 arg2');</code></p><p>OR without using the shell</p><p><code>$output = open3(my $out,&nbsp;my $in, 'command', 'arg1', 'arg2');</code></p><p><strong>5.a2p</strong></p><p><em>syntax:&nbsp;</em><code>a2p [options] [awkscript]</code></p><p>There is a Perl utility known as <code>a2p</code> which translates <code>awk</code> command to Perl. It takes awk script as input and generates a comparable Perl script as the output. Suppose, you want to execute the following <code>awk</code> statement</p><p><code>awk '{$1 = ""; $2 = ""; print}' f1.txt</code></p><p>This statement gives error sometimes even after escaping the variables (\$1, \$2) but by using <code>a2p</code> it can be easily converted to Perl script:</p><p>For further information, you can read it&rsquo;s documentation: <code><a href="https://perldoc.perl.org/a2p.html" target="_blank">a2p</a></code></p><p>More help at https://bioinformaticsonline.com/snippets/view/42920/perl-script-to-run-awk-inside-perl</p><p><strong>6. system()</strong></p><p><em>syntax:&nbsp;</em><code>system( "command" );</code></p><p>It is also a Perl function (<a href="https://perldoc.perl.org/functions/system.html" target="_blank">perlfunc</a>) that executes a command and waits for it to get finished first and then resume the Perl script. The return value is the exit status of the command. It can be called in two ways:</p><p><code>system( "command arg1 arg2" );</code></p><p>OR</p><p><code>system( "command", "arg1", "arg2" );</code></p><p>HELP</p><p>Here are some useful Perl cheat sheets that can be used as a quick reference guide.--&nbsp;<a href="https://www.pcwdld.com/perl-cheat-sheet" target="_blank">https://www.pcwdld.com/perl-cheat-sheet</a></p>]]></description>
	<dc:creator>Neel</dc:creator>
</item>

</channel>
</rss>