M
Mahesh Asolkar
I have the following script:
-----
#!/usr/bin/perl
use strict;
use warnings;
my %hist = ();
my @hist;
$hist{(split /\s+/)[3]}++
foreach (`$ENV{'SHELL'} -c history`);
print map {"$hist{$_} : $_\n"}
sort {$hist{$b} <=> $hist{$a}}
keys %hist;
-----
I want to change it such that it uses '`$ENV{'SHELL'} -c history`'
only if nothing is piped into the script. If I call the script like:
% myscript.pl
It should use '`$ENV{'SHELL'} -c history`'. However if it is called
like:
% history | myscript.pl
It should use the piped in data instead.
What would be the best approach?
Thanks,
Mahesh
-----
#!/usr/bin/perl
use strict;
use warnings;
my %hist = ();
my @hist;
$hist{(split /\s+/)[3]}++
foreach (`$ENV{'SHELL'} -c history`);
print map {"$hist{$_} : $_\n"}
sort {$hist{$b} <=> $hist{$a}}
keys %hist;
-----
I want to change it such that it uses '`$ENV{'SHELL'} -c history`'
only if nothing is piped into the script. If I call the script like:
% myscript.pl
It should use '`$ENV{'SHELL'} -c history`'. However if it is called
like:
% history | myscript.pl
It should use the piped in data instead.
What would be the best approach?
Thanks,
Mahesh