Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number

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
Cant find modules after upgrade
No replies — Read more | Post response
by cbtshare
on Feb 09, 2016 at 11:16

    I recently installed installed perl (v5.23.3) , now my old scripts wont work because it complains about modules, but those modules were installed and if I try reinstalling it says

    cpan -i Net::OpenSSH CPAN: Storable loaded ok (v2.51) Reading '/root/.cpan/Metadata' Database was generated on Tue, 09 Feb 2016 14:53:50 GMT CPAN: Module::CoreList loaded ok (v5.20160120) Net::OpenSSH is up to date (0.70). #>perl Can't locate Net/ in @INC (you may need to install the Net:: +OpenSSH module) (@INC contains: /usr/local/perl-5.23.3/lib/site_perl/ +5.23.3/x86_64-linux /usr/local/perl-5.23.3/lib/site_perl/5.23.3 /usr/ +local/perl-5.23.3/lib/5.23.3/x86_64-linux /usr/local/perl-5.23.3/lib/ +5.23.3 .) at line 5. BEGIN failed--compilation aborted at line 5.

    How do I install the modules in the new location or have the metadata read in the new location? thank you

Unable to establish SMB2 connection using Filesys::SmbClient
No replies — Read more | Post response
by Netras
on Feb 09, 2016 at 08:05

    Hello Perl Monks,

    I need to access a SMB host which requires SMB version 2. Filesys::SmbClient (3.2) has served me well working with SMB1 but does not successfully create a SMB2 connection. This is the error I get:

    samba_tevent: EPOLL_CTL_DEL EBADF for fde[0x27c9930] mpx_fde[(nil)] fd[8] - disabling

    Directly using smbclient with SMB version 2 works fine:

    smbclient -U domain\\user //HOSTNAME/ShareName -c "dir" -m SMB2

    But when omitting the max-protocol tag (-m) while using smbclient, a very similar error appears:

    smbclient -U domain\\user //HOSTNAME/ShareName -c "dir" samba_tevent: EPOLL_CTL_DEL EBADF for fde[0x7f454d1eff50] mpx_fde[(nil +)] fd[7] - disabling

    I assume that Filesys::SmbClient is trying to use SMB version 1 to connect to the target host and I have no idea how I can change this behaviour. I have checked the official module documentation with no success and tried forcing the client protocol version in /etc/samba/smb.conf but this has no effect on Filesys::SmbClient as well.

    Is there someone that has had this issue or has any ideas? I would appreciate any feedback and/or help in the matter.

    Thank you!

socket checker in multiple hosts for multiple destination
1 direct reply — Read more / Contribute
by Bams
on Feb 09, 2016 at 06:45

    Hi, I am trying to write a program in perl. it is to check socket from my local machine to multiple remote machines, to multiple destinations. The limitation i have is, on my local machine i only have standard modules installed. I am using expect to skip password as well 1. source hosts list 2. destination list contains host and port as a cvs file,1586,1234,5678 these files should be passed as argument , my program is still incomplete without expect. any help would be greatly appreciated

    #!/usr/bin/perl -w use Data::Dumper; use Expect; use strict; use warnings; my $exp = new Expect; $exp->log_file("SSHLOGFILE.txt"); $exp->log_stdout(0); my $user = 'xxxxxx'; my $pw = 'yyyyyyyy'; if( ! defined $ARGV[0] ) { print "Usage: source destination\n"; exit; } my $file1 = $ARGV[0] or die "Need to get CSV file on the command line\ +n"; my $file2 = $ARGV[1] or die "Need to get CSV file on the command line\ +n"; open my $info, $file1 or die "Could not open $file1: $!"; while( my $line = <$info>) { print $line; open(SSH,"/usr/bin/ssh xxxxxx\@host ps aux |") or die "$!\n"; open my $data, $file2 or die "Could not open $file2: $!"; for (my $nice = <$data>) { chomp ($nice); my ($servername, $portnumber) = split (',', $nice); print "$servername \n"; print "$portnumber \n"; while (<SSH>) { printf "%s %s\n", $servername, $portnumber; use IO::Socket; my $sock = new IO::Socket::INET (PeerAddr => $servername,P +eerPort => $portnumber,Proto => 'tcp'); print "ERROR: Could not create socket: $!\n" unless $sock +; printf "%s\n", "SUCCESS: Port Responded" if $sock; close($sock) if $sock; } close SSH; exit; redo; } close $data; } close $info; exit
HTML::Template duplication of tags
1 direct reply — Read more / Contribute
by Anonymous Monk
on Feb 09, 2016 at 02:44

    Is it permitted to use a <TMPL_VAR NAME=XX> tag more than once in an HTML doc? I could assign the same value to two different tags but that feels a bit clunky!

