Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

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
CavaPackager macOS no Perl distribution
1 direct reply — Read more / Contribute
by Anonymous Monk
on Feb 25, 2018 at 07:10

    Venerable monks

    Probably I am just a bit confused, but I am having problems in setting up Cava Packager. I can not find a single Perl distribution that is accepted by this packager. I am on macOS running all sort of Perl through Perlbrew. I tried 5.16.3 (according to Cava Packager website 5.16 is supported) but I am getting the following message when I try to pint to Cava Packager to dis distribution:

    2018-02-25 12:06:41 : Error : Only a Perl with threads is supported on + this platform. 2018-02-25 12:06:41 : Error : The selected Perl at /Users/at/perl5/per +lbrew/perls/perl-5.16.3/bin/perl cannot be used to create Cava Packag +er binaries. 2018-02-25 12:06:41 : Error : Only a Perl with threads is supported on + this platform. 2018-02-25 12:06:41 : Error : The selected Perl cannot be used to buil +d Cava Packager binaries

    I installed the latest CitrusPerl which is 5.24.1. This doesn't work too (which is strange to me: should both be compatible being the same project? An older version of CitrusPerl seems not to be available anymore (at least I haven't found it). Does it means I should give up trying CavaPackager?

    .
Perl Tk macOS segmentation fault 11
No replies — Read more | Post response
by Anonymous Monk
on Feb 25, 2018 at 03:22

    Dear monks

    Running the following simple Tk script on macOS (High Sierra), Perl 5.26.1 I get a "Segmentation fault 11". It must have to do with the loading of the png. Any idea? A bug?

    use strict; use warnings; use Tk; use Tk::PNG; my $png_image_file = 'annotate.png'; my $mw = Tk::MainWindow->new(); my $pic = $mw->Photo(-file => $png_image_file); my $btn = $mw->Button( -text => "Button mit PNG-Datei als Bild", -compound => 'top', -image => $pic, ); $btn->pack(-padx => 10, -pady => 10,); $mw->MainLoop(); exit(0);

    On top of this, I have a strange behavior of Tk entry widgets. If I change the layout of my keyboard, this change does NOT affect the Tk widgets! All other applications accepts the input of the new keyboard layout (I change it from Russian - my standard - to English or others) but Perl Tk seems not to see this. How can this be?

    PS: Perl Tk looks really bad on macOS (compared for example to Windows)... really '90s!

try catch getting ignored by SIG DIE subroutine
3 direct replies — Read more / Contribute
by dkhosla1
on Feb 25, 2018 at 02:08

    Appreciate insight on why if I have a defined SIG{__DIE__}, it is overriding a try/catch block? If I comment out the SIG{__DIE__} code, the 'catch' works; but otherwise it does not.

    use strict; #use diagnostics; use JSON qw(decode_json encode_json); use Try::Tiny; use warnings; $SIG{__DIE__} = sub { my $item = shift; my $lasterr = ""; $lasterr = $@ if (defined($@)); chomp ($item); print STDERR "DIE ERROR: $item : $lasterr\n"; local $! = 2; exit $!; }; # end SIG_DIE sub write_mets { my $collref; # Read first line of test file my $file = "data1"; open (my $f, "<", $file) || die "Error opening: $!"; my $json1 = <$f>; close ($f); try { $collref = decode_json ($json1); print STDOUT "Read file $file\n"; } catch { print STDERR "Error decoding data from $file $@ \n"; }; } write_mets(); 1;

    As run above, I get the following: (data1 has some bad json)

    $ perl S2.pl DIE ERROR: garbage after JSON object, at character offset 7413 (before + "n\n") at S2.pl line 30. :

    If I comment out the SIG_DIE code, I get

    $ perl S2.pl Error decoding data from data1
    Noticed also that $@ also does not have a value in this case. The detailed error is missing. I really need the SIG_DIE functionality for the rest of the code, just not have it get int he way in the try/catch section :-). After several hours of googling and trying, have given up. Monks! Help! Thanks!
XML Signature Validation in Perl
1 direct reply — Read more / Contribute
by chora_sid
on Feb 24, 2018 at 10:07

    I am working on SAML Authentication through ADFS. Code is in Perl CGI and I am relatively new to Perl CGI.

    I am able to get SAMLResponse back but struggling to get its signature/hash validated.

    In CPAN, its mentioned that required methods for authentication are in Crypt::OpenSSL::RSA library. However, some important methods like _load_public_x509_key, verify, etc are not present in this library.

    Request you to please help me on this. Please help me get RSA library with _load_public_x509_key, verify, etc subroutines. Also, please share some knowledge/implementation on xml authentication in Perl.

    Thanks in Advance !!!

