Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask

Seekers of Perl Wisdom

( [id://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
I thought I found a bug of Perl
2 direct replies — Read more / Contribute
by vincentaxhe
on Jul 14, 2024 at 06:02 as below;
    my $a = "abc"; my @b = $a =~ /.(?!a)/g; #comment this line to see the output my $c = 'test'; $c =~ s///; print $c
    run 'perl'; line 2 run or not, affect the rest. comment it and see for yourself.I use perl 5.38 in manjaro.


    It's beyong all expectations.

Net::DNS::Resolver::Recurse issue
1 direct reply — Read more / Contribute
by gtech99
on Jul 13, 2024 at 23:17

    I want to do a recursive dns lookup using Net::DNS::Resolver::Recurse , akin to doing dig +trace

    Great, the module's description even gives you a code example on how to do that.

    However, the module doesn't seem to try more than one NS in case of failure. I know I can do a loop where I can specify myself the NSs but how can I do that with this module ? I am testing one domain that has two NS listed. One answers properly, the other returns REFUSED.

    How can I get it to retry on the other server ?

Different presentation by SQLite
2 direct replies — Read more / Contribute
by jmClifford
on Jul 13, 2024 at 02:15

    Hi. I have an SQLite DB loaded from the web. I can read this with SQLite Expert Personal (5.4). On viewing a cell within the DB, I have the following observations;

    Column Name; inits_imperial Value (SQLite Expert); 'F' Value as Perl has on console; '°F'

    The above is with an original cell value that was downloaded (from the web). However, I can with the same Perl program create another row (with an Insert operation, $insert->execute('998', 'C', 'C', 'F'); ), where I get the expect behavior as below;

    Column Name; inits_imperial Value (SQLite Expert); 'F' Value as Perl has on console; 'F'

    The extra character from the former (and original cell) is , which I confirm is UTF-8 hex C3 82 (with Notepad++ hex presentation, after cut and paste).

    It appears the only way to rid my SQLite DB of these characters in the Perl console presentation (IDE is Eclipse) is to delete and insert the whole row again. Editing with SQLite Expect does not work. Can anyone shed light on this situation ??

    Regards JC......
Tk Entry widget confusion
2 direct replies — Read more / Contribute
by colintu
on Jul 12, 2024 at 05:56

    I have an Entry widget where the textvariable is initialised as a numeric before the widget is created. The widget and validate routine looks like:

    my @c_speed = (5, 8, 12, 8); my $cs_e1 = $seg1_f->Entry(-textvariable => \$c_speed[0], -width => +4, -validate => 'all', -vcmd => \&validate_speed, -font => $med_font)->grid( -row => 0, -column => 1, -sticky => "w"); sub validate_speed{ my $val = shift; $val ||= 0; #get alphas and punctuation out if( $val !~ /^\d+$/ ){ return 0 } if (($val >= 0) and ($val <= 20)) {return 1} else{ return 0 } }

    To me this looks like $val is being treated as a string (if( $val !~ /^\d+$/ )) and then on the next line as a numeric variable ($val >= 0) etc. The code does what I want/expect but how? Is this just 'magic behind the curtain'?

"readdir() attempted on invalid dirhandle" error?
2 direct replies — Read more / Contribute
by Anonymous Monk
on Jul 10, 2024 at 15:12
    I'm tearing my hair out over what should be a Perl 101 issue, and just can't tell what's going on. I have a script that processes some stuff, and then sends a directory over to a separate module for further processing. The module is unable to read the directory, and I don't know why. The code (so far!) is incredibly simple:
    sub process_directory { my ($self, $dir) = @_; print "TESTING: dir is [$dir]\n"; open my $dh, $dir or die "Could not open dir [$dir] for reading: $ +!\n"; my @files = readdir $dh; print "FILES: @files\n"; closedir $dh; }
    When I run this, I get:
    TESTING: dir is [/tmp/testdirectory] readdir() attempted on invalid dirhandle $dh at /path/to/ li +ne 14. FILES: closedir() attempted on invalid dirhandle $dh at /path/to/ l +ine 18.

    /tmp/testdirectory exists, it's a directory, and the caller has permissions to read it.

    I'm using strict and warnings. I don't get this--the open didn't fail; what's the problem here? I've searched for this, and the usual error is that people try reading a file as a directory or something like that; that's not the case here.
JAVA [[a-z]&&[^aeiou]] equivalence
4 direct replies — Read more / Contribute
by vincentaxhe
on Jul 10, 2024 at 00:59
    It's easy to guess what
    try to match, How perl do such thing, it's not included in primary perl pattern match knowledge.
SQLite returns funny characters
2 direct replies — Read more / Contribute
by jmClifford
on Jul 09, 2024 at 09:58

    Hi. I have SQLite with the Perl, where some text values returned are Degrees C and Degrees F and the "Degrees" is a small super scripted . And when this is returned to my Perl console it can show as °F. How can I easily convert / display this new font which I assume is not the usual ASCII (or my keyboard) font.

    Regards JC.....

Referer header
3 direct replies — Read more / Contribute
by frank1
on Jul 09, 2024 at 09:00

    Am having a problem from my script. this is the error am getting Forbidden (403) CSRF verification failed. Request aborted. You are seeing this message because this HTTPS site requires a Referer header to be sent by your Web browser, but none was sent. This header is required for security reasons, to ensure that your browser is not being hijacked by third parties.

    #!/usr/bin/perl use lib '.'; use strict; use warnings; use HTTP::Tiny; use JSON; use LWP::UserAgent; my $ua = LWP::UserAgent->new( ssl_opts => { verify_hostname => 0 }, ); $ua->agent("MyApp/0.1"); my $referer = $ENV{HTTP_REFERER}; my $callback = ""; my $address = ""; my $pending = "1"; my $confirmations = "1"; my $email = ''; my $json = "1"; my $post = "0"; my $priority = "default"; my $multi_token = "0"; my $convert = "0"; my $req = HTTP::Request->new(POST=>"https://link?callback=$callback&ad +dress=$address&pending=$pending&confirmations=$confirmations&email=$e +mail &post=$post&json=$json&priority=$priority&multi_token=$multi_token&con +vert=$convert"); $req->referer($referer); my $Response_Req = $ua->request($req); if($Response_Req->is_success){ print $Response_Req->content ."\n"; } else{ print "Error: " . $Response_Req->status_line; }
Closed:how to argparse same option to array instead of overwrite
2 direct replies — Read more / Contribute
by vincentaxhe
on Jul 09, 2024 at 00:15
    I wish arg parser can put same option's args into an array like this;
    use Getopt::xxx; getopts('e:'; \%options); if (ref $options{e} eq 'ARRAY'){ print 'you got e args with', $options{e}->@*; }else { print 'your e arg is ', $options{e} }
    I can run like -e 'a' -e 'b' to get 'you got e args with a b'.what module is designed to do such thing.


    I write my own argparser to keep order and add same option args:)

    my $all_options = "xp:b:f:s:"; my @s_options = $all_options =~ /[^:](?=:)/g; my @n_options = $all_options =~ /[^:](?!:)/g; my (@options, %options, $need); sub parsearg($$){ my ($index, $arg) = @_; if ($arg !~ /^-/){ return 1 if $index ne $need; } foreach (@s_options){ if ( $arg eq '-'.$_){ push @options, [$_, $ARGV[$index + 1]]; $need = $index + 1; return 0 } } foreach (@n_options){ if ($arg eq '-'.$_){ $options{$_} = 1; $need = $index; return 0 } } } while (my ($index, $argv) = each @ARGV){ last if parsearg $index, $argv; } my @files = splice @ARGV, $need + 1;
Console cursor position control
2 direct replies — Read more / Contribute
by jmClifford
on Jul 08, 2024 at 10:21

    Hi. I would like to control the position of the cursor on the console display of my Perl_Eclipse_IDE. When I, print "Input command: "; then the cursor needs to be at the end of this outputted string, and not where I stopped typing on a previous input.

    Regards JC.....

Add your question
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?

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

    How do I use this?Last hourOther CB clients
    Other Users?
    Others exploiting the Monastery: (2)
    As of 2024-07-24 00:49 GMT
    Find Nodes?
      Voting Booth?

      No recent polls found

      erzuuli‥ 🛈The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.