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
Getting man-page info on metacpan and search.cpan.org
1 direct reply — Read more / Contribute
by rockyb
on May 30, 2016 at 20:34

    Suppose I have a module and a command-line interface to that.

    Right now using Module::Build, if I create a directory called /bin those scripts get installed. I recently learn that Metacpan.org will treat POD files (.pod) as documentation for corresponding Perl modules (.pm). But will it do the same for command-line scripts?

    And if I want to link to that command from a readme or the corresponding library, can I do that with L<> and have it link correctly on metacpan?

    I can and will make experiments, but it would save a lot of spurious releases and testing and time waiting for indexing if someone out there just knew what works. Thanks.

Regular Expression on special character and alphanumeric values
5 direct replies — Read more / Contribute
by perlmad
on May 30, 2016 at 12:34

    Hi Monks

    I have a doubt on regular expression below is my code

    my $string="{'totalResultsCount':71-24,'securityList':[{'cusip':'91%27 +9-6.H:Y8','issueDate':'2016-06-02T00:00:00','securityType':'Bill'}"; $string =~ /'cusip':'(\w+\-\$\.\%)'/; print " first is : $1 \n\n";

    output is

    Use of uninitialized value in concatenation (.) or string at sample.pl + line 7. first is :

    Because the "\w+" on supports alphanumeric values but my question is how to include alphanumeric and special character with in the parenthesis , I have tried the above code but i could not get an exact answer , Is there need any changes in Regular expression ???

    Expected output

    first is :912796HY8
dbd::oracle truncation error
3 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.
3 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 qw[min 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_&#124;=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.

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.