Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid

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
net::ssh::perl Wrong key type
No replies — Read more | Post response
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 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 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 for key exchange localhost: Host key algorithm: ssh-ed25519 localhost: Algorithms, c->s: <implicit> +none localhost: Algorithms, s->c: <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 line 83.
    I've tried generating DSA type keys and the error is the same. Googling it is not helping either.

    Any help appreciated!


Undef value in Template Toolkit
1 direct reply — Read more / Contribute
by DreamT
on Aug 20, 2019 at 10:13
    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.


    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
    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.

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";
Portable way to determine if two names refer to the same file?
2 direct replies — Read more / Contribute
by jcb
on Aug 15, 2019 at 23:31

    I have spent the past hour or so trying Super Search and not finding a clear answer, so I ask my fellow monks how best to portably determine if two seemingly different names actually refer to the same physical file?

    I am not concerned about copies of the same file, only links, such that the same physical file appears under multiple names.

    On POSIX, the solution is easy: compare dev:ino tuples from the stat builtin and declare "same file" if they match. I have no idea if this also works on Windows or even if the problem exists on Windows — how well does Windows handle symlinks anyway and does it even support hardlinks at all?

    And what of the less-common platforms?

    Cross-posted in Categorized Questions and Answers at How do I portably determine if two filenames refer to the same file? as a place to collect answers for future reference.

    Edited 2019-08-16 by jcb: Clarify that stat refers to the Perl builtin. I had forgotten about the shell command with the same name.

List comparison problem
2 direct replies — Read more / Contribute
by perlmonkster
on Aug 15, 2019 at 22:12


    I somehow lost a final version of a simple Perl script to compare 2 lists, and cannot seem to figure out what is causing a problem with the version I have.

    The simple .pl script takes ListL.txt, compares it to ListH.txt, and then "Flags" any entries from ListH.txt that are on ListL.txt (plus gives two separate Counts at the bottom of the output). Using two short sample lists, the Counts are both correct, but for some reason one of the ListL.txt items that *should* show a ListH.txt "Flag" in the output does not. I've tried switching around Count statements, etc., but am completely baffled. Any insight as to how to fix things would be greatly appreciated.

    Here's the short code

    use strict; use warnings; my %H_list; open my $H_list, '<', 'listH.txt' or die "Cannot open listH.txt: $!"; + while (my $line = <$H_list>) { chomp $line; $line =~ s/\r//g; # removes windows CR characters $line =~ s/\s+$//; # removes trailing white spaces $H_list{$line} = 1 } close $H_list; my ($L_count, $H_count); open my $L_list, '<', 'listL.txt' or die "Cannot open listL.txt: $!"; + while (<$L_list>) { chomp; s/\r//; s/\s+$//; $L_count ++; print; $H_count ++ and print ' On List H' if exists $H_list{$_}; print "\n"; } print "List L UNIQUES: $L_count; FLAGGED From List H: $H_count \n";

    Here are the two short Test Lists and Test output:

    (ListL.txt) ABC123 DEF456 GHI789 (ListH.txt) ABC123 GHI789 (Test Output) ABC123 DEF456 GHI789 On List H List L UNIQUES: 3; FLAGGED From List H: 2

    As you can see, ABC123 should be also "Flagged" as "On List H", and is driving me NUTS as to why not.

    Thanks very much.

Regular expression for finding acronyms
2 direct replies — Read more / Contribute
by mldvx4
on Aug 15, 2019 at 22:07

    I'm trying to build a pattern that will extract acronyms. I've gotten fairly close, but it leaves off the final period where it should be saved. Notice that it is missing from the output. For example, "X.H.T.M.L" should be "X.H.T.M.L."

    I wrote the pattern below in a moment of insight and now that moment has passed. How may I modify it to preserve the trailing periods?

    #!/usr/bin/perl use strict; use warnings; while (<DATA>) { chomp; while( s/(?'foo' ( (?=([[:upper:]]\.\s){2})[[:upper:]\.\s]{2,} | (?=([[:upper:]]\s){2})[[:upper:]\s]{2,} | (?=([[:upper:]]\.){2})[[:upper:]\.]{2,} | [[:upper:]] ){2,} )//x ) { my $acronym = $+{foo}; print qq("$acronym"\n); } } exit(0); __DATA__ L F and LF and L.F. and L. F. and not L, F. some HTML some XML. or X.H.T.M.L. or X. H. T. M. L. or even X H T M L but not U and I, or You and I. ...

    Or if there is an existing function or module which does that already, I can use that instead.

New Meditations
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?

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 rifling through the Monastery: (8)
As of 2019-08-22 20:35 GMT
Find Nodes?
    Voting Booth?

    No recent polls found