Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical

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
Permission denied to module
2 direct replies — Read more / Contribute
by zdavek
on May 26, 2015 at 15:26

    We upgraded from perl 5.14.2 to perl 5.20.2 and updated most of our modules this last weekend. Our programming staff have no problems running anything but our end users are all getting messages like:

    Can't locate MIME/   Permission denied at /path_to_script/ line 18.
    BEGIN failed--compilation aborted at /path_to_script/ line 18.
    I'm guessing something has the wrong perms but cannot track it down. MIME::Lite is installed and the permissions are:
    drwxr-sr-x  3 root common     96 May 23 12:49 lib/site_perl/
    drwxr-sr-x 56 root common   8192 May 24 11:11 lib/site_perl/5.20.2/
    drwxr-sr-x  2 root common   8192 May 23 13:16 lib/site_perl/5.20.2/MIME/
    -r--r--r--  1 root common 105117 Nov  3  2013 lib/site_perl/5.20.2/MIME/
    I'll note that every normal user of our system is in the common group. Also end users have no problems if no modules are used.

PERL : Parse/Open an excel file and replace the negative values in a sheet to '0'
2 direct replies — Read more / Contribute
by DarshanS
on May 26, 2015 at 15:09

    I am having an Excel sheet which contains several numeric entries. Out of which, there are some negative numbers as well. I need to replace all the negative values in it to '0'. Over-writing in same excel is preferable output. More details: Excel name - Test.xls , Sheet name - Sheet1 , Say there are 20 - rows and columns containing several numeric entries. These rows and columns contains formulas too - Say, the values in D column are derived from the entries in C column after a minor manipulation like Add/Sub etc...

    Steps i have tried:- -------------------

    use Spreadsheet::ParseExcel; use Spreadsheet::ParseExcel::SaveParser; # Open the template with SaveParser my $parser = new Spreadsheet::ParseExcel::SaveParser; my $template = $parser->Parse('Test.xls'); my $f_volume; my $f_volume = $workbook->add_format(set_num_format => '#,##0'); $worksheet->write('A:D', $f_volume);

    Hi, I am very new to Perl. Please do help me out resolve a scenario where i am stuck. I tried from the already suggested similar query, but i couldn't fix it.

