Are perlfaq6 and perlop correct about "/o" modifier?
1 direct reply — Read more / Contribute
|
by Anonymous Monk
on May 09, 2026 at 09:06
|
|
|
perlfaq6:
In versions 5.6 and later, Perl won't recompile the regular expression if the variable hasn't changed, so you probably don't need the /o option. It doesn't hurt, but it doesn't help either.
perlop:
... the largely obsolete /o ...
The bottom line is that using /o is almost never a good idea.
Then what about something like benchmark below (this is 5.42, and I _do_ see a small but noticeable performance bump with real code which does some heavy lifting when parsing. I don't think any variables have changed; just wanted to split pieces of a regex into separate variables for clarity):
use strict;
use warnings;
use feature 'say';
use Benchmark 'cmpthese';
my $pat = qr/\d+/;
my $s = '123abc' x 1e6;
cmpthese -1, {
foo => sub { 1 while $s =~ /\G $pat \D+ /cgx },
bar => sub { 1 while $s =~ /\G $pat \D+ /cgxo },
};
__END__
Rate foo bar
foo 1213522/s -- -88%
bar 10345112/s 752% --
|
Underscore in scalar name not in main package
4 direct replies — Read more / Contribute
|
by InfiniteSilence
on May 08, 2026 at 15:49
|
|
|
So I am looking around in perlvar and I learn that if you preface a scalar variable name with an underscore it will by default be in the main package...wow, I think. I want to try that:
perl -e 'package Nether; our $val = 2000; my $_nonesuch = 3000; packa
+ge main; print __PACKAGE__ . qq~\t~ . $main::_nonesuch;'
Makes: main
What? ...what happened by my value? So I take away the package portion:
perl -e 'package Nether; our $val = 2000; my $_nonesuch = 3000; packa
+ge main; print __PACKAGE__ . qq~\t~ . $_nonesuch;'
main 3000
As an aside I should mention why I keep posting these cryptic things about basic Perl functionality. I am researching why people run into problems with Perl and give up. The target audience (for now) includes project management and product owners who have enough familiarity with the language to recommend its use but want to simultaneously reduce the backlash that might come from doing so.
Celebrate Intellectual Diversity
|
perllocal EXE_FILES and %Config
1 direct reply — Read more / Contribute
|
by Anonymous Monk
on May 08, 2026 at 07:56
|
|
|
I noticed some inconsistent entries in perllocal
for modules that have EXE_FILES:
Acme::MetaSyntactic (script/ is typical)
EXE_FILES: script/meta script/metafy
Pod::Parser
EXE_FILES: scripts/podselect
CGI-Kwiki
EXE_FILES: inc/SCRIPTS/kwiki-install
GD
EXE_FILES: bdf_scripts/bdf2gdfont.pl
App::FatPacker (bin/ is typical too)
EXE_FILES: bin/fatpack
Despite all that, everything listed as EXE_FILES ends up
in the same directory, specified (on my system) by 12 %Config variables
with the same exact value as $Config{bin}:
/Users/u/perl5/perlbrew/perls/perl-5.42.0/bin
My question is this: do these 12 Config variables have the same
value on all Perl installations? I guess there are actually 14
of these same vars, but the vendor values are blank on my system.
Here's a little script to check. I'd like to know if these
can be different values so I know which one(s) to use.
Thanks in advance.
#!/usr/bin/perl -l
# Check if all the bin and script dirs in %Config are the same.
use strict;
use warnings;
use Config;
@_ = qw/bin
binexp
initialinstalllocation
installbin
installscript
installsitebin
installsitescript
scriptdir
scriptdirexp
sitebin
sitebinexp
sitescript
sitescriptexp
vendorbin
vendorbinexp/;
printf "%-24s %-100s\n", $_, $Config{$_} for @_;
Output on my system:
bin /Users/u/perl5/perlbrew/perls/perl-5.42.0/bin
binexp /Users/u/perl5/perlbrew/perls/perl-5.42.0/bin
initialinstalllocation /Users/u/perl5/perlbrew/perls/perl-5.42.0/bin
installbin /Users/u/perl5/perlbrew/perls/perl-5.42.0/bin
installscript /Users/u/perl5/perlbrew/perls/perl-5.42.0/bin
installsitebin /Users/u/perl5/perlbrew/perls/perl-5.42.0/bin
installsitescript /Users/u/perl5/perlbrew/perls/perl-5.42.0/bin
scriptdir /Users/u/perl5/perlbrew/perls/perl-5.42.0/bin
scriptdirexp /Users/u/perl5/perlbrew/perls/perl-5.42.0/bin
sitebin /Users/u/perl5/perlbrew/perls/perl-5.42.0/bin
sitebinexp /Users/u/perl5/perlbrew/perls/perl-5.42.0/bin
sitescript /Users/u/perl5/perlbrew/perls/perl-5.42.0/bin
sitescriptexp /Users/u/perl5/perlbrew/perls/perl-5.42.0/bin
vendorbin
vendorbinexp
|
How do you determine what version of Perl your program requires?
3 direct replies — Read more / Contribute
|
by Anonymous Monk
on May 07, 2026 at 18:55
|
|
|
perlver seems to do a good job of figuring out the syntax (except that --blame often fails to find the reason), but what about modules? Perl::MinimumVersion says "Future plans are to also add support for tracing module dependencies"
but that hasn't happened yet. One might think corelist would help with core modules but it can be misleading. Let's say we use List::Util:
% corelist List::Util
List::Util was first released with perl v5.7.3
But 5.7.3 is not the version needed if uniq or uniqnum are used:
https://metacpan.org/dist/Scalar-List-Utils/changes:
1.44 -- 2016/03/17 23:08:46
CHANGES
* Added List::Util::uniq() and uniqnum()
% corelist -a List::Util | grep 1.44
NOPE
% corelist -r | grep 2016
v5.22.2 2016-04-29
...
5.22.2 is required to support uniq (or maybe an updated List::Util if that's possible). How do you determine what version of Perl your program requires? A robot told me this is a real gap in the Perl ecosystem...
|
perldoc -lf anomaly
2 direct replies — Read more / Contribute
|
by Anonymous Monk
on May 07, 2026 at 15:44
|
|
|
Why does "perldoc -lf splice" return perlfunc and perlop when the word "splice" does not exist in perlop?
% perldoc -lf splice
/Users/u/perl5/perlbrew/perls/perl-5.42.0/lib/5.42.0/pods/perlfunc.pod
/Users/u/perl5/perlbrew/perls/perl-5.42.0/lib/5.42.0/pods/perlop.pod
% grep 'splice' /Users/u/perl5/perlbrew/perls/perl-5.42.0/lib/5.42.0/pods/perlfunc.pod
L<C<splice>|/splice ARRAY,OFFSET,LENGTH,LIST> has three scalar arguments
... (19 lines deleted for brevity)
% grep 'splice' /Users/u/perl5/perlbrew/perls/perl-5.42.0/lib/5.42.0/pods/perlop.pod
% <- NOTHING!
|
Where is the new perlootut?
3 direct replies — Read more / Contribute
|
by InfiniteSilence
on May 04, 2026 at 09:57
|
|
|
shell> perldoc perlootut
"...This document was created in February, 2011, and the last major revision was in February, 2013....
I check metacpan...same document. I want to learn the latest techniques for OO in Perl. I remember reading that there were native classes added in 5.38. Is someone updating perlootut? Is is being superseded by another POD?
Celebrate Intellectual Diversity
|
Regex question - identify which pattern comes first
3 direct replies — Read more / Contribute
|
by harangzsolt33
on May 01, 2026 at 20:12
|
|
|
I feel like I have learned a lot in the past 10 years since I started learning Perl, but I still probably don't know more than half of what's possible using regex. I have often come across situations where I needed to identify which pattern occurs first in a string. So, I am not trying to capture a part of the pattern nor am I trying to identify if it occurs at all or where. I am just trying to figure our which of the possible patterns is FIRST in the string. For example:
Sample string: "AB ABDA DCACCB AAA BSAA CAAB ACS ABA DBA BA DASSABACA A"
I'm looking for either: BA[ABC]{2} OR CA[CD]{2} OR DA[SC]{2}
So, I would write: /BA[ABC]{2}|CA[CD]{2}|DA[SC]{2}/
Is there a way to get a return value of 1, 2, or 3 depending on which pattern was matched first? How would I do that?
|
copyfail challenge: making Perl version smaller
6 direct replies — Read more / Contribute
|
by dmitri
on Apr 29, 2026 at 21:37
|
|
|
Hello Fellow Monks!
By now, I am sure you have heard of the "732 bytes of Python code to root every major Linux distro."
(I checked it out -- it works. Don't run it on your own machine, though, as it will mangle your `su` binary).
At any rate -- I figured, we can make it smaller in Perl!
A half hour and a bunch of tokens later, I failed. My smallest version is 767 bytes.
Can anyone here do better?
|
Installation of 2 module prerequisites failing - using cpanm
2 direct replies — Read more / Contribute
|
by Intrepid
on Apr 28, 2026 at 17:52
|
|
|
Hi Monks. I don't know if anyone can help me with this, but I'll ask
anyhow.
I'm doing this on the commandline:
$ PERL5LIB=~/build/perl-testing-libs/lib/perl5 cpanm --self-contained \
--exclude-vendor -L ~/build/perl-testing-libs --wget --skip-satisfied \
--interactive --verbose YAML::LibYAML
The resulting message is
! Installing the dependencies failed: Module 'Test::More' is not installed
! Bailing out the installation for File-Temp-0.2312.
! Installing the dependencies failed: Module 'File::Temp' is not installed
When I try to build the two required modules alone, I can't get a succcessful
installation. What's going on?
EDIT
Sorry,I was tired and in a hurry and didn't give much contextual info. My System and my Perl are:
OS: CYGWIN_NT-10.0-26200; cpu type: x86_64; |12| cores, cpus present: |1|
Perl version v5.40.3, CygPerl.
– Soren
Apr 28, 2026 at 21:46 UTC
A just machine to make big decisions
Programmed by fellows (and gals) with compassion and vision
We'll be clean when their work is done
We'll be eternally free yes, and eternally young
Donald Fagen —> I.G.Y.
(Slightly modified for inclusiveness)
|
Perl Inheritance Not Working as Expected
1 direct reply — Read more / Contribute
|
by InfiniteSilence
on Apr 28, 2026 at 14:24
|
|
|
So I write a response to this blogs.perl.org post titled, 'Who Tests the Tester? Me!!!' by lichtkind and almost as soon as I hit the submit button I take a closer look at my test and say, 'oops...I forgot to change the class to the new subclass...I'll just change that and rerun my tests. No problem...'
t/01.t ............ ok
t/hsltupletest.t .. 1/?
# Failed test 'A is now between 0 and 360 since it is degrees'
# at t/hsltupletest.t line 22.
# Looks like you failed 1 test of 6.
t/hsltupletest.t .. Dubious, test returned 1 (wstat 256, 0x100)
Failed 1/6 subtests
t/tupletest.t ..... ok
Test Summary Report
-------------------
t/hsltupletest.t (Wstat: 256 (exited 1) Tests: 6 Failed: 1)
Failed test: 6
Non-zero exit status: 1
Files=3, Tests=12, 0 wallclock secs ( 0.08 usr 0.02 sys + 0.49 cusr
+ 0.07 csys = 0.66 CPU)
Result: FAIL
Denied!
Debugging reveals something extremely strange...
main::(./t/hsltupletest.t:8): my $prospectTupleRef = [qw~a b c~];
DB<1> n
main::(./t/hsltupletest.t:10): my $tuple = HSLTuple->new($prospectT
+upleRef, 'HSL');
DB<1> n
main::(./t/hsltupletest.t:12): ok($tuple->is_valid($prospectTupleRe
+f) == 0, "A B C is an array but not an HSL tuple");
DB<1> x $tuple
0 FakeTuple=HASH(0x5b2e6ee12a70)
'axes' => 3
'space_name' => 'HSL'
'tupledata' => undef
DB<2>
What? It says it is a FakeTuple even though I clearly used the HSLTuple! Unsurprisingly, it calls the is_valid() method of FakeTuple:
main::(./t/hsltupletest.t:20): ok($tuple->is_valid([qw~361 62 99~])
+ == 0 , "A must be between 0 and 360 since it is degrees");
DB<2> s
FakeTuple::is_valid(FakeTuple.pm:34):
34: my ($self, $data2Check) = @_;
DB<2> l
34==> my ($self, $data2Check) = @_;
35: my $result = 0;
36: for(0..2){$result++ if ($data2Check->[$_]=~m/\d+/ &&
37 $data2Check->[$_] >= 0 &&
38 $data2Check->[$_] <= 100)};
39
40: return ( $result == $self->no_of_axes() ) ? 1 : 0;
41 }
42
43 # code (loosely) borrowed from Basis.pm
DB<2>
Why did it not use my derived class and call my overridden method?
Celebrate Intellectual Diversity
|