Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
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
Read files not subdirectories
2 direct replies — Read more / Contribute
by wrkrbeee
on Jan 29, 2015 at 16:29

    Hi PerlMonks, I'm working to create a loop that will read all text (.txt) files in a directory, excluding any sub-directories. Simple enough, think I have the pattern match, but not enough knowledge to incorporate it into the IF or NEXT UNLESS condition. Once the files are read, I'm hoping to strip HTML tags with HTML::STRIP. I am grateful for any insight you may have. Here is the code I am working with:

    #! /usr/bin/perl -w use strict; use warnings; use lib "c:/strawberry/perl/site/lib"; use HTML::Strip; my $hs = HTML::Strip->new(); my $write_dir = 'G:\research\sec filings 10k and 10Q\data\filing docs\ +1993\Clean'; my $files_dir = 'C:\Dwimperl\Perl\1993'; opendir (my $dir_handle, $files_dir) || die "failed to open '$files_di +r' <$!>"; while (my $file = readdir($dir_handle) ) { next if $file eq '.' or $file eq '..';# or $file =~ /[0-9|-]+\.txt +$/; open my $file_handle, "/dwimperl/perl/1993/$file" or die "failed t +o open '$file' <$!>"; foreach my $line (<$file>) { my $clean_text = $hs->parse( ' ' ); print $write_dir "$file\n"; $hs->eof; } } close(); closedir $dir_handle;
How Do I Read An Old DB File?
2 direct replies — Read more / Contribute
by shachter
on Jan 29, 2015 at 14:03
    I am trying to read an aliases.db file that was, apparently, created by an old sendmail program. The “file” command reports:

    Berkeley DB (Hash, version 5, native byte-order)

    and this is, apparently, too old for DB_File to read. I have another aliases.db on another computer which is (according to the “file” command)

    Berkeley DB (Hash, version 9, native byte-order)

    and DB_File reads that one perfectly, so there is nothing wrong with my perl program. Lest you be tempted to tell me to use a more modern DB format for my aliases.db file, I tried that already, and it didn't work. I ran newaliases on my new computer, and sent the newly-generated aliases.db file back to my old computer, and my sendmail program on my old computer couldn't read it, so it was useless. I have to use the version-5 format. How do I write a perl program that can read it? If you do not think that this question is of general interest, please do me the kindness of replying to me at
    jay at m5 dot chicago dot il dot us
    Thank you in advance for any and all replies.
SessionID on a windows server
4 direct replies — Read more / Contribute
by mwhiting
on Jan 29, 2015 at 13:51

    Hi - I have a script that runs on both windows and linux servers. On windows, I use perl2exe to compile it, though I don't think that is the source of the problem here.

    The script uses CGI::Session for Session id's for the purposes of keeping a password from one session to the next. With a Linux/unix server, if you are logged in successfully, and later copy and paste the url from your browser (which contains a parameter with the Session id) into an email and send it to another computer, the second computer doesn't recognize the session id as valid for itself and re-prompts for password (as it should do).

    It would be an url similar to this:
    myserver.com/script.exe?dbNum=1&action=3&CGISESSID=e91b1bfb03f67854f9675b40f6a705ac

    But on a windows server the same action doesn't result in getting prompted for a password. The server will recognize the sessionID and just continue on as normal, even though noone has ever entered a password on this second pc before.

    Any insights as to why this would be?

Open directory command in perl
3 direct replies — Read more / Contribute
by Anonymous Monk
on Jan 29, 2015 at 12:25
    HI, I am using perl to open and read a directory which have many files and doing some operation using those files. Need to know how readdir behavior if files being continuosly written to this directory and perl program initiated in b/w?
Help with pp - Perl Packer
4 direct replies — Read more / Contribute
by perloHolic()
on Jan 29, 2015 at 11:08

    Good afternoon.

    THE PROBLEM : I'm afraid I'm having a problem with using pp to create a standalone perl executable. It DOES create a file.out, however running this file does NOT run in the same way as If I ran the script itself.

    THE REASON: The reason I am trying to create a standalone executable is because the program I have written in perl needs to work in our model office environment at work, which is not connected to a network, and has little or no perl modules outside the core modules, and no way of getting them (to the best of my knowledge that is.)

    MY UNDERSTANDING: As far as I am aware, the reason that I need the program to work in an environment where it would not run as a standalone script is a valid reason for making an executable that was self contained with necassary modules -(I had a chat with some very polite monks in the chatterbox).

    MY REQUEST: First and formost I'd like to understand why when I run the executable does it not behave/display in the same way as if I just ran the script? What would also be lovely is if someone could shed some general ambient light around the subject itself (common pitfalls/misunderstandings etc.), as after reading suid Perl with App::PAR::Packer (pp) and Convertion Perl Script to Exe with PAR::Packer pp to try and understand exactly what I was doing wrong, I was no better off. I know what you'll ask next what exactly have you tried? - well I simply ran pp -o file.out file.pl which I belive has created my executable which includes the script and necassary modules, and (stupidly) I thought voila! it worked! - how wrong I was. I run the executable now, and it runs funny , giving me this( : is not an identifier) in the window and the formatting all skewed...?

    As always, my deepest thanks to those who lend an ear, and apologies in advance if I have ommitted any necessities or have made myself unclear, me and the old How do I post a question effectively? don't always get along ;)

