Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
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
How to use the MiniCPAN mirror as the corporate mirror behind the firewall...
1 direct reply — Read more / Contribute
by lee_crites
on Nov 21, 2017 at 16:17

    Using MiniCPAN as Local CPAN

    Y'all;

    I need to build a complete CPAN mirror for use behind our corporate firewall. I found minicpan, and like how easy it was to build the mirror. So I have that put into an environment which has access to the "outside world" where it can push the mirror to a location accessible from the "inside world."

    Now I need to configure cpan/cpanm to use that mirror.

    I've done my searching about the internet, and found a lot of folks who said how to use the mirror on the local box -- meaning the box it is on (with file://whatever/). But I need to access the one mirror from across the entire inside world. I tried ftp://hostname/fqpn and made a link in /var/www/cpan to where it resides and tried http://hostname/cpan, but neither one worked. I'm sure I am just missing one little point, but it hasn't jumped out at me just yet.

    I'm not afraid to hack about until I get it working, but I'm sure that someone here has already perfected the process. And if not, then at least several folks have already tried and can tell me what didn't work, so I don't waste my time with that.

    Once I have the perfect process done, I'll come back and post the steps here for others who might want to try to do the same thing.

    Thanks muchly, DL

    Lee Crites
    lee@critesclan.com
Creating dispatch table with variable in function name
3 direct replies — Read more / Contribute
by nysus
on Nov 21, 2017 at 14:22

    I'm creating a dispatch table. This works:

    my %dispatch = map { $_, \&{$_} } qw(first last user_id email create_p +assword);

    But this doesn't

    my %dispatch = map { $_, \&{'_create_' . $_} } qw(first last user_id e +mail create_password);

    How can I tack on a '_create_' before each function name?

    $PM = "Perl Monk's";
    $MCF = "Most Clueless Friar Abbot Bishop Pontiff Deacon Curate";
    $nysus = $PM . ' ' . $MCF;
    Click here if you love Perl Monks

Trouble skipping lines using Perl
3 direct replies — Read more / Contribute
by LeBran
on Nov 21, 2017 at 10:55

    Hello all, I'm struggling to get Perl to work in skipping lines containing certain features which means I don't need to use them, basically I'm just unsure of the syntax, though it appears to work in some places and not in others

    Looking at this following table;

    chrM 2928 A G 17 0 0% A 46 105 69.54% + R Somatic 1 1.23052720566294E-008 17 29 50 55 + 4 13 0 0 chr1 108310 T C 9 0 0% T 3 5 62.5% Y + Somatic 1 0.0090497738 2 1 2 3 7 2 0 + 0 chr1 726958 T A 11 0 0% T 9 4 30.77% + W Somatic 1 0.0672877847 6 3 1 3 5 6 0 + 0 chr1 1412720 C A 33 0 0% C 22 6 21.43% + M Somatic 1 0.0067850063 10 12 3 3 14 1 +9 0 0 chr1 1822396 C G 6 0 0% C 4 4 50% S + Somatic 1 0.0699300699 3 1 2 2 4 2 0 +0 chr1 1822457 C T 10 0 0% C 4 4 50% Y + Somatic 1 0.022875817 3 1 2 2 6 4 0 + 0

    I'm trying to skip the lines which are chrM rather than chr1, the following code is what I came up with (I'm also extracting different columns)

    while (my $line = <FILE>) { next if ($. == 1); chomp $line; my @sepline = split ("\t", $line); my $chromosome = $sepline[0]; my $chrpos = $sepline[1]; my $nmreads = $sepline[8]; my $mutants = $sepline[9]; my $totalreads = $nmreads + $mutants; next if ($chromosome = /^chrM/); print ("$nmreads $mutants $totalreads\n"); }

    So the script works fine if I # out the lower next if function towards the bottom of the script, I've also tried "next if ($chromosome = "chrM");" and "if ($chromosome = "chrM") { next;} but neither will work. Is there something incorrect about my syntax or am I simply going about it completely the wrong way? Appreciate any help, cheers

