Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change

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
How to validate json with json-schema draft 4?
No replies — Read more | Post response
by bessarabov
on Nov 25, 2015 at 14:46

    I need to validate json files with json-schama in perl script. But unfortunately perl module JSON::Schema does not support the current version of json schema.

    Is there any way of validation json with json-schema draft 4 in perl?

    I have created a sample repo that shows the problem:

preferred loading of XS modules
2 direct replies — Read more / Contribute
by jason0
on Nov 25, 2015 at 13:17

    Most of the time, the scripts I write would benefit from using XS modules. For instance, there is (can be) a significant difference using Text::CSV_XS vs Text::CSV. I wrote a bit of code that will "use" Text::CSV_XS if available otherwise load Text::CSV. Often Text::CSV is installed in a system but not Text::CSV_XS.

    my @modules=qw/Text::CSV_XS Text::CSV/; my $module; foreach (@modules) { if ( eval "require $_" ){ $module=$_; $module->import(); last; } }
    Later, I use the following line:
    my $csv=$module->new( { binary => 1, });
    My question: is there already a way (such as someone else's module) to do this?

    Thank you for your time!


SOAP::Lite, undef values in the reply
No replies — Read more | Post response
by pme
on Nov 25, 2015 at 11:03
    Dear Monks,

    Is there a way to force SOAP::Lite to return 'undef' if the XML tag is empty?

    For example in case of '<Tag/>' I got this 'Tag' => '' but I would like to get 'Tag' => undef.

    Thanks in advance.

map sentence with subtraction interpreted as with negative number
2 direct replies — Read more / Contribute
by rsFalse
on Nov 25, 2015 at 07:07
[closed] map sentence as array slice indexes
2 direct replies — Read more / Contribute
by rsFalse
on Nov 25, 2015 at 06:43

    I tried to understand why the following (with map sentence) gives an error. Can't understand.
    use warnings; use strict; @_ = 'a' .. 'c'; print @_[ map $_ -1, grep { $_ > 0 and $_ <= 1 } map { $_ + 1 } -1 .. 1 ];
    Missing comma after first argument to map function at map_inside_splic line 12, near "]"
    And the following (with map block) don't give an error:
    use warnings; use strict; @_ = 'a' .. 'c'; print @_[ map {$_ -1} grep { $_ > 0 and $_ <= 1 } map { $_ + 1 } -1 .. 1 ];
    upd: thanks for answers below.
Why is mojolicious "routing to a callback" ?
2 direct replies — Read more / Contribute
by pcouderc
on Nov 25, 2015 at 04:27
    Hi monks, I am trying to authenticate and I success :
    sub startup { my $self = shift; my $r = $self->routes; $r->get('/:layout')->to('login#nolog'); $r->get('/:layout/logout')->to('login#logout'); my $auth = $r->under( sub { return defined($self->session('userid' +)) } ); $auth->get('/:layout/menu')->to('login#menu'); $r->any('/:layout/:dummy')->to('login#nolog');}
    I authenticate in sub nolog, I define userid and I redirect to "upsmichel/menu", I expect "login/menu.html.ep" to be rendered but instead I am routed to a callback ?
    why ? What do I miss ?
    Wed Nov 25 10:03:48 2015] [debug] GET "/upsmichel/nolog". [Wed Nov 25 10:03:48 2015] [debug] Routing to controller "Myapp::Contr +oller::Login" and action "nolog". [Wed Nov 25 10:03:48 2015] [debug] Rendering cached template "login/no +log.html.ep". [Wed Nov 25 10:03:48 2015] [debug] Rendering cached template "layouts/ +upsmichel.html.ep". [Wed Nov 25 10:03:48 2015] [debug] 200 OK (0.061906s, 16.154/s). [Wed Nov 25 10:04:02 2015] [debug] POST "/upsmichel/nolog". [Wed Nov 25 10:04:02 2015] [debug] Routing to controller "Myapp::Contr +oller::Login" and action "nolog". [Wed Nov 25 10:04:02 2015] [debug] 302 Found (0.031328s, 31.920/s). [Wed Nov 25 10:04:02 2015] [debug] GET "/upsmichel/menu". [Wed Nov 25 10:04:02 2015] [debug] Routing to a callback. [Wed Nov 25 10:04:02 2015] [debug] Nothing has been rendered, expectin +g delayed response.
