Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
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. Post a new question!

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.

User Questions
why package definition order affect the available of package variable
1 direct reply — Read more / Contribute
by fanasy
on Oct 20, 2019 at 06:06

    I can get the $testBegin::global but I cannot get the $testEnd::global
    my question is that
    it seems the test package definition location is the key for this issue.
    how perl consider the different order ? why perl can call testEnd::show_me() in main but can't see the $testEnd::global in main ?
    there is the code :

    #!/usr/bin/perl use feature qw/say/; use Data::Dumper; package testBegin { $global = "I'm in the testBegin package global version"; sub show_me { print "$tag: testBegin package $global\n"; } } testBegin::show_me(); print "-"x60; print "\n"; testEnd::show_me(); package testEnd { $global = "I'm in the testEnd package global version"; sub show_me { print "$tag: testEnd package $global\n"; } }

    output:
    : testBegin package I'm in the testBegin package global version
    ------------------------------------------------------------
    : testEnd package

cpanm says OK but module not really installed
4 direct replies — Read more / Contribute
by Anonymous Monk
on Oct 18, 2019 at 21:55
    I installed a cpan module with cpanm which reports: 1 distribution installed. All I can find is an install.json and an empty .packlist. Also "perllocal.pod" is appended! I browsed the module files on cpan but can't figure out why this happens with Astro::SpaceElevator (and its spiffy utf8 source: my $Δ = $P - $V).
Force Getopt::Long to Require ONLY Equals Sign Between Option Name and Value
3 direct replies — Read more / Contribute
by roho
on Oct 18, 2019 at 16:36
    Here is what I am trying to do. I have a command line option that is defined in Getopt::Long as having an optional string value as follows:

    use Getopt::Long; GetOptions( "ot:s" => \$ot ) or die("Error in command line arguments\n +");

    The problem occurs when -ot (without a value) is followed by either another option or a program argument. The -ot option will take the next word as its value.

    I know I can signal the end of options by using -- on the command line, but for backward compatibility before this program used Getopt::Long (the program previously used "/usr/bin/perl -s" to process command line options), I would like to tell Getopt::Long to always require an equals sign before a value so that -ot (without a value) can be followed by a program argument without the invervening -- in the command line.

    Here is what I am aiming for:

    Scenario #1:

    myprog.pl -ot=123 arg1 arg2 ...

    This works fine. Variable $ot='123'

    Scenario #2:

    myprog.pl -ot arg1 arg2 ...

    I need $ot to be set to the empty string '' instead of 'arg1', without the need of an intervening -- on the command line (hence the need to force Getopt::Long to require an equals sign between the option name and its value).

    Again, my goal is backward compatibility with the way this program was called before adding Getopt::Long, because this program is very central to the system and is literally called in thousands of places. TIA for any suggestions.

    "It's not how hard you work, it's how much you get done."

