Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

The Monastery Gates

( #131=superdoc: print w/replies, xml ) Need Help??

Donations gladly accepted

If you're new here please read PerlMonks FAQ
and Create a new user.

New Questions
Taint error on file upload
2 direct replies — Read more / Contribute
by Sanjay
on Oct 16, 2018 at 09:35

    Perl CGI giving error while using Taint when uploading a file:

    Insecure dependency in sysopen while running with -T switch at C:/Perl/site/lib/File/Temp.pm line 512.

    Script works fine when Taint is not used in the shebang line. Error when Taint is on.
    #!C:/Perl/bin/perl.EXE -wT # CGI program to check Taint problem while uploading file. It prompts # for the of the file to be uploaded and displays the name of the # uploaded file. # Tested in: # OS Windows-7 32 bit, Perl 5.22.3, Apache 2.2 # OS WindowsServer-2012 64 bit, Perl 5.24.2, Apache 2.4.20 # OS Centos-6.10 64 bit, Perl 5.26.1, Apache 2.2.15 use strict; use warnings; use CGI; use CGI::Carp qw (fatalsToBrowser warningsToBrowser); my $q = new CGI; my $p_upl_new_file = $q->param ("p_upl_new_file") || ''; &sPrintForm; exit; ################################################################### sub sPrintForm { print $q->header (); print $q->start_html (); print $q->start_form ({-name => "form1"}); print $q->h1 ({-align => "center"} , "File Upload Test"); print "<br><br>"; print $q->filefield (-name => 'p_upl_new_file'); print "<br><br>"; print $q->submit (-name => "action_submit" , -value => "Submit"); print "<br><br>"; print "File name $p_upl_new_file"; print $q->end_form; print $q->end_html; } # END #############################################################
Parallel::ForkManager for any array
3 direct replies — Read more / Contribute
by MissPerl
on Oct 16, 2018 at 09:09

    I wrote this simple script after some reading online.

    To achieve fastest execution time, I want to have the number of jobs == arraysize. (any array in script for looping repeating process) I guess the other words, is instead of running stuff serially (one after the other), i have them in parallel to minimize time taken.

    So in this case I wanna delete a directory, delete the directory1 in (/user/home/directory1/), but i am clueless why it does not work, all the files and subdirectories still there. Does the script automatically assign each files/subdirectories to each children?

    Let me know if I have overlooked stuff. I am ready to learn . Thank you . :)

    #! /usr/bin/perl use Parallel::ForkManager; $directory1 = "/user/home/directory1/"; my $pm = Parallel::ForkManager->new(10); my @files = glob("$directory1/*"); my $number = scalar(@files); for (my $i = 0; $i < $number; $i++) { $pm->start and next; system ("rm", "-fr", $files[i]); exit(0); $pm->finish; } $pm-> wait_all_children;
Using big numbers correctly
1 direct reply — Read more / Contribute
by robert44444uk
on Oct 16, 2018 at 05:44

    Dear Perl Monks, I want to use the exact Chinese Remainder Theorem solution in a program I am constructing but I am not confident which of the two long numbers below will be used by the scalar $crt1 in my program, or even which of the two is correct, although my gut tells me it is the solution shown by "say" is probably the one.

    What coding should I use to ensure that $crt1 is always used correctly and printed correctly? Very grateful for your enlightenment.

    #!/usr/bin/env perl use warnings; use strict; use Math::BigFloat lib=>"GMP"; use Math::Prime::Util qw/:all/; use feature ':5.10'; my $crt1=chinese([1,2],[1,3],[1,5],[5,7],[4,11],[9,13],[0,17],[14,19], +[22,23],[28,29],[28,31],[27,37],[3,41],[15,43],[9,47],[51,53],[55,59] +,[35,61],[17,67],[35,71],[67,73],[28,79]); say $crt1; printf ("crt solution is= %.0f\n",$crt1);
