Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
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
using perlbrew with apache
2 direct replies — Read more / Contribute
by Dave Howorth
on Feb 12, 2016 at 06:41

    I'm trying to use perlbrew with apache and my head hurts!

    I have a machine where I don't want to use the system perl with my applications, so I've installed perlbrew. It works fine for me, and it works fine for another user sharing my installation, but I can't figure out how to make it work for apache CGI scripts.

    I know this is a question that's been asked lots of times in various places, because google tells me so. But I haven't found any articles that answer all my questions.

    The first stumbling block of course is that apache doesn't have a login account, so can't setup perlbrew in the normal way. So the common wisdom appears to be to use the shebang line in the CGI scripts to hardwire a particular perlbrew perl. So OK, it feels a bit clunky because I have to modify every script every time I change perls, but hey. So I do that and discover that now it can't find the modules so I add a bunch of use lib statements to the scripts as well.

    That gets the script running, but all the script does is massage its arguments and 'system' an actual application program. So I add another hack that discovers the perl running the script and adds that to the 'system' call that runs the application. And after doing some tweaking to satisfy taint, that works too. But I have a nagging worry about which libraries it's using and it all feels kludgy.

    Except that the application program in turn executes various other applications in some circumstances, so before I can investigate my library doubts I'm faced with yet another case of the wrong perl.

    Now sure I could edit my application and however many other applications until it all works, but there's really got to be a better way! It feels like I'm falling down the rabbit hole. So I thought before I dive off and explore all kinds of wacky possibilities, I'd supplicate myself at the gates of the monastery and ask pretty please if anybody already knows a good way to do this?

WWW::Mechanize::Firefox hangs when jquery element clicked
1 direct reply — Read more / Contribute
by nysus
on Feb 12, 2016 at 06:13

    I've got a form in WordPress that uses the "Chosen" jquery plugin for drop down <select> fields. I'm having a tough time automating these fields with WWW::Mechanize::Firefox. The website for the plugin is here.

    When I click on the div tag associated with the drop down, it just hangs. Here is the code I'm using to click on it:

    $mech->click({xpath => '//div[@id="saved_venue_chosen"]'}, synchronize + => 0);

    The synchronize => 0 bit is supposed to prevent the script from waiting for a response from the server. However, I'm thinking that because clicking on the div tag causes jquery to change the classes of the div tag, it might be confusing WWW::Mechanize::Firefox.

    I tried this:

    my $i = $mech->xpath('//div[@id="saved_venue_chosen"]', one => 1); + $i->__event('focus'); $i->__event('click');

    It didn't work. Any other workarounds I might try?

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

Net::Telnet issue getting command output
2 direct replies — Read more / Contribute
by gballanti
on Feb 12, 2016 at 03:20

    Hello expert, I'm facing with a strange behaviour from Net::Telnet trying to get the command output from a Cisco device.
    The result from "show run" command is placed into a scalar but printing the contents I get a number.
    The dump log contests the right output.
    Below the simple code that I'm using.

    #/opt/ActivePerl-5.18/bin/perl use Net::Telnet; eval { $t = new Net::Telnet ( Timeout=>10, Errmode=> 'die', Prompt=> '/[# +>] $/' ); $t->open("x.x.x.x"); }; if($@) { print "error: " . $@ . "\n"; } else { print "success: " . $@ . "\n"; } $t->dump_log("file_dump"); $t->output_log("file_out"); #$t->max_buffer_length(50*1024*1024); $t->waitfor('/Username: ?$/i'); $t->print("*****"); $t->waitfor('/Password: ?$/i'); $t->print("*****"); $t->waitfor(-match=> '/> ?$/', -errmode=> "return") or die "login fail +ed: ", $t->lastline; $t->print("en"); $t->waitfor('/Password: ?$/i'); $t->print("*****"); $t->waitfor(-match=> '/# ?$/', -errmode=> "return") or die "login enab +le failed: ", $t->lastline; #$t->cmd(-string=> 'terminal pager 0', -timeout=> 30, -prompt=> '/# $/ +'); #$t->waitfor(-match=> '/# $/', -errmode=> "return") or die "prompt not + returned: ", $t->lastline; #@lines=$t->cmd(-string=> 'show run', -timeout=> 30, -prompt=> '/# $/' +); $t->print('terminal pager 0'); $t->waitfor('/# $/'); @showrun=$t->cmd('show run'); print @showrun . "\n"; print "moving to next statement\n";

    running the script I get:

    success:
    2280
    moving to next statement

    Anyone can help me ?
    Thanks

    **************************************************************

    I resolved, don't understand why but the command
    print @showrun . "\n";
    prints the numbers of element into the array.
    The following code show the array contents:
    print("@showrun\n");

insert a character
3 direct replies — Read more / Contribute
by ukhare
on Feb 12, 2016 at 00:51

    Hi,

    in a csv file how can i insert a character/special character on particular nth position in every row

    for example file1.csv, i want to insert space after every 5th character in every line

    Here is the sample data

    helloaviral howrusujay imgudyou

    expected output

    hello aviral howru sujay imgud you
