I have a simple question I was hoping you guys can help shed light on. I'm steadily learning perl.
Say I have a very large string, for example take the output of:
our $z = `du -B MB /home`
This will produce a string like the following:
1MB /home/debug/Music
1MB /home/debug/Downloads
20MB /home/debug
20MB /home/
What I would like to know is, how do I go about loading this string into an array with two columns, and n rows (where n is the number of lines in the du output)?
I was trying something like the following:
my $z1 = `du -B MB /home | tail -4`;
my @c0 = split (/n/, $z1);
my $z2 = join (/\t/, @c0);
my @c2=split(/\t/, $z2);
print @c2;
Which produces the following output:
1MB/home/debug/Music1MB/home/debug/Downloads20MB/home/debug20MB/home
I suppose I can use the substitution function s///g to substitue the directories for null values, and set the SPACE values to one array, and null the space values and set that to a second array, and can set 1 array as keys to the other.
Does anyone have any suggestions as to the best way to approach this?
Any help is appreciated.
Thanks,
Diego
splitshould be usingz1as the second parameter, right?