Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"

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
How can you tell what Perl version was used to compile a module
1 direct reply — Read more / Contribute
by johnniestang
on Mar 06, 2015 at 15:06
    I'm testing out a new Linux build and had the Support team install Sybase Open Client for me, which includes Sybase::CTlib. The box has Perl 5.10.1 installed but I'm getting the undefined symbol Perl_Tstack_sp_ptr error message. From the FAQ and, I know this error is because the module was compiled with something other than 5.10.1. Recompiling the module would be new for me. So is there a way to determine what Perl version Sybase::CTlib was compiled with?
[perl6] Complex Attribute Validation and/or Triggers
1 direct reply — Read more / Contribute
by duelafn
on Mar 06, 2015 at 10:03

    Are there ways in perl6 to write more complex attribute validators and/or before/after/around modifiers on attribute access? I can't seem to find anything that would let me, say, implement an interval class with a lower and upper bound, or call some code every time an attribute is changed. Did I miss it somewhere?

    class Interval { has Real $.lb is rw = die 'Lower bound is required'; has Real $.ub is rw = die 'Upper bound is required'; } ### Example which does not work: # class Interval { # has Real $.lb where * <= $.ub is rw = die 'Lower bound is requir +ed'; # has Real $.ub where * >= $.lb is rw = die 'Upper bound is requir +ed'; # after lb { say "Lower bound was changed!" if @_ } # } my $i = lb => 1, ub => 3); say $i.perl; $ = 0; # should print message say $i.perl; $ = 6; # should blow up! say $i.perl;


Math::Int128 issue on OS/X
1 direct reply — Read more / Contribute
by salva
on Mar 05, 2015 at 11:37
    I have this bug report for Math::Int128.

    The reporter is trying to use Math::Int128 C API but his module dies because of some unresolved symbol. It seems to me that the issue is related to the compilation/linking of the client module.

    I don't have a Mac and my knowledge of OS/X is quite limited, so I would really appreciate if somebody else could take a look at that.

