Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
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
Dependencies for a project - Perl6/Raku
No replies — Read more | Post response
by asoftware
on Aug 08, 2020 at 02:06

    Good day Monks,

    It has been a decade since I wrote any Perl, and recently I noticed the growth of Perl6 and the coining of "Raku". Side note, I am very pleased to see the Perl family withstanding the test of time. I recall my most productive engineering days were spent lovingly writing Perl.

    The wisdom I seek is two fold:

    1. Is there an ordained or at least idiomatic method of describing the module dependencies of a Raku project?
    2. Is there an ordained or at least idiomatic project structure for a Raku project? I see mi6, which appears to be the module structure required for module authors

    Generally, I am interested in understanding if there has been any formalization of describing required modules, not just in another module/package, but also in an arbitrary project. And potentially supporting project specific versions/installations of modules per project.

    Thanks for your time

    -- Cam
XML::LibXML::XPathContext->string_value - should ALL of the descendant's text be there?
1 direct reply — Read more / Contribute
by bobn
on Aug 07, 2020 at 22:52

    So I started playign around with XML parsing (well HTML but it's well enough formed I can use XML parsers on it). I ran into something on the Perl side of things I don't understand.

    I get a nodeset, start walking through it and getting text out, but when it comes out, for each node I get the text contained in node element AND the text of all of it's descendants (contained elements).

    I'm getting this with XML::LibXML::XPathContext, but it happens with XML::XPath as well.

    The event driven parsers I've tried don't seem to have this issue - they think that Text belongs to the innermost containing element, just like I do. lxml.etree in python, their binding for libxml2, does not do this, (though it definitely has oddities of it's own - check out "tail text" sometime, it's a doozy!).

    I'm going to stop now, 'coz I'm becoming increasingly sure I'm just missing something stupidly.

    Is it supposed to do this, and if so, how do I get at just the text for the outermost element of my node?

    #!/usr/bin/perl use XML::LibXML::XPathContext; our $contents = <<EOT; <html> <head> <title>Title_Text</title> </head> <body> <p>paragraph_text</p> <div> <div> innnermost_text </div> </div> </body> </html> EOT open my $fh, '>', './x.html'; print $fh $contents; close $fh; my $init_node = XML::LibXML->new->parse_file('./x.html'); my $xp = XML::LibXML::XPathContext->new($init_node); my $i= 0; my $nodeset = $xp->findnodes('//*'); for my $node ($nodeset->get_nodelist) { my $elname = $node->getName(); print qq[<$elname> node - $i\n]; my $text = ''; $text = $node->string_value(); # this brings in text of # *all* descendant nodes $text =~ s/(\s)+/$1/msg; print 'Text = ', $text, "\n"; $i++; }
    Produces:
    <html> node - 0 Text = Title_Text paragraph_text innnermost_text <head> node - 1 Text = Title_Text <title> node - 2 Text = Title_Text <body> node - 3 Text = paragraph_text innnermost_text <p> node - 4 Text = paragraph_text <div> node - 5 Text = innnermost_text <div> node - 6 Text = innnermost_text

    --Bob Niederman,

    All code given here is UNTESTED unless otherwise stated.

IO::Socket::SSL install problems
1 direct reply — Read more / Contribute
by Anonymous Monk
on Aug 07, 2020 at 19:04

    Hello smart monks, I'm trying to install IO::Socket::SSL from CPAN on a windows 10 server and it keeps on hanging. I've tried shipping the connection tests and a force install and I get to the point below where it sits for hours. Any help on how to get past this would be greatly appreciated. Terminal output is right below:

    # connect to 0: success reuse=0 version=TLSv1_3 t/session_ticket.t ................ 1/6 # connect to 0: success reuse= +1 version=TLSv1_3 # connect to 1: success reuse=1 version=TLSv1_3 # connect to 1: success reuse=0 version=TLSv1_3 # connect to 0: success reuse=0 version=TLSv1_3 # connect to 0: success reuse=1 version=TLSv1_3 t/session_ticket.t ................ ok t/sessions.t ...................... ok t/set_curves.t .................... ok t/signal-readline.t ............... skipped: signals not relevant on t +his platform t/sni.t ........................... ok t/sni_verify.t .................... 1/17

    Thanks!

Should I worry about "Inappropriate ioctl for device"?
3 direct replies — Read more / Contribute
by Lady_Aleena
on Aug 07, 2020 at 08:29

    I just saw that one of my dies returned "Inappropriate ioctl for device" at the end of the string I wanted to be returned. Is it something I need to worry about, or can I safely ignore it? I've tried to figure out what it means, and what I did wrong from various Google searches and reading here and elsewhere about it. I just do not understand it. So, other than knowing that "ioctl" stands for "input/output control" and I did something inappropriate with it, I am a bit lost.

    So, do I dive in and drive myself a little crazy trying to figure it out? Can I safely ignore it, not letting it worry me? Could it bite me later?

    Here is the code where I got the message.

    My OS is Debian 10 (Buster); my perl versions are 5.28.1 local and 5.16.3 or 5.30.0 on web host depending on the shebang.

    No matter how hysterical I get, my problems are not time sensitive. So, relax, have a cookie, and a very nice day!
    Lady Aleena
How to retrieve WebService::Solr facet value properly?
2 direct replies — Read more / Contribute
by swiftlet
on Aug 06, 2020 at 21:35
    I couldn't find any example to retrieve WebService::Solr facet value on perldoc or Google. Currently, I am using a dirty way, "Dumper and Regex" to retrieve it. Any idea what's the official proper way to do it?
    my %options = ( rows=> 100, "facet"=> "on", "facet.field"=> "author_id", ); use Data::Dumper; my $response = $solr->search("\*:\*", \%options); my $data = Dumper(\$response); my %facet; if($data =~ m#"facet_fields":{\s*"author_id":\[\s*([^\]]+)\]},#i){ my $authors = $1; while($authors =~ m#"([^"]+)",(\d+),#gi){ $facet{$1} = $2; } }
Regex on excel
3 direct replies — Read more / Contribute
by Jabber_tango
on Aug 06, 2020 at 09:58

    Hi, Has anybody got some sample code that could assist me with a project please? I have the following.. 1 Excel file with anything upto 100,000 rows and multiple columns. 2 A text file with list of regular expressions in (Some 100+) I need to run all the reg expressions, and if entire expression match send to a file "Matched" If partial expressions matched send to a file "Partial" Does anybody have a nice clean way to do this? Or suggestions please? I have used Perl in the past extensively, but not for a few years. Many Thanks Mark

Basic but stupid problem i cannot wrap my head around
3 direct replies — Read more / Contribute
by baxy77bax
on Aug 06, 2020 at 04:57
    hi,

    so the problem is the folloving:

    perl -le '$t="a/b"; if ($t =~/^(.*?)\//){$z=$1}elsif($t=~/\/(.*)/){$z= + $1} print $z' #prints a perl -le '$t="/b"; if ($t =~/^(.*?)\//){$z=$1}elsif($t=~/\/(.*)/){$z= +$1} print $z' #prints nothing
    it is probably something stupid , as i am quite tired but why isn't the second case being evaluated (or it is but why is it returning 0 )

    thnx

    baxy

HTML::Tidy - Tidyp install issues
1 direct reply — Read more / Contribute
by Anonymous Monk
on Aug 06, 2020 at 00:01

    Hello oh wise a great monks. I have spent a day on this without a solution so I am turning to you for help. I am trying to install HTML::Tidy on a Windows 10 server and am stuck! I know that tidyp is need so I'm trying to install Alien::Tidyp first as it searches the box for tidyp and if it's not there should install it. That's where I get this error:/

    -c src/buffio.c -o src/buffio.o gcc -Isrc -Iinclude -O2 -Wall -D_WIN32_WINNT=0x0500 -DSUPPORT_ACCESSIB +ILITY_CHECKS=1 -DSUPPORT_ASIAN_ENCODINGS=1 -DSUPPORT_UTF16_ENCODINGS= +1 -c src/clean.c -o src/clean.o gcc -Isrc -Iinclude -O2 -Wall -D_WIN32_WINNT=0x0500 -DSUPPORT_ACCESSIB +ILITY_CHECKS=1 -DSUPPORT_ASIAN_ENCODINGS=1 -DSUPPORT_UTF16_ENCODINGS= +1 -c src/config.c -o src/config.o gcc -Isrc -Iinclude -O2 -Wall -D_WIN32_WINNT=0x0500 -DSUPPORT_ACCESSIB +ILITY_CHECKS=1 -DSUPPORT_ASIAN_ENCODINGS=1 -DSUPPORT_UTF16_ENCODINGS= +1 -c src/entities.c -o src/entities.o gcc -Isrc -Iinclude -O2 -Wall -D_WIN32_WINNT=0x0500 -DSUPPORT_ACCESSIB +ILITY_CHECKS=1 -DSUPPORT_ASIAN_ENCODINGS=1 -DSUPPORT_UTF16_ENCODINGS= +1 -c src/fileio.c -o src/fileio.o gcc -Isrc -Iinclude -O2 -Wall -D_WIN32_WINNT=0x0500 -DSUPPORT_ACCESSIB +ILITY_CHECKS=1 -DSUPPORT_ASIAN_ENCODINGS=1 -DSUPPORT_UTF16_ENCODINGS= +1 -c src/istack.c -o src/istack.o gcc -Isrc -Iinclude -O2 -Wall -D_WIN32_WINNT=0x0500 -DSUPPORT_ACCESSIB +ILITY_CHECKS=1 -DSUPPORT_ASIAN_ENCODINGS=1 -DSUPPORT_UTF16_ENCODINGS= +1 -c src/lexer.c -o src/lexer.o gcc -Isrc -Iinclude -O2 -Wall -D_WIN32_WINNT=0x0500 -DSUPPORT_ACCESSIB +ILITY_CHECKS=1 -DSUPPORT_ASIAN_ENCODINGS=1 -DSUPPORT_UTF16_ENCODINGS= +1 -c src/localize.c -o src/localize.o gcc -Isrc -Iinclude -O2 -Wall -D_WIN32_WINNT=0x0500 -DSUPPORT_ACCESSIB +ILITY_CHECKS=1 -DSUPPORT_ASIAN_ENCODINGS=1 -DSUPPORT_UTF16_ENCODINGS= +1 -c src/mappedio.c -o src/mappedio.o In file included from src/mappedio.c:100: src/streamio.h:204:15: error: expected identifier or '(' before numeri +c constant #define CR 0xD ^~~ gmake: *** [C:\STRAWB~1\cpan\build\Alien-Tidyp-v1.4.7-7\patches\Makefi +le.mingw:45: src/mappedio.o] Error 1 ###ERROR### [512] during make ... at inc/My/Builder/Windows.pm line 3 +9. KMX/Alien-Tidyp-v1.4.7.tar.gz C:\Strawberry\perl\bin\perl.exe ./Build -- NOT OK Stopping: 'install' failed for 'Alien::Tidyp'. Failed during this command: KMX/Alien-Tidyp-v1.4.7.tar.gz : make NO

    Please note I'm trying to install using CPAN. I even installed cpanm to try and get the pms thinking it might do something different. So I'm stuck my script uses Tidy::HTML but I can't get tidyp on the box so I can't install HTML::Tidy. I'm not doing anything too fancy with Tidy, here's my code:

    my $contents_of_file = 1; @files = glob "$call_dir/*.html"; printf "Got %d files\n", scalar @files; my $tidy = HTML::Tidy->new( { tidy_mark => 1, #output_xhtml => 1, # yes #output_xhtml => 1, # yes add_xml_decl => 1, # no wrap => 76, error_file => 'errs.txt', char_encoding => 'utf8', indent_cdata => 1, clean => 1, fix_bad_comments =>1 }); for my $file (@files){ $$temp_var = read_file( $file ); if ( $$temp_var =~ m|^URL.*| ){ next } # this + is empty file for error message in output. my $tres = $tidy->parse( $file, $$temp_var ); print "Tidy file: $file, result is $tres\n"; open OUT,'>',$file or die "$!"; print OUT $tidy->clean( $file, $$temp_var ); print "cleaning " . $file. "\n"; close OUT; } $temp_var = undef;

    I would be open to using another module that I could install that could do this. Up till 3AM last night trying to find a solution, not looking to go there again tonight

    Thanks in advance for any help/insight!

    The tired nub

    PS - I also did take the time to install Cygwin thinking I could d/l the source and compile by I've got no clue what I'm doing there.

Tk pop-up if condition is met
2 direct replies — Read more / Contribute
by IB2017
on Aug 05, 2020 at 17:18

    Is it possible to allow a popup in a text widget only if a condition is met, i.e. if a text has been selected? This is the code I have so far, which creates a popup, however, it checks if something has been selected only agter its creation.

    use strict; use warnings; use Tk; use Tk::Text; my $mw = tkinit(); my $text = $mw->Text()->pack(); $text->insert('end',"This is my first line\n"); $text->insert('end',"This is my second line\n"); PupupTextWidget($mw, $text); $mw->MainLoop(); sub PupupTextWidget{ my ($mw, $obj) = @_; my $messagePopupSave; if ($^O eq 'MSWin32'){ $messagePopupSave="Do something (ctrl+s)"; }else{ $messagePopupSave="Do something (cmd+s)"; } my $menu = $mw->Menu(-tearoff=>0, -menuitems=>[ [command=>$messagePopupSave, -command=>[sub { my $UserInput=$obj->getSelected; print $UserInput; }, $obj,]], [qw/command Copy/, -command=>['clipboardCopy', $obj,]], ]); $obj->menu($menu); return $obj; }
Looking for alternative for IPC::Shareable (or increase size)
7 direct replies — Read more / Contribute
by DomX
on Aug 05, 2020 at 16:55
    Hey Monks!
    I'm having a hard time today. I almost finished my program with over 9000 lines, but have one problem:

    Communication between my worker (forked unit) and master (GUI unit) has a size issue: (worker fills shared array, master reads content into not shared array and cleans shared array.)
    Length of shared data exceeds shared segment size at ./myprogram.pl line 1210.
    Buffer size is declared to be "65536". (No idea of unit, I think it's bytes.) This happens on one array element, when the containing string is longer than 65536.


    What I want to know:
    - is there a possibility to increase the size?
    - is there an alternative function, which allows me to share (bit long) text data between processes, without writing to disk? (Writing to Sqlite would decrease speed on this step extremely)

    If you don't know something like this, the only idea I have left is to make a Sqlite database "transfer", with just one column "data", and each row contains one string of my array. Many forks writing to it (slow...) and master reading and cleaning this table, just to prepare it to be saved in correct table and correct columns...

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 scrutinizing the Monastery: (4)
    As of 2020-08-08 09:10 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?
      Which rocket would you take to Mars?










      Results (51 votes). Check out past polls.

      Notices?