Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer

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
No docs on the GTK+3 module?
2 direct replies — Read more / Contribute
by GnomoP
on Feb 25, 2018 at 15:45
    I've been attempting to write some everyday-use Gtk3 applications. After deciding on Perl's bindings for Gtk3, admittedly due to some bias towards Perl, I was able to understand the way some of these bindings work. However, the tutorials I've been reading when looking for references are often too old (and hence incomplete) or short and cut-dry. I can't find any documentation, aside from the loose references made on the CPAN page for the module. Does anyone know of such a thing?
prove --state=failed,save
1 direct reply — Read more / Contribute
by 1nickt
on Feb 25, 2018 at 13:56

    I am trying to use prove --state=failed,save. But it seems to not work as documented.

    The first thing that is unclear is whether "test" in the doc refers to individual tests, or to test files. So I tried it both ways.

    At the urging of Bishop toolic I am posting here my test files and results.

    With multiple tests in a single file:

    As you can see all four tests were run the second time as well as the first time. There also does not seem to be anything in the .prove file that records the outcome of the individual tests.

    With multiple test files:

    As you can see, again all four test files were run the second time as well as the first time. The only difference is that on the second run the failing test files were run first, and then the ones that had succeeded on the first run. Again, this is not the behaviour the documentation describes.

    Any clues gratefully accepted, especially if you are using this feature yourself with success.

    The way forward always starts with a minimal test.
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
    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(; $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 = ""; 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";
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.
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 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).

Why use warnings? -w
10 direct replies — Read more / Contribute
by harangzsolt33
on Feb 21, 2018 at 23:56
    What do the "use warnings;" and "use strict;" statement do exactly? So far I have noticed that when I try to use an uninitialized variable, it gives me a compilation error. That's NO BIG DEAL, I think. I mean, we're told in Perl tutorials, that we don't have to initialize variables in Perl. We can just start using them. Right? Just like in JavaScript or QBASIC.

    So, WHAT EXACTLY HAPPENS IF I START USING UNINITIALIZED VARIABLES IN PERL? And why are people saying that we shouldn't get in the habit of doing this? In JavaScript, an uninitialized variable automatically becomes a global variable when we use it. So, if I refer to A in my function, then when I type "A = 5" it becomes a global variable. But if I initialize it as "var A = 5" then it becomes a temporary variable that exists only within the scope of that function. Is Perl treating variables the same way?

    What else happens if I quit using the "warnings" and "strict"? Is there any other trouble that may arise? ARE MY PERL SCRIPTS GOING TO RUN SLIGHTLY FASTER IF I DON'T USE STRICT AND WARNINGS? I am just trying to think of all the pros and cons, but so far all I've heard is that you got to use these two. But I don't know why. I want to understand the whys.

variables passed from main to package
1 direct reply — Read more / Contribute
by FryingFinn
on Feb 21, 2018 at 20:38
    I trying to get an application to set a couple of Global (?) variable that will be used in package subroutines. I thought I could use  $main::DEBUG my test main is
    #!/usr/bin/perl ## this is perl5.16 my $DEBUG = 1233; my $VERBOSE=5; use strict; use warnings; use Getopt::Long; my $Usage = "this is Usage"; Getopt::Long::GetOptions( 'd=i' => \$DEBUG, 'v=i' => \$VERBOSE ) or die "Incorrect u +sage! $Usage\n"; print "in MAIN DEBUG is $DEBUG \n"; print "In Main VERBOSE is $VERBOSE \n"; use lib "../lib"; use myApp; myApp::testprint(); myApp::testprint2();
    The code for is
    package myApp; my $DEBUG = $main::DEBUG; my $VERBOSE = $main::VERBOSE; print " has DEBUG [$DEBUG]\n"; print " has VERBOSE [$VERBOSE]\n"; 1; sub testprint { print "in myApp::testprint DEBUG is [$DEBUG]\n"; print "in myApp::testprint VERBOSE is [$VERBOSE]\n"; } sub testprint2 { my $DEBUG = $main::DEBUG; my $VERBOSE = $main::VERBOSE; print "in myApp::testprint2 DEBUG is [$DEBUG]\n"; print "in myApp::testprint2 VERBOSE is [$VERBOSE]\n"; }
    The results.
    ./xVERBOSE has DEBUG [] has VERBOSE [] in MAIN DEBUG is 1233 In Main VERBOSE is 5 in myApp::testprint DEBUG is [] in myApp::testprint VERBOSE is [] in myApp::testprint2 DEBUG is [] in myApp::testprint2 VERBOSE is []
    any help would be appreciated tks gerry