Can't locate installed module
1 direct reply — Read more / Contribute
by arnauldvm
on Oct 15, 2018 at 18:28

    Installed Text::Unidecode (with no error message).

    Then:

    $ perl -e 'use Text::Unidecode' Can't locate Text/Unidecode.pm in @INC (you may need to install the Te +xt::Unidecode module) (@INC contains: ~/perl5/lib/perl5 ~/perl5/lib/p +erl5 /usr/local/Cellar/perl/5.28.0/lib/perl5/site_perl/5.28.0/darwin- +thread-multi-2level /usr/local/Cellar/perl/5.28.0/lib/perl5/site_perl +/5.28.0 /usr/local/Cellar/perl/5.28.0/lib/perl5/5.28.0/darwin-thread- +multi-2level /usr/local/Cellar/perl/5.28.0/lib/perl5/5.28.0 /usr/loca +l/lib/perl5/site_perl/5.28.0/darwin-thread-multi-2level /usr/local/li +b/perl5/site_perl/5.28.0) at -e line 1. BEGIN failed--compilation aborted at -e line 1.

    But:

    $ ls -lF ~/perl5/lib/perl5/Text total 56 drwxr-xr-x 258 xxx staff 8772 Oct 15 23:02 Unidecode/ -r--r--r-- 1 xxx staff 28162 Nov 26 2016 Unidecode.pm

    Tried 3 different installation methods (cpan -i, cpanm, manual install).

    (And this module used to work on the same host few years ago. Lot's of system updates since then, though.)

    I've read numerous posts on similar topics, but couldn't find any hint to debug this.

    Context: MacOS Sierra 10.12.16, perl installed with homebrew

    $ uname -a Darwin Drogon.local 16.7.0 Darwin Kernel Version 16.7.0: Thu Jun 21 20 +:07:39 PDT 2018; root:xnu-3789.73.14~1/RELEASE_X86_64 x86_64 $ perl -e 'print $];' 5.028000

    Thanx in advance!

Simple prog isnt cooperating
3 direct replies — Read more / Contribute
by catfish1116
on Oct 15, 2018 at 17:32
    I cant get the following code to cooperate:

    #!/bin/perl

    use v5.12;

    use warnings;

    MY CODE:

    my $Namelist = 'Wilma Fred Barney Betty Dino';

    if ( $Namelist ~= m/\w+a/) {

    print "Matched|$<$&>$|\n";

    say "The name that matched was $1 \n";

    } else {

    print "No match: \n";

    }

    My error(s)

    syntax error at ./exer_8_3 line 8, near "$Namelist ~"

    syntax error at ./exer_8_3 line 11, near "}"

    TIA, Catfish
how to get Config values into a hash
1 direct reply — Read more / Contribute
by Aldebaran
on Oct 15, 2018 at 16:51

    Hello monks,

    I frequently replicate others' posts so as to help if I can, learn more of a gigantic language, and have new scripts that will improve my own capabilities. So it is that chungley2000 rolled in with a question that morphed into about how to get values from Config. I've been playing with the values for a couple days now, and I wrote a script to see what output resulted from the 4 method function calls that this module exports. I've commented out failed attempts to herd these values into lexical variables.

    #!/usr/bin/perl -w use 5.011; use Config qw(myconfig config_sh config_vars config_re); use Data::Dumper; say myconfig(); say "---------------"; say config_sh(); say "---------------"; say config_vars(); say "---------------"; my $ref_Env = \%ENV; say Dumper $ref_Env; my $version = config_re("version"); say "version is $version"; # my $archname = $Config{'archname'}; #produces error: %Config unknown say "---------------"; #my $ref_Config = \%CONFIG; #say Dumper $ref_Config;

    Abridged output, where I've commented on values with a double hashmark:

    Summary of my perl5 (revision 5 version 26 subversion 1) configuratio +n: Platform: osname=linux osvers=4.9.0 archname=x86_64-linux-gnu-thread-multi --------------- Author='' CONFIG='true' ## big snip from say myconfig(); zcat='' zip='zip' --------------- ##nothing for say config_sh(); --------------- $VAR1 = { 'TEXTDOMAIN' => 'im-config', 'SSH_AUTH_SOCK' => '/run/user/1000/keyring/ssh', 'IM_CONFIG_PHASE' => '2', 'PERL5LIB' => '/home/bob/perl5/lib/perl5', ## snip in ENV data 'LESSCLOSE' => '/usr/bin/lesspipe %s %s' }; version is 1 ##config_re("version"); ---------------

    My experience with the large family of Config modules has been with Config::Tiny, where I have imported such values from an .ini file. Now I would like to import the values from the myconfig() method into a hash.

    If I had to get values quick and dirty, I would create a temp file with Path::Tiny, then read it with Config::Tiny. But when you have the darn thing in memory already, it seems like a significant work-around, in particular, when you are only going to delete the file for being a security risk. I don't want these data to be persistent beyond the first few lines of a perl script. Other modules from the Config namespace seem promising, but, for example CONFIG::Hash seems like it might be the thing I'm looking for, but not quite. There are at least 12 screens of matches for Config in cpan.

    I could also use bash to pipe these values, but do I really need a shell? It seems like there could be a perl-only solution to this, which is more portable. My question then is how to to herd the = joined and newline separated values from

    config_vars()

    into a hash.

    Thank you for your comment,

Inline::Python for windows 10
4 direct replies — Read more / Contribute
by tobbes
on Oct 15, 2018 at 08:19
    Greetings. As I am unable to get Inline::Python to compile properly on windows 10. Appearantly it relies on the module Proc::ProccessTable which from what I have heard does not work on windows. Is there an alternative? Or does anybody know if there is a precompiled version somewhere? I am running active state perl and I have not been able to find it in their repo. Any help would be greatly apreciated. OK, I think i may have broken something so I tried reinstalling mingw and clicked everything i could install. Now when I run cpan19> notest install Inline::Python I get this output:

    Running install for module 'Inline::Python'
    Running make for N/NI/NINE/Inline-Python-0.56.tar.gz
    Prepending C:\Perl\cpan\build\Test-Warn-0.36-2ZLr_C/blib/arch C:\Perl\cpan\build\Test-Warn-0.36-2ZLr_C/blib/lib C:\Perl\cpan\build\ExtUtils-InstallPaths-0.011-
    ePu0hw/blib/arch C:\Perl\cpan\build\ExtUtils-InstallPaths-0.011-ePu0hw/blib/lib C:\Perl\cpan\build\ExtUtils-Config-0.008-7dv9vN/blib/arch C:\Perl\cpan\build\ExtUtils-Config-0.008-7dv9vN/blib/lib C:\Perl\cpan\build\ExtUtils-Helpers-0.026-5pberY/blib/arch C:\Perl\cpan\build\ExtUtils-Helpers-0.026-5pberY/blib/lib C:\Perl\cpan\build\ExtUtils-PL2Bat-0.001-sr4UpL/blib/arch C:\Perl\cpan\build\ExtUtils-PL2Bat-0.001-sr4UpL/blib/lib to PERL5LIB for 'get' Has already been unwrapped into directory C:\Perl\cpan\build\NINE-ELKF6g
    Prepending C:\Perl\cpan\build\Test-Warn-0.36-2ZLr_C/blib/arch C:\Perl\cpan\build\Test-Warn-0.36-2ZLr_C/blib/lib C:\Perl\cpan\build\ExtUtils-InstallPaths-0.011-ePu0hw/blib/arch C:\Perl\cpan\build\ExtUtils-InstallPaths-0.011-ePu0hw/blib/lib C:\Perl\cpan\build\ExtUtils-Config-0.008-7dv9vN/blib/arch
    C:\Perl\cpan\build\ExtUtils-Config-0.008-7dv9vN/blib/lib C:\Perl\cpan\build\ExtUtils-Helpers-0.026-5pberY/blib/arch C:\Perl\cpan\build\ExtUtils-Helpers-0.026-5pberY/blib/lib C:\Perl\cpan\build\ExtUtils-PL2Bat-0.001-sr4UpL/blib/arch C:\Perl\cpan\build\ExtUtils-PL2Bat-0.001-sr4UpL/blib/lib to PERL5LIB for 'make' 'C:\Perl\bin\perl.exe Makefile.PL INSTALLDIRS=site' returned status 512, won't make
    Skipping test because of notest pragma
    Running make install
    Make had some problems, won't install

    Which isn't very helful to me, it seems it is just a general fail to make. Also it says it can't make clean because it is missing a Makefile, which i suppose is bad. I tried downloading the tar and doing the installation manually. appearantly I have a too old version of ExtUtils::MakeMaker

    Doing
    > upgrade ExtUtils::MakeMaker
    or
    > install ExtUtils::MakeMaker
    results in:
    Catching error: "Modification of non-creatable hash value attempted, subscript \"build_requires\" at C:/Perl/lib/CPAN.pm line 9734.\cJ\cI...propagated at C:/Perl/lib/CPAN.pm line 3266.\cJ" at C:/Perl/lib/CPAN.pm line 281. CPAN::shell() called at C:\Perl\bin/cpan.bat line 211
    Maybe it's time to give up? Is it at all possible to get cpan to play nicely with windows? I am running perl 5.10 from active state.

DBD::MariaDB or DBD::Mysql
3 direct replies — Read more / Contribute
by Anonymous Monk
on Oct 14, 2018 at 04:32
    I'm confused.For accessing Mysql which driver do I use?
Searching Database Question
3 direct replies — Read more / Contribute
by htmanning
on Oct 13, 2018 at 19:40
    Monks, I have a database of an inventory of keys. People check keys in and out. I'm trying to write an audit routine where I can look for errors in the database. Sometimes people check out a key, but forget to check it back in. The next time they check it out the number of keys on hand gets out of whack. I can easily search for all records that have either a negative number or more than one key on hand which is okay, but I'd like to search for all records where a check out doesn't have a corresponding check in. For example, if one key has two check ins or two check outs in a row, it would be flagged. I'm really not sure how to do this. Any ideas?

    Thanks!

CPAN modules for inspecting a Perl distribution?
5 direct replies — Read more / Contribute
by nysus
on Oct 12, 2018 at 15:30

    I've downloaded a distribution with many modules and submodules. I'm wondering if there is a tool out there to help analyze the contents of the distribution's modules. It might, for example, give me a simple breakdown of all the different modules and what directory they are in as well as provide a listing of what functions/methods each module provided and other relevant information that might help me more quickly assess how the distribution is laid out. Does any such beast exist? Thanks.

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

sprintf and arrays of unknown (in advance) length
7 direct replies — Read more / Contribute
by Anonymous Monk
on Oct 11, 2018 at 20:12

    This probably sounds like a very basic question, but I just spent the last half-hour going through the perl documentation (and even through the system sprintf man page), and couldn't find it.

    Let's suppose I have an array that I don't know the length of (or even one long enough that I don't want to write out the format for each variable). Yes, I know I could build an output string by looping over the array, but I am trying to learn about sprintf. :)

    Two questions:

    1. Is there some way of "repeating" a format (ie. use this parameter for the next ten variables or for all remaining variables)?

    2. What happens when perl "runs out" of parameters (there are more variables to print than parameters in the format)? Does it start from the beginning (probably not), repeat the last format (think some languages do this), or just throw an error?

how do I "initialize" $_
4 direct replies — Read more / Contribute
by Anonymous Monk
on Oct 10, 2018 at 23:12
    This is among the basics. I thought I am trying to read in the first line of a file, and then print it.
    #!/usr/bin/perl -w use strict; open (FILEHANDLE, '<', 'some.file') or die "Can't open some.file for r +eading.\n"; <FILEHANDLE>; print; close FILEHANDLE;
    That produces:
    Use of uninitialized value $_ in print at ./file.pl line 6, <FILEHANDL +E> line 1.
    What am I not understanding?
New Cool Uses for Perl
Resistor network simplifier
1 direct reply — Read more / Contribute
by roboticus
on Oct 13, 2018 at 18:41

    Hello, fellow monks!

    This isn't really all that cool, but I'm posting it just in case someone might be interested. I'm trying to get back to my QRP transmitter/receiver project and had just wanted to convince myself that Pi attenuators properly reduced to the expected input and output impedance. Rather than do a couple by hand, I went full nerd and wrote code to do it instead.

    Essentially, the code lets you create a network of resistors (via the build_impedance() function) and pi_pads (via build_pad()) and attach them together via the named ports. Once you've got the network built, remove all named nodes you don't care about and then tell it to generate the simplified network.

    The code, as it is now, should give you:

    $ perl attenuator_pad.pl ********************************************************************** +********** 10dB Attenuator terminated w/ 50 ohms ********************************************************************** +********** 10dB Pad N: in_neg(1) in_pos(2) out_neg(3) out_pos(4) (1 3 0.05), (2 1 100), (2 4 75), (4 3 100) 50 ohm terminator N: in_neg(5) in_pos(6) (6 5 50) 10dB Pad + terminator N: in_neg(1) in_pos(2) (1 3 0.05), (2 1 100), (2 4 75), (4 3 50), (4 3 100) Simplified network N: in_neg(1) in_pos(2) (1 2 52) ********************************************************************** +********** Two pads cascaded and terminated ********************************************************************** +********** PAD 10dB N: in_neg(1) in_pos(2) out_neg(3) out_pos(4) (1 3 0.05), (2 1 100), (2 4 75), (4 3 100) PAD 20dB N: in_neg(5) in_pos(6) out_neg(7) out_pos(8) (5 7 0.05), (6 5 68), (6 8 270), (8 7 68) TERM 50ohm N: in_neg(9) in_pos(10) (10 9 50) PAD 20dB + TERM 50ohm N: in_neg(5) in_pos(6) (5 7 0.05), (6 5 68), (6 8 270), (8 7 50), (8 7 68) PAD 10dB + PAD 20dB + TERM 50ohm N: in_neg(1) in_pos(2) (1 3 0.05), (2 1 100), (2 4 75), (3 7 0.05), (4 3 68), (4 3 100), ( +4 8 270), (8 7 50), (8 7 68) RESULT! N: in_neg(1) in_pos(2) (1 2 52.5)

    I just hardcode the commands to build the networks up front, and then let it do its thing.

    Comments about my coding style are always welcome, as I'm typically the only person who ever reads my code. Questions about it are just as welcome.

    ...roboticus

    When your only tool is a hammer, all problems look like your thumb.

Embedding WebPerl Code Demos into Other Pages
1 direct reply — Read more / Contribute
by haukex
on Oct 10, 2018 at 14:14

    I was inspired by LanX's comment here:

    You know, you could use this technology to build a training site for Perl with interactive programming challenges...

    And I created a set of HTML pages that can be embedded into <iframe>s and run Perl!

    WebPerl Code Demo Editor

    Includes documentation, I hope it's clear, let me know if you have questions!

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 romping around the Monastery: (6)
As of 2018-10-17 09:51 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    When I need money for a bigger acquisition, I usually ...














    Results (92 votes). Check out past polls.

    Notices?