How to input text into Facebook's event form with WWW::Mechanize::Firefox?
1 direct reply — Read more / Contribute
by nysus
on Feb 09, 2016 at 01:23

    Facebook has no API for submitting an event to a Facebook page. So I'm attempting to use WWW::Mechanize::Firefox with this script:

    my $mech = WWW::Mechanize::Firefox->new(activate => 1); $mech->autoclose_tab(0); $mech->get(''); if ($mech->title eq 'Facebook - Log In or Sign Up') { $mech->submit_form( with_fields => { email => '', pass => 'my_password', } ); } sleep(1); $mech->get(''); my $page_id = 777777777777777; $mech->click({ synchronize => 0, xpath => '//a[text() = "Create Event" +]' }, 10, 10); sleep(3); # selects all input fields and sets value to 'hello world' # even though values are set, the fields remain blank despite trying t +o simulate some js events # per suggestion from Corion, the man himself, at http://www.perlmonks my @selectors = $mech->selector('input'); foreach my $selector (@selectors) { $selector->__event('focus'); $selector->{value} = 'hello world'; $selector->__event('change'); $selector->__event('blur'); } # attempts to publish event, results in form errors because fields are + blank $mech->click({ synchronize => 0, xpath => '//button[text() = "Publish" +]' });

    I have verified that the input fields are getting values set by printing the values out. I'm sure there's got to be a way to do this but I can't figure it out.

    $PM = "Perl Monk's";
    $MCF = "Most Clueless Friar Abbot Bishop Pontiff Deacon";
    $nysus = $PM . $MCF;
    Click here if you love Perl Monks

