Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer

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
dbd::oracle truncation error
2 direct replies — Read more / Contribute
by wal
on May 30, 2016 at 07:42
    hi there i get an truncation error on a field but don't know why
    can anybody help me? thanks
Perl includes to reuse code.
2 direct replies — Read more / Contribute
by Anonymous Monk
on May 30, 2016 at 01:28

    I have created a file called and the contents of the file are as below:

    # System Modules
    # use CGI;
    use HTML::Template;
    use File::stat;
    use File::Type;
    use File::Temp;
    use JSON;
    use Time::Local;
    use POSIX 'strftime';
    use XML::Simple;
    use XML::Parser;
    use IO::Socket::INET;
    use Digest::MD5 qw(md5 md5_hex md5_base64);
    use Data::Dumper;
    use Net::SMTP;
    use Net::SMTP::TLS;
    use MIME::Base64;
    use Compress::Zlib;
    use URI::Escape;
    use Locale::Country;
    use Socket;
    use HTML::Entities;
    use List::Util qwmin max;
    use IO::Uncompress::Gunzip qw(gunzip $GunzipError);
    use IO::Compress::Gzip qw(gzip $GzipError);

    Then I have another module called In this module I am using a function of perl module Data::Dumper.
    For example as below:
    print Dumper(%HASH);
    print Data::Dumper(%HASH);
    But this gives me error saying the function Dumper is unknown.
    But use Data::Dumper is already defined in
    The error however goes away if I defined use Data::Dumper in as well.
