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.
|
I'm really confused and frustrated about how to get my PERL5LIB environment variable set correctly.
I'm on MacOS Sequoia, aarch64, running zsh, installed Perl 5.40.1 from source, into the /opt/perl_5.40.1 directory.
I already have a Perl 5.38.2, also built from source, located in the /opt/perl directory.
I have a MacPorts version of Perl installed (5.34.3). I removed an additional MacPorts Perl version 5.38.3 that I had installed recently.
I was reading in the Programming Perl book about PERL5LIB...I don't understand the order of the paths that should be in the PERL5LIB.
I've installed MANY Perl modules from CPAN using cpanm, specifying -L path respective to each version of Perl.
I have a section in my ~/.zshrc for Perl that looks like this:
I'm not using homebrew and I'm not using perlbrew.
I was using Sidef (installing manually as a standalone executable, not as a Perl Module) for some while, then things went bonkers when I installed Perl 5.38.3 from MacPorts (I think). Now Sidef fails, and many Perl programs fail that require modules (some work, some fail).
./wagstaff_primes.pl
Can't locate local/lib.pm in @INC (you may need to install the local::
+lib module) (@INC entries checked: /opt/perl_5.40.1/lib/site_perl/5.4
+0.1/darwin-2level /opt/perl_5.40.1/lib/site_perl/5.40.1 /opt/perl_5.4
+0.1/lib/5.40.1/darwin-2level /opt/perl_5.40.1/lib/5.40.1) at ./wagsta
+ff_primes.pl line 4.
BEGIN failed--compilation aborted at ./wagstaff_primes.pl line 4.
The aforementioned is a script from Rosetta Code.
find /opt/perl_5.40.1/lib -type f -name lib.pm
/opt/perl_5.40.1/lib/5.40.1/darwin-2level/lib.pm
/opt/perl_5.40.1/lib/lib/perl5/local/lib.pm
|
GetOptions(
'f' => \my $filename,
'bar' => \my $bar,
'bruce' => \my $batman,
'u' => \my $universe,
);
foo(
file => $filename,
maybe bar => $bar,
maybe baz => $batman,
maybe universe => $universe,
)
The above will invoke foo() with only the hash keys that have a defined value. This is better in the sense that this allows foo() to make a difference between parameter was not passed at all and parameter was passed, but was undef:
sub foo( %options ) {
if( ! exists $options{ baz } ) {
$options{ baz } = 'Superman';
};
...
}
Now, I'd like to have something similar(ish) to maybe on the receiving side for subroutines and objects, but I'm lacking a good name and a good syntax for it. The idea is to only set a value in a hash if the key does not exist yet. This is different from the // operator, because that one only checks for defined-ness, not for existence.
If we already had full-grown subroutine keyword parameters, this could be written in a declarative way as:
sub foo( :$baz = 'Superman', :$bar, :$file, :$universe='DC' ) {
}
(actually, I'm not sure if the above is correct for an invocation foo( baz => undef )).
But we don't have named parameters in the syntax yet, so we have to deparse the parameters ourselves:
sub foo( %options ) {
...
}
Let's assume that option is a good name for this (I'm not convinced):
sub option ( $key, $def, $options ) {
if( !exists $options->{ $key } ) {
$options->{ $key } = $def;
}
return $options
}
Then we could have a syntax like this:
sub foo( %options ) {
option baz => 'Superman',
option universe => 'DC',
\%options;
return \%options
}
But I'm not entirely happy with this approach for two reasons:
- It doesn't strike me as overly elegant. I'm happy with it being not overly elegant, but there are some warts:
- There must be something like this on CPAN already
Test file:
|
I am doing my annual revision and upload of an income-tax-related CPAN module. For testing on Windows (to which I myself don't have access), this year I added an AppVeyor configuration file (.appveyor.yml) essentially cloned from one of existing AppVeyor config files.
$ cat .appveyor.yml
version: 1.0.{build}
branches:
except:
- /travis/
skip_tags: true
cache:
- C:\strawberry -> .appveyor.yml
install:
- if not exist "C:\strawberry" cinst strawberryperl
- set PATH=C:\strawberry\perl\bin;C:\strawberry\perl\site\bin;C:\str
+awberry\c\bin;%PATH%
- cd C:\projects\%APPVEYOR_PROJECT_NAME%
- cpanm --installdeps .
build_script:
- perl Makefile.PL
- gmake
test_script:
- gmake test TEST_VERBOSE=1
notifications:
- provider: Email
to:
- [email protected]
on_build_status_changed: true
However, the AppVeyor process repeatedly fails. Here's the relevant part of the output:
If I download the log.txt file from this run, the last 10 to 12 lines match the tail of the output above.
My other distros using .appveyor.yml configuration files build and test as expected, so I am at a lost as to explain why this one does not. Any suggestions?
|