Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW

The Monastery Gates

( #131=superdoc: print w/replies, xml ) Need Help??

Donations gladly accepted

If you're new here please read PerlMonks FAQ
and Create a new user.

New Questions
Why perl with strict allows to use -bareword?
2 direct replies — Read more / Contribute
by hurricup
on Jun 27, 2017 at 16:04

    According to docs for strict subs:

    This disables the poetry optimization, generating a compile-time error if you try to use a bareword identifier that's not a subroutine, unless it is a simple identifier (no colons) and that it appears in curly braces or on the left hand side of the => symbol.

    But use Some::Thing -base;, for example, works and not looks like example in docs. Also, it may cause a surprise, when sub with name 'base' been defined before this use.

textual GUI using only part of the terminal
3 direct replies — Read more / Contribute
by morgon
on Jun 26, 2017 at 18:27

    I have a very basic understanding of curses to build full-screen text GUIs, but I cannot figure out if it is possible to build a text-based GUI in Perl that only uses part of the terminal screen estate.

    What I mean is something like the "fzf" tool (which is written in go) does. Usually it takes over the whole terminal, but when supplying an argument like "--height 50%" it only takes a part of the terminal screen size, but within that part there is a GUI.

    Is is possible to do something like that in Perl (using curses or something else)?

    Many thanks.

LibXML setNodeName error
1 direct reply — Read more / Contribute
by geddie2001
on Jun 26, 2017 at 10:48

    I am attempting to write a perl script that reads an xsl document and changes every instance of <xsl:element name =" foobar"> to <foobar> (essentially stripping out the `xsl:element name` so that the code is easier to read)

    Here is what I have in `test.xsl`:
    <?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet version="1.0" xmlns:xsl=" +ansform"> <xsl:element name="foo"> <xsl:value-of select="bar"/> </xsl:element> </xsl:stylesheet>
    In ``:
    use strict; use warnings; use XML::LibXML; my $reader = XML::LibXML->load_xml(location => "test.xsl") or die "can +not read input file\n"; my $xpath_context = XML::LibXML::XPathContext->new($reader); foreach my $element_node ($xpath_context -> findnodes('//xsl:element') +) { my @attributes = $element_node -> attributes(); $element_node -> setNodeName($attributes[0]); }
    The output when I run this script is:  bad name at line 12 Any help would be greatly appreciated
Warnings using -w
3 direct replies — Read more / Contribute
by Anonymous Monk
on Jun 26, 2017 at 10:07
    Hi Monks!

    This test script is to ask what would be an alternative and why I get this warning message:
    Use of uninitialized value $_[0] in string eq at /usr/local/share/perl5/ line 2209. if I use "-w".
    If I remove the "-w" and use instead "use warnings" I don't get the warning, is it because of been deprecated?
    The version of Perl I have is v5.10.1
    Any suggestions?
    #!/usr/bin/perl -w use strict; use CGI qw(:standard); use CGI::Carp qw( fatalsToBrowser set_message ); my $q = new CGI; print $q->header(); my $msg = escapeHTML( scalar $q->param( 'msg' )) || 'No Msg'; my $error = escapeHTML( scalar $q->param( 'error' )) || ' No error'; my $error_msg = ($msg) ? $msg : ($error) ? $error : ''; print "<br><br>Msgs: $error_msg <br><br>"; exit;

    Thanks for looking!
Match all Non-0 and Letters
7 direct replies — Read more / Contribute
by arblargan
on Jun 24, 2017 at 03:05

    I'm relatively new to Perl and am having a terribly difficult time figuring this one out. I'm expecting a string in the following format:


    Essentially, a normal word will be 7 0's followed by a number between 0-9 (8-digits total). However, occasionally there is corruption in the file being processed, causing the format to have something like the following:

     FFFFFFFF or  6C163512

    I want to skip these lines of corruption and loop until the corruption has been passed. This is where the tricky part comes in (at least for me). I have tried every combination of matching I can think of, but can't seem to get this one squared away. Below are the lines of code I have tried:

    $Disc = get_word(); $D1 = substr($Disc,0,7); $D2 = substr($Disc,7,1); if ($D1 !~ /0+/ and $D2 !~ /([0-9]+)/) ##Catches FFFFFFFF just fine, b +ut not 6C163512 #### $D1 = 6C16351 and $D2 = 2 ###Get words until corruption is cleared. Works great with FFFFFFF +F, but will not catch 6C163512 if ($D1 !~ /0000000/ and $D2 !~ /\D/) ## Same as above ###Get words until corruption is cleared. Works great with FFFFFFF +F, but will not catch 6C163512 if ($Disc =~ /[1-9a-ZA-Z]{7}\D/ ## Same as above ###Get words until corruption is cleared. Works great with FFFFFFF +F, but will not catch 6C163512

    I've been working on this forever and can't seem to figure out how to dynamically catch this corruption in the event that all F's have migrated from the string word. I created the $D1 and $D2 variables to try and see why the regex patterns weren't matching, but I still can't figure it out.

    Lastly, it should be noted that occasionally, the line of corruption will show as 01020102. The corruption value will be dynamic. This is why I simply can't use /\D+/ for the majority of the string as the first 7 digits must be 0 for a valid word.

Generate a report for every month for a year
4 direct replies — Read more / Contribute
by younggrasshopper13
on Jun 23, 2017 at 16:10
    Hey guys! I have a perl script that I use generate billing reports that gets ran and emailed every month via cronjob to report on some metrics. The perl script runs fine (I originally got this working because of some help from the wonderful monks!) For security reasons I cannot post the script itself but I can post how the current date filter works:
    y $START_DATE = `date '+%Y-%m-%d' -d "-1 month"`; my $END_DATE = `date '+%Y-%m-%d'`; chomp $START_DATE; chomp $END_DATE; my $URL = "http://url/url/url/dump?end_date=$END_DATE&start_date=$STAR +T_DATE&type=csv";
    What I need to do is setup this script to generate a monthly report every month for past 2 years. Is there any easy way to do this with the $START_DATE and $END_DATE? Can anyone help me do this?
Wide character in subroutine entry using encode_qp
1 direct reply — Read more / Contribute
by rumburak
on Jun 23, 2017 at 13:21
    use strict; use warnings; use utf8; use MIME::QuotedPrint; binmode STDOUT, ":encoding(UTF-8)"; my $str = "a\x{201E}z"; #my $str = "az"; #my $str = "a\x{201C}z"; #my $str = "a\x{03C9}z"; #my $str = "az"; #works print $str, "\n"; my $str_q = encode_qp($str); print $str_q, "\n";

    gives me this error message / faulty output:

    az Wide character in subroutine entry at ./ line 18.

    Only the fifth version of $str is working.... Can anyone tell me what is going here? (It is perl 5.24.1.)

Architecture design for full stack development.
4 direct replies — Read more / Contribute
by SimonClinch
on Jun 23, 2017 at 10:42
    Hi Monks, I am developing a website from scratch which will hopefully have plenty of activity some time in the future after it goes live. Although I am still developing it on Windows, I will migrate it to Linux/Apache, with Perl and Postgres completing the rest of the picture before and after migration. I am inclined to avoid PHP for performance reasons.

    While loading the database with some initial reference data (about 1GB), using one-off code that got fixed as I went along, I somehow managed to "lose" some PK values, because sequences do not roll back if accessed with nextval.

    But it occurred to me that when the system goes live, it will need to manage deleted values. Although I was careful to use bigint for PK values where necessary, I don't want to have the situation where the PK values stay fragmented and increase fragmentation over time.

    It was at this point that I realised I needed DBIx::Class, otherwise I would have layers of raw SQL hiding in any homegrown DBMS/Perl framework and that had to be avoided at all costs.

    So I am at the point where I have installed DBIx class and feel obliged to determine the rest of the architecture (MVC perhaps) and at the same level of detail, before writing any methods to dynamically defrag my keys (probably through use of an idpool table/class where inserters will look before calling nextval if nothing is in the pool for the table).

    It becomes clear that the defrag code belongs in the "Controller" part of the framework. But having never built a Controller before, I am hoping for advice on what the classes should look like in there, e.g. should I have a dbController class that uses methods in DBIx. Should it inherit from the Schema and/or should I have some kind of parent-of-all utility class? I am keen to make a good choice now rather than have to make fundamental architecture mods later. Many thanks in advance,


    One world, one people

Memory needed for perl process
4 direct replies — Read more / Contribute
by bsshetty17
on Jun 23, 2017 at 02:26

    Hi Monks, 2 quick questions. 1) What is the minimum memory required to start a perl process? 2)I need to install following cpan modules in HP_UX: \t Text::CSV_XS; \t SOAP::Lite; \t XML::Twig; \t Config::IniFiles; \t Parallel::ForkManager; Informatica is also installed in the same server. Informatica administrator is not agreeing to install the modules saying, It causes the informatica performance degradation. Can any one help to defend this? Thanks,