how can i be in the same entry if my validation fails in Tk?
1 direct reply — Read more / Contribute
by yedukondalu
on Nov 25, 2015 at 00:21

    Given above is my code.In that I am validating the name entry not to contain any numeric values.If it does the messageBox displays and goes to the next entry..I need the cursor to be in the same entry if the validation fails. And the other is when I give any character in age enter both messageBoxes i.e dob and ages displays are popping up.

    #!usr/bin/perl use warnings; use strict; use Tk; #$\="\n"; my $name; my $age; my $dob; open(my $fh,'+<','details.txt') || die "Can't open the file details.tx +t $!"; #creating a Mainwindow: my $window = MainWindow->new(); my $first_frame = $window -> Frame()->pack(-side => 'top',-ipadx => 10 +,-fill => 'x', -ipady => 1); $first_frame -> Label(-text => 'Fill the details listed below') -> gr +id(-row => 0 ,-column => 2,-rowspan => 1); my $frame = $window -> Frame(-background => 'grey')->pack(-side => 'to +p',-ipadx =>150,-fill => 'x',-ipady => 60); my $name_label=$frame -> Label(-text => 'Name') -> grid(-row => 2, -co +lumn=> 0); my $name_entry=$frame->Entry(-background => 'white',-foreground => 'bl +ack', -textvariable => \$name, -validate => 'focusout',-validatecomma +nd => \&check_name)->grid(-row =>2, -column=>1); my $age_label=$frame -> Label(-text => 'age')-> grid(-row => 4, -colum +n=> 0); my $age_entry = $frame -> Entry(-background => 'white',-foreground => +'black', -textvariable => \$age,-validate => 'focusout',-validatecomm +and => \&check_age) -> grid(-row =>4, -column=>1); my $dob_label=$frame -> Label(-text => 'DOB')-> grid(-row => 6, -colum +n=> 0); my $dob_entry = $frame -> Entry(-background => 'white',-foreground => +'black',-textvariable => \$dob, -validate => 'focusout',-validatecomm +and => \&check_dob) -> grid(-row =>6, -column=>1); $name=$name_entry -> get(); $age = $age_entry -> get(); $dob = $dob_entry -> get(); my $submit = $frame -> Button(-text => 'submit', -command =>sub {&subm +it} ) -> grid( -row =>8, -column=>1); $frame -> Label(-background => 'grey') -> grid(-rowspan=> 6); $frame -> Label(-text => 'After adding all the details click quit to e +xit') -> grid( -row => 16, -column=> 1); $frame -> Label(-background => 'grey') -> grid(-rowspan=> 6); my $quit = $frame -> Button(-text => 'Quit', -command =>sub {exit} ) - +> grid(-row =>25, -column=>1); sub submit { my $line= join(' ',$name,$age,$dob); print $fh $line,"\n"; if(!($?)) { my $button = $frame -> messageBox( -icon => 'info',-message => ' +Details added successfully to file', -type => 'Ok' ); $name_entry->delete('0', 'end'); $age_entry->delete('0', 'end'); $dob_entry->delete('0', 'end'); } } sub check_name { if (($name =~ m/[0-9]/)) { $name_entry -> messageBox( -icon => 'info',-message => 'Name shoul +d not contain numeric values' ,-type => 'Ok'); $name_entry->delete('0', 'end'); } } sub check_age { if (($age=~ m/[a-z]/i)) { $age_entry -> messageBox( -icon => 'error',-message => 'age shoul +d not contain characters' ,-type => 'Ok'); $age_entry->delete('0','end'); } } sub check_dob { if (!($dob=~ m/\d{1,2}[\/|\:]\d{1,2}[\/|\:]\d{4}/)) { $age_entry -> messageBox( -icon => 'error',-message => 'Enter vali +d date' ,-type => 'Ok'); $dob_entry->delete('0', 'end'); } } MainLoop;
