Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
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
DBI vs Apache::DBI
2 direct replies — Read more / Contribute
by DaisyLou
on Aug 23, 2019 at 08:25

    I have a bunch of scripts that "use DBI;" . One of the scripts, a particularly database intensive one, says "use Apache::DBI" (which incidentally fail to load).

    Is there a difference between Apache::DBI and DBI or can I just change this line to "use DBI" without impact?

Convert pem to ssh-rsa
1 direct reply — Read more / Contribute
by jpsaraiva
on Aug 23, 2019 at 08:06

    Hello

    On Windows, I'm using Crypt::PK::RSA to generate key pairs like this:

    use Crypt::PK::RSA; my $pk = Crypt::PK::RSA->new(); $pk->generate_key(256, 65537); my $private_pem = $pk->export_key_pem('private'); my $public_pem = $pk->export_key_pem('public');

    Private key format is fine. Public key is generated like this:

    -----BEGIN RSA PUBLIC KEY----- ... -----END RSA PUBLIC KEY-----

    Since I need to add this key to authorized_keys files it needs to be in a ssh-rsa format.

    Can easly be done using ssh-keygen to convert:

    $ ssh-keygen -y -f privatekey > publickey

    I found this thread explaining the process and having several solutions none perl based.

    And all end up being dependent on ssh-keygen or open-ssl both not natively available on Windows

    Does anyone know how to do this only in perl or if it is even possible?

net::ssh::perl Wrong key type
1 direct reply — Read more / Contribute
by jpsaraiva
on Aug 22, 2019 at 13:23
    Hello, I'm trying to write some code capable of authenticating with a private key on windows. I generate my key with no passphrase:
    c:\var\client>ssh-keygen Generating public/private rsa key pair. Enter file in which to save the key (/home/user/.ssh/id_rsa): client_k +ey Enter passphrase (empty for no passphrase): Enter same passphrase again: Your identification has been saved in client_key. Your public key has been saved in client_key.pub. The key fingerprint is: SHA256:eBU07eoloUWInreyZ2WkYMvBAhISc2OIsiE1gp+iS4E user@localhost The key's randomart image is: +---[RSA 3072]----+ |O=* . o+. | |X=.o . . .o. | |+= o o . ... | |E.o . B...+ . | |... +.=S* o | |.. +.+ = . | |.. o + o | |. . o . | | o | +----[SHA256]-----+
    The key can be used successfully to authenticate:
    c:\var\client>ssh -i client_key localhost Last login: Thu Aug 22 16:34:22 2019 $
    My perl code is very simple at the moment:
    use Net::SSH::Perl; my $server='localhost'; my %params = ( "protocol" => '2', "use_pty" => 0, "options" => ["stricthostkeychecking no"], "identity_files" => ["client_key"], "debug" => 1, ); $ssh = Net::SSH::Perl->new($server, %params); $ssh->login();
    But executing it returns Wrong key type.
    c:\var\client>perl test.pl localhost: Reading configuration data C:\Users\user\.ssh\config localhost: Reading configuration data C:\windows\ssh_config localhost: Connecting to localhost, port 22. localhost: Remote version string: SSH-2.0-OpenSSH_8.0 localhost: Remote protocol version 2.0, remote software version OpenSS +H_8.0 localhost: Net::SSH::Perl Version 2.14, protocol version 2.0. localhost: No compat match: OpenSSH_8.0. localhost: Connection established. localhost: Sent key-exchange init (KEXINIT), waiting for response. localhost: Using curve25519-sha256@libssh.org for key exchange localhost: Host key algorithm: ssh-ed25519 localhost: Algorithms, c->s: chacha20-poly1305@openssh.com <implicit> +none localhost: Algorithms, s->c: chacha20-poly1305@openssh.com <implicit> +none localhost: Generating ephemeral key pair. localhost: Entering Curve 25519 Key Exchange. localhost: Sent client public key, waiting for reply. localhost: Received host key, type 'ssh-ed25519'. localhost: Host 'localhost' is known and matches the host key. localhost: Verifying server signature. localhost: Send NEWKEYS. localhost: Waiting for NEWKEYS message. localhost: Enabling encryption/MAC/compression. localhost: Sending request for user-authentication service. localhost: SSH2_MSG_EXT_INFO received localhost: SSH Extension activated: server-sig-algs=ssh-ed25519,ssh-rs +a,rsa-sha2-256,rsa-sha2-512,ssh-dss,ecdsa-sha2-nistp256,ecdsa-sha2-ni +stp384,ecdsa-sha2-nistp521 localhost: Service accepted: ssh-userauth. localhost: Trying empty user-authentication request. localhost: Authentication methods that can continue: publickey,passwor +d,keyboard-interactive. localhost: Next method to try is publickey. localhost: Trying pubkey authentication with key file 'client_key' Wrong key type at C:/Strawberry/perl/site/lib/Net/SSH/Perl/Auth/Public +Key.pm line 83.
    I've tried generating DSA type keys and the error is the same. Googling it is not helping either.

    Any help appreciated!

    Regards.

