Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
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
I am Getting an Error like this Can't locate pathUtil.pm in @INC
4 direct replies — Read more / Contribute
by Anonymous Monk
on Nov 21, 2022 at 07:26

    I am executing one of the Perl file in "Linux OS" I am getting an error like this:

    Can't locate pathUtil.pm in @INC (you may need to install the pathUtil + module) (@INC contains: /usr/local/lib/perl5/site_perl/5.36.0/x86_64 +-linux /usr/local/lib/perl5/site_perl/5.36.0 /usr/local/lib/perl5/5.3 +6.0/x86_64-linux /usr/local/lib/perl5/5.36.0 /usr/local/lib/perl5/sit +e_perl) at pod_check.pl line 14. BEGIN failed--compilation aborted at pod_check.pl line 14 (#1) (F) You said to do (or require, or use) a file that couldn't be fo +und. Perl looks for the file in all the locations mentioned in @INC, un +less the file name included the full path to the file. Perhaps you nee +d to set the PERL5LIB or PERL5OPT environment variable to say where +the extra library is, or maybe the script needs to add the library nam +e to @INC. Or maybe you just misspelled the name of the file. See "require" in perlfunc and lib. Uncaught exception from user code: Can't locate pathUtil.pm in @INC (you may need to install the +pathUtil module) (@INC contains: /usr/local/lib/perl5/site_perl/5.36. +0/x86_64-linux /usr/local/lib/perl5/site_perl/5.36.0 /usr/local/lib/p +erl5/5.36.0/x86_64-linux /usr/local/lib/perl5/5.36.0 /usr/local/lib/p +erl5/site_perl) at pod_check.pl line 14. BEGIN failed--compilation aborted at pod_check.pl line 14.

    I have found the module like Path::Util.pm. That I have Installed But the error is not resolved. I think it is asking for the combined module like pathUtil.pm, That module I haven't found the Mcpan.org also

    So can anyone help me to solve this issue?

$^O empty in windows powershell
3 direct replies — Read more / Contribute
by WithABeard
on Nov 21, 2022 at 06:44

    When I run the following code in command prompt (cmd), I get the "MSWin32", as expected

    perl -e "print $^O;"

    But when I run the same code in powershell, I get nothing.

    The following code works though, outputting the same in both shells:

    perl -MWin32 -e "print Win32::GetOSName();"

    This outputs Win10Build 19043 (64-bit)

    Is this a bug?

    I'm using StrawberryPerl, perl version: v5.32.1 built for MSWin32-x64-multi-thread

Perl XS binding to a struct with an array of chars*
2 direct replies — Read more / Contribute
by MaxPerl
on Nov 20, 2022 at 05:18

    Hello Seekers of Perl Wisdom,

    I try to make a perl binding to the following struct

    struct _Edje_Message_String_Set { int count; char *str[1]; };

    At the moment my try of an implementation looks like this (only the important parts):

    [...] typedef Edje_Message_String_Set EdjeMessageStringSet; MODULE = pEFL::Edje::Message::StringSet PACKAGE = pEFL::Edje::M +essage::StringSet EdjeMessageStringSet * _new(class,count, val_arr) char *class int count AV *val_arr PREINIT: EdjeMessageStringSet *message; int index; char *string; STRLEN len; CODE: message = malloc(sizeof(Edje_Message_String) + count * sizeof(char + *)); message->count = count+1; for (index = 0; index <= count; index++) { SV *tmp = *av_fetch(val_arr,index,0); string = SvPVutf8(tmp,len); message->str[index] = savepvn(string,len); } RETVAL = message; OUTPUT: RETVAL MODULE = pEFL::Edje::Message::StringSet PACKAGE = EdjeMessageSt +ringSetPtr [...] void str(message) EdjeMessageStringSet *message PREINIT: int count; char **vals; int index; PPCODE: count = message->count; vals = message->str; EXTEND(SP,count); for (index = 0; index <count; index ++) { PUSHs( sv_2mortal( newSVpv( vals[index], 0 ) )); } void DESTROY(message) EdjeMessageStringSet *message CODE: free(message);

    Unfortunately I get different errors (e.g. corrupted size vs. prev_size, double_free or corruption (out), segfault, invalid pointer etc.). Following a simple test code:

    use pEFL::Edje::Message::StringSet; my $i = 0; while ($i<100) { my @str = ("Hello", "Wordl", "from Perl"); my $str_msg = pEFL::Edje::Message::StringSet->new(@str); my @strings = $str_msg->str(); print "COLORS @strings\n"; $i++; } print "The script goes to the end\n";

    Where is my misunderstanding?

    PS:

    I tried to use perl XS memory allocation, too. But this doesn't help. For example the following doesn't work:

    PREINIT: [...] char **val; CODE: New(0,val,count+1, char*); New(0,message,1,EdjeMessageStringSet); message->count = count+1; for (index = 0; index <= count; index++) { SV *tmp = *av_fetch(val_arr,index,0); string = SvPVutf8(tmp,len); New(0,val[index],len,char) val[index] = savepvn(string,len); } Move(val,message->str,count+1,char*); RETVAL = message; OUTPUT: RETVAL

    btw. how can one allocate memory in Perl XS with size calculated from different types (here Edje_Message_Signal_Set and char(*))?

    Thank you so much for your help!!!

    Max

