Reputation: 633
I have following code in the Perl language:
#!/usr/bin/perl
use strict;
use warnings;
use Data::Dumper;
my $DF = "/usr/bin/df -Pk"; # HP-UX
my @temp = split /\n/, `$DF`;
shift @temp;
print Dumper \@temp;
And the output is something as below (shorter for better readability):
$VAR1 = [
'/dev/vg00/lvol6 114224 46304 67920 41% /home',
'/dev/vg00/lvol7 8340704 4336752 4003952 52% /opt',
'/dev/vg00/lvol4 520952 35080 485872 7% /tmp',
];
I want to converting the @temp
array (or create a new array) to multi-dimensional (array of arrays) like this:
$VAR1 = [
['/dev/vg00/lvol6', 114224, 46304, 67920, '41%', '/home'],
['/dev/vg00/lvol7', 8340704, 4336752, 4003952, '52%', '/opt'],
['/dev/vg00/lvol4', 520952, 35080, 485872, '7%', '/tmp'],
];
Anyone help? Thanks in advance! :)
Upvotes: 3
Views: 145
Reputation: 414
This is how I would do it
my @lines = `$DF`;
my @data = map { [split] } @lines;
print Dumper \@data;
This is assuming that there is no unexpected whitespace in a path
Upvotes: 1