Regex Substring SORT Conundrum
5 direct replies — Read more / Contribute
by Polyglot
on Mar 05, 2015 at 10:38

    Dear Perl Monks,

    I've looked at some posts here on a substring sort HERE and HERE which seem inapplicable to my case, but which do indeed present some of the difficulty of this sort (no pun intended) of task.

    I'm needing to create a particular sort order for Biblical citations, based on the chronological order in which they would normally occur in the Bible. This order has no relationship to either numerical values nor to alphabetical values. Each reference must be sorted principally by the Book Title, but it must also include the chapter(s) and verse(s) (if present) which follow the book.

    Here is a sample of the references needing to be sorted, and how I would hope it might look after being sorted.

    Biblical References
    UnSorted InputSorted Output
    Acts 4:29-31 Numbers 14:10 Luke 1:20 John 16:15 Acts 2:4 1 Peter 1:22 Psalm 56:3 2 Corinthians 12:2, 4, 1, 11 Ephesians 3:18, 19 Ephesians 4:14, 13, 17, 18; 5:15, 16 Matthew 24:24 Colossians 2:6-8 Hebrews 10:35-39 Hebrews 4:10-12 Philippians 1:6, 27-29 Matthew 7:6-12, 15 Philippians 2:13-15
    Numbers 14:10 Psalm 56:3 Matthew 7:6-12, 15 Matthew 24:24 Luke 1:20 John 16:15 Acts 2:4 Acts 4:29-31 2 Corinthians 12:2, 4, 1, 11 Ephesians 3:18, 19 Ephesians 4:14, 13, 17, 18; 5:15, 16 Philippians 1:6, 27-29 Philippians 2:13-15 Colossians 2:6-8 Hebrews 4:10-12 Hebrews 10:35-39 1 Peter 1:22

    Ideally, the sort should be done by the book first, and secondarily by its chapter/verse values. To begin with, I created a hash identifying each book and assigning it a numerical value for sort purposes. For now, I'm content with any permutation of the book reference having an equal value. A snippet follows.

    sub byBiblicalBookOrder { my %sortdata = ( 'Genesis' => '100', 'Gen' => '100', 'Ge' => '100', 'Gn' => '100', 'GEN' => '100', 'GE' => '100', 'GN' => '100', 'GENESIS' => '100', 'Exodus' => '200', 'Exo' => '200', 'Ex' => '200', 'Exod' => '200', 'EXO' => '200', 'EX' => '200', 'EXOD' => '200', 'EXODUS' => '200', 'Leviticus' => '300', 'Lev' => '300', 'Le' => '300', 'Lv' => '300', 'LEV' => '300', 'LE' => '300', 'LV' => '300', 'LEVITICUS' => '300', ... 'Revelation' => '9000', 'Rev' => '9000', 'Re' => '9000', 'The Revelation' => '9000', 'Apocalypse' => '9000', 'Apoc' => '9000', 'REVELATION' => '9000', 'REV' => '9000', 'RE' => '9000', 'THE REVELATION' => '9000', 'APOCALYPSE' => '9000', 'APOC' => '9000' ); if ($sortdata{$a} > $sortdata{$b}) { return 1 } elsif ($sortdata{$b} > $sortdata{$a}) { return -1 } else { return 0 } } # END SUB byBiblicalBookOrder

    But the problem is that perl's $a and $b also include extraneous book and chapter numbers for each reference, and therefore are not matched anywhere in the hash. To try to sort by the book names only, I tried calling the script like this:

    print sort byBiblicalBookOrder map{/^(.*)(?>(?:\s.{1,5}(:\d+)*.*))/} @ +references;

    ...which didn't work. So far, anything I've tried either yields an alphabetical sort, a truncated sort (no chap/verse), or an unsorted result.

    I wish this did not challenge me so much. It shows I still have sooo much to learn before I can feel I've really come close to proper utilization of the Perl language.

    Your wisdom is much appreciated!



Help me to understand increment / decrement operator behavior in perl
7 direct replies — Read more / Contribute
by sam_bakki
on Mar 04, 2015 at 00:55

    Hi Monks

    I have the following code, IMHO it should print "T1" but to my surprise, It print "T2". Then I compile the "C" version of the same code in gcc and executed, It also printed "T2" , Then the C version, I have compiled in Visual Studio, It prints "T1" "T2".

    I am confused now. Can some one please throw light?

    use strict; my $a = 10; #IMHO: $a-- should finish the current operation and then -1 if ($a == $a--) { print "\n T1"; } $a=10; #IMHO: --$a should -1 first and continute with current operation , i.e + if compare if ($a == --$a) { print "\n T2"; } #ENV: #Active Perl 5.20, Windows 7, x64 #Output # T2

    Thanks & Regards,
    Bakkiaraj M
    My Perl Gtk2 technology demo project - , contributions are welcome.

