Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
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
Output Queue from Multiple Threads
3 direct replies — Read more / Contribute
by bigbot
on Jul 31, 2015 at 09:56

    Hi monks, I had a question about implementing an output queue from multiple threads, using Thread::Queue. It's "working" without warnings or errors, but the memory usage gets way out of control, and it's also a lot slower than using locks and shared variables (which I assume it cause I screwed something up). I understand the memory usage would go up if the output queue was getting more than it could handle. In any case I can't seem to find many examples so any advice would be appreciated.

    The reason I wanted to use an output queue is that the worker queue is processing very large files on different computers (so it made sense to use threads). The output needs to be serialized. Previously I used a lock as I said. I heard that using an output queue would be better design. So I want to pass the output from the worker threads to the output queue and print the data there.

    sub runSearch { my $outputQueue = Thread::Queue->new(); my $outputThread = threads->create(\&outputSub,$outputQueue); my $workerQueue = Thread::Queue->new(); my @workerThreads = map threads->create(\&workerSub,$workerQueue,$ou +tputQueue), 1..$numThreads; $workerQueue->engueue($_) foreach @computer; $workerQueue->enqueue(undef) for 1..$numThreads; $outputQueue->enqueue(undef); $_->join for @workerThreads; $outputThread->join; } sub workerSub { my ($workerQueue,$outputQueue) = @_; while (my $computer = $workerQueue->dequeue()) { ## SSH command retrieving grep results and processing $outputQueue->enqueue($results); } } sub outputSub { my $outputQueue = $_; while (my $packet = $outputQueue->dequeue()) { print $results; } }
execute csh file from perl script
4 direct replies — Read more / Contribute
by argha
on Jul 31, 2015 at 07:43
    hello folks, i want to execute run_dynamic.csh file from my perl script. also my cshell file consist of environment variables command like setenv. i tried system("csh","file pointer"); but not working. please throw some light on it. thanks, argha
How to capture compile errors from child program?
4 direct replies — Read more / Contribute
by bulrush
on Jul 31, 2015 at 06:03
    I have a parent program, parent.pl that calls a child program, child.pl, like this:
    @z=`perl child.pl -option1 -option2`
    
    The whole command line for child.pl is in a scalar variable but that shouldn't matter. So I noticed that @z in parent.pl would return completely blank after I made some changes to child.pl. Lo and behold I had compile or syntax errors in child.pl, so none of my other error messages (written to STDOUT with "print") would be written from child.pl.

    So when I'm running parent.pl, how do I capture compile errors when calling child.pl? Do I have to do something like

    @z=`perl -c child.pl`;
    
    before I do anything else? Will @z return STDERR messages or just STDOUT? If I did
    @z=`perl child.pl -option1 -option2` or die "Possible compile errors in child.pl";
    
    Would that do what I want?

    Thank you. Looking for some input so I can learn more about this.

Replacement for the "unsupported" Graph module?
1 direct reply — Read more / Contribute
by pokki
on Jul 31, 2015 at 05:54

    Hello Monks,

    I've used the Graph module for lots of graph-related tasks and I've always been happy with it. I don't need a superfast module, or one that consumes very little memory, since I don't have many graphs and they aren't very big. I don't need complex operations either; neighbor/descendant/ancestor list, maybe some shortest paths.

    Is there an heir to Graph, now that its author has stopped maintaining it? Or should I just keep using it and hope it doesn't break in the future? What do you guys use, or do you just write your own adjacency maps?

How to use * operator in JOIN
3 direct replies — Read more / Contribute
by ravi45722
on Jul 31, 2015 at 05:00
    my $placeholders = join(',',('?') * 8);

    I need an output of ?,?,?,?,?,?,?,? But its returning zero. I dont know where i mistaken. Plz correct it

Email Module
4 direct replies — Read more / Contribute
by caseycole589
on Jul 31, 2015 at 03:16

    I'm trying to convince my work to use Perl for our email in a web app running on asp.net is this do able or does any one have advice/opinions. How hard is it to get something like this working on a windows server? Any input would be appreciated. I know I could do this easily in c# and probably should, but I'm looking for any excuse to get Perl running on our servers. That way I can have an excuse for using it on more projects moving forward.

Command line perl software development
4 direct replies — Read more / Contribute
by anomilie
on Jul 30, 2015 at 20:51
    Hi PerlMonks, I have a few perl scripts that I want to turn into a command line program that others can downlaod and use. I'm familiar with command line arguments etc. Also I know of scrum and agile, which its what I'm looking for either. The blanks that I am currently having is what is need to transition this code to an executable. How does the installation of subroutines work? how should I structure my code collection? Your help is much appreciated.
perlrun: -a implicitly sets -n
2 direct replies — Read more / Contribute
by 1nickt
on Jul 30, 2015 at 19:10

    Hi all, in perlrun under the documentation for the -a switch it states:

    -a implicitly sets -n.

    My testing seems to show this is not the case:

    $ cat test.dat foo bar baz quux $ perl -wMstrict -M5.010 -ane 'say $F[0]' test.dat foo baz $ perl -wMstrict -M5.010 -ae 'say $F[0]' test.dat Variable "@F" is not imported at -e line 1. Global symbol "@F" requires explicit package name at -e line 1. Execution of -e aborted due to compilation errors.

    Am I missing something?

    The way forward always starts with a minimal test.
stat on file name containing single quotes
5 direct replies — Read more / Contribute
by perlpipe
on Jul 30, 2015 at 17:21

    On my windows 7 system I have a directory named:

    E:\Music\Ray LaMontagne\2010 - God Willin' & The Creek Don't Rise

    In my program the variable $fn contains the above string. When I do a stat on that variable I get an undefined return value. The same with -d or -f as in:

     @s=stat $fn;

    or

    if (-d $fn) {print "Directory"}

    Is there any way to get the stat to work?

    I am running activestate perl 5.16.2 with a "use 5.12.0".

Net::SSH2 limitation?
1 direct reply — Read more / Contribute
by bbarrette
on Jul 30, 2015 at 17:04
    Greetings Monks, I am having a hard time tracking down this issue I am having with the Net::SSH2 module. Basically, my code will read in a file containing information to be programmed into a menu-driven network device. The code will iterate through about 21 lines before simply exiting in the middle of a print statement. I am positive it is not due to faulty file input as I can replicate the issue with any file exceeding 21 lines. I'd like to know if there is any kind of debugging I can do that will show why the program is crashing. All code is contained below:
    #!/usr/bin/perl use 5.010; use strict; use warnings; use Net::SSH2; use Data::Validate::IP; #Variables my $host = $ARGV[0]; my $tacacsusername = $ARGV[1]; my $tacacspassword = $ARGV[2]; my $fh = $ARGV[3]; my $validator = Data::Validate::IP->new; if (@ARGV != 4 || !$validator->is_ipv4($host)) { print "Invalid arguments, exiting."; exit; } open(my $data, '<', $fh) or die "Could not open '$fh' $!\n"; my $ssh = Net::SSH2->new(); $ssh->connect($host, 22); $ssh->auth_password($tacacsusername, $tacacspassword); if($ssh->auth_ok) { my $channel = $ssh->channel(); $channel->blocking(0); $channel->shell(); print $channel "network\n"; #Enter network context print $channel "ddelete\n"; #Clear DAT table print $channel "yes\n"; #Confirm clearing DAT sessions print $channel "b\n"; #Return to main context print "$_" while <$channel>; #Print output to console #Iterate the CSV file line by line while (my $line = <$data>) { chomp $line; my @fields = split "," , $line; print $channel "subscribers\n"; #Enter subscriber context print $channel "add\n"; #Add subscriber print $channel "$fields[1]\n"; #Mac Address print $channel "$fields[0]\n"; #Hostname print $channel "1\n"; # Type of Profile 1=Device print $channel "$fields[2]\n"; #IP Address print $channel "\n"; #Subnet print $channel "\n"; #User Definable 1 print $channel "\n"; #User Definable 2 print $channel "\n"; #Upstream Bandwidth in kbps print $channel "\n"; #Downstream Bandwidth in kbps print $channel "\n"; #QOS Policy print $channel "$fields[3]\n"; #VLAN print $channel "\n"; #Proxy arp print $channel "\n"; #SMTP Redirection print $channel "b\n"; #Exit subscriber context print "$_" while <$channel>; #Print output to console if(scalar(@fields) > 5 && $fields[4] ne ''){ print $channel "system\n"; #Enter system context print $channel "static\n"; #Enter static portmap context print $channel "add port\n"; #Add new portmap print $channel "$fields[2]\n"; #IP Address print $channel "$fields[4]\n"; #SNMP Internal port print $channel "$fields[1]\n"; #Mac Address print $channel "$fields[5]\n"; #SNMP External port print $channel "UDP\n"; #UDP on first pass for SNMP print $channel "\n\n"; #Remote IP, port print $channel "enable\n"; #Use access control print $channel "b\nb\n"; #Return to main context print "$_" while <$channel>; #Print output to console } if(scalar(@fields) > 7 && $fields[6] ne ''){ print $channel "system\n"; #Enter system context print $channel "static\n"; #Enter static portmap context print $channel "add port\n"; #Add new portmap print $channel "$fields[2]\n"; #IP Address print $channel "$fields[6]\n"; #MGMT Internal port print $channel "$fields[1]\n"; #Mac Address print $channel "$fields[7]\n"; #MGMT External port print $channel "TCP\n"; #TCP on second pass for MGMT print $channel "\n\n"; #Remote IP, port print $channel "enable\n"; #Use access control print $channel "b\nb\n"; #Return to main context print "$_" while <$channel>; #Print output to console } if(scalar(@fields) > 9 && $fields[8] ne ''){ print $channel "system\n"; #Enter system context print $channel "static\n"; #Enter static portmap context print $channel "add port\n"; #Add new portmap print $channel "$fields[2]\n"; #IP Address print $channel "$fields[8]\n"; #MGMT Internal port print $channel "$fields[1]\n"; #Mac Address print $channel "$fields[9]\n"; #MGMT External port print $channel "TCP\n"; #TCP on second pass for MGMT print $channel "\n\n"; #Remote IP, port print $channel "enable\n"; #Use access control print $channel "b\nb\n"; #Return to main context print "$_" while <$channel>; #Print output to console } else { print $channel "b\nb\n"; #Return to main context } print "$_" while <$channel>; #Print output to console } print $channel "b\n"; print $channel "logout\n"; print "$_" while <$channel>; print "\n"; $channel->send_eof(); $channel->close(); $ssh->disconnect(); } else { print "ERROR: Please verify credentials as the connection to the +gateway failed\n"; }

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!
  • 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 web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others imbibing at the Monastery: (9)
    As of 2015-08-01 17:11 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      No recent polls found
      past polls