Friday, December 28, 2012

What is the substitute to '>/dev/null'?

|:’ is built-in pipe-based data sink and faster than ‘>/dev/null’. For instance,

echo "Hello World!" >/dev/null
can be rewritten as
echo "Hello World!" |:

How could you figure out the shell currently being run?

readlink -f /proc/$$/exe

Thursday, December 27, 2012

What are the ways to read contents of a file in Perl?

open (FH, "< io.txt") or die $!;
while(<FH>)
{
 print $_;
}
close(FH);

or

use Fcntl;

sysopen(FH, "io.txt", O_RDONLY) or die $!;
while(<FH>)
{
 print $_;
}
close(FH) || die "Couldn't close file properly.";

or

use IO::File;

my $FH = new IO::File("io.txt", "r") or die "could not open $filename : $!\n";
while ($line = $FH->getline())
{
   print $line;
}
$FH->close();