[SOLVED] MCE GitHub examples page missing
2 direct replies — Read more / Contribute
by kcott
on Nov 19, 2022 at 21:12

    G'day All,

    Following the MCE (CPAN) documentation link to https://github.com/marioroy/mce-examples this afternoon, resulted in a "404 Page not found".

    For more details, see the "GitHub mce-examples - 404 Page not found" issue that I've just raised.

    In the interim, if this page has simply moved, and anyone knows of the new location, please advise. Thankyou.

    Update: Problem solved. ++Mario has restored the page and added 2022 updates. Thanks.

    — Ken

Global match and capture group in look-ahead == under-populated "@-"?
3 direct replies — Read more / Contribute
by Anonymous Monk
on Nov 19, 2022 at 06:47
    use strict; use warnings; use Data::Dump 'dd'; $_ = 'a'; dd s/(?=(a))/b/; dd @-; dd $_; $_ = 'a'; dd s/(?=(a))/b/g; dd @-; dd $_;

    Is this a bug?

    1 (0, 0) "ba" 1 0 "ba"
null output on program
4 direct replies — Read more / Contribute
by Nobby
on Nov 18, 2022 at 19:37
    Hey,

    A mini summary, I have a script that has a hash ref of programs, this works normally if there is content output, but if there is an error by the program called, I get no output - including the error line.

    For speed and brevity, in debugging I used traceroute as an example, if it looks up and performs the trace, it works but if it cant lookup, there is nothing., example...

    sub main { print "Content-type: text/html\n\n"; print "<HTML> <HEAD>\n"; ....(omitted since this part works if real output print "</HEAD>\n"; open("runmain","$commands{$PROGRAM} $TARGET_HOST |"); while (<runmain>) { chomp $_; print "$_\n"; } print "</pre> </div></html>\n"; close ("runmain");
    if I use traceroute to a hostname using -4 that resolves, traceroute output returns, however if I use -6 where it is known there is no ipv6 record, it just outputs nothing, there is no testing for null out put it should just print what it is given.

    using traceroute on command line shows output

    "aussiebb.com.au: No address associated with hostname Cannot handle "host" cmdline arg `aussiebb.com.au' on position 1 (argc + 2)
    But the script returns
    <pre> Content-type: text/html <HTML><HEAD> .... </HEAD> <BODY bgcolor=white text=#2554C7> </pre></div></html>
    As far as the script is concerned, it should have no clue the above output is any less relevant to an actual traceroute return with a reply.

    I guess i'm missing the obvious, but i've spent way too many hours trying to sort this out, commenting out line by line and multi lines trying to find where it is going wrong, thus I am am here asking for some perl spiritual learning :)

    I have omitted a lot of the header and html code, that would be irrelevant, I might have missed one or two so if the html looks wrong, dont worry it is OK, given the above, Thanks

How does AnyEvent work?
2 direct replies — Read more / Contribute
by Anonymous Monk
on Nov 17, 2022 at 16:43
    If Perl is single threaded how does AnyEvent work? I mean does it spawn threads ,processes? Or is it like Nodejs event loop that does io so it doesn't spawn anything? And if that is so how does it handle CPU bound operations?
I am getting an error when executing an One of the Perl file.
1 direct reply — Read more / Contribute
by Anonymous Monk
on Nov 17, 2022 at 04:37

    I am executing my one of the Perl File and I am getting an error like the below:

    Can't exec "expect": No such file or directory at /usr/local/lib/perl5/5.36.0/IPC/Open3.pm line 290 (#1) (W exec) A system(), exec(), or piped open call could not execute +the named program for the indicated reason. Typical reasons include: +the permissions were wrong on the file, the file wasn't found in $ENV{PATH}, the executable in question was compiled for another architecture, or the #! line in a script points to an interpreter +that can't be run for similar reasons. (Or maybe your system doesn't s +upport #! at all.)

    Can anyone help me regarding on these issue

content type in LWP::UserAgent
1 direct reply — Read more / Contribute
by BernieC
on Nov 16, 2022 at 17:53
    I know this is a dumb question but I'm lost in a maze of twisty passages going back and forth between LWP::UserAgent and HTTP::Request::Common. I have a very simple question. I need to send a POST with the body being JSON data and I understand {I think} that to make that play nice with the server I should have a "content-type: application/json" header ... it should be trivial but I can't figure out where to stick that information in the $ua->POST() call. I must be missing something obvious.
Finding multiword units in a corpus
2 direct replies — Read more / Contribute
by veg_running
on Nov 16, 2022 at 07:43

    I have code that searches for words from a list in a large corpus of tokenised sentences and then assigns a unique ID to those words if it finds them. I would like to upgrade this code to also match multi-word units in the corpus.

    My tag set is a simple 2 column file, tab separated. The first column includes the word (or multi-word unit) to find and the second column the tag to assign to it:

    udebe <ZUL-SIL-0016-n> ulimi <ZUL-SIL-0017-n> izinyo <ZUL-SIL-0018-n> izinyo lomhlathi <ZUL-SIL-0019-n> ingemuva lomqala <ZUL-SIL-0024-n> umphimbo <ZUL-SIL-0025-n>

    The output I require is also a text file and looks like this (produced with the current code below):

    Lokho akusoze <ZUL-SIL-1364-b> kukwenze isilomo . Ukuzihlola amabele <ZUL-SIL-1234-n> kungahlenga impilo <ZUL-SIL-0238-n +> yakho . Amakhala agxiza amafinyila <ZUL-SIL-0095-n> . Gcoba <ZUL-SIL-1484-v> amafutha <ZUL-SIL-0572-n> kuwo wonke amabhering +i . Sebenzisa amafutha <ZUL-SIL-0572-n> afanelekile . Zama <ZUL-SIL-0296-n> ukugwema ukudla <ZUL-SIL-0569-n> okuncinca amafu +tha <ZUL-SIL-0572-n> .

    My code currently looks like this:

    use strict; use warnings; my $corpusname = "GoldStandardCorpus.Original.MG.2022-11-10"; my %words2ids; open my $lemmas, "<", $corpusname.".tagset.txt" or die $!; while (my $line = <$lemmas>) { chomp($line); my ($word, $id) = split "\t", $line; $words2ids{ lc($word) } = $id; } my %freq; open my $output, ">", $corpusname.".possible-annotation.txt" or die $! +; open my $corpus, "<", $corpusname.".txt" or die $!; while (my $line = <$corpus>) { chomp($line); my @tokens = split ' ', $line; foreach my $token (@tokens) { my $lct = lc $token; if (my $id = $words2ids{ $lct }) { $freq{$lct}++; $token .= " $id"; } } say { $output } "@tokens"; } open my $notfound, ">", $corpusname.".tags-not-found.txt" or die $!; foreach my $word (sort keys(%words2ids)) { next if exists $freq{$word}; say { $notfound } "$word\t$words2ids{$word}"; }

    Any suggestions would be greatly appreciated! I am thinking some sort of sliding window to search for strings of words, but have no idea how to implement this. Thank you!


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? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (3)
As of 2022-11-28 22:18 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Notices?