SOAP::Lite encoding mess?
2 direct replies — Read more / Contribute
by nikosv
on Oct 18, 2019 at 08:02
    I've got the same CGI script running on two separate servers.

    Server A specs are :
    Centos 6.5
    Apache/2.2.15 (Unix)
    perl5 (revision 5 version 10 subversion 1)
    SOAP::Lite 1.27

    Server B specs are :
    Centos 5.6
    Apache/2.2.3
    perl5 (revision 5 version 8 subversion 8)
    SOAP::Lite 0.714

    The CGI script is a very simple test.cgi :
    #!/usr/bin/perl
    
    use SOAP::Transport::HTTP;
    
    SOAP::Transport::HTTP::CGI->dispatch_to('test')->handle( );
    
    package test;
    
    sub select {
    
    
    my $class = shift;
    my $a1 	= shift;
    my $a2 	= shift;
    my $a3	= shift;
    my $a4  = shift;
    my $a5 	= shift;
    my $a6	= shift;
    my $a7	= shift;
    my $a8	= shift;
    my $a9  = shift;
    my $a10	= shift;
    my $a11	= shift;
    my $a12	= shift;
    my $a13 = shift;
    my $a14 = shift;
    my $a15	= shift;
    
     return [$a1.$a2];
    
    }
    
    

    the client calling the script is :
    use SOAP::Lite +trace;
    
    my $soap = SOAP::Lite->uri("http://192.168.1.262/test")->
    proxy("http://192.168.1.262/cgi-bin/test.cgi")->
    select("16/09/2019 17:04:00","16/09/2019","13/09/2019 13:44:09","Α","B",1,"s","e","g","x","x","748",3519999,4015,2)->result;
    
    print "\n";
    print "result is ", @{$soap};
    

    Note that parameter "A" is in Greek the rest are in English.Both servers have as locale LANG=el_GR.ISO8859-7

    When the client calls the script on Server A, all the parameters consumed by test.cgi have the UTF8 flag on,except Greek "A".(Dumped with Devel::Peek)
    SV = PV(0x1f243c8) at 0x1b37880
      REFCNT = 1
      FLAGS = (POK,pPOK,UTF8)
      PV = 0x1f3cef0 "16/09/2019 17:04:00"\0 UTF8 "16/09/2019 17:04:00"
      CUR = 19
      LEN = 24
    $VAR1 = \'16/09/2019 17:04:00';
    SV = PV(0x1f243c8) at 0x1b37880
      REFCNT = 1
      FLAGS = (POK,pPOK,UTF8)
      PV = 0x1f3cef0 "16/09/2019"\0 UTF8 "16/09/2019"
      CUR = 10
      LEN = 24
    $VAR1 = \'16/09/2019';
    SV = PV(0x1f243c8) at 0x1b37880
      REFCNT = 1
      FLAGS = (POK,pPOK,UTF8)
      PV = 0x1f3cef0 "13/09/2019 13:44:09"\0 UTF8 "13/09/2019 13:44:09"
      CUR = 19
      LEN = 24
    $VAR1 = \'13/09/2019 13:44:09';
    SV = PV(0x1f243c8) at 0x1b37880
      REFCNT = 1
      FLAGS = (POK,pPOK)
      PV = 0x1f3cef0 "\301"\0
      CUR = 1
      LEN = 24
    $VAR1 = \'Α';
    SV = PV(0x1f243c8) at 0x1b37880
      REFCNT = 1
      FLAGS = (POK,pPOK,UTF8)
      PV = 0x1f3cef0 "B"\0 UTF8 "B"
      CUR = 1
      LEN = 24
    $VAR1 = \'B';
    SV = PV(0x1f243c8) at 0x1b37880
      REFCNT = 1
      FLAGS = (POK,pPOK,UTF8)
      PV = 0x1f3cef0 "1"\0 UTF8 "1"
      CUR = 1
      LEN = 24
    $VAR1 = \'1';
    SV = PV(0x1f243c8) at 0x1b37880
      REFCNT = 1
      FLAGS = (POK,pPOK,UTF8)
      PV = 0x1f3cef0 "s"\0 UTF8 "s"
      CUR = 1
      LEN = 24
    $VAR1 = \'s';
    SV = PV(0x1f243c8) at 0x1b37880
      REFCNT = 1
      FLAGS = (POK,pPOK,UTF8)
      PV = 0x1f3cef0 "e"\0 UTF8 "e"
      CUR = 1
      LEN = 24
    $VAR1 = \'e';
    SV = PV(0x1f243c8) at 0x1b37880
      REFCNT = 1
      FLAGS = (POK,pPOK,UTF8)
      PV = 0x1f3cef0 "g"\0 UTF8 "g"
      CUR = 1
      LEN = 24
    $VAR1 = \'g';
    SV = PV(0x1f243c8) at 0x1b37880
      REFCNT = 1
      FLAGS = (POK,pPOK,UTF8)
      PV = 0x1f3cef0 "x"\0 UTF8 "x"
      CUR = 1
      LEN = 24
    $VAR1 = \'x';
    SV = PV(0x1f243c8) at 0x1b37880
      REFCNT = 1
      FLAGS = (POK,pPOK,UTF8)
      PV = 0x1f3cef0 "x"\0 UTF8 "x"
      CUR = 1
      LEN = 24
    $VAR1 = \'x';
    SV = PV(0x1f243c8) at 0x1b37880
      REFCNT = 1
      FLAGS = (POK,pPOK,UTF8)
      PV = 0x1f3cef0 "748"\0 UTF8 "748"
      CUR = 3
      LEN = 24
    $VAR1 = \'748';
    SV = PV(0x1f243c8) at 0x1b37880
      REFCNT = 1
      FLAGS = (POK,pPOK,UTF8)
      PV = 0x1f3cef0 "3519999"\0 UTF8 "3519999"
      CUR = 7
      LEN = 24
    $VAR1 = \'3519999';
    SV = PV(0x1f243c8) at 0x1b37880
      REFCNT = 1
      FLAGS = (POK,pPOK,UTF8)
      PV = 0x1f3cef0 "4015"\0 UTF8 "4015"
      CUR = 4
      LEN = 24
    $VAR1 = \'4015';
    SV = PV(0x1f243c8) at 0x1b37880
      REFCNT = 1
      FLAGS = (POK,pPOK,UTF8)
      PV = 0x1f3cef0 "2"\0 UTF8 "2"
      CUR = 1
      LEN = 24
    $VAR1 = \'2';
    
    On the contrary when the client calls the script on Server B, all the parameters consumed by test.cgi have the UTF8 flag OFF,including Greek "A"
    SV = PV(0x12399a50) at 0x12036080
      REFCNT = 1
      FLAGS = (POK,pPOK)
      PV = 0x123a07e0 "16/09/2019 17:04:00"\0
      CUR = 19
      LEN = 24
    $VAR1 = \'16/09/2019 17:04:00';
    SV = PV(0x12399a50) at 0x12036080
      REFCNT = 1
      FLAGS = (POK,pPOK)
      PV = 0x123a07e0 "16/09/2019"\0
      CUR = 10
      LEN = 24
    $VAR1 = \'16/09/2019';
    SV = PV(0x12399a50) at 0x12036080
      REFCNT = 1
      FLAGS = (POK,pPOK)
      PV = 0x123a07e0 "13/09/2019 13:44:09"\0
      CUR = 19
      LEN = 24
    $VAR1 = \'13/09/2019 13:44:09';
    SV = PV(0x12399a50) at 0x12036080
      REFCNT = 1
      FLAGS = (POK,pPOK)
      PV = 0x123a07e0 "\301"\0
      CUR = 1
      LEN = 24
    $VAR1 = \'Α';
    SV = PV(0x12399a50) at 0x12036080
      REFCNT = 1
      FLAGS = (POK,pPOK)
      PV = 0x123a07e0 "B"\0
      CUR = 1
      LEN = 24
    $VAR1 = \'B';
    SV = PV(0x12399a50) at 0x12036080
      REFCNT = 1
      FLAGS = (POK,pPOK)
      PV = 0x123a07e0 "1"\0
      CUR = 1
      LEN = 24
    $VAR1 = \'1';
    SV = PV(0x12399a50) at 0x12036080
      REFCNT = 1
      FLAGS = (POK,pPOK)
      PV = 0x123a07e0 "s"\0
      CUR = 1
      LEN = 24
    $VAR1 = \'s';
    SV = PV(0x12399a50) at 0x12036080
      REFCNT = 1
      FLAGS = (POK,pPOK)
      PV = 0x123a07e0 "e"\0
      CUR = 1
      LEN = 24
    $VAR1 = \'e';
    SV = PV(0x12399a50) at 0x12036080
      REFCNT = 1
      FLAGS = (POK,pPOK)
      PV = 0x123a07e0 "g"\0
      CUR = 1
      LEN = 24
    $VAR1 = \'g';
    SV = PV(0x12399a50) at 0x12036080
      REFCNT = 1
      FLAGS = (POK,pPOK)
      PV = 0x123a07e0 "x"\0
      CUR = 1
      LEN = 24
    $VAR1 = \'x';
    SV = PV(0x12399a50) at 0x12036080
      REFCNT = 1
      FLAGS = (POK,pPOK)
      PV = 0x123a07e0 "x"\0
      CUR = 1
      LEN = 24
    $VAR1 = \'x';
    SV = PV(0x12399a50) at 0x12036080
      REFCNT = 1
      FLAGS = (POK,pPOK)
      PV = 0x123a07e0 "748"\0
      CUR = 3
      LEN = 24
    $VAR1 = \'748';
    SV = PV(0x12399a50) at 0x12036080
      REFCNT = 1
      FLAGS = (POK,pPOK)
      PV = 0x123a07e0 "3519999"\0
      CUR = 7
      LEN = 24
    $VAR1 = \'3519999';
    SV = PV(0x12399a50) at 0x12036080
      REFCNT = 1
      FLAGS = (POK,pPOK)
      PV = 0x123a07e0 "4015"\0
      CUR = 4
      LEN = 24
    $VAR1 = \'4015';
    SV = PV(0x12399a50) at 0x12036080
      REFCNT = 1
      FLAGS = (POK,pPOK)
      PV = 0x123a07e0 "2"\0
      CUR = 1
      LEN = 24
    $VAR1 = \'2';
    

    I have tried several scenarios and tests and can't find out why this is happening. Maybe some change in Perl/SOAP::Lite ?

