Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
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
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
2 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.
Data to fetch from Database to display in graph
2 direct replies — Read more / Contribute
by Sarat1729
on Feb 22, 2018 at 09:52
    Hi Monks, I am trying to display certain data fetched from database (using Select from a SQL Server DB) in a graph. I tried to achieve the same using GD::Graph with normal sample data (not from database though), but not sure how I can make it using the data from Database. Can someone help? Also, I want to use 2 vertical axis on a single horizontal axis on either side with different values and if one uses histograms, the other should use lines (Seems messy, but that's ok for me).
Learning/Trying to use Net::Curl with Cookie Jar
2 direct replies — Read more / Contribute
by YenForYang
on Feb 22, 2018 at 08:37

    I've never used libcurl before, but I wanted to start using it in curl for improved HTTP performance. I've been looking through all the Net::Curl::Easy:: keys, browsing the contents and comparing with curl.haxx.se and noticed that Net::Curl doesn't have a curl_easy_cleanup function.

    I'm asking this because on the manual page for CURLOPT_COOKIEJAR, it says

    ...will make libcurl write all internally known cookies to the specified file when curl_easy_cleanup is called.

    So...How does one store cookies in a cookie jar (file) by specifying CURLOPT_COOKIEJAR?

    EDIT: To give an idea of what I'm trying to do for now (this case): I'm making a simple GET request pretty much equivalent to this: curl -qsL -b cookies.txt -c cookies.txt <URL> and parse the html response content (html of URL).

OT: Converting some js to Perl
4 direct replies — Read more / Contribute
by BrowserUk
on Feb 22, 2018 at 07:16

    I'm converting some js, and have come across numerous examples of this construct:

    if(function(){return a.indexOf(Lb)!=-1 }())return Mb;
    I can convert that to:
    if( sub{ return index( $a, $lb ) != -1 }->() ) return $Mb;

    But this achieves the same thing (in Perl):

    if( index( $a, $lb ) != -1 ) return $Mb;

    The question(aimed at js progs): Is there anything inherent in the js code that my second Perl versions misses?

    Or is this just a case of someone defining an inString() function, that then got inlined, but not unwrapped?


    With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority". The enemy of (IT) success is complexity.
    In the absence of evidence, opinion is indistinguishable from prejudice. Suck that fhit

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 all is quiet...

    How do I use this? | Other CB clients
    Other Users?
    Others meditating upon the Monastery: (5)
    As of 2018-02-25 01:36 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?
      When it is dark outside I am happiest to see ...














      Results (312 votes). Check out past polls.

      Notices?