Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

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
Download full perl documentation?
5 direct replies — Read more / Contribute
by Anonymous Monk
on Nov 24, 2023 at 22:36
    Is it any longer possible to download full perl documentation,
    that I can read while I'm off-line?
    
    I can now read on-line e.g. https://perldoc.perl.org/perlvar .
    I'm glad that the information is still available.
    
    I used to be able to see essentially this page by typing,
    at the bash prompt, something like 'man perlvar'.  I'd like to
    be able to do this now, when I'm off-line, NOT by pulling
    up a page from the internet, such as the above example.
    
    Is this any longer possible?
    
    Trying to figure out how to do this, I see messages such
    as "You need to install the perl-doc package to use this program."
    
    These fail to find or to install anything useful:
      apt install perl-doc
      apt install perldoc
      apt search perldoc
      apt search perl-doc
      aptitude install perl-doc
      aptitude install perldoc
      aptitude search perldoc
      aptitude search perl-doc
      cpan -i perl-doc
      cpan -i perldoc
    
    If it's any longer possible to download full perl documentation
    onto my computer's hard drive, I'd like to know what it is.
    
    My thanks in advance for any suggestions.
    
    Very truly yours,
    
    jf02ir@gmail.com
    
IP address can't recognize by Net::Ping
5 direct replies — Read more / Contribute
by Anonymous Monk
on Nov 23, 2023 at 22:55
    Hi monks,

    I've found Net::Ping can't recognize IP but DBI can:

    $IP = "192.168.0.1 192.168.0.2 192.168.0.3"; for my $ip_addr (split /\s/, $IP){ my $p = Net::Ping->new(); if ($p->ping( $ip_addr )) { $my_state->{IP_stat} = 'UP'} #can't ping else{ $my_state->{IP_stat} = 'unreachable'; next; } $p->close(); my $dbh = DBI->connect("dbi:" . $db_type . ":" . $ip_addr . "/" . $ser +vice_name, $sysUser, $sysPass ); #can connect
    I guess Net::Ping treat varaible as number not string , but DBI don't. is there a way to resolve it ? Thanks

    s
Google translate dumbs down when browser launched via Mechanize
2 direct replies — Read more / Contribute
by bliako
on Nov 23, 2023 at 19:16

    I am experimenting enquiring https://translate.google.com with the same phrase when the browser is either launched via WWW::Mechanize::Chrome or not (i.e. as usual by "clicking on its icon").

    I have observed that the greek phrase
    "Πληθαίνουν και βαραίνουν τα ερωτήματα"
    translates differently depending on how the browser was launched:

    1. via Mechanize and Chrome the translation is Are growing and heavy the questions -- which I consider dumb, compared to
    2. The questions are multiplying and burdening yielded in the same way but when the browser (chrome or firefox) was launched "normally".

    The second translation is produced with Firefox and Chrome, with or without uBlock. The reference to uBlock is because I thought that that was the decisive factor before I realised it was the way the browser is launched (Hence my delirious rumblings at the CB some minutes ago ...).

    If some Monks want to experiment:

    use Log::Log4perl qw(:easy); use WWW::Mechanize::Chrome; Log::Log4perl->easy_init($ERROR); my $mech = WWW::Mechanize::Chrome->new( headless => 0, launch_arg => [] ); sleep(1000);

    Any ideas what this mystery (to me) is all about?

    bw, bliako

    12h EDIT:

    Here is one English phrase (from https://www.gutenberg.org/cache/epub/35461/pg35461.txt) translated from google-translate with two mechs: Perl-chrome and Python-firefox to two languages: Greek and German:

    "They were a very vocal people. They enlivened their wanderings by feasts, at which there was much drunkenness and at which a special sort of man, the bards, would sing and recite."

    1. The Greek translation with google-mech-perl yields:
      "Ήταν ένας πολύ φωνητικός λαός. Ζήτησαν την περιπλανώμενη τους από τις γιορτές, στις οποίες υπήρχε πολύ μεθυστικότητα και στην οποία θα τραγουδούσαν και θα απαγγέλλουν ένα ειδικό είδος ανθρώπου, οι bards."
      Exactly the same translation with firefox-mech-python. But properly-launched Firefox yields
      "Ήταν πολύ φωνητικός λαός. Ζωντανεύουν τις περιπλανήσεις τους με γλέντια, στα οποία υπήρχε πολύ μέθη και στα οποία ένα ιδιαίτερο είδος ανθρώπου, οι βάρδοι, τραγουδούσε και απήγγειλε."
      Which is much more correct. Firstly, the word "bards" translates correctly to "βάρδοι" (this is left un-translated in both mech cases). Also the tense of the last two verbs is wrong in the mech cases and additionally the two verbs are in slightly different tense (difference between will recite and would recite. Also, the proper Firefox translates these two verbs correctly in singular form because it detects that the singers was the "special sort of man" (singular) and not "bards" (plural). Anyway, I am not expert on grammar/syntax of any language but the mech translations "sound" weird to my ears. The bottom line is that both mech cases yield "weird-sounding" translations, haphazard I would say, whereas the properly-launched firefox (and chrome) yield a much better-sounding translation.
    2. The same text to German:
      "Sie waren ein sehr lautstarker Volk. Sie belebten ihre Wanderungen durch Feste, bei denen es viel Trunkenheit gab und zu denen eine besondere Art von Mann, die Barden, singen und rezitieren würde."
      from both mech. Proper Firefox yields:
      "Sie waren ein sehr lautstarkes Volk. Sie belebten ihre Wanderungen durch Feste, bei denen viel getrunken wurde und bei denen eine besondere Art von Menschen, die Barden, sang und rezitierte."
      Zero German understanding from me, so I can not comment.

It has already been asked 6 years ago to the VerbalOverflow website without any answer yet: https://stackoverflow.com/questions/43585256/why-is-google-translate-api-giving-me-different-results-on-certain-machines

Audio input and processing - recommendations
5 direct replies — Read more / Contribute
by Ashx
on Nov 21, 2023 at 17:51
    Hey all

    I want to make a program which does the following :

    - Input audio from sound card line-in
    - Get it in raw format (FIFO of the data, xxxx Hz sampling rate x xxxx bit resolution)
    - Do some processing which would be suitable to show a matching visualization (so need to be able to run DTFT to obtain the spectrum)

    This should be able to run in near real time (no requiring of "proper" real time, just be able to run along with the arriving analog input, not buffering it all for revisit later

    This should run on a modern Linux system, where the main sound platform is ALSA, and support for old Linux sound technologies (OSS, etc) might not be available or not work correctly etc

    So what i am asking is, what libraries or example code would you recommend me to look into ? - I found several mentions of modules on cpan which use OSS, but i am not sure whether it is supported properly on modern linux, and whether there are any newer and better suited libraries which are not widely known

    Best Wishes - Ash
Send email with recipient name
2 direct replies — Read more / Contribute
by frank1
on Nov 21, 2023 at 10:38

    1). I need help with sending emails with their names in email body

    2). Can i just loop to make sure each recipient gets email or Sub is enough. to send to over 100k emails

    DB ID name email 1 jane test@test.com 2 tom tom@tom.com
    my $msg = "Hello 'name' welcome to earth"; my $query = $dbh->prepare("SELECT DISTINCT email FROM users"); $query->execute(); my $records = $query->fetchall_arrayref; my @to; for my $em ( @$records ) { push @to, @$em; } for my $recipient(@to) { mail($recipient); } sub mail { my $recipient = shift; my $smtpserver = 'smtp.dddd.com'; my $smtpport = 587; my $smtpuser = ''; my $smtppassword = ''; my $transport = Email::Sender::Transport::SMTP->new({ host => $smtpserver, ssl => 'starttls', port => $smtpport, sasl_username => $smtpuser, sasl_password => $smtppassword, }); my $email = Email::Simple->create( header => [ To => $recipient, From => 'dddd@ddd.com', Subject => $sub, 'Content-Type' => 'text/html', ], body => $msg, ); sendmail($email, { transport => $transport }); my $Response = "Success!"; }
Wide characters in Windows filenames with File::Copy
2 direct replies — Read more / Contribute
by slugger415
on Nov 20, 2023 at 14:10

    Hello esteemed monks, I am having trouble using wide characters in filenames on Windows 10 using File::Copy. The wide characters appear just fine if I write them to a text file, and I can manually copy/paste them into filenames in Windows Explorer, but if I use File::Copy they come out all wonky.

    use File::Copy; my $oldname = "file.txt"; my $newname = "Hildur_Guðnadóttir.txt"; copy(oldname, $newname);

    This file name comes out looking like so:

    Hildur_Guðnadóttir.txt

    Yet if I open a file and write $newname to it, it displays just fine.

    Any way to do this correctly with (or without) File::Copy ?

    Thanks, Scott

"exit 1" and "exit(1)" are apparently not the same
3 direct replies — Read more / Contribute
by syphilis
on Nov 19, 2023 at 00:47
    Hi,

    I guess it's accepted and expected, but I can't find any documentation that explains this differing behaviour.
    Without the enclosing parens, the exit function behaves as I expect - otherwise the specified value is apparently ignored, and the exit call defaults to exit 0.
    D:\>perl -wle "`exit 1`; print $?;" 256 D:\>perl -wle "`exit(1)`; print $?;" 0 D:\>perl -wle "`exit 2`; print $?;" 512 D:\>perl -wle "`exit(2)`; print $?;" 0 D:\>perl -wle "$x = 1;`exit $x`; print $?;" 256 D:\>perl -wle "$x = 1;`exit($x)`; print $?;" 0
    What am I failing to understand ?

    I'm seeing this behaviour on Windows 11 with perl-5.38.0 and perl-5.39.4. That's the only testing I've done.

    Cheers,
    Rob
is there anything more VEXING than checking the $cgi->checkbox ?
2 direct replies — Read more / Contribute
by misterperl
on Nov 17, 2023 at 16:11
    I just wasted another 1/2 day trying to coerce this to work. It worked earlier today, and after a few cosmetic edits, it stopped working. Like:

    $cgi->checkbox( { -name => 'cb-1', -value => 1, -label => "", -checked + => 'checked' } );

    And the result is the same as when I leave out the -checked part: the html does NOT say checked. I inspected the actual HTML and its inexplicably missing. I added a debug point to print the HTML right after the checkbox ; its decidedly not there. The most vexing part- earlier today it worked. I've run the usual gauntlet of trying "checked", 1, "on" etc , recommended by various Perl sites; none cooperate today.

    So being the end of the day Friday, I hate to be defeated, but I just added:

    $cb = $cgi->checkbox( { -name => 'cb-1', -value => 1, -label => "" } ) +; $cb =~ s/(value)/checked $1/;

    Which is really undesirable, and FUGLY, since the preference is to let the Perl CGI do the work. But unlike the CGI, THIS WORKS!

    I'll review this Monday for suggestions but note to whoever wrote the Perl CGI- checkbox is a HOT MESS! Everytime I write code that has to check a checkbox it's like i DREAD it! Pretty much everything else in the CGI works as stated, but since this setting is stated like 6 different ways, maybe its not amazing it seldom works.

    This was so frustrating that Monday I plan to look at the actual checkbox code IN the Perl CGI, but I just know it'll be like a switch with 3 globs, 2 closures, and 3 evals!!

how to import::into v5.020
1 direct reply — Read more / Contribute
by M4
on Nov 15, 2023 at 15:02
    Hi Monks,

    I have this module I use which imports things I always need. Now I can translate:

    use strict; use warnings; use feature 'say';
    to:
    strict->import::into($caller); warnings->import::into($caller); feature->import::into($caller, 'say');
    But how do I translate:
    use v5.020;
    ?
Add 1 to an arbitrary-length binary string
5 direct replies — Read more / Contribute
by einhverfr
on Nov 15, 2023 at 04:33

    Esteemed monks

    I am trying to do some more complex etcd tasks and one of them is listing all keys by a prefix. The current API from Net::Etcd only allows for start and end ranges, and they suggest incrementing the range start by one bit to do a prefix search. However, since the keys are typically text strings, this is a bit of a problem.

    I found advice suggesting casting strings to unsigned longs and incrementing and then casing back. Unfortunately these are arbitrary length strings and so I have no guarantee that this will be enough space.

    Is there some way of incrementing a string by one bit that I haven't seen? Maybe a Perl module or some way of incrementing a base-64-encoded string or something?


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 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?Last hourOther CB clients
Other Users?
Others cooling their heels in the Monastery: (8)
As of 2024-04-18 16:28 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found