mod_perl best practices to increment XML payload
1 direct reply — Read more / Contribute
by glasswalk3r
on Jun 22, 2017 at 17:23

    Hello monks,

    I've being studying mod_perl in the past to implement a project that uses Apache as a reverse proxy, receives a SOAP request, modifies the payload (XML), handles it to the real web application, and returns back the response to the requester.

    What is the best practice in this case? I checked out Apache::ReverseProxy, but it defines a full handler and I'm guessing that using a Input or Output filter handler would be a better option (based on my readings of mod_perl2 User Guide book) combined with the standard Apache modules proxy and proxy_http to avoid reinventing the wheel.

    PS: I know mod_perl2 is not the "sexiest" framework at the moment, but I want to take advantage of already having it available on particular web servers by default.


    Alceu Rodrigues de Freitas Junior
    "You have enemies? Good. That means you've stood up for something, sometime in your life." - Sir Winston Churchill
Pulling from a list and inserting into XML documents
4 direct replies — Read more / Contribute
by gng4life
on Jun 22, 2017 at 09:25
    Hello All, First post so go easy on me. I'm getting back into Perl after not touching it for years so I am like a noob. This is what I need to do. I have text file A that three fields, for example IP address, MAC, hostname, and there about 200 of them, comma separated (I can change this to a csv or whatever if easier). I have about 200 XML documents that I need to search for tags and enter those three fields above into that section, save it, open the next document and enter the same three fields, save, repeat for all docs. Here is an example:
    File A hosta,,00000C123456, hostb,,00000C123457, hostc,,00000C123458, hostd,,00000C123459, etc...(about 200 items, will have more later) File 1 . <HOST_NAME></HOST_NAME> <HOST_IP></HOST_IP> <HOST_MAC></HOST_MAC> . . File 2 . <HOST_NAME></HOST_NAME> <HOST_IP></HOST_IP> <HOST_MAC></HOST_MAC> . . File 3 . <HOST_NAME></HOST_NAME> <HOST_IP></HOST_IP> <HOST_MAC></HOST_MAC> . . After all the docs are done, they will look like this... File 1 . <HOST_NAME>hosta</HOST_NAME> <HOST_IP>,</HOST_IP> <HOST_MAC>00000C123456</HOST_MAC> . . File 2 . <HOST_NAME>hostb</HOST_NAME> <HOST_IP>,</HOST_IP> <HOST_MAC>00000C123457</HOST_MAC> . . etc.
    I have portable strawberry Perl right now on my work computer. If it would be easier to do it in ActivePerl or in Strawberry Perl installed version, let me know and I can spin it up on another workstation. So what is the best way to do this? Thanks for any help!