Loop though class attributes
2 direct replies — Read more / Contribute
by ZX81Meister
on Feb 24, 2018 at 02:02

    Hi there, I've just discovered the means of OOP in Perl and got a newbie question... I've defined a class with attributes like this:

    sub new { my $class = shift; my $s = {}; bless $s, $class; $s->{Laboratory} = new MotionSensorB('Laboratory', 'senMotion_H2_S1 +'); $s->{Fruitcellar} = new MotionSensorA('Fruitcellar', 'senMotion_H1_S1 +'); return $s; }

    In the same package I want to loop through the attributes, that is, access the elements Laboratory and Fruitcellar:

    sub event { my $c = shift; foreach my ??? (???) { print ??? . "\n"; }

    I'm not so firm with arrays, hashes, references etc. and trying all sorts of combinations, but can't get it right. How can I achieve it?

DBI Update dynamically
5 direct replies — Read more / Contribute
by Anonymous Monk
on Feb 23, 2018 at 08:50

    Hello, I am in need to access dynamically a Sqlite database using DBI. For inserting a new record, I use the following and works fine:

    my @record=(undef, 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19 +,20,21,22,23); my $sth = $dbh->prepare("INSERT INTO Data VALUES (@{[join',', ('?' +) x @record]})"); $sth->execute(@record);

    Any chance do do something similar with an Update statement?

Net::Telnet issue - Vasanth
2 direct replies — Read more / Contribute
by vasanth.easyrider
on Feb 23, 2018 at 07:22

    Hi Perl monks
    I have a requirement. Need to do telnet to a remote router and execute 2 commands and capture the output. I have written perl code, given below. The issue i am facing is, output is getting captured for first command, but for second command, output is not getting captured. I am providing sample outputs for both the commands (may be it will help is identifying the reason for this issue)

    Note - Is this issue because of empty lines in the command 2 output? please suggest

    command 1 sample output -

    Fri Feb 23 15:10:52.014 IST
    R/S/I Modules LED Status
    0/RP0/*
    host Critical-Alarm Off
    host Major-Alarm Off
    host Minor-Alarm Off


    command 2 sample output -

    RP/0/RP0/CPU0:BLR-WFD-MPL-COR-RTR-42-237#show isis neighbors
    Fri Feb 23 11:22:50.269 IST

    IS-IS IGP neighbors:
    System Id Interface SNPA State Holdtime Type IETF-NSF

    IS-IS CORE neighbors: System Id Interface SNPA State Holdtime Type IETF-NSF BPL-CPT-MPL-COR-RTR-42-241 BE4 PtoP Up 27 L2 Capable BLR-MPL-LTE-PE-RTR-211 BE8 PtoP Up 26 L2 Capable BLR-MPL-LTE-PE-RTR-211 BE70 PtoP Up 29 L2 Capable BLR-MPL-LTE-PE-RTR-211 BE71 PtoP Up 22 L2 Capable

    Perl code -

    #!/usr/bin/perl use strict; use warnings; use Switch; use Net::Telnet(); my ($host,$hostname,$username, $passwd, $Eleprompt,$t,@output); $host = q(10.0.0.225); $username = q(user_name); $passwd = q(My_Password); $Eleprompt = q(RP\/0\/RSP0\/CPU0:LCK-MPL-PE-RTR-225\#); eval { if($t = new Net::Telnet (Timeout => 20, Prompt => $Eleprompt)) { print "Got the expected prompt for $hostname\n"; } print "connection status = $t\n"; $t->open($host); my $CS = $t->login($username, $passwd); print "login status = $CS\n"; @commandoutput1 = $t->cmd("admin show environment leds"); print "output is = @commandoutput1 \n"; @commandoutput2 = $t->cmd("show isis neighbors"); print "output is = @commandoutput2 \n"; }; if($@) { print "since we got error w.r.t shell prompt for the IP $host, +we are proceeding with next device\n - $@"; next; }
SSH connection to 100 routers
2 direct replies — Read more / Contribute
by vasanth.easyrider
on Feb 23, 2018 at 06:13

    Hi Perl monks

    I have a requirement where i need to connect to 900 routers and execute few commands and capture the output. I am using Net::OpenSSH module for fulfilling my requirement. But we have ssh key authentication issue that is causing a problem for me. I cant manually connect to 900 servers to establish the SSH key. Is there a method for me to tackle it in script. The script given below is being used to connect to 1 router and execute the command

    #!/usr/bin/perl use strict; use warnings; use Net::OpenSSH; my ($ssh,$password); my $host = "10.0.0.183"; my $user_name = q(username); $password = q(My_Password); $ssh = Net::OpenSSH->new($host, user => $user_name, password => $passw +ord); my $output = $ssh->system("show isis neighbors") or die "remote command failed: " . $ssh->error; print "output is = $output\n";
Telnet Error - Vasanth
2 direct replies — Read more / Contribute
by vasanth.easyrider
on Feb 23, 2018 at 03:11
    Hi Perl monks I have an issue. I have a command to be executed on remote server. I am using Net::Telnet module to connect to remote server. But the command output is not getting captured, not sure why. Can you please help me -
    command to be executed - "show isis neighbors"
    The code is -
    #!/usr/bin/perl use strict; use warnings; use DBI; use Switch; use Net::Telnet(); my $file = $ARGV[0] or die "Need to get CSV file on the command line\n +"; #reading the hostname, IP address and credentials in a csv file gi +ven as an argument my $sum = 0; my ($host,$hostname,$username, $passwd, $Eleprompt,$t,$string,$match,$ +output,@output); open(my $data, '<', $file) or die "Could not open '$file' $!\n"; my $i=1; while(my $line = <$data>) { chomp $line; my @fields = split "," , $line; $host = $fields[0]; $hostname = $fields[1]; $username = $fields[2]; $passwd = $fields[3]; $Eleprompt = $fields[4]; print "IP of device $i = $host\n"; print "Hostname of device $i = $hostname\n"; print "Username of device $i = $username\n"; print "password of device $i = $passwd\n"; print "login prompt of device $i = $Eleprompt\n"; eval { if($t = new Net::Telnet (Timeout => 20, Prompt => $Ele +prompt)) { print "Got the expected prompt for $hostname\n +"; } print "connection status = $t\n"; $t->open($host); my $CS = $t->login($username, $passwd); print "login status = $CS\n"; $string = "show isis neighbors"; $match = $Eleprompt; @output = $t->cmd("admin show environment leds"); + #String => $string,Prompt => $match); print "output is = @output\n"; @output = $t->cmd("show running-config lpts punt exces +sive-flow-trap"); #String => $string,Prompt => $ +match); print "output is = @output\n"; @output = $t->cmd(String => $string,Prompt => $matc +h,Errmode => die); #String => $string,Prompt => +$match); print "output is = @output\n"; };

    Sample output of the command -
    RP/0/RP0/CPU0:BLR-WFD-MPL-COR-RTR-42-237#show isis neighbors
    Fri Feb 23 11:22:50.269 IST

    IS-IS IGP neighbors:
    System Id Interface SNPA State Holdtime Type IETF-NSF

    IS-IS CORE neighbors: System Id Interface SNPA State Holdtime Type IETF-NSF BPL-CPT-MPL-COR-RTR-42-241 BE4 *PtoP* Up 27 L2 Capable BLR-MPL-LTE-PE-RTR-211 BE8 *PtoP* Up 26 L2 Capable BLR-MPL-LTE-PE-RTR-211 BE70 *PtoP* Up 29 L2 Capable BLR-MPL-LTE-PE-RTR-211 BE71 *PtoP* Up 22 L2 Capable BLR-MPL-LTE-PE-RTR-211 BE12 *PtoP* Up 23 L2 Capable BLR-WFD-MPL-COR-RTR-42-236 BE1 *PtoP* Up 23 L2 Capable NDL-OKH-MPL-COR-RTR-42-206 BE2 *PtoP* Up 21 L2 Capable BLL-MPL-LTE-PE-RTR-42-55 BE9 *PtoP* Up 22 L2 Capable
How CGI works
3 direct replies — Read more / Contribute
by Sarat1729
on Feb 22, 2018 at 09:55
    Hi Monks, I am new to CGI scripting but need to understand the code in our project. I am unsure what is the starting point and where to start and how it works. Can someone please explain how it works.

Add your question
Title:
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?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the monks are mute...

    How do I use this? | Other CB clients
    Other Users?
    Others cooling their heels in the Monastery: (3)
    As of 2018-02-25 18:28 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?
      When it is dark outside I am happiest to see ...














      Results (314 votes). Check out past polls.

      Notices?