Strings/Numbers aren't equating properly
3 direct replies — Read more / Contribute
by M4ver1k
on Feb 21, 2018 at 18:29

    Edit: This is fixed. It was my fault...Flawed logic, it took time to work out. Explanation at the bottom of this post.

    I'm trying to compare results from an LDAP server to what lives on a MySQL server. Overall it works, right now I'm trying to optimize a part of it. I took the results of an LDAP query returning a single string value to an array '@ldap' which I then sorted alphabetically.

    Now I'm doing a search in MySQL, and as I iterate through the results, I'm comparing one column to the '@ldap' array and then I remove any matches out of '@ldap'. The problem is that sometimes, even though strings appear identical, it doesn't count it as a match and so fails to remove the match out of '@ldap', which creates redundant work at the end of the script.

    Here's the problematic code:
    $sth = $dbh->prepare("select * from table order by mid"); # So +rting alphabetically $sth->execute(); while(my $info = $sth->fetchrow_hashref){ my $count = 0; my $mid = $$info{'mid'}; chomp($mid); my $num = 0; if ($mid =~ /^[0-9]+$/){ # Checks to see if string hap +pens to be only numbers print fh "$mid is a number\n"; $num = 1; # If so, change value } else { print fh "$mid is a string\n"; # Prints to a t +ext file for me to look at. } print "$mid - \$num = $num\n" if ($debug > 0); foreach my $id (@ldap){ chomp($id); # Check to see if we've found a correlating LD +AP entry from MySQL if ($num == 1){ print fh "$mid - $id - Equating as numbers.\n"; last if ($count > 15); if ($mid == $id){ # Check type to see if we have + data on it if ($$info{'type'} ne 'NA'){ # If we do, then remov +e this ID from the list to retry splice @ldap, $count, +1; last; } } } else { print fh "$mid - $id - Equating as strings.\n"; last if ($count > 15); # To drastically shorten during troubleshooting if ($mid eq $id){ # Check type to see if we have + data on it if ($$info{'type'} ne 'NA'){ # If we do, then remov +e this ID from the list to retry splice @ldap, $count, +1; last; } } } $count++; } } $sth->finish;

    At first I thought it was because sometimes the strings contain only numbers, so I decided to check if they do contain only numbers, and if so, compare using '==' instead of 'eq'. I also was expecting to be able to use just $$info{'mid'} directly for comparison, so I did my $mid = $$info{'mid'}; for the sake of troubleshooting.

    In the file output, regardless of if they equate as strings or numbers, sometimes it just doesn't match when it looks like it should. Now I'm stumped. I'd be grateful for help, thank you!

    Edit: It's working now. My flawed logic was here:

    if ($$info{'type'} ne 'NA'){ # If we do, then remove this ID from the list to retry splice @ldap, $count, 1; last; }

    I ended up having a lot more entries of type 'NA' than I was expecting, and due to work later in the script it ended up making more sense to put those entries into another array to separate out the work. So I changed the logic to this:

    if ($$info{'type'} eq 'NA'){ push(@file, $id); } # If we do, then remove this UID from the list to retry splice @ldap, $count, 1; last;
    I appreciate everyone's time, thank you.
Undefined value error
1 direct reply — Read more / Contribute
by clarkmurph
on Feb 21, 2018 at 12:54

    Hello, I get the following error when I execute the below script "Can't call method "mail" on an undefined value at ./recalert.plx line 24, <RECCHK> line 9." I did not write the original perl script, I just modified the email addresses to work in my environment, and the email addresses in the below script are sanitized. The script has worked for about three years without issue, I really have no perl experience, and not sure what the error means, or how to fix it/ Please help

    #!/usr/bin/perl -w $from = ''; $to = ''; $servername = ''; # $user ='username'; # $pwd ='password'; open RECCHK, "/tmp/statusmon.eml"; @recchkvar = <RECCHK>; use Sys::Hostname; my $host = hostname(); my $host1 = uc($host); open STDERR, '>&STDOUT'; #redirect STDERR output to STDOUT use Net::SMTP; $smtp = Net::SMTP->new("$servername", Debug => 1); ### Enable below if authentication required and set parameters above # $smtp->datasend("AUTH LOGIN\n"); # $smtp->datasend("$user\n"); # $smtp->datasend("$pwd\n"); sleep(2); $smtp->mail("$from"); $smtp->to("$to"); $smtp->data; $smtp->datasend("Subject: 79XX/69XXC/WB3 InfiniStream $host1 has an is +sue, and requires investigation \n"); foreach $line (@recchkvar) { $smtp->datasend("$line\n"); } close RECCHK; $smtp->dataend; $smtp->quit
New Meditations
Revitalising your own old posts
6 direct replies — Read more / Contribute
by stevieb
on Feb 21, 2018 at 19:32

    Periodically, I'll go through my posts via the normal mechanism and sort by lowest-highest-this-that-other, and sometimes, like today, I have found one that I'd like to reply to.

    Now, this post has a (relatively) high XP count, and the responses have 15-25% higher than that.

    I want to reply to a poster on such thread legitimately (orig post count was ~45, replies were 60+), but I don't want it realized that I'm doing it in order to get exposure on the overall hierarchical post.

    How do Monks handle these situations? Shatter humility or what?


    ps. I have been accused of raising posts for XP+ before, but those who raised that are irrelevant to me.

New Cool Uses for Perl
My first cpan module - App::ForKids::LogicalPuzzleGenerator
3 direct replies — Read more / Contribute
by pawel.biernacki
on Feb 23, 2018 at 14:06

    Hi! I would like to introduce my module - my first contribution to It is generating a logical puzzle. Get it from You can use it as follows:

    use App::ForKids::LogicalPuzzleGenerator; my $x = App::ForKids::LogicalPuzzleGenerator->new(range=>3, amount_of_facts_per_session => 4); print $$x{intro_story}; print $$x{story}; print $$x{solution_story};

    It is heavily using AI::Prolog. An example of such puzzle is below:

    John,Patrick and James live here. Each has a different favourite fruit (pinapples,apples,pears). Each has a different profession (fisherman,blacksmith,witcher).

    - My name is John. The one who likes apples is not a blacksmith. Patrick is not a witcher. James does not like pinapples. James is not a fisherman.

    - My name is James. John does not like pears. Patrick does not like apples. I don't like apples. The one who likes apples is not a fisherman.

    John likes apples. John is a witcher. Patrick likes pinapples. Patrick is a fisherman. James likes pears. James is a blacksmith.

    Pawel Biernacki
Log In?

What's my password?
Create A New User
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (4)
As of 2018-02-26 04:16 GMT
Find Nodes?
    Voting Booth?
    When it is dark outside I am happiest to see ...

    Results (316 votes). Check out past polls.