Recommendations for efficient data reduction/substitution application
9 direct replies — Read more / Contribute
by atcroft
on Mar 03, 2015 at 13:54

    Can anyone recommend the most efficient method of applying a large number of regular expression substitutions (> 100) to a relatively large number of input data lines (> 10_000_000)?

    In a recent project at $work, I wrote a script to generate a report of logged problem occurrences. In this process, I have to simplify the data by removing variations that are "noise" relative to the issues I am looking at (such as a process ID, an amount of free memory when a memory use threshold is crossed, or a part of a message with more detail than needed in this report). Once I've broken the record into a few basic parts, I currently have a list of 100+ regexen, replacement strings, and order of application to use (currently stored in a DB table), and a simple for loop to apply them to each record:

    foreach my $regex (@conversions) { if ( $entry{$k} =~ s/$regex->{from}/$regex->{to}/g ) { $regex->{count}++; # Count of applications used to determine if # a particular substitution is warranted. } }
    I have the nagging feeling, however, that there is a more efficient way of dealing with this. (Also, this processing takes up the largest percentage of the processing time in the script, which often takes hours to run.) Any thoughts/suggestions?

    Thank you for your time and attention, and any direction you may provide.

Debating With Friends
4 direct replies — Read more / Contribute
by exquisitemb
on Mar 02, 2015 at 23:22
    Hi All -- A friend is doing some weird embedded programming in C, and getting some strange results, so he asked what perl did (just for the sake of asking). I wrote up the quick comparison, and I got interesting results, now I'm intrigued. How/why does this work? (Yes, I know this is really stupid code)
    #!/usr/bin/perl $x; if(($x=1) eq ($x=2)) { print "equal\n"; } else { print "not equal\n"; }
    Result is that it gives is "equal". Why?
Re learning Perl
9 direct replies — Read more / Contribute
by Anonymous Monk
on Mar 02, 2015 at 16:18


    I've been dabbling with Perl on and off since a while. Managed to write some decent scripts. After a two year gap, am looking forward to give it another try.

    I started with Learning Perl Book, as many here would have started, and by the time I finished about 70% of it, was able to write scripts that helped automate monitoring stuff. Of course I have forgotten most of the syntax etc, so wondering if its better to start once again with "Learning Perl", or directly jump to Intermediate Perl and then, as and when need arises, "refill" the gap by going back to Learning Perl? I've heard that it's the next book to go for after Learning Perl.

    Wanted to see how much I still remember. So quickly whipped up the following.

    #!/usr/bin/perl use warnings; use strict; my @numbers = (1..100); my @tripled = map {$_ *3} @numbers; print "tripled -> $_\t" foreach (@tripled); print "\n"; my @ends_with_2 = grep {$_ =~ /2$/} @numbers; print "Ends With 2 -> $_\t" foreach (@ends_with_2); my %somehash = ( "firstname" => "first", "secondname" => "middle", "lastname" => "surname", ); print "\n"; foreach my $thing (sort keys %somehash) { print "Key$thing, Value is $somehash{$thing}\n"; }

    And it worked.

    perl tripled -> 3 tripled -> 6 tripled -> 9 tripled -> 12 triple +d -> 15 tripled -> 18 tripled -> 21 tripled -> 24 tripled -> +27 tripled -> 30 tripled -> 33 trip led -> 36 tripled -> 39 tripled -> 42 tripled -> 45 triple +d -> 48 tripled -> 51 tripled -> 54 tripled -> 57 tripled -> +60 tripled -> 63 tripled -> 66 trip led -> 69 tripled -> 72 tripled -> 75 tripled -> 78 triple +d -> 81 tripled -> 84 tripled -> 87 tripled -> 90 tripled -> +93 tripled -> 96 tripled -> 99 trip led -> 102 tripled -> 105 tripled -> 108 tripled -> 111 triple +d -> 114 tripled -> 117 tripled -> 120 tripled -> 123 tripled -> +126 tripled -> 129 tripled -> 132 trip led -> 135 tripled -> 138 tripled -> 141 tripled -> 144 triple +d -> 147 tripled -> 150 tripled -> 153 tripled -> 156 tripled -> +159 tripled -> 162 tripled -> 165 trip led -> 168 tripled -> 171 tripled -> 174 tripled -> 177 triple +d -> 180 tripled -> 183 tripled -> 186 tripled -> 189 tripled -> +192 tripled -> 195 tripled -> 198 trip led -> 201 tripled -> 204 tripled -> 207 tripled -> 210 triple +d -> 213 tripled -> 216 tripled -> 219 tripled -> 222 tripled -> +225 tripled -> 228 tripled -> 231 trip led -> 234 tripled -> 237 tripled -> 240 tripled -> 243 triple +d -> 246 tripled -> 249 tripled -> 252 tripled -> 255 tripled -> +258 tripled -> 261 tripled -> 264 trip led -> 267 tripled -> 270 tripled -> 273 tripled -> 276 triple +d -> 279 tripled -> 282 tripled -> 285 tripled -> 288 tripled -> +291 tripled -> 294 tripled -> 297 trip led -> 300 Ends With 2 -> 2 Ends With 2 -> 12 Ends With 2 -> 22 + Ends With 2 -> 32 Ends With 2 -> 42 Ends With 2 -> 52 + Ends With 2 -> 62 Ends With 2 -> 72 Ends With 2 -> 82 Ends With 2 -> 92 Key is firstname, Value is first Key is lastname, Value is surname Key is secondname, Value is middle

    I remembered Map and Grep, but did not remember the syntax. A quick look at the perldocs refreshed it and it sort of came back to me. So question is, should I jump in to reading (and trying out exercises) in Intermediate Perl, or should I go back to Learning Perl and start all over again?

Splitting folded MIME headers into indivual headers?
5 direct replies — Read more / Contribute
by sebastiannielsen2
on Mar 02, 2015 at 15:43

    Im trying to split a scalar containing multiple MIME header lines, that might be folded, into a Array that should hold one complete header per element

    I tried with the following:

    @fixedheaders = split(/\n\S/, $fixedmsgheader);

    But that eats the first char in header lines. I need to split the header line so it takes folded header lines in consideration and NOT splitting a folded header line in the middle.

Artificial Intelligence Exchanging Heuristic
1 direct reply — Read more / Contribute
by nat47
on Mar 02, 2015 at 15:43
    I'm trying to find code examples of what an exchanging heuristic looks like. I haven't been able to find code examples for almost any AI algorithms.

    I think that people often call this k-exchange.

    For people who don't know what I'm talking about, see this
SSL Certificate Verification problem, using LWP::UserAgent
2 direct replies — Read more / Contribute
by ManyHats
on Mar 02, 2015 at 13:44

    The script below fails with this error: 500 Can't connect to (certificate verify failed) Can't connect to (certificate verify failed) LWP::Protocol::https::Socket: SSL connect attempt failed error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed at /Library/Perl/5.16/LWP/Protocol/ line 47.

    My best take on the error message is that the SSLeay (openssl) code is unable to verify the certificate. However, if I use the command 'openssl s_client -host -port 443', I get an OK at the end (see below), making me think that openssl is able to verify the certificate. So I have a "reality mismatch" with which I need help.

    New, TLSv1/SSLv3, Cipher is AES256-SHA Server public key is 2048 bit Secure Renegotiation IS supported Compression: NONE Expansion: NONE SSL-Session: Protocol : TLSv1 Cipher : AES256-SHA Session-ID: 8FA80F5DE8D33D29B20AE38665A96F1EE29517E229038F6EDDE9D8 +CA294DFEF8 Session-ID-ctx: Master-Key: D1E833AEFD8C0D9345BAD5996ED1B1D0D6E8F58CABBCAE47071B15 +0B49AD510A1A2D4075719C5296D01FDDBA3DFD67C3 Key-Arg : None Start Time: 1425321673 Timeout : 300 (sec) Verify return code: 0 (ok)

    If I uncomment the line that sets verify_hostname to zero, the error goes away. It is my understanding that all this option does is to disable the identify check that is done outside of openssl.

    Note that "working" code will still break because this code snippet does not providing the proper login information. In other words, I expect a whiny message from Salesforce that will include "INVALID_LOGIN: Invalid username, password"

    I do get more debug information if I run the program like this: 'perl -MIO::Socket::SSL=debug30 Testcase':

    Newton:salesforce_work tpl$ perl -MIO::Socket::SSL=debug30 Testcase DEBUG: .../IO/Socket/ new ctx 140688297857808 DEBUG: .../IO/Socket/ socket not yet connected DEBUG: .../IO/Socket/ socket connected DEBUG: .../IO/Socket/ ssl handshake not started DEBUG: .../IO/Socket/ not using SNI because openssl is too +old DEBUG: .../IO/Socket/ set socket to non-blocking to enforce + timeout=120 DEBUG: .../IO/Socket/ Net::SSLeay::connect -> -1 DEBUG: .../IO/Socket/ ssl handshake in progress DEBUG: .../IO/Socket/ waiting for fd to become ready: SSL w +ants a read first DEBUG: .../IO/Socket/ socket ready, retrying connect DEBUG: .../IO/Socket/ Net::SSLeay::connect -> -1 DEBUG: .../IO/Socket/ ssl handshake in progress DEBUG: .../IO/Socket/ waiting for fd to become ready: SSL w +ants a read first DEBUG: .../IO/Socket/ socket ready, retrying connect DEBUG: .../IO/Socket/ Net::SSLeay::connect -> -1 DEBUG: .../IO/Socket/ ssl handshake in progress DEBUG: .../IO/Socket/ waiting for fd to become ready: SSL w +ants a read first DEBUG: .../IO/Socket/ socket ready, retrying connect DEBUG: .../IO/Socket/ ok=0 cert=140688300414128 DEBUG: .../IO/Socket/ Net::SSLeay::connect -> -1 DEBUG: .../IO/Socket/ SSL connect attempt failed DEBUG: .../IO/Socket/ SSL connect attempt failed error:140 +90086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify fai +led DEBUG: .../IO/Socket/ fatal SSL error: SSL connect attempt +failed error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certif +icate verify failed DEBUG: .../IO/Socket/ IO::Socket::INET6 configuration fail +ed DEBUG: .../IO/Socket/ free ctx 140688297857808 open=140688 +297857808 DEBUG: .../IO/Socket/ free ctx 140688297857808 callback DEBUG: .../IO/Socket/ OK free ctx 140688297857808 500 Can't connect to (certificate verify fail +ed) Can't connect to (certificate verify failed) LWP::Protocol::https::Socket: SSL connect attempt failed error:1409008 +6:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed +at /Library/Perl/5.16/LWP/Protocol/ line 47.
    The message from line 2458 says that OK is zero, which makes me think that openssl already said that the certificate is bad (does openssl 0.9.8 check identity? Why would it not like it now even though is seems to like it in the openssl s_client command?)

    I'd appreciate any enlightenment

    #!/usr/bin/perl -w use strict; use LWP::UserAgent; use Mozilla::CA; # To set debug we can run the program like this: perl -MIO::Socket::S +SL=debug30 Testcase # Print versions #print "LWP::UserAgent->VERSION is " . LWP::UserAgent->VERSION . "\n"; my ($Request, $Reply, $res); # A User agent for all WWW requests my $ua = LWP::UserAgent->new( timeout => 120 ); $ua->ssl_opts( # verify_hostname => 0, SSL_ca_file => Mozilla::CA::SSL_ca_file(), SSL_verifycn_scheme => 'http', SSL_verifycn_name => '', ); my $LoginXML = <<EOF; <?xml version="1.0" encoding="utf-8" ?> <env:Envelope xmlns:xsd="" xmlns:xsi="" xmlns:env=""> <env:Body> <n1:login xmlns:n1=""> <n1:username>USERNAME</n1:username> <n1:password>AUTHCODE</n1:password> </n1:login> </env:Body> </env:Envelope> EOF $Request = HTTP::Request->new(POST => " +rvices/Soap/u/22.0"); $Request->header( 'Content-Type' => 'text/xml; charset=UTF-8', 'SOAPAction' => 'login' ); $Request->content($LoginXML); # Make the request and check the results $res = $ua->request($Request); $Reply= $res->content; if (!($res->is_success)) { warn $res->status_line, "\n"; warn $Reply, "\n"; } else { warn "The request succeeded\n"; }
change unintialized warning
3 direct replies — Read more / Contribute
by hailholyghost
on Mar 02, 2015 at 08:31
    Hello, I have a 355 line code that takes about 3 hours to run. I find errors like "Use of uninitialized value in subroutine entry at line 311" I have 4 different arrays on this line which could have been uninitialized. How can I set perl to change this warning to something like "Use of uninitialized value $hash{key1}{key2} in subroutine entry at line 311" in other words, how can I get the uninitialized warnings to tell me which value is uninitialized? To compensate for the vague warning, I have littered my code with "if(!defined($var))" but I would prefer a better solution than this. thanks, -DEC
New Meditations
Why PerlMonks is an amazing place.
4 direct replies — Read more / Contribute
by Anonymous Monk
on Mar 03, 2015 at 01:34


    I know this is not a question, but as an anonymonk, I cannot post it anywhere else, so here goes.

    I was the same guy who asked a question on "Re learning Perl". I even gave a small code snippet I wrote just to show how much I remember. This was pretty late in the night. I woke up half expecting someone to shoo me away at worst, or un answered post at best, because I was not sure how my question would be perceived. To my amazement and satisfaction, not a *single* sullen response!!!. The monks who responded genuinely wanted to guide. They suggested tips and books. Truly, there is no other forum like this. I've been here so many times, asked so many questions, but not even once, I repeat, not even once was I rudely sent back. I've seen much much worse forums, but there is something different here at the Monastery. Whenever someone asks me why I use Perl, I tell them 1) Because this is the only scripting language I know (and like) and 2) that they should visit PerlMonks. It's the most amazing place to come to ask questions and get genuine answers.

    It's also here at PerlMonks that I learnt that it's ok if you do not remember syntax, you can look up the documentation, no one expects you to remember everything by heart. As long as you have the basic fundamentals clear, you can barge ahead, and then fill in the gaps. You monks may not believe it, but there are other places not so forgiving/understanding/helpful.

    I hope the place stays as wonderful as it is right now. Thank you Monks.