To process xml files within multiple subfolders in perl
2 direct replies — Read more / Contribute
by codewalker
on Nov 24, 2015 at 23:04

    Hi, I Just want process all xml files within multiple subfolders

    But my current code is used to grep the files within the folder

    use strict; undef $/; my $path = $ARGV[0]; my $out = $ARGV[1]; opendir(DIR, $path) || die "cannot read folder path"; my @xmlfiles = grep {/\.xml$/i} readdir(DIR); closedir(DIR); foreach my $xml(@xmlfiles) { open(FIN, "$path/$xml") or die("Couldn't open input File!!"); my $file = <FIN>;

    Can anyone knows how to process within multiple folders in perl

installation of modules
1 direct reply — Read more / Contribute
by cbtshare
on Nov 24, 2015 at 23:00
    Hello, I am trying to install padre on opensuse 14 , I installed trhough yast but nothing showed up so I decided to run padre from the command line and got the following error:
    padre Can't load '/usr/lib/perl5/vendor_perl/5.18.2/x86_64-linux-thread-mult +i/auto/Wx/Scintilla/' for module Wx::Scintilla: libwx_gtk cannot open shared object file: No such file o +r directory at /usr/lib/perl5/5.18.2/ line 68. at /usr/lib/perl5/vendor_perl/5.18.2/x86_64-linux-thread-multi/Wx/Sci line 32. Compilation failed in require at /usr/lib/perl5/vendor_perl/5.18.2/Pad +re/Wx/ line 15. BEGIN failed--compilation aborted at /usr/lib/perl5/vendor_perl/5.18.2 +/Padre/Wx/ line 15. Compilation failed in require at /usr/lib/perl5/vendor_perl/5.18.2/Pad +re/Wx/ line 50. BEGIN failed--compilation aborted at /usr/lib/perl5/vendor_perl/5.18.2 +/Padre/Wx/ line 50. Compilation failed in require at /usr/lib/perl5/vendor_perl/5.18.2/Pad +re/Wx/ line 58. Perl exited with active threads: 1 running and unjoined 0 finished and unjoined 0 running and detached
    so I tried installing the module, but getting an error, can I get help please, I tried googling but nothing.
    install Wx::Scintilla Reading '/root/.cpan/Metadata' Database was generated on Tue, 24 Nov 2015 17:17:02 GMT Running install for module 'Wx::Scintilla' Checksum for /root/.cpan/sources/authors/id/A/AZ/AZAWAWI/Wx-Scintilla- +0.39.tar.gz ok Scanning cache /root/.cpan/build for sizes ...................................................................... +......DONE Configuring A/AZ/AZAWAWI/Wx-Scintilla-0.39.tar.gz with Build.PL Created MYMETA.yml and MYMETA.json Creating new 'Build' script for 'Wx-Scintilla' version '0.39' AZAWAWI/Wx-Scintilla-0.39.tar.gz /usr/bin/perl Build.PL -- OK Running Build for A/AZ/AZAWAWI/Wx-Scintilla-0.39.tar.gz Use of uninitialized value $location in split at inc/Module/Build/Scin line 58. Use of uninitialized value in concatenation (.) or string at inc/Modul +e/Build/ line 59. Can't exec "wx-config": No such file or directory at inc/Module/Build/ line 64. Use of uninitialized value $configtest in pattern match (m//) at inc/M +odule/Build/ line 65. Cannot find wx-config for wxWidgets. Perhaps you need to install wxWid +gets development libraries for your system? at inc/Module/Build/Scint line 66. AZAWAWI/Wx-Scintilla-0.39.tar.gz ./Build -- NOT OK Failed during this command: AZAWAWI/Wx-Scintilla-0.39.tar.gz : make NO
Local Perl - CGI - Apache.
2 direct replies — Read more / Contribute
by lanta
on Nov 24, 2015 at 18:19

    For a CGI script, I need to use Perl installed in a user directory. The webserver user("apache" in my case) has access to the directory( /home/some_user/perl/bin ) and can stat the files in that location from the command line. While running the script the user is not able to stat the directory. I wrote the following script to test

    #!/bin/bash echo Content-type: text/plain echo "" echo "I am " whoami stat /home/some_user

    and get the following result
    I am Apache stat: cannot stat '/home/some_user': Permission denied.

    Any ideas?

    CGI(not mod_perl) Redhat 2.6.32 Apache 2.2.15

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 cooling their heels in the Monastery: (8)
    As of 2015-11-25 21:25 GMT
    Find Nodes?
      Voting Booth?

      What would be the most significant thing to happen if a rope (or wire) tied the Earth and the Moon together?

      Results (691 votes), past polls