DBD::Oracle installation problem - "Can't load Oracle.dll" / "Exec format error"
1 direct reply — Read more / Contribute
by topbanana
on May 26, 2015 at 15:07
    Hi, I'm trying to install DBD::Oracle on cygwin. I am only a beginner with perl, and the whole cpan/make/build thing is entirely new to me also. So to the problem. in cpan I run: cpan[2]> install DBD::Oracle and a load of guff is spewed out. All is well until the following lines:
    t/00versions.t ................ Can't load '/home/J/.cpan/build/DBD-Or +acle-1.74-nSxxhX/blib/arch/auto/DBD/Oracle/Oracle.dll' for module DBD +::Oracle: Exec format error at /usr/ lib/perl5/5.14/i686-cygwin-threads-64int/ line 190. at t/00versions.t line 10. Compilation failed in require at t/00versions.t line 10. BEGIN failed--compilation aborted at t/00versions.t line 10. # Looks like your test exited with 8 before it could output anything. t/00versions.t ................ Dubious, test returned 8 (wstat 2048, +0x800)
    Now, I don't really know what I'm doing here because it's all new to me, but I've had a go and so far all I can say is that /home/J/.cpan/build/DBD-Oracle-1.74-nSxxhX/blib/arch/auto/DBD/Oracle/Oracle.dll does exist:
    J-PC:J >ls -l /home/J/.cpan/build/DBD-Oracle-1.74-nSxxhX/blib/arch/aut +o/DBD/Oracle/Oracle.dll -rwxr-xr-x 1 J None 721811 May 26 15:07 /home/J/.cpan/build/DBD-Oracle +-1.74-nSxxhX/blib/arch/auto/DBD/Oracle/Oracle.dll
    The failing code is in .cpan/build/DBD-Oracle-1.74-nSxxhX/t/00versions.t:
    use DBD::Oracle qw/ ORA_OCI /;
    which is called by (or perhaps vice versa) the following code in /usr/lib/perl5/5.14/i686-cygwin-threads-64int/
    my $libref = dl_load_file($file, $module->dl_load_flags) or croak("Can't load '$file' for module $module: ".dl_error());
    So that module exists. Can anybody tell me what I can do here? By the way, I don't know what it does but I saw somebody somewhere mention ldd to check a library for links or something, so I did that:
    J-PC:J >ldd /home/J/.cpan/build/DBD-Oracle-1.74-nSxxhX/blib/arch/auto/ +DBD/Oracle/Oracle.dll ntdll.dll => /cygdrive/c/Windows/SysWOW64/ntdll.dll (0x779d000 +0) kernel32.dll => /cygdrive/c/Windows/syswow64/kernel32.dll (0x7 +72f0000) KERNELBASE.dll => /cygdrive/c/Windows/syswow64/KERNELBASE.dll +(0x75810000) ??? => ??? (0x6f640000)
    There's nothing that I can see in the cpan output that says a variable doesn't exist. Can anybody help me here? Any help is greatly appreciated as I'm totally in the dark. Thanks. ===================================================== EDIT: ===================================================== Here is some more of the cpan output, which suggests that the shared library isn't where it ought to be (although as I have said, it is where it is supposed to be, or at least, something is there):
    t/000-report-versions-tiny.t .. ok t/00versions.t ................ Can't load '/home/J/.cpan/build/DBD-Or +acle-1.74-nSxxhX/blib/arch/auto/DBD/Oracle/Oracle.dll' for module DBD +::Oracle: Exec format error at /usr/ lib/perl5/5.14/i686-cygwin-threads-64int/ line 190. at t/00versions.t line 10. Compilation failed in require at t/00versions.t line 10. BEGIN failed--compilation aborted at t/00versions.t line 10. # Looks like your test exited with 8 before it could output anything. t/00versions.t ................ Dubious, test returned 8 (wstat 2048, +0x800) Failed 2/2 subtests t/01base.t .................... 1/6 # Failed test 'install_driver' # at t/01base.t line 24. # got: 'install_driver(Oracle) failed: Can't load '/home/J/.c +pan/build/DBD-Oracle-1.74-nSxxhX/blib/arch/auto/DBD/Oracle/Oracle.dll +' for module DBD::Oracle: Exec forma t error at /usr/lib/perl5/5.14/i686-cygwin-threads-64int/ + line 190. # at (eval 11) line 3. # Compilation failed in require at (eval 11) line 3. # Perhaps a required shared library or dll isn't installed where expec +ted # at t/01base.t line 21. # ' # expected: '' # Failed to load Oracle extension and/or shared libraries # Looks like you failed 1 test of 6.
Quoting package names
1 direct reply — Read more / Contribute
by hurricup
on May 26, 2015 at 14:57

    I'm tired to excite with some perl basics i didn't know... But after i've started work on Camelcade I'm really ashamed...

    Anyway. Today i've discovered that i can pass bareword package name as a function parameter. Can you imagine? :)

    The question is: why the ... i see quoted package names everywhere?


    use parent qw(Foo Bar);
    instead of
    use parent Foo::,Bar::;
    I suppose that it is some compatibility mode, but not sure...

Test::MockModule and EXPORT
No replies — Read more | Post response
by jfroebe
on May 26, 2015 at 13:02

    Hi all,

    I'm trying to mock a module's subroutines that are exported using the Exporter module and @EXPORT. The problem I'm running into is Test::MockModule doesn't overload the subroutines in @EXPORT but will with @EXPORT_OK.

    use_ok( 'Test::MockModule'); my $module = new Test::MockModule("silly::module"); # this works and overloads the export_ok_sub() $module->mock('export_ok_sub', sub { return }); # this doesn't overload the export_sub() $module->mock('export_sub', sub { return });

    What am I missing? I know it is something simple.

    Jason L. Froebe

    Blog, Tech Blog

Do i need really to update perl 5 to perl 6?
7 direct replies — Read more / Contribute
by Muskovitz
on May 26, 2015 at 12:13
    Hi Monks! is it a must to update perl 5 to perl 6? There's a lot of changes in Perl 6 and also some said that learning perl 6 is like learning another language do i need really to update and learn perl 6 for future developing in perl?