eval: Why use the 'Zombie error' idiom?
4 direct replies — Read more / Contribute
by DouglasDD
on Oct 18, 2019 at 05:38
    A common idiom for eval is
    eval { do_something_that_might_die(); 1; } or do { my $error = $@ || 'Zombie error'; deal_w($error) || die; }

    Is that because $@ might contain something "false-y" (like 0, '0', "", undef)?
    (If so, who cares? Why would I care if the "reason string" is false-y or not?)

    Or is it a hold-over from bugs in ancient versions of perl?
    If so, how old? if we already require versions greater than $v can we dispense with it?

    ((Sorry monks, I'm sure this has been asked before, but searches like "perl eval zombie error" and the like are mostly about zombie processes and code that already contains that boilerplate.))

    Edit: I Forgot to mention that our local coding standards discourage Try::Tiny apparently because it's edge cases have been tripped over in the past.

Pre-Forking Daemon with Parallel::ForkManager
5 direct replies — Read more / Contribute
by enemyofthestate
on Oct 17, 2019 at 16:40

    Has anyone used, or have an idea how to use, Parallel::ForkManager in a pre-forking daemon? I know how to do it using an adapted formula 17.12 from Perl Cookbook but P::FM is a pretty slick way to handle the forks. I have only used it in client programs where it works very well.

Need help calling perl from javascript
3 direct replies — Read more / Contribute
by kruegerm
on Oct 17, 2019 at 14:56
    I have written a perl script I can access from a URL: https://hostname/myweb/myScript.pl?id=1234&stg=13 I get the proper results using the URL

    In javascript/jscript, I have tried loading the script ($('#element').load()) - I've tried full ajax calls within a function:

    $.ajax({ url: '/myweb/myScript.pl', type: 'post', data: { 'id' : '1234', 'stg' : '13' } });
Meaning of //
5 direct replies — Read more / Contribute
by hanspr
on Oct 17, 2019 at 12:55

    Im revising a code written in perl and I'm finding the use of "//" in different ways: tests, shift, others.

    return 1 unless ($flag // 0) return 1 unless ($flag // 1) if $HAS_FOCUS // '' $socket = shift // $SOCKET_CLIENT;

    I have searched and I do not find what does "//" means. In what section of the documentations is this explained

weird bug with IO::Prompter, prompt spells out the word 'prompt'
2 direct replies — Read more / Contribute
by daxim
on Oct 17, 2019 at 11:01
    This works:

    › perl -MIO::Prompt=prompt -e'prompt -menu => [6..9]'

    This does not (type letters and/or Enter key when prompted):

    › perl -MIO::Prompter=prompt -e'prompt -menu => [6..9]'

    Can you repro?

p5p vs CPAN
3 direct replies — Read more / Contribute
by Anonymous Monk
on Oct 17, 2019 at 00:24
    Is there a list somewhere of CPAN modules that get broken by the slow painful drip of backward incompatible changes to the perl interpreter? I can see the damage by visiting CPAN and clicking Testers on broken modules but wonder if someone has scraped that all together into a Wall of Shame. I'm fixing broken orphaned modules locally with no way help fix the official and CPAN is in an advanced state of decay. What if CPAN put orphaned modules on a wiki or something so we could all just fix the thing and move on? Imagine how fast the 1/2 of CPAN that is probably broken would be fixed!

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":


  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?
    Username:
    Password:

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

    How do I use this? | Other CB clients
    Other Users?
    Others surveying the Monastery: (4)
    As of 2019-10-20 11:10 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?
      Notices?