Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
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
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
    DBD::Oracle::st fetchall_arrayref failed: ORA-24345: A Truncation or n +ull fetch error occurred (DBD ERROR: ORA-01406 error on field 8 of 12 +2, ora_type 1) [for Statement "SELECT "ADVERTISEMENT_ID","DELIVERY_GR +OUP_ID","PUBLISHING_GROUP_ID","ADDRESS_ID","PERSON_ID","REF_PROPERTY" +,"REF_HOUSE","REF_OBJECT","VOLUME","OBJECT_CATEGORY","OBJECT_TYPE","D +ISTANCE_FROM_PUBLIC_TRANSPORT","DISTANCE_FROM_SHOPS","DISTANCE_FROM_K +INDERGARTEN","DISTANCE_FROM_SCHOOL","DISTANCE_FROM_SCHOOL2",to_char(" +PUBLISH_UNTIL", 'YYYY-MM-DD HH24:MI:SS'),"FLOOR","NUMBER_ROOMS","NUMB +ER_APPARTMENTS","SURFACE_LIVING","SURFACE_PROPERTY","SURFACE_USABLE", +"YEAR_BUILT","WITH_VIEW","FIRE_PLACE","CABLE_TV","LIFT","FAMILY","PAR +KING","GARAGE","ROOFFLOOR","BALCONY","SITUATION","TITLE",to_char("AVA +ILABLE_FROM", 'YYYY-MM-DD HH24:MI:SS'),"VISIT_NAME","VISIT_PHONE","VI +SIT_EMAIL","VISIT_REMARK","AD_DESCRIPTION","AD_DESCRIPTION2","RENT_NE +T","RENT_EXTRA","PRICE_UNIT","SELLING_PRICE","OFFER_TYPE","SENDER_ID" +,"CURRENCY","YIELD","CONTACT_PERSON","TARGET_DESTINATION","DATA_DELIV +ERER_ADDRESS_ID","URL",to_char("TIMESTAMP", 'YYYY-MM-DD HH24:MI:SS'), +"AD_LOGO",to_char("CREATED", 'YYYY-MM-DD HH24:MI:SS'),"BILLING_ADDRES +S_ID","BILLING_NUMBER","DISTANCE_FROM_MOTORWAY","ROOM_HEIGHT","HALL_H +EIGHT","MAX_FLOOR_LOADING","CARRYING_CAPACITY_CRANE","CARRYING_CAPACI +TY_ELEVATOR","ISDN","WHEELCHAIR_ACCESS","ANIMAL_ALLOWED","RAMP","LIFT +ING_PLATFORM","RAILWAY_TERMINAL","RESTROOMS","WATER_SUPPLY","SEWAGE_S +UPPLY","POWER_SUPPLY","GAS_SUPPLY","MUNICIPAL_INFO","OBJECT_REFERENZ" +,"FTP_DIRECTORY","FILE_NAME",to_char("FILE_DATE", 'YYYY-MM-DD HH24:MI +:SS'),to_char("RECORD_DATE", 'YYYY-MM-DD HH24:MI:SS'),"AGENCY_ID","BU +ILT_NEW","BUILT_OLD","CORNER_HOUSE","GARDENHOUSE","HIGHFLOOR","MIDDLE +_HOUSE","MINERGY_BUILT","MINERGY_CERTIFIED","NUMBER_FLOORS","PLOT_CON +NECTED","ROOMMATE","SWIMMINGPOOL","UNDER_LAW","UNDER_ROOF","WORLD","Y +EAR_RENOVATED","AD_LOGO_2","AD_URL_TITLE","CONTACT_FORM","DEFAULT_CON +TACT_FORM_TYPE","VERSION","OBJECT_URL_DELIVERER","MINIMUM_SURFACE_USA +BLE","CO_OWNERSHIP_NUMERATOR","CO_OWNERSHIP_DENOMINATOR","GEAK_CLASS" +,"HEATING_SYSTEM","HEATING_USAGE_PER_YEAR","SURFACE_LIVING_BUILDING", +"EKZ_LOWER","EKZ_UPPER","SHOW_ENERGY_RATING","HIDE_EVALO_RATING","ENE +RGY_DOC_TYPE_1","ENERGY_DOC_FILENAME_1","ENERGY_DOC_FILENAME_ORIG_1", +"ENERGY_DOC_TYPE_2","ENERGY_DOC_FILENAME_2","ENERGY_DOC_FILENAME_ORIG +_2" FROM "HOMEGATE"."ADVERTISEMENT_LOADER" a"] at /root/perl5/lib/per +l5/Ora2Pg.pm line 10280. ERROR: ORA-24345: A Truncation or null fetch error occurred (DBD ERROR +: ORA-01406 error on field 8 of 122, ora_type 1)
    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
    Hi,

    I have created a file called system_mod_includes.pm 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);
    1
    ;


    Then I have another module called Utils.pm. In this module I am using a function of perl module Data::Dumper.
    For example as below:
    print Dumper(%HASH);
    OR
    print Data::Dumper(%HASH);
    But this gives me error saying the function Dumper is unknown.
    But use Data::Dumper is already defined in system_mod_includes.pm.
    The error however goes away if I defined use Data::Dumper in Utils.pm 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?

    Thanks...

    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?

    Thanks!,

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 = 'https://xyz.com/download?wsdl'; my $url = 'https://xyz.com/download'; 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 ( +IO::Handle.new(:path(...) 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
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 drinking their drinks and smoking their pipes about the Monastery: (6)
    As of 2016-05-30 13:30 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?