Can't call method "proxy" on an undefined value at
1 direct reply — Read more / Contribute
by Anonymous Monk
on Feb 08, 2016 at 23:08

    I know I'm missing something but I can't see why I'm getting the error, Can't call method "proxy" on an undefined value at. Here's my code

    open(my $fh, '<', 'cities.txt') or die $!; print $fh; open(my $prx, '<', 'proxies.txt') or die $!; print $prx; mkdir 'Bing', 0755; mkdir 'Bing/1Parsed/', 0755; mkdir 'Bing/1Parsed/Html/', 0755; chomp(my @cities = <$fh>); close($fh); chomp(my @prx = <$prx>); close($prx); open($fh, '<', 'keywords.txt') or die $!; for my $city (@cities) { seek($fh, 0, 0); while (my $keywords = <$fh>) { chomp($keywords); print "$city $keywords\n"; my $xml1 = $link1 . $city ."+". $keywords . $link2 . $city ."+". $ +keywords . $link3; #my $xmla = $link3 . $row . ".com"; #my $xmlx = $link4 . $row; my $filename1 = "Bing/".($city)."_". ($keywords) . ".html"; open my $fh1, ">", $filename1 or die("Could not open file. $!"); #toggle proxy selection my $prx=$_; my $ua->proxy('http', $prx); $ua->agent('Mozilla/8.0'); print "using:"; print "proxy"; print $prx;

    The above is a piece of a sub script in a bigger script. Any guidance is greatly appreciated

Howto Threads
2 direct replies — Read more / Contribute
by sunder
on Feb 08, 2016 at 22:28
    So i am an Engineer for a ISP. I have a need to validate Customer Routers are reachable before and after a maintenance by pinging them. The current program that I use doesn't thread to speed things up so it can take a long time to complete.

    Here is the overview what i am trying to do.

    Give the program a list of ip's to ping in a list\array.
    Thread to create a process for each ping task.
    Then when the ping task completes return the outcome (Latency or Unreachable) back to the original process and put it in to array
    Then print the results.

    I have never done any programming with threads or forking.

    First off is threads the correct way to program this?

    Second does someone know of a good tutorial or have a good example?

    Thanks in advance
Inline C solaris vs linux
2 direct replies — Read more / Contribute
by ccgcube
on Feb 08, 2016 at 17:07

    Hi All,

    I'm working on a set of tools that must run on both solaris and linux. I've written a set of packages using Inline::C, primarily to manipulate large arrays. The code compiles and runs correctly on linux.

    It compiles and runs on solaris too, but I'm not getting the results I'm looking for.

    The code below is the smallest version of the code I can come up with to demonstrate the problem. The newthing() function is intended to return a pointer to a blessed object, in this case our small struct Thing. In the interest of full disclosure, newthing() was stolen almost verbatim from Inline::C-Cookbook (thanks!).

    That reference may be used from the perl side to call $thingref->bump() from the perl side. The bump function should increment thing->index, and assign the simtime parameter to thing->simtime.

    The problem is that the solaris version does not increment the index, and does not appear to handle the simtime parameter correctly. Both values stay at zero when they should be non-zero (recall that this runs correctly on linux). A sample of the output follows the code.

    My first quess was that I've got a type mismatch somewhere. Changing the type of the obj parameter to bump() from SV * to UV * or IV * compiles, but produces this message at runtime:

    Can't locate object method "bump" via package "Short" at ./p_passi +ng_blessed line 58.

    ... and I am obviously guessing.

    The version of perl on both systems is 5.18.4.

    perl -V on solaris returns this (among other things):

    intsize=4, longsize=4, ptrsize=4, doublesize=8, byteorder=87654321 d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=1 +6 ivtype='long long', ivsize=8, nvtype='double', nvsize=8, Off_t='of +f_t', lseeksize=8

    I suspect that somewhere along the line, my object has been misallocated, and it is the difference between ivsize and ptrsize that is the source of the issue... but again, I'm guessing.

    package Short; use Inline C; use strict; # no strict 'refs'; 1; ## # __DATA__ __C__ #ifndef Newx # define Newx(v,n,t) New(0,v,n,t) #endif typedef struct { UV index; UV simtime; } Thing; // -------------------------------------------------------- // shamelessly stolen from Inline::C-Cookbook // SV* newthing( const char * classname ) { Thing * thing; SV * obj; SV * obj_ref; Newx( thing, 1, Thing ); thing->index = 0; thing->simtime = 0; obj = newSViv( (IV)thing ); obj_ref = newRV_noinc(obj); sv_bless( obj_ref, gv_stashpv( classname, GV_ADD ) ); SvREADONLY_on( obj ); return obj_ref; } // -------------------------------------------------------- // void DESTROY(SV* obj) { Thing* thing = (Thing*)SvIV(SvRV(obj)); printf("FREE thing size : %d\n", sizeof( thing ) ); Safefree( thing ); } // -------------------------------------------------------- // void bump( SV* obj, UV simtime ) { Thing* thing = (Thing*)SvIV(SvRV(obj)); printf("obj size : %lu\n", sizeof( obj ) ); printf("obj val : %lx\n", (unsigned long)obj ); printf("thing size : %d\n", sizeof( thing ) ); printf("thing val : %lu\n", (unsigned long)thing ); printf("thing simtime p : %lu\n", simtime ); printf("thing simtime A : %lu\n", thing->simtime ); printf("thing index A : %lu\n", thing->index ); thing->simtime = simtime; thing->index += 1; printf("thing simtime B : %lu\n", thing->simtime ); printf("thing index B : %lu\n", thing->index ); }

    Sample Output

    # --------------------- Devel::Peek::Dump output so we can compare values: SV = IV(0x2bf2d8) at 0x2bf2d8 REFCNT = 1 FLAGS = (PADMY,ROK) RV = 0x2216b0 SV = PVMG(0x4372c8) at 0x2216b0 REFCNT = 1 FLAGS = (OBJECT,IOK,READONLY,pIOK) IV = 7888424 NV = 0 PV = 0 STASH = 0x30a5e8 "Short" # --------------------- perl passing simtime: 20 obj size : 4 obj val : 2bf2d8 thing size : 4 thing val : 7888424 thing simtime p : 0 << should be 20 thing simtime A : 0 thing index A : 0 thing simtime B : 0 << should be 20 thing index B : 0 << should be 1 perl passing simtime: 40 obj size : 4 obj val : 2bf2d8 thing size : 4 thing val : 7888424 thing simtime p : 0 << should be 40 thing simtime A : 0 thing index A : 0 thing simtime B : 0 << should be 40 thing index B : 0 << should be 2 FREE thing size : 4

    Thanks in advance,

Preferred authentication in Net::SFTP::Foreign
2 direct replies — Read more / Contribute
by mithunbh
on Feb 08, 2016 at 16:43
    So we have a huge setup of SFTP connections and their configurations and now we are encountering situations where we have to tune the Preferred Authentication. Since the basis of Net::SFTP::Foreign was supposed be to piggy back on the underlying ssh libraries we naively assuming ~/.ssh/config would be fully honored except that the module has chosen to explicitly override Preferred Authentication.

    Does anyone have suggestions what can be done to stop the module from overriding it other than explicitly forking off from the package ?

Do a named regex group in 5.8?
3 direct replies — Read more / Contribute
by crusty_collins
on Feb 08, 2016 at 15:57
    I was wondering if I can do a named group regex with some kind of trickery like is available in 5.10?
    any ideas?

    snippet from
    (?<x>abc){3} matches abcabcabc. The group x matches abc.

    "We can't all be happy, we can't all be rich, we can't all be lucky and it would be so much less fun if we were. There must be the dark background to show up the bright colours." Jean Rhys (1890-1979)

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 taking refuge in the Monastery: (10)
    As of 2016-02-09 16:35 GMT
    Find Nodes?
      Voting Booth?

      How many photographs, souvenirs, artworks, trophies or other decorative objects are displayed in your home?

      Results (321 votes), past polls