Write special chars to PDF. UTF8?
1 direct reply — Read more / Contribute
by tel2
on Feb 11, 2016 at 23:16
    Hi Monks,

    Below is a cut-down version of my code which allows me to enter characters like e-acute (by typing Alt-130) onto a web form, and it writes them back to the web page OK, but when it writes it to a PDF, the acute chars don't appear correctly.  I've worked around this for a couple of chars with the "quick hack" you can see in the code, but I'd like to have a proper fix for all special chars.  I'm guessing I might need to "use utf8", or something, and I have read some articles on Unicode & UTF8, but haven't worked out what I need to do here yet.

    How can I get this code to write the special chars to the PDF file correctly, without the "quick hack"?

    Also, am I supposed to have:

    Content-Type: text/html; charset=utf-8\n
    AND
    <meta charset='UTF-8'>
    Or what?  Seems a bit duplicated.
    #!/usr/bin/perl use CGI; use PDF::API2; use constant mm => 25.4 / 72; $cgi = new CGI; $f1 = $cgi->param(f1); #Content-Type: text/html; charset=utf-8\n # <meta charset='UTF-8'> if (defined($f1)) { open (FILE, ">utf8_test1.out") or die "Can't open outfile"; print FILE $f1; close FILE; open (FILE, "<utf8_test1.out") or die "Can't open infile"; $f2 = <FILE>; close FILE; $pdf = PDF::API2->new(); $font1 = $pdf->corefont('Arial'); $page = $pdf->page; # Add blank page $page->mediabox(210/mm, 297/mm); $text = $page->text(); $text->font($font1, 28); $text->translate(20/mm ,280/mm); # A quick hack to handle a couple of special chars $f2 =~ s/\303\251/\351/g; # e-acute $f2 =~ s/\303\272/\372/g; # u-acute $text->text('PDF Output:' . $f2); $pdf->saveas('utf8_test1.pdf'); } print <<EOF; Content-Type: text/html; charset=utf-8\n <!DOCTYPE html> <html lang='en-NZ'> <head> <title>Test UTF-8</title> <meta charset='UTF-8'> </head> <body> <form method='post'> Input: <input type='text' name='f1' value='$f1'> <br> <input type='submit' name='submit' value='Submit'> <br> Output: $f1 </form> </body> </html> EOF

    Thanks.

regular expression to match specific members of a bus_name
4 direct replies — Read more / Contribute
by boleary
on Feb 11, 2016 at 23:01

    trying to build a regular expression to match bus names in a design.

    so if the bus is pce_rx_n[15:0], I want to be able to match pce_rx_n1 but not pce_rx_n10...pce_rx_n15

    I can't figure out what to put at the end of the regex..

    I can't use a dollar at the end of the regex because i also want to match pce_rx_n1_blah

    I've tried /pce_rx_n1\D/ but that only works for the pce_rx_n1_blah case

    /pce_rx_n1\D?/ doesn't work because no \D will match

    I thought this might be the answer... but no dice /pce_rx_n1[\D$]?/

    #!/usr/bin/perl -w use strict; #setup bus pins my @pinList=(); for my $i (0..15) { push @pinList,"pce_rx_n$i"; push @pinList,"pce_rx_p$i"; push @pinList,"pce_tx_n$i"; push @pinList,"pce_tx_p$i"; push @pinList,"cwx_tx_n${i}_blah"; push @pinList,"cwx_rx_p${i}bleh"; } # #Here lies the match string I am trying to build #I loosened it up more to match the tx or rx pins with any # pce or cwx prefix #my $match_str="[tr]x_n1[\\D\$]"; # #here is the Fix from Anaomalous Monk using the zero width #negative look-ahead assertion # my $match_str="[tr]x_n1(?!\\d)"; print "match_str=$match_str\n"; #now highlight any matches foreach my $pn (@pinList){ print "$pn"; if ($pn=~/$match_str/i) { print "***"; } print"\n"; }
Proc::ProcessTable truncating cmndline and fname
1 direct reply — Read more / Contribute
by rgren925
on Feb 11, 2016 at 19:24
    Hello Perl Monks.

    I am using Proc::ProcessTable and am having problems on Solaris and HP-UX where the cmndline value is being truncated at 80 and 64, respectively.

    In addition, the fname is being truncated at 16 and 15, respectively.

    All is working fine on AIX and Linux (RHEL).

    Any ideas? Thanks. Rick

in file insert character in every row on nth position
3 direct replies — Read more / Contribute
by ukhare
on Feb 11, 2016 at 13:43

    Hi,

    in a csv file how can i insert a character/special character on particular nth position in every row

    for example file1.csv

    Here is the sample data

    2016-02-06-0240:00 2016-02-06-0540:00 2016-02-06-0740:00

    expected output

    2016-02-06-02:40:00 2016-02-06-05:40:00 2016-02-06-07:40:00
