Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses

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
cgi questions/calling perl binary in non default location
No replies — Read more | Post response
by Anonymous Monk
on Aug 23, 2019 at 12:41
    1. I logged in as root and installed Apache with yum install httpd
    2. Still as root, and inside /var/www/cgi-bin/ I wrote a simple test cgi script
    print "Content-type: text/html\n\n";
    print "Hello World!";
    3.tested it with 'lynx http://localhost/cgi-bin/1.cgi' and it was ok

    First question: The script is owned by root.Should I change the owner to what (i.e apache?), and what should the correct permissions be?

    The problem started when I needed to use an other version of perl, more up to date than system perl, installed in another users home directory:
    so '#!/usr/bin/perl' of the script should point to '#!/home/mytestuser/bin/perl'

    4.Again as root I make the change and try 'lynx http://localhost/cgi-bin/1.cgi' once again but I get an interal server error,'permission denied' I've played around with the permissions, even changing the perl's executable ones to chmod a+x+w+r but the nothing changed.

    Second question:
    When calling the script from the web, what user does it run under given it is owned by root with permissions 755? does it run as root or apache?

    Third question:
    If I could picture it then it goes like this : Web-->request-->Apache user-->perl bin of 'mytest' user-->/var/www/cgi-bin/1.cgi-->permission denied
    Who does not have permission and to what?
Problem executing command via ssh
No replies — Read more | Post response
by mgalindez
on Aug 23, 2019 at 11:45

    I need to execute a program in a remote machine, that takes its input from STDIN.

    I created a user in such remote machine, and set my program as the shell for that account (so I don't need to provide shell access).

    On my local node, I have this program:

    #!/usr/bin/perl use IPC::Open3; use POSIX; $inputfile= $ARGV[0]; open(FILE, '<', "$ARGV[0]") or die $!; $command= "ssh user\"; $pid = open3('<&FILE', '>&STDOUT', '>&STDERR', $command); $ret=waitpid( $pid, 0 );

    What I expect is that I pass the name of the file as arguments of this program ($ARGV[0]), and the contents of this file is fed as STDIN of the child I've spawn with open3. This should be received as STDIN of my remote program, and the results of the remote program would be printed on STDOUT.

    This works well. However, my program only reads the first line, and then terminates.

    If I do a manual test, and do ssh, and type multiple lines of input, then things work as expected.

    Any clues?


change \n to \t
2 direct replies — Read more / Contribute
by yueli711
on Aug 23, 2019 at 11:11

    Hello, I have file here. I want to change file 1.fa to file 1.txt. Thanks in advance for great help! Best, yue

    open(IN1, "1.fa") || die "Cannot open this file"; @lines = <IN1>; $i = 0; for (@lines) { $lines[$i]=~s/\nA/\tA//g; $lines[$i]=~s/\nT/\tT//g; $lines[$i]=~s/\nC/\tC//g; $lines[$i]=~s/\nG/\tG//g; $lines[$i]=~s/\nN/\tN//g; $thislines[$i]=$lines[$i]; print $thislines[$i]; $i++; } open(OUT, ">1.txt") || die "Cannot open this file"; for $thisline(@thislines){ print OUT $thisline;} close(OUT); close(IN1);
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


    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?

Insert into element into arrays ref
3 direct replies — Read more / Contribute
by Anonymous Monk
on Aug 22, 2019 at 13:23
    Hi there Monks!

    I need to insert the @$data2 value into the @$data1. The code I have only updates the first element in the @$data1:
    #!/usr/bin/perl use strict; use warnings; use Data::Dumper; my $data1 = [ { 'NAME' => 'PAUL DY', 'DATE' => '2009-05-05', 'NUMBER' => '00001', }, { 'NAME' => 'ANTHONY RD', 'DATE' => '2012-01-07', 'NUMBER' => '00003', }, { 'NAME' => 'RUTH RD', 'DATE' => '2018-01-07', 'NUMBER' => '00023', }, ]; my $data2 = [ { 'CODE' => 'X11', } ]; @$data1= ({map { %$_ } (@$data1, @$data2)}); print Dumper $data1;

    Thanks for helping!
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 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!

    Regards. Unable to find in history
1 direct reply — Read more / Contribute
by daxim
on Aug 22, 2019 at 06:49
    • run
    • execute !!1
    Got: Unable to find !1 in history

    Expect: 1

    How do I make it stop? I have already tried without success:

    #!/usr/bin/env perl use 5.030; use lib 'lib'; use utf8; use strictures; use autodie qw(:all); use Moops; use Kavorka; use perl5i::2 -skip => [qw(Signatures)]; use Devel::REPL::Plugin::ReadLineHistory::WithoutExpansion; $_REPL->load_plugin(qw( Colors DataPrinter DumpHistory FindVariable History Interrupt LexEnv MultiLine::PPI OutputCache Packages Peek PPI Refresh ReadLineHistory::WithoutExpansion ShowClass Completion CompletionDriver::Globals CompletionDriver::INC CompletionDriver::Keywords CompletionDriver::LexEnv CompletionDriver::Methods CompletionDriver::Turtles )); $_REPL->term->Attribs->{history_quotes_inhibit_expansion} = 1; $_REPL->term->Attribs->{do_expand} = 0;
interactive google earth access
2 direct replies — Read more / Contribute
by Tsunami perl user
on Aug 21, 2019 at 10:41
    Is is possible to communicate interactively with google earth from a perl script? Specifically, 1. can I place symbols on the map, 2. have the operator hover over the symbol and get a small popup 3. click on the symbol and activate (or deactivate) some independent graphic and 4. control the map corners (expand, rotate, etc.)?
Missing module perl
2 direct replies — Read more / Contribute
by ridwan
on Aug 21, 2019 at 04:00

    Hi Good Afternoon All.

    I'm planning install perl in my office(development machine), but in development machine there's not connection internet. And installation stuck in missing module perl

    So, I make a lokal vbox, in there, I make a repo cpan(internet connection).

    and case is, how to connect the development to my repo. I've been use mini cpan mirror but doesn't work. Maybe my configure cpan is wrong.

    I am tired of this problem. Anybody help me ?


Add your question
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?

    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 surveying the Monastery: (5)
    As of 2019-08-23 17:28 GMT
    Find Nodes?
      Voting Booth?

      No recent polls found