Я пытаюсь воспроизвести одни и те же результаты тремя разными способами, но мне сложно понять, как заставить его работать при использовании «use Shell»; (метод 2a ниже), любая помощь?
#!/usr/bin/perl
# v5.10.1 / linux
use strict;
use warnings;
use Shell;
# method 1 start
my $result = `df -H | grep -vE '^Filesystem|tmpfs|cdrom|none' | awk '{ print \$5 "\t" \$1}'`;
print $result . "\n";
# end of method 1
# I would like to try to reproduce the above but by using "use Shell", even if the above is already somehow using such anyway?!
# method 2a start
my $result2 = df ("-H"); # use powers of 1000 not 1024 # human readable
print $result2 . "\n"; # I can only get it working up to here
# end 2a
# 2b)
# or use regexs on df -H's output
my @linesofoutput= $result2=~/(.*?)\n/g; # needs checking to see if I'm getting the lines right with this?!
foreach my $temp(@linesofoutput){
if (($temp =~ /^Filesystem/)||($temp =~ /^tmpfs/)||($temp =~ /^cdrom/)||($temp =~ /^none/)){
# do nothing for lines starting with Filesystem, tmpfs or cdrom or none
# print "Do not show: $temp\n";
}else{
#print "$temp\n"; # lines wanted
my @words = split(/\s/, $temp); # make an array out of each line, splitting on any whitespace character: space, tab, newline, etc
@words = grep(!/^$/, @words); # remove empty elements. check this(not starting with, ending with)???
print "$words[4]". "\t"."$words[0]"."\n"; # filesystem entries are in index0, size index1, used index2, avail 3...
# be careful of /path/name of file or folder... because of the gaps, and so they could be made up of multi indexs
}
}
# end of method 2b