Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
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
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 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
3 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.
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?
Child process lingers after keyboard interrupt on Windows
2 direct replies — Read more / Contribute
by toughy
on Oct 10, 2018 at 19:01

    Hello,

    I am trying to make a script to automate our project build process and I run into a surprising issue:

    With either of open('-|'), IPC::Open3 or IPC::Cmd::run, the child process lingers still alive after a keyboard interrupt (^C) or a timeout alarm from IPC::Cmd. The main script receives the signal and exits as expected, but the build process is still running in the background and visible in Task Manager window.

    Contrast this with a call to system() which does The Right Thing: keyboard interrupt will stop the child process, and only after that will the parent process by interrupted.

    Can I fix this somehow please ?

    I would like to run a couple of my build commands in parallel, and ensure they always terminate before the main script, especially in case of errors, abort, interrupt, other signals like TERM, HUP, QUIT...

    Is this possible please ?

    Issue not present on Linux or with perl6 Proc class

<JUNCTION>; how to recognize
5 direct replies — Read more / Contribute
by fatkatie
on Oct 10, 2018 at 14:38
    low hours pilot here

    I want to recognize a uSWin directory type '<JUNCTION>'

    If I do a command window 'dir' this entry is not shown.

    If I do a command window 'dir /a:d' the entry is shown as: 07/14/2009  12:08 AM    <JUNCTION>     Documents and Settings [C:\Users]

    If I do a perl opendir and iterate, the entry, array file name, is shown as:  Documents and Settings

    Using file tests -d and -l has not helped me recognize the junction. Is there a way to do so?

    env:
    This is perl 5, version 18, subversion 4 (v5.18.4) built for MSWin32-x64-multi-thread
    uSWin7pro64

    Thank you.

Perl Catalyst
2 direct replies — Read more / Contribute
by akuk
on Oct 10, 2018 at 09:50

    Hi Folks,

    I am working on a Project to migrate the Legacy App in Perl to Catalyst Framework. Legacy app has its own authentication mechanism. And it uses Crypt::PBKDF2 to store the password in the database.

    I want to use Catalyst::Plugin::Authentication instead of custom login mechanism for catalyst but I didn't find a way to authenticate password using Authentication Plugin

    Legacy:

    $pbk_crypt = Crypt::PBKDF2->new( hash_class => 'HMACSHA2', hash_args => { sha_size => 512, }, iterations => 10000, salt_len => 10, ); $pass = $pbk_crypt->generate('password');

    Catalyst

    __PACKAGE__->config( 'Plugin::Authentication' => { default => { class => 'SimpleDB', user_model => 'DB::User', password_type => 'self_check', }, )
    And in the User table following code is added:
    __PACKAGE__->add_columns( 'password' => { passphrase => 'rfc2307', passphrase_class => 'SaltedDigest', passphrase_args => { algorithm => 'SHA-512', salt_random => 10, iterations => 10000, }, passphrase_check_method => 'check_password', }, );

    And in Controller :

    if ($username and $password) { if ($c->authenticate({ username => $username, password => $password } )) { $c->response->redirect($c->uri_for_action('/profile')); return; } else { # Set an error message $c->stash(error_msg => "Bad username or password."); } }
    but it's not working. I am not sure what I am doing wrong here.
Catch connection error MSSQL
3 direct replies — Read more / Contribute
by Anonymous Monk
on Oct 09, 2018 at 09:30

    Hello,

    I want to connect to a MSSQL server and catch a connection error if it happens. I used to use on MySQL an eval which, as far as I remember worked fine. However, I can not catch an error if it happens now, if for example the password is wrong. This is what I am using:

    print "Connecting to MSSQL terminology database... "; eval{ $dbh = DBI->connect("dbi:ODBC:Driver={SQL Server};Server=$SqlDatabase +Name;UID=$SqlDatabaseUser;PWD=$SqlDatabasePassword", {PrintError => 0 +, RaiseError => 1, AutoCommit => $AutoCommit, FetchHashKeyName => 'NA +ME_lc',}) ; $dbh->{'mysql_enable_utf8'} = 1; }; if ($@) { print "ERRRRRRRRRRRROR\n"; }

    Any idea what I am doing wrong?

New Meditations
The joy of Perl, 20 years later
1 direct reply — Read more / Contribute
by Anonymous Monk
on Oct 09, 2018 at 10:55
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 examining the Monastery: (6)
As of 2018-10-16 00:22 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    When I need money for a bigger acquisition, I usually ...














    Results (82 votes). Check out past polls.

    Notices?