An overlapping regex capture
2 direct replies — Read more / Contribute
by Peter Keystrokes
on Jun 21, 2017 at 15:18

    Hi there,

    I have a script which extracts sequences from a file containing thousands of fasta sequences and creates separate files for each of them.

    Here is my script:

    #!/usr/bin/perl use strict; use warnings; my %id2seq = (); my $id = ''; open File,"human_hg19_circRNAs_putative_spliced_sequence.fa",or die $! +; while(<File>){ chomp; if($_ =~ /^>(.+)/){ $id = $1; }else{ $id2seq{$id} .= $_; } } foreach $id (keys %id2seq){ if (-f $id){ print $id." Already exists, about to override it","\n" } open my $out_fh, '>>', "$id.fa" or die $!; print $out_fh (">".$id."\n",$id2seq{$id}, "\n"); close $out_fh; } close File;

    Now, the human_hg19_circRNAs_putative_spliced_sequence.fa file which I am working on contains sequences as such:



    My script captures each sequence header as the key of a hash and captures the sequence itself as the hash. But the problem is that I want to name the files with only a part of the $id and not the whole of it i.e. hsa_circ_0000001.

    Is there a simple way to do this? Or do I have to create a new hash to extract filenames?


Log In?

What's my password?
Create A New User
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (1)
As of 2017-06-27 21:28 GMT
Find Nodes?
    Voting Booth?
    How many monitors do you use while coding?

    Results (615 votes). Check out past polls.