Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
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
Surface fitting with PDL
1 direct reply — Read more / Contribute
by Xilman
on Aug 09, 2020 at 13:42

    Greetings Fellow Monks.

    The background (pun intended) to my request is that I have some astronomical images in FITS format and I would like to remove a spatially varying background as the first stage of image enhancement. It seems clear to me that PDL is the way to go, though I am quite prepared to be convinced otherwise

    CPAN contains some PDL modules which perform least squares fitting to one-dimensional data. I realise that surface fitting can be performed by re-arranging the data so that it appears to be linear (by storing it by rows or by columns) and that the independent variables can be munged to suit. However, that would appear to be inelegant and potentially costly for surface fitting to large image patches.

    Surely someone must have encountered this situation before and has written code to deal with it?

    I undoubtedly can write my own code but I am lazy. If I do need to write a function I will endeavour to make it publicly available.

Multiline search and replace in file(s)
2 direct replies — Read more / Contribute
by g_speran
on Aug 09, 2020 at 01:57

    Looking for assistance on how to loop through a list of files, search for a Multiline pattern and Replace the multiline. Below is all I have gotten so far but cant figure out how to match the multiline pattern. Any assistance is appreciated.

    my $MODFILE; my @files = <Test*_Copy>; foreach $MODFILE (@files) { # Need to Search and Replace Here #How to Search entire contents of file and Replace??? s/Marry Had A\nLittle Lamb\nShe Was GOOD\n/CHANGED!!!\n/smg; } File Contents (Test1_Copy) Marry Had A Little Lamb She Was GOOD Not Changing this Or This Marry Had A Little Lamb She Was GOOD Line 9 Line 10
Generalizing a REGEX
2 direct replies — Read more / Contribute
by Anonymous Monk
on Aug 08, 2020 at 14:55
    foreach (@newlist) { $_ =~ s/[.](.*)/($section) }

    The above code performs the transform cat.1 ---> cat(1) It also performs the transform ls.so.conf.5 ---> ld(5) # which is WRONG! Is there a way to generalize this regex so it does: cat.1 ---> cat(1) ld.so.conf.5 ---> ld.so.conf(5) Thanks

bird graphic in learning perl 7th edition
1 direct reply — Read more / Contribute
by pmclot
on Aug 08, 2020 at 02:44

    Why is there a bird graphics next to the notes in learning perl 7th edition? What does the bird represent? bird's eye view?

Dependencies for a project - Perl6/Raku
1 direct reply — Read more / Contribute
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"?
4 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


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 cooling their heels in the Monastery: (2)
    As of 2020-08-09 20:15 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?
      Which rocket would you take to Mars?










      Results (55 votes). Check out past polls.

      Notices?