Undef value in Template Toolkit
1 direct reply — Read more / Contribute
by DreamT
on Aug 20, 2019 at 10:13
    Hi,
    I want to set a value to undef in a TT template:
    [% hashref.value1 = undef %]
    , but this only produces an empty string.
    $VAR1 = { ... 'value1' => '' ... }

    Is there a way around this? From what I've read it seems to be a "feature" in Template Toolkit that undefs are treated as empty strings.
minimal superstrings/maximal substrings
6 direct replies — Read more / Contribute
by stevena
on Aug 19, 2019 at 20:23

    Given a lexicon with long words and short words (happening to be length 9 and up, and 8 and down, respectively), I am looking to enumerate all minimal extensions of a short by a long; that is, with no intervening word (either long or short) that extends the short and is extended by the long. (Extensions could also be called strict superstrings.)

    I.e., if   'w > x' means word w extends word x, I want to find all pairs (L, S), such that:

    * L > S

    * there's no W with L > W > S,

    where L, S, W are restricted to lexicon words.

    For example, (NUMERICAL, NUMERIC) is desired, but not (SOCIOBIOLOGIST, OLOGIST) because SOCIOBIOLOGIST > BIOLOGIST > OLOGIST.

    I am looking for transparent code conducive to my adding less interesting constraints. (Fine if you guide me without writing the code. Also happy to see code.)

    Not homework or work -- solely hobby-related. Thanks!

Defining an XS symbol in the Makefile.PL
4 direct replies — Read more / Contribute
by syphilis
on Aug 18, 2019 at 00:59
    Hi,
    In an XS file I have the following line of code:
    printf("%.16e", sqrt(2.0));
    I want to rewrite that line as:
    printf(MY_FORMAT, sqrt(2.0));
    I also wish to then define MY_FORMAT to "%.16e" in the Makefile.PL.

    This is normally achieved by assigning an appropriate value to DEFINE in the WRITEMAKEFILE() section of the Makefile.PL - eg:
    WRITEMAKEFILE( .... DEFINE => '-DMY_FORMAT="%.16e"', .... );
    But that specific incantation fails to work - and I haven't been able to hit on the incantation that *does* work.
    Update: By "not work", I mean that it either won't compile or it leads to runtime crashes (depending upon the actual incantation I've tried).
    Any help would be much appreciated.

    I've also spent a couple of hours trying to get this working in Inline::C. If I can get it to work in Inline::C, then I'll be able to use the incantation in the Makefile.PL that Inline::C generates.
    Here's that Inline::C script:
    use strict; use warnings; use Config; use Inline C => Config => USING => 'ParseRegExp', CCFLAGSEX => '-DMY_FORMAT="%.16e"', BUILD_NOISY => 1, ; use Inline C =><<'EOC'; SV * foo(void) { printf(MY_FORMAT, sqrt(2.0)); printf("\n"); } EOC foo();
    I've tried various escapes around "%.16e" but nothing has been successful.
    In C, it's pretty simple to achieve:
    C:\_32\C>type try.c #include <stdio.h> #include <math.h> int main(void) { printf(MY_FORMAT, sqrt(2.0)); return 0; } C:\_32\C>gcc -o try.exe try.c -DMY_FORMAT=\"%.16e\" C:\_32\C>try 1.4142135623730951e+000 C:\_32\C>
    I'm not all that bothered if it turns out that Inline::C can't handle the construct, but I *would* like to know how to do it in the XS file via the Makefile.PL if, indeed, that's possible at all.

    Cheers,
    Rob
