Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine

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
Custom log file to alternative to db
No replies — Read more | Post response
by Thenothing
on May 21, 2018 at 13:37

    Dear friends, hello again, I hope you are doing fine

    This thread is not relation to problem with code, but relation to opiniˇn about this idea I implement for fun and test if work, all end work.

    the target, is detect unsuccessful logins from user ip, and show recaptcha after 15 Attempts

    I was looking for a way to keep records of failed attempts, but all information about this was create a database and save the records, time, user, unsuccessful logins, in the end I not want to install a db aplication, then I remember how work Fail2ban (Fail2ban scans log files (e.g. /var/log/apache/error_log) and bans IPs that show the malicious signs)

    So I implement this method with this feautures:

    * auto create file, when the file does no exist

    * used pure perl to read and write file with open function

    * used regex to get timestamp, user, date, etc

    * show recaptcha when unsuccessful logins are > of 15 in period of time of 5 minutes or less

    * remove all data just the line relation to user and ip, etc, and reset the timestamp every 12 hours

    what do you think about this is idea, is bad ?

    All is working good, I have a dude relation what happend when multiple user conect to page login and do brute force attent, that mean the function open have to write in parallel ?

XMLOut in XML::Simple returning unwanted xml format
3 direct replies — Read more / Contribute
by perl_help27
on May 21, 2018 at 10:10
    Hello Monks, I kind of need your help. I have the following code:
    use XML::Simple; use Data::Dumper; my $hash= { 'root' => { 'item1' => { 'item1a' => 'n1', 'item1b'=>'jh' } } }; my $xs = new XML::Simple; my $xml = $xs->XMLout($hash, NoAttr => 1, RootName=>undef,); print Dumper $xml;
    This is outputting :
    <root> <name>item1</name> <item1a>n1</item1a> <item1b>jh</item1b> </root>
    But I want the xml to be ALL nested like that:
    <root> <item1> <item1a>n1</item1a> <item1b>jh</item1b> </item1> </root>
    What do you think I should do?? Please help I am stuck :S Thanks
Multiline replace regexp.
3 direct replies — Read more / Contribute
by nikolay
on May 21, 2018 at 08:47
    my $q='qqqweqwe asdasdasd zxczxczxc tyutyutyi '; my $a='zxczxczxc';
    How do i remove with regexp all the chars of the $q variable content, starting from the beginning of it and down to $a, including $a variable content? -- Something like:
    -- if it could work with multiline. (As the content of both variables can change, the regexp uses * instead of +). Thank you.
perltidy and UTF-8 BOM
2 direct replies — Read more / Contribute
by morelenmir
on May 21, 2018 at 00:07

    As part of the shift to working with a plain text editor I would like to employ the 'perltidy' batch file and script to ensure my code is readable and consistent in presentation. However I have encountered a problem in doing so.

    I use UTF-8 encoding with a matching BOM for all my Perl sources. Unfortunately when I run 'perltidy' on a file with this layout I recieve the following error:

    Perltidy version is 20180220 1: unexpected character decimal 239 (´) in script 1: unexpected character decimal 187 (╗) in script 1: unexpected character decimal 191 (┐) in script 1: Giving up after error

    If I remove the BOM, but otherwise keep the UTF-8 encoding then 'perltidy' works as expected. Alternately if I set the -UTF8 switch then I get both the error message and the entire source file becomes double-spaced on new lines. Is there any way around this problem?

    "Aure Entuluva!" - Hurin Thalion at the Nirnaeth Arnoediad.
Embedding command-line arguments within source code
4 direct replies — Read more / Contribute
by morelenmir
on May 20, 2018 at 13:55

    I am currently in the process of moving from EPIC and Eclipse to writing my Perl programmes with a straightforward text editor and then debugging with the native debugger. For me the two most useful features of EPIC were the ability to set a breakpoint visually by clicking in the left margin and also being able to specify the command-line arguments for a script.

    So far as setting breakpoints goes I have learned it is possible to do effectively the same thing in a text editor by adding $DB::single = 1; at the position in the source where you want the debugger to halt. However I have not yet found a way of pre-specifying the command-line arguments for a script within the source code. Is this possible? I always use GetOpt::Long to unpack and access any passed arguments. Therefore one idea that strikes me is to manually set the contents of $ARGV[n] at the top of the source before any other code is run. Would this approach work?

    Any suggestions or insight in this matter would be much apreciated!

    "Aure Entuluva!" - Hurin Thalion at the Nirnaeth Arnoediad.
launching external process macOS
2 direct replies — Read more / Contribute
by Anonymous Monk
on May 20, 2018 at 13:36

    I am quite new to using Perl on a macOS, so be patient.

    On Windows I usually launch external processes from the Shell using "system". For example to run "pdftotxt.exe" I use the following:

    system ("pdftotext", "-enc", "UTF-8", "myPDF.pdf","myTXT.txt");

    Which is the best way to achieve the same in a script for macOS?

How to dereference array of ref.s?
3 direct replies — Read more / Contribute
by nikolay
on May 20, 2018 at 10:35
    In the following code i want to dereference the array's element $a[0].
    my $q='qwer'; my @a=( \$q );
    How to do that? Using additional variable i do it so
    my $a=$a[0]; print "$a\n";
    How to do the same w/o additional variable. Reading PERL documentations did not reveal me the secret of syntax of the case. Thanks for advice.