Converting hash into js object properties
1 direct reply — Read more / Contribute
by nysus
on Nov 21, 2017 at 10:52

    What module exists where I can take a hash like this:

    my %hash = ( rules => {name => '"required"', email => { required => true, email => true } }, message => { name => '"Please specify your name"', email => { required => '"We need your email address to +contact you"', email => '"Your email address must be in the format +of name@domain.com"', } } );
    </code>

    And convert it to something like this for use in a js function:

    rules: { name: "required", email: { required: true, email: true } }, messages: { name: "Please specify your name", email: { required: "We need your email address to contact you", email: "Your email address must be in the format of name@domain. +com" } }

    Ideally, the module would be smart enough to know when to double quote the values and when not to.

    $PM = "Perl Monk's";
    $MCF = "Most Clueless Friar Abbot Bishop Pontiff Deacon Curate";
    $nysus = $PM . ' ' . $MCF;
    Click here if you love Perl Monks

5.26 and prebuilt libraries on Windows
1 direct reply — Read more / Contribute
by Marc-Philip
on Nov 21, 2017 at 10:29
    Hi, I'm trying to build perl 5.26.1 from source on Windows using the Visual Studio 2010 on a 64bit machine:
    1. edit win32/Makefile to set CCTYPE=MSVC100
    2. run vcvarsall.bat amd64 to open a command shell with the development environment
    3. cwd with that shell to the win32 folder
    4. run nmake

    This succeeds. Now I want to build the Compress::Raw:Zlib extension, that comes with the perl tarball, against my prebuilt zlib. To do this, one needs to set the environment variables ZLIB_LIB and ZLIB_INCLUDE to the folders that contain zlib.lib resp. zlib.h and BUILD_ZLIB to "False". When I run nmake now, I get this error:

    link -out:..\..\lib\auto\Compress\Raw\Zlib\Zlib.dll -dll -nolo +go -nodefaultlib -debug -opt:ref,icf -ltcg -libpath:"c:\perl\lib\COR +E" -machine:AMD64 Zlib.obj "..\..\lib\CORE\perl526.lib" "C:\SAPDev +elop\hmexternals\perl\import\content\src_zlib-1.2.11-sap7-ntamd64.tar +.gz\zlib-1.2.11-sap7-ntamd64-release-msvc2010\lib\zlib.lib" "c:\Progr +am Files (x86)\Microsoft Visual Studio 10.0\VC\\lib\oldnames.lib" "c: +\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\lib\x64\kernel32.li +b" "c:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\lib\x64\user3 +2.lib" "c:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\lib\x64\g +di32.lib" "c:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\lib\x6 +4\winspool.lib" "c:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\ +lib\x64\comdlg32.lib" "c:\Program Files(x86)\Microsoft SDKs\Windows\v +7.0A\lib\x64\advapi32.lib" "c:\Program Files (x86)\Microsoft SDKs\Win +dows\v7.0A\lib\x64\shell32.lib" "c:\Program Files (x86)\Microsoft SDK +s\Windows\v7.0A\lib\x64\ole32.lib" "c:\Program Files (x86)\Microsoft +SDKs\Windows\v7.0A\lib\x64\oleaut32.lib" "c:\Program Files (x86)\Micr +osoft SDKs\Windows\v7.0A\lib\x64\netapi32.lib" "c:\Program Files (x86 +)\Microsoft SDKs\Windows\v7.0A\lib\x64\uuid.lib" "c:\Program Files (x +86)\Microsoft SDKs\Windows\v7.0A\lib\x64\ws2_32.lib" "c:\Program File +s (x86)\Microsoft SDKs\Windows\v7.0A\lib\x64\mpr.lib" "c:\Program Fil +es (x86)\Microsoft SDKs\Windows\v7.0A\lib\x64\winmm.lib" "c:\Program +Files (x86)\Microsoft SDKs\Windows\v7.0A\lib\x64\version.lib" "c:\Pro +gram Files (x86)\Microsoft SDKs\Windows\v7.0A\lib\x64\odbc32.lib" "c: +\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\lib\x64\odbccp32.li +b" "c:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\lib\x64\comct +l32.lib" "c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\\lib +\msvcrt.lib" -def:Zlib.def Creating library ..\..\lib\auto\Compress\Raw\Zlib\Zlib.lib and obje +ct ..\..\lib\auto\Compress\Raw\Zlib\Zlib.exp Zlib.obj : error LNK2001: unresolved external symbol __security_check_ +cookie Zlib.obj : error LNK2001: unresolved external symbol memcpy zlib.lib(inflate.obj) : error LNK2001: unresolved external symbol memc +py zlib.lib(deflate.obj) : error LNK2001: unresolved external symbol memc +py zlib.lib(trees.obj) : error LNK2001: unresolved external symbol memcpy Zlib.obj : error LNK2001: unresolved external symbol __imp_memmove Zlib.obj : error LNK2001: unresolved external symbol memcmp Zlib.obj : error LNK2001: unresolved external symbol strlen Zlib.obj : error LNK2001: unresolved external symbol __imp__errno Zlib.obj : error LNK2001: unresolved external symbol __imp_printf Zlib.obj : error LNK2001: unresolved external symbol memset zlib.lib(deflate.obj) : error LNK2001: unresolved external symbol mems +et LINK : error LNK2001: unresolved external symbol _DllMainCRTStartup zlib.lib(zutil.obj) : error LNK2001: unresolved external symbol __imp_ +malloc zlib.lib(zutil.obj) : error LNK2001: unresolved external symbol __imp_ +free ..\..\lib\auto\Compress\Raw\Zlib\Zlib.dll : fatal error LNK1120: 11 un +resolved externals NMAKE : fatal error U1077: '"c:\Program Files (x86)\Microsoft Visual S +tudio 10.0\VC\BIN\amd64\link.EXE"' : return code '0x460' Stop.

    The problem is that the path to msvcrt.lib is wrong. It uses c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\\lib\msvcrt.lib, but there's the amd64 part missing. The correct path is C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\lib\amd64\msvcrt.lib. Please note the missing amd64 is NOT where there's a double backslash.

    Compiling against the very same prebuilt zlib with the very same procedure works in perl 5.24.1. I suspect a problem in perl 5.26.1. I've noticed that libpth in Config_heavy.pl in 5.26.1 is libpth='"c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\\lib"', where it's libpth='\lib' in perl 5.24.1.

    Does anyone have an idea? Please note that

    • this is not a problem of the Compress:Raw:Zlib extensions, but of the perl itself.
    • Compress::Raw::Zlib has a problem on Windows as well (https://rt.cpan.org/Ticket/Display.html?id=123699)

    Thanks and Regards Marc-Philip

[tk] passing a variable to -value field in radio button
1 direct reply — Read more / Contribute
by Anonymous Monk
on Nov 21, 2017 at 09:51

    Hi Monks, I am building a graphical interface for my program, using radio Buttons

    I would like to have 3 buttons linked to a same variable, 2 of them have a fixed -value field. I want the last one to be configurable by the user

    I would like to configure this value using a ttk_entry, here's an extract of my code

    $Mode="Mode1"; my $entry26 = $lf21->new_ttk__radiobutton(-text => "Mode1", -variable +=> \$Mode, -value => "Mode1"); my $entry27 = $lf21->new_ttk__radiobutton(-text => "Mode2", -variable +=> \$Mode, -value => "Mode2"); my $entry28 = $lf21->new_ttk__radiobutton(-text => "Other:", -variable + => \$Mode, -value => $OtherMode ); my $entry29 = $lf21->new_ttk__entry( -validate => 'focusout', -textvariable => \$OtherMode, );

    From the tests i did, i can say that $OtherMode takes the value of the entry but, if I select the last button, the $Mode variable contains an empty string

    do you have any idea of what i did wrong?

    thanks in advance, have a great day :)