The error says the value is uninitialized, but it works anyway
9 direct replies — Read more / Contribute
by mizducky
on Aug 17, 2019 at 05:29
    This is a homework assignment, and it works. If I use strict, I don't get an error, but if I use warnings, it says "Use of uninitialized value in string eq at line 7", it prints this error twice (I assume its for the two times that the match is found).
    Here is the code I am turning in for my assignment, but I still want to know why its giving me those errors, and if I should do something better. So I'm really just hoping for someone to help me understand what is happening to cause this error.
    my @colors = qw(red green blue yellow pink purple brown); my $count = @colors; my @drop = qw(pink brown); my $num = 0; foreach $num (1..$count){ $num--; if ($colors[$num] eq $drop[0] or $colors[$num] eq $drop[1]){ splice (@colors, $num, 1); } } print "@colors \n";
New Meditations
Help with my crap
4 direct replies — Read more / Contribute
by stevieb
on Aug 22, 2019 at 20:59

    Esteemed Monks and fellow travelers,

    I'm in a position where I've got a tad bit too much to handle, so I'm putting out a request.

    For years, I've supported Perl in ways that nearly defied logic relative to my real life. Came from nothing, did something, blah blah blah.

    Many have done that. What I appreciate is the attentive use and comprehensive addition to Perl that so many Monks and others have contributed to my favourite language over the last near-20-years.

    Now, I'm not as dynamic. I'm not as fluid and liquid to bounce from one thing to the other by the minute. I can't maintain my library of software myself anymore.

    For that, and for many other reasons, I'm hoping to liquidate or at least get help with some of my Open Source Software projects.

    I'm STEVEB on the CPAN, and my repo stash is here. Take a look and let me know if there's anything you'd like to grab or take part in.

    berrybrew, as well as a few CPAN dists I favour I'd like to oversee, but mostly, take a look and let me know if you want to overtake anything.

    License retention, DVCS experience (repos stay in a freely-available and accessible location), and a proven love for Perl are absolute requirements. I put my love into what I've done. I would hope someone would take my silly code and keep it something that's usable.

    One last statement... don't take job offers seriously without doing extreme and exceptional due diligence. I got fucked up the ass while I had head injuries. Sickening, yep, fucking angering, yep, don't accept any job if you don't get paid in advance. This world is a different place anymore. I am just too tired to be raped without appreciation.

    Street-smart linguistic troublemaker who didn't see a fabricated theft coming right at him. I'm ashamed.

    -stevieb

Truth and Falsehood
3 direct replies — Read more / Contribute
by haukex
on Aug 17, 2019 at 05:19

    Truth and Falsehood

    In Perl, the following values are false in boolean context:

    • The number zero (0)
    • The string "0"
    • The empty string ""
    • undef

    All other values are true.

    Boolean context is a scalar context. Therefore the following things, when evaluated in boolean/scalar context, are also false:

    • An empty array, which evaluates to the number of elements it contains, i.e. zero (0).
    • An empty hash, which evaluates to a false value when it is empty.
    • The empty list (), which evaluates to undef.

    A true value negated by ! or not, plus many of Perl's builtins/operators, return a special false value: When evaluated as a string it is treated as "", but as a number, it is treated as 0, without causing any warnings.

    When the Perl documentation says that a operator or function returns "a false value" or "a true value" (or more simply, "false" or "true"), it may return any of the above values.

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 taking refuge in the Monastery: (5)
As of 2019-08-23 18:20 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?