Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
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
Incompatibility after perl 5.10 packing and UTF-8 strings
3 direct replies — Read more / Contribute
by powerperl
on Aug 03, 2022 at 14:18

    You can refer incompatibility in perldelta doc of v5.10. My concern is I am upgrading old perl before v5.10 to v5.20. Should I worry about it. How to identify if this incompatibility is serious concern for me. I my codebase I found lot of usage of pack and unpack. It is mentioned that 'use bytes' will give old behaviour back.

    Can we do it everywhere ? How to handle this incompatibility in general if we are jumping from version before 5.10 to version after 5.10 that is 5.20. I know that it is complex to take such high jump I am trying to take care of everything. Good explanation will help me here.

Inconsistent results with keys on thread shared hashes
2 direct replies — Read more / Contribute
by izomiac
on Aug 03, 2022 at 00:22
    I've been stumped with a bug in my code for days, until I traced it down to a fairly simple subroutine that gave inconsistent results when two or more threads were running. Here's an isolated version of the problem:
    #!/usr/bin/perl use strict; use warnings; $|=1; use threads; use threads::shared; my %testOne :shared = (A => 1, B => 2, C => 3, D => 4, E => 5); my %testTwo = (A => 1, B => 2, C => 3, D => 4, E => 5); my $inc :shared = 1; do { threads->create(sub { while (1){ my $i = join('', sort keys %testOne); my $j = join('', sort keys %testTwo); print "$inc-1\t$i\n" if ($i ne 'ABCDE'); print "$inc-2\t\t$j\n" if ($j ne 'ABCDE'); } }); } while (sleep 5 && $inc++ && $inc < 100);
    I'm running this with Strawberry Perl on Windows, and my application uses threads so the Tk GUI doesn't freeze. I want to be able to use a lot of worker threads for a CPU-bound genetic sorting algorithm. Is this a bug in perl, or have I misunderstood something?
Diagnosing "Input/output error"
4 direct replies — Read more / Contribute
by Anonymous Monk
on Aug 02, 2022 at 13:18

    I'm seeing a very weird problem in a large Catalyst-based app I have to maintain.

    The logging system is set up on the application level, using Log::Dispatch::File (FileRotate, specifically); every Controller simply sets a different logfile as necessary (or disables logging entirely). The setup is exactly the same for every Controller: they inherit the same begin.

    Exactly one Controller has very frequent errors: 'Caught exception in My::Controller:ThisParticularController->begin "Cannot write to '/path/to/logs/ThisParticularController.log': Input/output error at /path/to/Log/Dispach/File.pm line 101."' However, this controller also very frequently does successfully write to this logfile. No other Controller ever reports this error. This Controller is probably the busiest one, but it's not a vast difference. There are no differences in permissions for this file, and it's in the same filesystem as all the other logs.

    I simply can't see any difference with how logging is handled for this Controller vs. any of the others, and I don't know what "Input/output error" actually means. What can I do to try to figure this out?

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 ?
7 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.


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 avoiding work at the Monastery: (3)
As of 2022-08-09 04:13 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?