Loading a part of the file to array using Tie::File
8 direct replies — Read more / Contribute
by ansh007
on Nov 21, 2017 at 09:44

    I am extremely new to perl and working on my 1st perl code. I am stuck at a point, where I need to read a part of a file using Tie::File;

    My Old code:
    open(LOG_READ,"cat $InLogFilePath|tail -n +$InStartLineNumber|") || di +e "can not open file :$!"; my @all_lines = <LOG_READ> ; close (LOG_READ); for (@all_lines) {.. }

    But this could eat a lot of memory, as the files are huge. So I found Tie::File online, that happens not to load arrays in memory. 1st question, is that correct ?

    If yes, I get:

     tie @array, 'Tie::File', $filename or die ...;

    But I do not want to read the whole file. Let's say I want to read from line number 100 till end. How do I do it, using Tie::File ? something similar to:

    tie @array, 'Tie::File', "cat $InLogFilePath|tail -n +$InStartLineNumber" or die ...;

    Looking forward to your help monks :)

"indir" in shebang line
3 direct replies — Read more / Contribute
by ForgotPasswordAgain
on Nov 21, 2017 at 04:28
    In perlrun, it mentions:
    If the #! line does not contain the word "perl" nor the word "indir", the program named after the #! is executed instead of the Perl interpreter.
    I found with git that "indir" support was added in a cleanup commit for Perl 5.0 in 1994 and was mentioned in perlrun in 2012. Just out of curiousity, what is "indir" referring to?