Passing a file handle and two arrays to a function by reference.
5 direct replies — Read more / Contribute
by subr01
on May 26, 2015 at 09:28

    How to pass a filename or a filehandle, two arrays to a function? I have done this:

    open INPUT,"$old"; my (@arrayold,@arraynew); myfunc(*INPUT,\@arrayold,\@arraynew) sub myfunc { my ($file,@array1,@array2) = @_ ; my $j = 0; my $k = 0; while (my $line = <$file) { my($word1,$word2) = split(",",$line); $array[$j++] = $word1; $array[$k++] = $word2; } }

    As you can guess, my function reads a file which has info like:

    1,//http:abcd 2,//http:avcd

    into two arrays one containing the number and the other containing the address. I am only getting blank arrays. Am I passing it wrong? Kindly help.

1 direct reply — Read more / Contribute
by pmamatsis
on May 26, 2015 at 08:51
    Hello everybody, i would like to seek some advice for the MCE parallel library.
    I have an assignment at the office that i need to use it along with one database connection per worker process.
    What i am doing is...i am creating a database connection into the "main" body of my perl script in order to construct an array and then i am passing this array into the 'worker' sub.
    The problem rises when into the 'worker' sub i am trying to connect to the database again in order to execute a stored procedure based on the arguments provided by the main process...i am getting a series of errors about re-defining some functions from the DBI. One of the errors is the following:

    Subroutine DBI::st::ora_stmt_type redefined at C:/Perl64/site/lib/DBI. +pm line 1405, <__ANONIO__> line 2.

    What am i missing about the use of the MCE library ? Any kind of advice of what i am doing wrong ?

    Best regards and
    thank you in advance,
Perl CGI redirect
1 direct reply — Read more / Contribute
by jbt424
on May 26, 2015 at 08:32
    I need to create a Perl CGI script that will accept a single parameter as input. The parameter will be a fully qualified URL and the script will redirect the browser to the URL that has been passed as the parameter. The method is a GET and not a POST.

    The browser address bar will accept the full script with the URL parameter like this: http://webserver/cgi-bin/ I am new to Perl. I stole this code but it does not do a GET and I think I am using a bad example or one that does not apply to what I need to do:

    !/usr/local/bin/perl use strict; use warnings; use CGI qw(:standard); use CGI::Carp qw(warningsToBrowser fatalsToBrowser); use DBI; my $q = new CGI; print "Content-Type: text/html\n\n"; #print redirect(-url => ''); if ($q->param("Login")) { print "<META HTTP-EQUIV=refresh CONTENT=\"1;URL=\ +">\n"; } else { print header, # create the HTTP header start_html('Bad Parameter...1'), # start the HTML h1('Bad Parameter....2'), # level 1 header end_html; # end the HTML }; print <<END1; <HTML> <HEAD> <TITLE> </TITLE> </HEAD> <body> <form NAME="login" METHOD="POST"> <input type="hidden" name="submit" value="Submit"> <TABLE align="center" bgcolor=#B0C4DE> <TR> <TD> Enter The URL:</TD> </TR> <TR></TR> <TR></TR> <TR></TR> <TR></TR> <TR></TR> <TR> <TD><b>PASSWORD</b> :<input type="password" name=" +Password" size="20" maxlength="15" /></TD> </TR> <TR></TR> <TR></TR> <TR></TR> <TR></TR> <TR></TR> <TR> <TR> <TD align="center" colspan="2"> <input type="submit" name="Login" value="Login +"> <input type="reset" name="submit" value="Cance +l"> </TD> </TR> </TABLE> </FORM> </BODY> </HTML> END1
Run a script in parallel mode
5 direct replies — Read more / Contribute
by Anonymous Monk
on May 26, 2015 at 08:24
    Dear wise Monks,
    I hereby ask your wisdom regarding the following problem:
    I have a perl wrapper script that receives an input file with some protein sequences (I work with Bioinformatics) and then it calls a JAVA program that needs to run on each of the sequences separately (i,e, this piece of code cannot be parallelized, not written by me and I don't know JAVA). What I was thinking to do is, since I have like a 20 core machine, I could split the big file into smaller ones, run the JAVA code in parallel and then output all results in one file (the output file that the Perl wrapper will use to show to the user).
    My question therefore is, is there a straight-forward way to do this task? I am not very experienced with Perl so if you would please be patient with me I would really appreciate that.

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!
  • 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
  • Outside of code tags, you may need to use entities for some characters:
            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 lurking in the Monastery: (10)
    As of 2015-05-27 10:31 GMT
    Find Nodes?
      Voting Booth?

      In my home, the TV remote control is ...

      Results (530 votes), past polls