Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Seekers of Perl Wisdom

( #479=superdoc: print w/replies, xml ) Need Help??

If you have a question on how to do something in Perl, or you need a Perl solution to an actual real-life problem, or you're unsure why something you've tried just isn't working... then this section is the place to ask.

However, you might consider asking in the chatterbox first (if you're a registered user). The response time tends to be quicker, and if it turns out that the problem/solutions are too much for the cb to handle, the kind monks will be sure to direct you here.

Post a new question!

User Questions
Python equivalent of an Ovid, brian d foy, or chromatic
3 direct replies — Read more / Contribute
by davebaker
on Aug 02, 2022 at 11:13

    I'll be doing some work with Python's Django web framework, and wonder if any Perl people have needed to do so also, but in particular I'm asking whether you've located authors of books and articles on the Python language (or Django in particular) who are in the league of Curtis "Ovid" Poe, brian d foy, or chromatic.

    I've taken the liberty of posting here because you'll know exactly what I mean by the question, and other Perl developers might have needed to go down this road.

    There are so damned many Python and Django resources that it's nearly impossible for this longtime Perl enthusiast to find the diamonds among the coals, even using criteria like reader reviews.

Is it ever legitimate to override $^O ?
6 direct replies — Read more / Contribute
by syphilis
on Aug 01, 2022 at 21:53
    Ken Williams' Path-Class module has a test file (t/01-basic.t) that begins with:
    BEGIN { $^O = 'Unix'; # Test in Unix mode }
    Without that override, many tests fail on Windows because paths that are expected to contain '/' are detected as instead containing '\\'.
    And there are also cases of an expected empty string being detected as '0'.
    Try building Path::Class on Windows and watch it pass - then comment out the BEGIN{} block in t/01-basic.t and examine the failures then elicited by that script.
    (BTW, I don't know how that override hack even works.)

    The trouble is that, beginning with perl-5.34.0, this hack fails to deliver because running 'perl -Mblib t/01-basic.t' fails in the way already outlined above, irrespective of whether that override is included or commented out.
    In addition (with perl-5.34.0 onwards and the BEGIN{} block included), t/01-basic.t fails in an entirely different way when run inside the Test::Harness (as part of 'make test'):
    t/01-basic.t .......... 1/78 Can't call method "relative" on an undefi +ned value at C:\sisyphusion\Path-Class-0.37\blib\lib/Path/Class/Entity.pm line 7 +6. t/01-basic.t .......... Dubious, test returned 22 (wstat 5632, 0x1600)
    What bug(s) should be investigated ?
    Is overriding $^O a legitimate thing to do ?
    Is it a bug that, on perl-5.34 and later, the "Can't call method "relative"..." error arises ? If so, is it a Path::Class bug ? or a Test::Harness bug ? or a perl bug ?.
    Is it a bug that, on perl-5.34 and later, the override loses its effectiveness when run outside Test::Harness ? If so, is it a Path::Class bug ? or a perl bug ?

    Cheers,
    Rob
How to collect output of DB2 query run interactive mode using perl script
2 direct replies — Read more / Contribute
by Rishi2Monk
on Aug 01, 2022 at 14:32
    TiTle: How to collect output of DB2 query run interactive mode using perl script

    I need to write a perl script which will run the DB2 query (describe "select * from ") in interactive mode and collect the output of it to get the colname, typename and length from it. Here is what I have tried so far. My main goal is to collect the colname, typename and length from the query 'describe "select * from indic.name"'. Kindly let me know if any other efficient alternative way is there. I can not use DBI module as it was not installed.

    use strict; use warnings; my @cmd_list = ( 'db2', 'connect to ctinld01 user db2tf0 using db2tf0' +, 'describe select * from indic.name'); $|++; # turn off buffering my $shpid = open( my $sh, '|-', '/bin/bash' ) or die "Can't open a shell process: $!\n"; for my $cmd ( @cmd_list ) { if($cmd eq "describe select * from indic.name") { open (STDOUT, "| tee -ai logs.txt"); print $sh "$cmd\n"; print "It Works!"; close STDOUT; } else { print $sh "$cmd\n"; } } print $sh "exit\n"; close $sh; waitpid( $shpid, 0 ); print "Shell's all done. Moving right along...\n";
    perltidy and experimental for_list
    1 direct reply — Read more / Contribute
    by ibm1620
    on Aug 01, 2022 at 13:39
      Dear Monks,

      Perltidy (ver 20220613) currently doesn't handle the v5.36 for_list syntax.

      Running perltidy -npro:

      Before:

      #!/usr/bin/env perl use v5.36; no warnings q/experimental::for_list/; for my ( $k, $v ) ( %ENV ) { say "$k=$v"; } say "Done";
      After:
      #!/usr/bin/env perl use v5.36; no warnings q/experimental::for_list/; for my ( $k, $v ) (%ENV){ say "$k=$v"; } say "Done";
      Does its experimental status mean that it won't be supported by perltidy? Are there .perltidyrc settings to keep it from removing the line break following the closing bracket?

      Thanks!

    URL resolve (operations on path etc.)
    2 direct replies — Read more / Contribute
    by bliako
    on Jul 31, 2022 at 03:37

      Esteemed Monks,

      I am trying to translate the following Node.js fragment to Perl (it takes a URL and sort of chdir to it, clever enough to remove endpoint if a file and query):

      const url = require('url'); const x = 'http:/a.com/a/b/c/d/e.json?x=1&y=2'; const y = '../../../'; console.log(url.resolve(x, y));

      result is : http:/a.com/a/

      Now, if x='http:/a.com/a/b/c/d/e.json/?x=1&y=2'; (i.e. the path points to a "directory" rather than to a "file") the result is http:/a.com/a/b/ (as expected IMO)

      I tried to do this with URI but failed:

      use URI; my $x = 'http:/a.com/a/b/c/d/e.json?x=1&y=2'; my $y = '../../../'; my $u = URI->new($x); my $p = $u->path().'/'.$y; $u->path($p); print $u; <c> <p>With this result: <c>http:/a.com/a/b/c/d/e.json/../../../?x=1&y=2

      The Node.js version seems to be able to understand that the last segment before the query is a "file" and removes it. Then it does the merging of the two paths including successful relative operations (../). What is the safest way to achieve that behaviour in Perl? The last resort would be to shell-out to Node.js ...

      bw, bliako

    Building with -MCPAN but cannot find libraries
    1 direct reply — Read more / Contribute
    by mldvx4
    on Jul 30, 2022 at 15:13

      I'm trying add Image::Scale manually using -MCPAN, but get an error in that the installation process cannot find the installed libraries:

      # perl -MCPAN -e shell

      Once in the shell, I try to install the module:

      cpan[1]> install Image::Scale Reading '/root/.cpan/Metadata' Database was generated on Sat, 30 Jul 2022 16:29:03 GMT Running install for module 'Image::Scale' Checksum for /root/.cpan/sources/authors/id/A/AG/AGRUNDMA/Image-Scale- +0.14.tar.gz ok Scanning cache /root/.cpan/build for sizes ...................................................................... +......DONE 'YAML' not installed, will not store persistent state Configuring A/AG/AGRUNDMA/Image-Scale-0.14.tar.gz with Makefile.PL Image::Scale requires at least one of libjpeg or libpng, please instal +l one or both and try again. No 'Makefile' created AGRUNDMA/Image-Scale-0.14.tar.gz /usr/bin/perl Makefile.PL -- NOT OK Failed during this command: AGRUNDMA/Image-Scale-0.14.tar.gz : writemakefile NO -- No + 'Makefile' created

      The system seems to have the libraries installed:

      $ find / -type f \( -name 'libpng*' -o -name 'libjpeg*' \) -print /usr/lib/libpng16.so.16.37.0 /usr/lib/libjpeg.so.8.2.2 /usr/lib/libpng16.a

      What steps have I missed or gotten wrong?

    Big cache
    6 direct replies — Read more / Contribute
    by Liebranca
    on Jul 28, 2022 at 17:39

      Hello everyone,

      My monolith makescript maker/syntax file generator/auto FFI-bindings emitter/parser/preprocessor/inliner/someday to be compiler thingy has a lot of hashes, alright. Translation tables, symbol tables, keywords organized by loose cathegories, lots of cool stuff.

      Now, the data actually in use by the program is generated from perl variables that are usually hases as well; because there's some processing of these I need to do at init time I thought just start saving these things to disk before it gets too big and actually slows down startup.

      I'm doing that with store/retrieve and already have a mechanism in place to either load the file if it exists and no update is needed, else regenerate. This is done automatically on INIT blocks. Looks something like this:

      my $result; INIT {load_cache('name',\$result,\&generator,@data)};

      ^slightly abbreviated for clarity, but you get the idea. Now, this is fine but it essentially means I need a separate file for each instance of some structure, which is undesirable in my case.

      I'd much rather do this per-package, or a multitude of packages even, and it wouldn't really be too difficult to implement. So what's the question? There's no question. But I'd like to request some general advice on *local* databases, meaning my own computer: no cloud, no net, no servers no mambo, I save things to disk and no one else needs to know.

      See, I can not duck for "Database" and not get flooded with absolutely irrelevant results about frameworks for whatever it is modern web developers and java mongers are concerned with. It's ridiculous and it's driving me crazy.

      So... tips? Conventional wisdom? Pitfalls? What to watch out for? That kind of stuff. It might be mostly just things I already know but I'd rather hear them twice than never.

      Just for context, I'm on a half-burned, half-dead one decade old model two core cpu and the bigger file in this scenario is like what, 64kb. Absolutely *gargantuan* quantities of data. But I'm interested in efficiently storing this program data uncompressed so that I don't end up with a million small files that need to be read individually at startup.

      Cheers, lyeb.

      free/libre post licensed under gnu gplv3; your quotes will inherit.
    Merging multiple variations of a serial number
    9 direct replies — Read more / Contribute
    by Doozer
    on Jul 28, 2022 at 10:01

      Dear monks,

      I am trying to organise a number of lists of item serial numbers (stored in a small number of files). The problem I have is each unit can have up to 5 variations of it's serial number stored across the multiple files (poorly designed system but there we go). Let me provide an example below:

      012212316000140 = Full 15 digit serial. This comprises of month and year (0122), core serial (1231600014), check digit (0)
      01221231600014 = 14 digit version (minus the last check digit)
      2212316000140 = 13 digit version 1 (minus the leading 2 month digits but including the last check digit)
      1221231600014 = 13 digit version 2 (minus the leading zero for the month and minus the check digit). These entries would need to be corrected to add the leading zero and therefore become the 14 digit version
      221231600014 = 12 digit version (minus both leading month and last check digit)
      1231600014 = 10 digit version (just the core serial)

      As you can see this is a nightmare and different areas use different versions of the serial. My first step is to try and make a hash using the base 10 digit serial as the key, and then have key value pairs for each of it's possible forms. For example:

      { '1231600014' => { '15' => '012212316000140', '14' => '01221231600014' } }

      The other option which might be easier to manage within a JSON file is to store each core serial along with it's leading month and year, and check digit as seperate keys for example

      { '1231600014' => { 'check' => '0', 'month' => '01', 'year' => '22' } }

      The main thing that is giving me a headache is processing each serial and working out if we already have an entry for it, as well as valid entries for each possible form

      Any assistance would be greatly appreciated. I fear I am overcomplicating this in my head. I'm happy to provide more information and clarity if required

      Thanks!

    Core Dump while building from source on AIX
    1 direct reply — Read more / Contribute
    by flynn7312
    on Jul 28, 2022 at 08:05
      Hey Monks, While trying to build 5.36.0 on AIX with gcc, i get the follwing exception during "make install"
      LIBPATH=/opt/itsv/applperlbin/perl-5.36.0:/opt/itsv/applperlbin/perl-5 +.36.0 ./perl -Ilib -I. -f pod/buildtoc -q gmake: *** [makefile:421: pod/perltoc.pod] Illegal instruction (core d +umped)

      as seen, it uses the perl from the sourcetree which seems not ready for this task

      compile time output (-V):
      root@aixbuildhostng: /opt/itsv/applperlbin/perl-5.36.0 # LIBPATH=/opt/ +itsv/applperlbin/perl-5.36.0:/opt/itsv/applperlbin/perl-5.36.0 ./per +l -Ilib -I. -V Summary of my perl5 (revision 5 version 36 subversion 0) configuration +: Platform: osname=aix osvers=7.1.0.0 archname=ppc-aix-thread-multi-64all uname='aix aixbuildhostng 1 7 00fb1a6d4c00 powerpc aix ' config_args='-des -Dprefix=/opt/itsv/applperlbin/install-5.36.0 -D +version=5.36 -Dmyhostname=uscss-nostromo -Darchname=ppc-aix -Dcf_by=W +eyland Corp -Dcc=gcc -Dccflags=-maix64 -O2 -L/opt/freeware/lib64 -L/u +sr/lib64 -L/opt/freeware/lib -L/usr/lib -D_ALL_SOURCE -D_ANSI_C_SOURC +E -D_POSIX_SOURCE -DUSE_NATIVE_DLOPEN -DNEED_PTHREAD_INIT -I/opt/free +ware/include -Dlddlflags=-G -bI:$(PERL_INC)/perl.exp -bE:$(BASEEXT).e +xp -bnoentry -lc -lm -L/opt/freeware/lib64 -L/usr/lib64 -L/opt/freewa +re/lib -L/usr/lib -Dldflags=-Wl,-b64 -L/opt/freeware/lib64 -L/usr/lib +64 -L/opt/freeware/lib -L/usr/lib -Wl,-blibpath:/opt/itsv/applperlbin +/install-5.36.0/lib/perl5/5.36/CORE:/opt/freeware/lib/64:/opt/freewar +e/lib:/usr/lib:/lib -Duseshrplib -Dshrpldflags=-H512 -T512 -bhalt:4 - +bM:SRE -bE:perl.exp -Dar=/usr/bin/ar -Dfull_ar=/usr/bin/ar -Darflags= +-X64 -Dnm=/usr/bin/nm -X64 -B -Dinstallprefix=/opt/itsv/applperlbin/i +nstall-5.36.0 -Dvendorprefix=/opt/itsv/applperlbin/install-5.36.0 -Dv +endorlib=/opt/itsv/applperlbin/install-5.36.0/share/perl5/vendor_perl + -Dvendorarch=/opt/itsv/applperlbin/install-5.36.0/lib/perl5/5.36/ven +dor_perl -Dsiteprefix=/opt/itsv/applperlbin/install-5.36.0 -Dsitelib= +/opt/itsv/applperlbin/install-5.36.0/share/perl5/site_perl -Dsitearch +=/opt/itsv/applperlbin/install-5.36.0/lib/perl5/5.36/site_perl -Dpriv +lib=/opt/itsv/applperlbin/install-5.36.0/perl5/5.36 -Darchlib=/opt/it +sv/applperlbin/install-5.36.0/lib/perl5/5.36 -Dusethreads -Duseithrea +ds -Duselargefiles -Dd_semctl_semun -Di_syslog -Dman3ext=3 -Duseperli +o -Dinstallusrbinperl=n -Ubincompat5005 -Uversiononly -Dscriptdir=/op +t/itsv/applperlbin/install-5.36.0/bin -Duse64bitint' hint=recommended useposix=true d_sigaction=define useithreads=define usemultiplicity=define use64bitint=define use64bitall=define uselongdouble=undef usemymalloc=n default_inc_excludes_dot=define Compiler: cc='gcc -maix64' ccflags ='-D_THREAD_SAFE -maix64 -O2 -L/opt/freeware/lib64 -L/usr/ +lib64 -L/opt/freeware/lib -L/usr/lib -D_ALL_SOURCE -D_ANSI_C_SOURCE - +D_POSIX_SOURCE -DUSE_NATIVE_DLOPEN -DNEED_PTHREAD_INIT -I/opt/freewar +e/include -DNEED_PTHREAD_INIT -fwrapv -maix64 -DUSE_64_BIT_ALL -D_FOR +TIFY_SOURCE=2' optimize='-O' cppflags='-D_THREAD_SAFE -maix64 -O2 -L/opt/freeware/lib64 -L/usr/ +lib64 -L/opt/freeware/lib -L/usr/lib -D_ALL_SOURCE -D_ANSI_C_SOURCE - +D_POSIX_SOURCE -DUSE_NATIVE_DLOPEN -DNEED_PTHREAD_INIT -I/opt/freewar +e/include -DNEED_PTHREAD_INIT -fwrapv' ccversion='' gccversion='8.3.0' gccosandvers='' intsize=4 longsize=8 ptrsize=8 doublesize=8 byteorder=87654321 doublekind=4 d_longlong=define longlongsize=8 d_longdbl=define longdblsize=8 longdblkind=0 ivtype='long' ivsize=8 nvtype='double' nvsize=8 Off_t='off_t' lseeksize=8 alignbytes=8 prototype=define Linker and Libraries: ld='gcc -maix64' ldflags =' -Wl,-b64 -L/opt/freeware/lib64 -L/usr/lib64 -L/opt/free +ware/lib -L/usr/lib -Wl,-blibpath:/opt/itsv/applperlbin/install-5.36. +0/lib/perl5/5.36/CORE:/opt/freeware/lib/64:/opt/freeware/lib:/usr/lib +:/lib -Wl,-b64' libpth=/opt/freeware/lib /usr/lib /usr/ccs/lib /usr/lib64 libs=-lpthread -lbind -lnsl -lgdbm -ldbm -ldb -ldl -lld -lm -lcryp +t -lpthreads -lc perllibs=-lpthread -lbind -lnsl -ldl -lld -lm -lcrypt -lpthreads - +lc libc=/lib/libc.a so=a useshrplib=true libperl=libperl.a gnulibc_version='' Dynamic Linking: dlsrc=dl_aix.xs dlext=so d_dlsymun=undef ccdlflags='-Xlinker -bE:/opt/itsv/applperlbin/install-5.36.0/lib/p +erl5/5.36/CORE/perl.exp' cccdlflags=' ' lddlflags=' -Wl,-b64 -Wl,-G -Wl,-bI:$(PERL_INC)/perl.exp -Wl,-bE: +$(BASEEXT).exp -Wl,-bnoentry -lpthreads -lc -lm -L/opt/freeware/lib64 + -L/usr/lib64 -L/opt/freeware/lib -L/usr/lib' Characteristics of this binary (from libperl): Compile-time options: HAS_TIMES MULTIPLICITY PERLIO_LAYERS PERL_COPY_ON_WRITE PERL_DONT_CREATE_GVSV PERL_MALLOC_WRAP PERL_OP_PARENT PERL_PRESERVE_IVUV USE_64_BIT_ALL USE_64_BIT_INT USE_ITHREADS USE_LARGE_FILES USE_LOCALE USE_LOCALE_COLLATE USE_LOCALE_CTYPE USE_LOCALE_NUMERIC USE_LOCALE_TIME USE_PERLIO USE_PERL_ATOF USE_REENTRANT_API USE_THREAD_SAFE_LOCALE Built under aix Compiled at Jul 28 2022 13:48:49 @INC: lib . /opt/itsv/applperlbin/install-5.36.0/lib/perl5/5.36/site_perl /opt/itsv/applperlbin/install-5.36.0/share/perl5/site_perl /opt/itsv/applperlbin/install-5.36.0/lib/perl5/5.36/vendor_perl /opt/itsv/applperlbin/install-5.36.0/share/perl5/vendor_perl /opt/itsv/applperlbin/install-5.36.0/lib/perl5/5.36 /opt/itsv/applperlbin/install-5.36.0/perl5/5.36
      when using miniperl instead no exeption occurs
      root@aixbuildhostng: /opt/itsv/applperlbin/perl-5.36.0 # LIBPATH=/opt/ +itsv/applperlbin/perl-5.36.0:/opt/itsv/applperlbin/perl-5.36.0 ./min +iperl -Ilib -I. -f pod/buildtoc -q root@aixbuildhostng: /opt/itsv/applperlbin/perl-5.36.0 #
      an hints very welcome! chris
    How to duplicate every member of an array
    5 direct replies — Read more / Contribute
    by soblanc
    on Jul 28, 2022 at 04:00
      Hi, I would like to duplicate (or triplicate) every member of my array, how should I do? By instance, @array = (a,b,c,d), I want to obtain @array_final = (a,a,b,b,c,c,d,d) So in the end it would double (or triple) the number of member in my array. Thank you in advance!


Add your question
Title:
Your question:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":


  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (3)
As of 2022-08-08 14:04 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?