perl6 rational number problem
2 direct replies — Read more / Contribute
by freakcoco
on Nov 20, 2017 at 23:14
    Hi Monk, I love perl6 number, it use rationals number by defulat.
    But how about large number? can I use it by default?
    some code like that:
    my Rat @example =  1 , * ** 0.9999 ... Inf;
    This work fine on  @example[^4]
    But when the number going bigger , it will stored float point by default and type check fail.
    How can i fix that?



    fixed question: Addition 、 Subtraction 、Multiplication 、 Division 、 Modulo
    my Rat @ex01 = 1.0 , * + 0.9999 ... Inf; my Rat @ex02 = 1.0 , * - 0.9999 ... Inf; my Rat @ex03 = 1.0 , * * 0.9999 ... Inf; my Rat @ex04 = 1.0 , * / 0.9999 ... Inf; my Rat @ex05 = 1.0 , * % 0.9999 ... Inf; my %ex = :add(@ex01), :substrat(@ex02), :mult(@ex03), div(@ex04), mod(@ex05); try { for < add substrat mult div mod > -> $op { for 1 .. 20 -> $count { .say; (%ex{$op})[$count] } } }
    This try will fail in Multiplication and Division
    Why?
    How to fix it?
Perl, Android web app, AJAX, JSON
3 direct replies — Read more / Contribute
by monx663
on Nov 20, 2017 at 17:49
    Hi all

    This is not a 100% Perl question but I am Perl programmer and my question touches on Perl heavily. There is a fully functional web based CMS that is written in Perl for which I would like to make certain functionality available to an Android app being written. The requirements are not that "heavy".

    The Android App needs to do the following few things:

    * Send a username/password combination to gain access to the CMS backoffice.

    * Call certain URLs which will enable the app to get a list of objects (images,names, other table contents) available in the CMS's database.

    * Probably POST to certain URLs in order to be able to upload images and create content.

    My question is: What methodology/APIs should I be looking at to complete this Perl CMS/Android app "integration". I was thinking of writing an AJAX layer that would expose certain methods to the Android app, which will be calling them via HTTP requests. I was also thinking of modifying certain of the CMS's packages to perhaps implement methods for JSON based communication of textual and binary data (images). I have also heard of Mojolistic, which supposedly is intended for writing RESTful APIs but find this a bit of an overkill for my scenario.

    Does anybody want to offer any of his thoughts about which route to pursue?


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?
    Discipulus 'Thou art so fat-witted with drinking of old sack..' ++Shakespeare

    How do I use this? | Other CB clients
    Other Users?
    Others exploiting the Monastery: (10)
    As of 2017-11-23 11:33 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?
      In order to be able to say "I know Perl", you must have:













      Results (334 votes). Check out past polls.

      Notices?