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

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
Puzzled by the ListUtil.xs in Scalar-List-Utils-1.52.tar.gz
2 direct replies — Read more / Contribute
by syphilis
on Aug 24, 2019 at 09:51
    In making some edits to the file mentioned in the subject line, I stumbled upon something that kept me occupied for way longer than I care to admit.
    I believe that it will prove to be readily reproducible, but I'd be delighted if that turns out to *not* be the case.
    Please feel free to test this.

    In this ListUtil.xs you will find the following:
    Line 1193: sv_setpvf(keysv, "%.15" NVgf, SvNV(arg)); Line 1194:#ifdef HV_FETCH_EMPTY_HE
    I find that the code becomes uncompilable if I insert an empty line between those 2 lines:
    Line 1193: sv_setpvf(keysv, "%.15" NVgf, SvNV(arg)); Line 1194: Line 1195:#ifdef HV_FETCH_EMPTY_HE
    On both Ubuntu and MS Windows (perl-5.30.0 and others) that modification quickly produces the following error (during the 'make' stage of the build):
    Code is not inside a function (maybe last function was ended by a blan +k line followed by a statement on column one?) in ListUtil.xs, line 1 +195 Makefile:360: recipe for target 'ListUtil.c' failed
    Can someone explain that behaviour to me ?
    Are XS files typically that sensitive to white space ? (I've struck nothing like it before.)

Failed to close file
7 direct replies — Read more / Contribute
by ovedpo15
on Aug 24, 2019 at 05:58
    Hello monks!,
    I have the following code:
    open(PACK,">$pack") or die("failed to open file $pack"); print PACK <<_M_E; #!/usr/intel/bin/tcsh -f $sanity_code $tests _M_E close(PACK) or die("failed to close file $pack");
    Always when I run my tests I get:
    failed to close file <path> at <script> line 400.
    The strange thing is that I never get it for opening, just for closing.
    What could bring to this behavior? how to solve it?
    Thank you all for the comments. I added the $! and it prints "Disk quota exceeded". But it looks like I have available space.
    I run `df /path/to/the/file/which/we/try/to/open` and I have 57% free space. What could be the issue?
[OT] Endianness and extended precision (80-bit) long doubles
2 direct replies — Read more / Contribute
by syphilis
on Aug 24, 2019 at 04:14
    The extended precision long double uses only 10 bytes, but is assigned either 12 bytes (32-bit architecture) or 16 bytes (64-bit architecture).
    On my little endian machine, the unused (meaningless) bytes are at the high end (at indexes 10-11 or 10-15).
    So, I have a C for loop that iterates through the meaningful bytes:
    for(i = 0; i < 10; i++) { do stuff with the byte at index number i }

    I'd like to know whether I can use the exact same code on a big endian machine - or whether doing so will actually access the unused bytes.
    NOTE: The order in which I iterate through the meaningful bytes is irrelevant for my exercise - but the loop must avoid those unused bytes.

    Unfortunately, I don't have a suitable big endian machine on which I can test ... and I haven't managed to google up the answer yet.
    Anyone know the answer ?

Running interactive SSH session in windows
3 direct replies — Read more / Contribute
by srinidhi27
on Aug 24, 2019 at 03:53

    Team, i know this has been in discussion for long time. But i haven't got an answer searching entire web since yesterday. I need to run series of commands in windows after logging to an server running SSH server.

    The problem is as you might have guessed being interactive.....

    I can run one of commands bby lot of methods.. I will list what i have tried so that people can suggest something i don't know.

    1. Net::SSH2 -- not supported in windows

    2. Net:OpenSSH -- again not supported in windows

    3. Install openSSH in widnows itself and using System and backticks to run dos commands. Yes Openssh can be installed in windows

    without cgywin environment a discovery i made yesterday.

    4. IPC::Cmd, a tool similar to using system command but doesn't provide interactive session. Everytime you run new terminal session is spawned.

    5. Ofcourse tried plain system and exec and backticks also turned futile. Worked liked a charm for single command run and shutoff.

    6. IPC::Session, not avaiable in Active Perl i use and don't know how to install it currently. Supposedly provides for interactive session using terminal. Not been able to get it working..

    7. plink tool is also good failing to work even when list of commands is fed to it externally. Cisco Box i am trying to SSH to is throwing illegal characters error. Weird right?

    Any leads is appreciated..

cgi questions/calling perl binary in non default location
3 direct replies — Read more / Contribute
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
2 direct replies — Read more / Contribute
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
5 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
4 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!

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 lurking in the Monastery: (5)
    As of 2019-08-25 09:49 GMT
    Find Nodes?
      Voting Booth?

      No recent polls found