New Cool Uses for Perl
EEPROM on i2c Real Time Clock Modules
1 direct reply — Read more / Contribute
by anita2R
on Mar 03, 2015 at 18:16

    Recently I bought a Real Time Clock module to attach to a Raspberry Pi using i2c. Getting the RTC up and running was pretty straight forward, but then I noticed that the board included an Atmel AT24C32 eeprom.

    Despite extensive searches I could not find information on accessing the eeprom. I already had the HiPi::BCM2835::I2C module installed, but again the available documentation was limited, but in the end I produced two scripts for reading and writing to the eeprom, using its sequential 32 byte read and write function. This allows sequential reads or writes for up to 32 bytes from a page address.

    As a 'less than Perl Monks novice' I humbly place the following two scripts here for others who want to use the eeproms on their RTC modules. Any advice on improving my code would be welcome

    Write to eeprom

    The script must be called as root, but permission are put back to a normal user in the script. The two variables $user and $group need to be entered, and if necessary the eeprom address on the i2c bus should be changed - it is currently 0x57, and is on the i2c-1 bus (change to i2c-0 for rev. 1 Raspberry Pi's)

    The write program requires a start address after the -a parameter (there is no default) and input can be piped to the script, entered as text in quotes after a -t parameter, or put as a path/filename after -t for a text file to be used as source

    Example calls

    Write to eeprom code (improved commenting - thanks to roboticus)

    Read from eeprom

    The script to read from the eeprom is simpler. It requires a start address after the -a parameter (defaults to 0) and a length of data to read after the -l parameter (defaults to 32). Optionally a -o parameter takes a path/filename to receive output. A valid path is required, but if the file is not present it is created. Existing files are appended to. With no -o option the output is to screen formatted with the hex addresses, if a -h parameter is included the display is in hex, rather than the default character display.

    Revised Read from eeprom code based on feedback from roboticus


Log In?

What's my password?
Create A New User
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (7)
As of 2015-03-07 02:19 GMT
Find Nodes?
    Voting Booth?

    When putting a smiley right before a closing parenthesis, do you:

    Results (183 votes), past polls