Performance comparison Apache/FastCGI/Plack vs Apache/FCGI vs Plack standalone vs Apache/mod_perl (was "New version of Mod_perl")
2 direct replies — Read more / Contribute
by adamarc
on Jan 29, 2015 at 11:02
    thank you stonecolddevin & sundialsvc4.
    You inspired me to look at other options, and I decided to load test all of them with a simple script that connects to a MySQL database to select some UTF8 data, and return it.
    I did the test twice. I included a big Perl module (~650KB) in the second test to check if the compilation phase makes sense.
    All of the configurations properly returned the UTF8 text.
    I did the test on an 8-core Intel 3770 with 16GB of RAM (which was not a bottleneck). OS: FreeBSD 10.0.

    I'm curious to hear about what your opinion is of the below results. I find the number of Apache 2.4/FCGI too good to be true, but could not find any errors. Maybe somebody can replicate the test?

    100 concurrent requests with ~10KB script: Requests Correct Requests Error AVG_msec Apache 2.4/FCGI 202510 0 14 Apache 2.4/FastCGI/Plack 25584 0 116 Plack standalone 17012 0 175 Apache 2.2/mod_perl 1828 1128 185 100 concurrent requests with ~650KB script: Requests Correct Requests Error AVG_msec Apache 2.4/FCGI 55697 0 52 Apache 2.4/FastCGI/Plack 13971 0 213 Plack standalone 13042 0 228 Apache 2.5/mod_perl 1689 0 217

    See here the used scripts, and configuration.

    Apache/FCGI script

    Apache/FastCGI/Plack script
    Plack standalone: the same script as Apache/FastCGI/Plack
    The command that I used to run it: perl ./fcgiplack.fcgi &> fcgiplack.log &

    Apache/mod_perl:
    SQL script to create the used database:

    Initial post with title: New version of Mod_perl Dear respected Perl monks,

    I have a mod-perl site that I want to continue using, but my distro doesn't distribute the mod-perl package anymore because there is none available that works with Apache 2.4. It turns out that the loyal mod_perl development team cannot release a compatible version due to a lack of testers.

    Can somebody help by assisting them in submitting a bug report?
Module to get domain name from hostname
1 direct reply — Read more / Contribute
by gatkins
on Jan 29, 2015 at 10:47
    Hello, dear monks,
     
    I'm searching for a module which can find a domain name starting from a hostname. Example:
     
    sub-190-88-236ip52.rev.onenet.an >> onenet.an
    mailserver2.bite.ac.uk >> bite.ac.uk
    bzq135-block4--9170.isdn.net.il >> isdn.net.il
    whatever.site.com >> site.com
     
    It would be easy if the TLD was just .com / .net / .org. This can be done just by cutting the hostname. The problem is when the TLD is .co.uk or .net.il or .net.br for example.
    If you know any module which can do this, please share.
Find nonnumeric scalars
5 direct replies — Read more / Contribute
by urbs33
on Jan 29, 2015 at 09:59

    Guys I am working with millions of lines of data that "should" all be in the same format, however I am finding hundreds of lines that are not. A line may have ~10 fields space delimited. Suppose I am splitting the line into scalars that I can work with, and perform math on. Suppose fields 6-8 are supposed to be numeric and available for math. I am getting non-numeric warnings on several of them and just want to write the line out to an "errors" file so that I can resolve the formatting.

    How can I do something to test if scalar 6, 7, or 8 is not numeric (or even empty), write the line to a file and move to the next line. I can handle the "else". I'd prefer to use standard perl as it is very difficult at my company to pull in additional packages.

How can one create an array of the indices at which a given character appears in a string?
5 direct replies — Read more / Contribute
by tkguifan
on Jan 29, 2015 at 07:50
    The naive solution:
    my $input='rnbqkbnr'; my $search='n'; my $index=0; my @result; foreach(split //,$input) { if($_ eq $search) { push(@result,$index); } $index++; } print "Result: ",join(' , ',@result);
    Is there a shortcut to do it more simply?
Rendering POD to (not with!) templated files
1 direct reply — Read more / Contribute
by pokki
on Jan 29, 2015 at 05:54

    Esteemed monks,

    I wrote a small darkpan browser for $work and I have the following issue...

    The app is built as a Dancer web app. One of the features is that module PODs (ours, or dependencies from CPAN's) should be rendered to HTML and displayed in a page. I use Pod::Simple::XHTML to do the heavy lifting here. Since I also want the app to be relocatable without breaking all the inter-POD links, I have done this:

    my $pod_renderer = Pod::Simple::XHTML->new; # this is going to be inserted in a larger document $pod_renderer->html_header('[% TAGS [- -] %]'); $pod_renderer->html_footer(''); # http://localhost:5000/mirror/integration/module/Acme::Foo $pod_renderer->perldoc_url_prefix('[- request.uri_base -]/mirror/[ +- selected_mirror -]/module/'); $pod_renderer->output_string(\my $html); $pod_renderer->parse_file($module); # spew $html into a file on disk

    (ignore the [- selected_mirror -] part, that's just because we have multiple Pinto instances and the app can generate links e.g. from the integration to preproduction releases of a module)

    When rendering the full module page, I have a total of three (!) template rendering passes: once to turn the POD-rendered-as-template into HTML; once to render the regular .tt file, which includes the previously rendered HTML directly; and finally once because the .tt file has a layout and Dancer's template engine works like this.

    The first pass (POD to .tt) uses custom TAGS because otherwise the Template.pm PODs would not render properly (they of course include lots of [% %] everywhere). [- -] turned out to be a very bad idea (USAGE: foobar [-optional]) and I need to fix this.

    The second and third pass are just Dancer's standard template to HTML rendering. The module page has other things besides the rendered POD, so it needs to be its own template that somehow includes the templated POD...

    I feel like the way I wrote it is now a cluster[beep] of badly thought-out fixes upon badly thought-out fixes. Have you guys done something like this? How did you do it? Alternatively, do you see a simpler/better solution?


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
  • Outside of code tags, you may need to use entities for some characters:
            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 meditating upon the Monastery: (5)
    As of 2015-02-01 20:59 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      On my keyboard, Caps lock is:








      Results (12 votes), past polls