Problems starting the debugger
1 direct reply — Read more / Contribute
by morelenmir
on May 19, 2018 at 21:58

    Hey Guys!

    I am in the process of getting back in to Perl after being away from programming as a whole for quite a while. I thought this might be a good time to learn how to use the built-in debugger. Previously I ran 'EPIC' inside 'Eclipse', but ended up very much disliking that IDE. Therefore this time around I intend to write programmes in a text editor called 'EditPad Pro' and then employ the native Perl debugger as necessary. Unfortunately I have run in to some problems straight out of the gate,

    As a test I started with the simplest of all one-line programmes, saved as '':

    say "Hello";

    Next, at the console window I used the command:

    perl -d

    This is the output I received from Perl:

    Loading DB routines from version 1.51 Editor support available. Enter h or 'h h' for help, or 'perldoc perldebug' for more help. <main::(test.plx:1): print "hello"; Unable to get Terminal Size. The Win32 GetConsoleScreenBufferInfo call + didn't work. The COLUMNS and LINES environment variables didn't work +. at C:/StrawberryPERL/perl/vendor/lib/Term/ReadLine/ line 41 +0. at C:/StrawberryPERL/perl/vendor/lib/Term/ line 462. Term::ReadKey::GetTerminalSize(GLOB(0x28025f4)) called at C:/S +trawberryPERL/perl/vendor/lib/Term/ReadLine/ line 410 readline::get_window_size called at C:/StrawberryPERL/perl/ven +dor/lib/Term/ReadLine/ line 1114 readline::init called at C:/StrawberryPERL/perl/vendor/lib/Ter +m/ReadLine/ line 208 require Term/ReadLine/ called at C:/StrawberryPERL/ +perl/vendor/lib/Term/ReadLine/ line 63 eval {...} called at C:/StrawberryPERL/perl/vendor/lib/Term/Re +adLine/ line 63 Term::ReadLine::Perl::new("Term::ReadLine", "perldb", GLOB(0x2 +8b27bc), GLOB(0x28025f4)) called at C:/StrawberryPERL/perl/lib/perl5d line 6868 DB::setterm() called at C:/StrawberryPERL/perl/lib/ +line 1849 DB::_DB__read_next_cmd(undef) called at C:/StrawberryPERL/perl +/lib/ line 2786 DB::DB called at test.plx line 1 SetConsoleMode failed, LastError=|6| at C:/StrawberryPERL/perl/vendor/ +lib/Term/ line 346. at C:/StrawberryPERL/perl/vendor/lib/Term/ReadLine/ line 1 +581. readline::readline(" DB<1> ") called at C:/StrawberryPERL/per +l/vendor/lib/Term/ReadLine/ line 11 Term::ReadLine::Perl::readline(Term::ReadLine::Perl=ARRAY(0x61 +1b1c), " DB<1> ") called at C:/StrawberryPERL/perl/lib/ li +ne 7367 DB::readline(" DB<1> ") called at C:/StrawberryPERL/perl/lib/ line 1858 DB::_DB__read_next_cmd(undef) called at C:/StrawberryPERL/perl +/lib/ line 2786 DB::DB called at test.plx line 1

    I am using a fresh install of the newest Strawberry Perl (32Bit), which is release I run this in Windows 7 (64Bit), patched with the latest updates. For what it is worth the same error occurs if I try the 64Bit edition of Strawberry Perl either. Other than this, Perl programmes themselves run without any problem. It is only when I try to execute them under the native debugger that I encounter an issue.

    Can any of you chaps suggest a solution for this?

    A quick search of the forum came up with a very similar issue reported by 'Ovid' way back in 2007. However that gentleman encountered the error while employing something called 'Prove', which I have never come across before and is certainly not something I am using myself. I think most of the suggestions in that thread related to using 'Prove', so I do not know how to apply them in my own far simpler situation.


    Well... A degree more persistence with the search function, both here and over at Google suggested another approach to sort this out that was not centred on 'Prove'; create an environment variable 'TERM' and set its value to 'dumb' (case sensitive for each I believe). After doing so perl -d began working like a charm!!! So... I guess that is the fix. Which is good of course, but I have no idea why I couldn't find that result the first half-dozen times I searched for an answer... Weird indeed. Still. The jobs a good'un--problem solved!

    "Aure Entuluva!" - Hurin Thalion at the Nirnaeth Arnoediad. fails to load
2 direct replies — Read more / Contribute
by geoffleach
on May 19, 2018 at 17:16

    perl5 (revision 5 version 26 subversion 2) linux 4.15.3-300.fc27.x86_64
    new install


    perl -e 'use IO::Prompter'
    Want.c: loadable library and perl binaries are mismatched (got handshake key 0xdb80080, needed 0xde00080)

    I understand what this means. What I can't figure out is the offending library

    Any ideas? Strategies?


How do I use "Long Doubles" in perl?
3 direct replies — Read more / Contribute
by cnd
on May 19, 2018 at 10:46
    My perl has them:
    #perl -e 'use Config;print "long doubles\n" if $Config{d_longdbl} eq " +define";' long doubles
    But they are not default:-
    # perl -e 'use Config;if ($Config{uselongdouble} eq "define") {print " +long doubles by default\n";} else {print "not default? How to use???\ +n"}' not default? How to use???
    So how do I force their use?

    I do not want to use external modules, and yes, I know all about base-2 and float precision.

Add your question
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?

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

    How do I use this? | Other CB clients
    Other Users?
    Others studying the Monastery: (7)
    As of 2018-05-21 18:02 GMT
    Find Nodes?
      Voting Booth?