How to wait for putty to finish before proceeding.
3 direct replies — Read more / Contribute
by SwaJime
on Feb 11, 2016 at 12:18

    Howdy again,

    More info: This is Windows 7 Enterprise running ActivePerl 5.16.3

    I've run into another problem.

    Whereas before switching to use pageant, this command does not return control to the calling script until the putty window is closed.

    putty -ssh -l $user $address -t -m $filename

    This command returns immediately and I have no way of knowing when the putty window is closed by the user.

    pageant @ppk_files -c putty -ssh -l $user $address -t -m $filename

    The reason this is a problem is because I'm trying to run two consecutive calls to putty. One to one server setting up data, the second to a second server to process that data, which is not ready until the user closes the first putty session.

    Here are sample files to illustrate: In Test1.pl, the second putty window is not opened until the first putty window is closed. This is the desired behavior. In Test2.pl, the second putty window is opened before the first window is closed. This is not good because the data has not been set up yet.

    Test1.pl:

    #!/usr/bin/perl # use strict; use warnings; system('putty -ssh -l root 192.168.100.2 -t -m C:\Users\JWSIMP~1\AppDa +ta\Local\Temp\BoKFVjf1B9'); system('putty -ssh -l operations 192.168.10.245 -t -m C:\Users\JWSIMP~ +1\AppData\Local\Temp\d60NPopq6A');

    Test2.pl:

    #!/usr/bin/perl # use strict; use warnings; system('pageant F:\.keys\acuroot_1_8_12_rsa.ppk F:\.keys\acuroot_1_8_1 +3_rsa.ppk -c putty -ssh -l root 192.168.100.2 -t -m C:\Users\JWSIMP~1 +\AppData\Local\Temp\BoKFVjf1B9'); system('pageant F:\.keys\operations_rsa.ppk -c putty -ssh -l operation +s 192.168.10.245 -t -m C:\Users\JWSIMP~1\AppData\Local\Temp\d60NPopq6 +A');

    So, long story short ... how can I get that functionality back? I don't want both sessions opening at the same time.

    Please forgive me if this is something that is already documented. I have been searching for an answer for quite some time now.

    Thanks,

    John

Multi level dependency structure
4 direct replies — Read more / Contribute
by MH1
on Feb 11, 2016 at 12:09

    Greetings monks, long time lurker, first post. Typically I can googlefoo my way around to find a solution but I'm not sure how to go about that for this problem. I have a flat file consisting of item and item dependencies. But I need to be able to track it back to find all the potential dependencies, basically following the rabbit down the hole.

    Plain Example: if item1 requires item2 and item3, and item3 requires item4 -> then item1 also requires item4.

    I'm working with around 120k rows so I know the relationships are going to be rather complex, however a task is a task.

    Relevant Code:

    #load hash after some parsing in a foreach loop push(@{$jobs{$JobName}{1}}, $blah); ... $level =1; $nextlevel = 2; while ($level <= 10) { foreach my $dep (keys %jobs) { foreach (@{$jobs{$dep}{$level}}) { print "$dep $level $_\n"; push( @{$jobs{$dep}{$nextlevel}},@{$jobs{$_}{$level}} ); next if ${$jobs{$_}{$level}}[0] eq "$dep"; last if ${$jobs{$_}{$level}}[0] eq ''; #this cancels the loop +if any of the dependencies don't have dependencies, which is a proble +m if there's additional } } $level++; $nextlevel++; }

    So one of the problems is the last statement is prematurely breaking the loop if X dep doesn't have a dep, but there's additional deps in the array. Without that terminate feature the script will run until the while loop has been fulfilled, I have no way of breaking out once I have tracked all the dependencies down. As for CPAN and modules, given my environment I'm very limited on what I can use.

    Example Data(first column is job, rest are dependencies):

    job1, job2,job1, job3,job2 job4,job2 job5,job2,job4 job6,jobz joba,job4,jobb jobz,jobbc,job2

    Any guidance will be greatly appreciated!

    I figured it out, made some loop structure changes, thanks VinsWorldcom for your replay

    while ($level <= 10) { foreach $dep (keys %jobs) { foreach (@{$jobs{$dep}{$level}}) { print "Key:$dep Value:$_ Lvl:$level Seen:$seen{$_}\n"; if ($seen{$_} eq '') { push( @{$jobs{$dep}{$nextlevel}},@{$job +s{$_}{$level}} ); } $seen{$_} = 1; next if ${$jobs{$_}{$level}}[0] eq "$dep"; last if $seen{$_} == 1; } } %seen = ''; @temparray = ''; $level++; $nextlevel++; }

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

    How do I use this? | Other CB clients
    Other Users?
    Others scrutinizing the Monastery: (6)
    As of 2016-02-14 21:51 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

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





      Results (471 votes), past polls