I wonder if someone could tell me why this code is not working. It is to sort the records from highest percent to lowest. (I edited the regexp in split)
Found one error. the
mao{$_[0]} should be
map {$_->[0]} and the split needed a newline (\n) at the end of the pattern
split(/(?<=workspace\/data)\n/, $s)
Now, I'm getting the correct sorted output.
C:\Old_Data\perlp>perl try3.pl
>>> prd1702
Filesystem Size Used Avail Use% Moun
+ted on
/workspace 3.9T 746G 3.1T 23% /wor
+kspace/data
>>> prd1703
Filesystem Size Used Avail Use% Moun
+ted on
/workspace 3.9T 687G 3.2T 18% /wor
+kspace/data
>>> prd1701
Filesystem Size Used Avail Use% Moun
+ted on
/workspace 3.9T 887G 3.0T 13% /wor
+kspace/data
(Below, the code before fixes noted above)
#!/usr/bin/perl
use strict;
use warnings;
use feature 'say';
#https://stackoverflow.com/questions/79472778/sorting-the-content-of-a
+-file
my $s = <<EOF;
>>> prd1701
Filesystem Size Used Avail Use% Moun
+ted on
/workspace 3.9T 887G 3.0T 13% /wor
+kspace/data
>>> prd1702
Filesystem Size Used Avail Use% Moun
+ted on
/workspace 3.9T 746G 3.1T 23% /wor
+kspace/data
>>> prd1703
Filesystem Size Used Avail Use% Moun
+ted on
/workspace 3.9T 687G 3.2T 18% /wor
+kspace/data
EOF
my @data = map {$_[0]}
sort {$b->[1] <=> $a->[1]}
map {[$_, /\s(\d+)%/]} split(/(?<=workspace\/data)/, $s);
It is printing error as:
C:\Old_Data\perlp>perl try3.pl
Use of uninitialized value in numeric comparison (<=>) at try3.pl line
+ 23.
Use of uninitialized value in numeric comparison (<=>) at try3.pl line
+ 23.