Perl UTF-8 serving HTML5
2 direct replies — Read more / Contribute
by $h4X4_|=73}{
on May 29, 2016 at 12:22

    Update: I got it to work. Viewing the source problem was the header text/plain, I needed text/html. The "Content-Length" issues was

'g' flag w/'qr'
8 direct replies — Read more / Contribute
by perl-diddler
on May 28, 2016 at 22:25
    I was trying a few examples from the "Mastering Perl" (brian d foy) book relating to RE's. I noted w/interest, the 3 ways he used to match a "qr" expression on page 3.

    sub iregex { qr/ ... /ix } 1) my $regex = iregex() if ($isbn =~ m/$regex/ ) { print "Matched!\n } 2) my $regex = iregex() if ($isbn =~ $regex ) { print "Matched!\n } 3) if ($isbn =~ iregex() ) { print "Matched!\n }
    I especially liked methods 2 & 3 as they didn't need interpolation, with 3 being better as it didn't require an intermediate variable.

    Seeing that I wanted to try out capturing all matching sub expressions using 'g' added to my 'qr' expression, but I'm getting a deprecation error:

    > perl -we'use strict;use P; my $re = qr{ (\w+) }gx; my $dat = "Just another cats meow"; my @matches = $dat =~ $re; P "#matches=%s, matches=%s", scalar(@matches), \@matches; exit scalar(@matches);' output: Having no space between pattern and following word is deprecated at -e + line 2. Bareword found where operator expected at -e line 2, near "qr/ (\w+) / +gx" syntax error at -e line 2, near "qr{ (\w+) }gx" Execution of -e aborted due to compilation errors.

    If I move the 'g' option down to where the RE is used and use a *second* "RE" operator (i.e.: /.../g) and interpolate my expression into another RE (the slowest of the above 3 options), I get:

    > perl -we'use strict;use P; my $re = qr{ (\w+) }x; my $dat = "Just another cats meow"; my @matches = $dat =~ /$re/g; P "#matches=%s, matches=%s", scalar(@matches), \@matches; exit scalar(@matches);' output: #matches=4, matches=["Just", "another", "cats", "meow"]

    So why can't I add the global switch to the "qr" expression? FWIW, I also tried qr{ (?xg) }. Perl strips out the 'g' and tells me to add it to the end of the RE -- where it is deprecated:

    perl -we'use strict;use P; my $re = qr{ (?xg) (\w+) }; my $dat = "Just another cats meow"; my @matches = $dat =~ $re; P "#matches=%s, matches=%s", scalar(@matches), \@matches; exit scalar(@matches);' output: Useless (?g) - use /g modifier in regex; marked by <-- HERE in m/ (?xg + <-- HERE ) (\w+) / at -e line 2. #matches=1, matches=["another"]

    So how can I attach the "/g" modifier to my "qr" regex so I can use the direct match as in #2 or #3 above?


    P.S. - I also just noticed that in addition to stripping out the 'g' option, the 'x' option doesn't seem to work in the regex's parens, i.e. - (?x).

How does $. work in one liner?
4 direct replies — Read more / Contribute
by elevenfly
on May 28, 2016 at 18:20

    Hello! I found a code like this:

     perl -n -e 'print $_ if 1..2' test.txt

    This code will only print the first and second in test.txt and I was told that if will compare $. with the line number I provide. But what is the reason for that?

    Can anyone provide any help?


converting context free grammar to BNF
3 direct replies — Read more / Contribute
by nido203
on May 28, 2016 at 14:48

    Hello! I have a problem with converting this grammar to BNF version in Perl. I am using Parse RecDescent

    $grammar = q{ start: seq seq: '(' seqstr(s) ')' seqstr: seq | tagstr tagstr: OZN ( seq | rijec ) OZN: /[A-Z.,?'*:`*]+ / rijec: /[\w-?,:<*`*]+/ };

    i tried this but it is not working.

    use Grammar::BNF; my $g = Grammar::BNF.generate(Q:to<END> <start> => <seq> <seq> => '(' <seqstr(s)> ')' <seqstr> => <seq> | <tagstr> <tagstr> => <OZN> '(' <seq> | <rijec> ')' <OZN> => /[A-Z.,?'*:`*]+ / <rijec> => /[\w-?,:<*`*]+/ END );
Perl code help
2 direct replies — Read more / Contribute
by usertest
on May 28, 2016 at 14:34
    I have a requirement to delete certains lines between two patterns (START and END) which contain a string (def) - for example
    Source Data START abc def ghi END START xyz abc END Output should be START xyz abc END
Mojo::DOM find tag after another tag
2 direct replies — Read more / Contribute
by luxs
on May 28, 2016 at 13:23
    I've got simple HTML
    yada...yada...yada.. <img src="111"> yada...yada...yada.. <img src="222"> yada...yada...yada.. <h1>Some title</h1> yada...yada...yada.. <img src="333"> yada...yada...yada.. <img src="444">
    How can I find "333" and "444" (i.e. atributes of IMG tags after H1 tag) with mojo::dom functions? PS. With regex this is a trivial task.
SOAP authentication
1 direct reply — Read more / Contribute
by feiiiiiiiiiii
on May 28, 2016 at 11:30

    Hi guys,

    I'd like to create a SOAP client and connect to the soap web service. However, I'm having trouble getting through the authentication. Here is what it does through the web browser. The Perl login process will be a simulation of this.

    1, Enter the WSDL address into the web browser

    2, It will redirect me to the login url

    3, I enter the username and password

    4, Login succeeds. It redirects me to the original WSDL url and show the content.

    5, Once I've logged in, the cookie will be carried in all subsequent requests. So I won't be challenged to login again

    I believe the key points to handle this in Perl is:

    1, Handle the redirection of HTTP requests

    2, The protocol is HTTPS. Maybe there's some special handling of SSL?

    3, Handle the basic authentication

    4, Handle the cookie

    I tried the code as below:

    my $wsdl_url = ''; my $url = ''; my $user = 'abc'; my $password = '123'; SOAP::Transport::HTTP::Client::get_basic_credentials = sub { return ($user, $password); }; my $client= SOAP::Lite -> service($wsdl_url); my $cookie_jar = HTTP::Cookies->new(); $client->proxy($url, cookie_jar => $cookie_jar, );

    If I try to call a method of the client, all I get is fault message or 401 not authorized error. What is the standard code for implementing this?

    Thank you so much!

Perl6: unexpected exception when printing to a writable file handle
1 direct reply — Read more / Contribute
by stevieb
on May 28, 2016 at 10:42

    So, I've spent an hour or two every night this week reading through the perl6 intro, and several of the various official perl6 docs, but I've run into an issue. I don't know if this is my problem, or a problem with the docs.

    From the open() documentation, there is the following code example (spurt() simply prints something to the file):

    my $fh = open("test", :w); spurt $fh, "stuff\n";

    But when I test it (code is verbatim, the line num in the error is the spurt() line):

    my $wfh = open("in.txt", :w); spurt $wfh, "a\n"; $wfh.close;

    ... it results in:

    Type check failed in binding $path; expected Cool but got IO::Handle ( in block <unit> at nl.pl6 line 2

    Can someone explain where I'm going wrong? If it's relevant, I just installed the most recent p6 bits yesterday afternoon.

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 the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others drinking their drinks and smoking their pipes about the Monastery: (6)
    As of 2016-05-30 13:30 GMT
    Find Nodes?
      Voting Booth?