Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

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
Can I re-use modules compiled with a different build of Perl, but with the same version number on the same machine?
5 direct replies — Read more / Contribute
by neuty
on Jan 30, 2015 at 14:47

    My department's production servers (RHEL5) have no access to the Internet or any CPAN repository. Therefore, when we need to use a specific Perl module with our scripts, we download them to our terminals from the CPAN website, scp them over to our dev machines, untar them, and then build them locally. We then distribute them to a shared network file system so that other developers may use them, and so that they are available on the prod machines as well. In this way we build a library of Perl modules that slowly grows over time. Our current set of modules were built using my system Perl, which /usr/bin/perl -V lists as revision 5 version 10 subversion 1.

    However, we're interested in building a separate copy of Perl that we can also upload to the networked file system. This way we are not tied to using each of our machines' system Perl, which can change from machine to machine (and is frequently 5.8.8, which is outdated for a few necessary modules). A sort of "central" Perl that can be standard across each machine.

    Therefore, I needed to build a local copy of Perl in my home directory. I made sure to install the same version as my system Perl, perl-5.10.1. I did this using the following Configure followed by a simple make,make test, make install:

    ./Configure -des -Dprefix=/home/myuser/localperl -Duserelocatableinc

    -Dprefix installed it to the folder localperl in my home directory, while the -Duserelocatableinc flag made it so the @INC would change if the folder was moved (ie., uploaded to the networked file system).

    The issue comes when I try to test it out with one of my scripts that requires a module from our library of manually built Perl modules. I keep getting the following error:

    /home/myuser/localperl/bin/perl: symbol lookup error: .../auto/DBI/DBI.so: undefined symbol: Perl_Istack_sp_ptr

    Obviously my script uses the shared DBI module but is running into errors. From doing research on the Internet, people have said that I would need to recompile the modules using the new build of Perl.

    However, the two Perls are the same version and were built on the same machine. I have tried to rebuild the local Perl using the Configure settings as close to the machine Perl as possible to try to see if that would work:

    -Dversion=5.10.1
    -Dmyhostname=localhost
    -Dcc=gcc
    -Dinc_version_list=5.10.0
    -Darchname=x86_64-linux-thread-multi
    -Dusethreads
    -Duseithreads
    -Duselargefiles

    So far this has not stopped the error. My system Perl actually used many more Configure options, but since I was so unfamiliar with them, I didn't throw them into the local Perl build for obvious precautionary reasons.

    First, can someone help me get a better understanding of what is preventing these modules from working with my locally built Perl? It makes sense that modules would not work under different versions of Perl, but it surprises me that it doesn't work with the same version built on the same machine. It also does not make sense to me that a module would lock itself info a specific Perl build like a "license" type scenario, so my intuition is that the module is incompatible with some unseen setting/library that the local Perl is built under.

    Second, is there a way to get my locally built Perl to work with the modules compiled with the system Perl, or will I have to recompile them all and redistribute a fresh set of modules?

    Thank you for any and all help! I have tried Googling the answer, but any issues dealing with this only bring up different Perl versions, which is not the situation I am currently facing.

Generate a # between 1 and 50 in groups of 5
7 direct replies — Read more / Contribute
by Hayest
on Jan 30, 2015 at 13:45

    Hello, as the title states, I'm trying to get a Perl program to generate a number between 1 and 50 in groups of 5. This is for a school assignment, and I'm wondering where I need to go next (I am a beginner with Perl and programming in general). Here is what I have so far:

    #!/usr/bin/perl use strict; use warnings; use List::Util 'shuffle'; my @numbers = (1 .. 50); print shuffle(@numbers);

    I was able to find the 'shuffle' utility which works to print my whole array (with numbers between 1 and 50). Now I know how to create a for loop which would go through each number in the array and print on a new line:

    for ($i = 0; $i < @numbers; ++$i) { ... }

    What I want to know is how would I get it to pick five of the numbers inside of it, and print them each on a new line (5 new lines with a number between 50 on each line), line break, print 5 more, line break, etc. I want the program to terminate after it does this for 5 cycles. Any thoughts? Any help would be much appreciated!!!

Using threads to process multiple files
4 direct replies — Read more / Contribute
by anli_
on Jan 30, 2015 at 11:36
    Hey. I'm trying to get the feel for how multithreading works with perl in an effort to try to speed up my scripts. My test case is that I want to parse two relatively large files and place all the lines from each file into separate hashes. Normally I would just go over them one by one with a while loop and populate my hashes that way. Like so.
    open IN, '<', $ARGV[0]; my %hash1; while (<IN>) { next unless ( $_ =~ m/^\@HWI/ ); my ($header) = split(/ /, $_); $hash1{$header} = 1; } close IN; open IN2, '<', $ARGV[1]; my %hash2; while (<IN2>) { next unless ( $_ =~ m/^\@HWI/ ); my ($header) = split(/ /, $_); $hash2{$header} = 1; } close IN;
    Instead I thought I'd try doing both files at once. Like so:
    my @threads = ("1","2"); # Loop through the array: foreach(@threads){ # Tell each thread to perform our 'parseLines()' subroutine. $_ = threads->create(\&parseLines, shift(@ARGV)); } #Tries to join the running threads #Some check implemented to avoid quitting the loop, before everything +is joined my @running = threads->list(threads::running); #Array of running threa +ds my @joinable = threads->list(threads::joinable); #Array of joinable th +reads my @catcher; while (scalar(@running) != 0 || scalar(@joinable) > 0) { #While as lon +g as there are running or joinable threads @running = threads->list(threads::running); #Repopulate running, n +ot sure if needed. foreach(@threads){ if ($_->is_joinable()) { push(@catcher, $_->join()); #Put's parsed file as hash-ref int +o array } } @joinable = threads->list(threads::joinable); @running = threads->list(threads::running); } sub parseLines{ open IN, '<', $_[0]; my %hash; while (<IN>) { next unless ( $_ =~ m/^\@HWI/ ); my ($header) = split(/ /, $_); $hash{$header} = 1; } close IN; return \%hash; }
    While the multithreaded code works, it's about 50% slower than the first one, so nothing is really accomplished there. It seems to me that maybe the problem is that the threads take a long time passing the created hashes back to the main script. So it's shuffling things around in memory, but I'm on really thin ice here I must admit. Any input is appreciated.
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?

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?
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 I access object data in a user defined sort cmp function?
6 direct replies — Read more / Contribute
by tkguifan
on Jan 28, 2015 at 09:19
    I want to sort the keys of a hash stored within an object. If I create a user defined cmp function for my sort, it only gets the values $a and $b. Within this cmp function how do I access the $self of the object?
    # object $self={ hash_ref=>{item1=>'value1',item2=>'value2'} } # cmp funtion sub byvalue { #instead of $a<=>$b; #something like $self->{hash_ref}->{$a}<=>$self->{hash_ref}->{$b}; #how do I access $self in this function? } # object's sort function sub sort_hash_ref_keys_by_value { my $self=shift; my @keys=sort byvalue keys(%{$self->{hash_ref}}); }
Get fullpath of file using grep
2 direct replies — Read more / Contribute
by Anonymous Monk
on Jan 28, 2015 at 09:12
    Having the following line I get just the filename. How can I modify it to get all path including the file name?
    my $directory; @files = grep {-f "$directory/$_" && /\.dat$/i} readdir DIR;

    I would like to get: c:\temp\file1.dat

    Right now I just get: file1.dat

use sqlldr with perl
4 direct replies — Read more / Contribute
by gary16
on Jan 28, 2015 at 01:41

    hi,everybody I m from China.And I now have a strange problem.This day I have imported the oracle data with sqlldr. AND I used the system() to call the sqlldr.The data text is encoded by GB2312;The title of the data text also is .When I run the perl script,The perl create a new data text encoded by utf8 and replace the old one.Here is my code.Have anybody figured out what is happened??

    #!/usr/bin/perl -w use strict; use Net::FTP; use Date::Calc qw(:all); use Encode qw(:all); $filename="&#27979;&#35797;&#25991;&#26412;"; if($filename){ system(" sqlldr test1/123456 data=$filename control=importwz.ctl"); + }
Execution Error DBI usr/.lck
1 direct reply — Read more / Contribute
by Anonymous Monk
on Jan 27, 2015 at 12:03
    Hi all, I can connect to my database fine (I think) but can't execute the statements.
    The error I get is
    DBD::DBM::st execute failed: Execution ERROR: Cannot open /Users/action_type.lck: No such file or d +irectory (2) at /usr/local/ActivePerl-5.20/lib/DBI/DBD/SqlEngine.pm l +ine 1589. . [for Statement "select distinct action_type, description from action_ +type "] at LoadACtionType.pl line 11. Cannot execute the statement Execution ERROR: Cannot open /Users/action_type.lck: No such file or d +irectory (2) at /usr/local/ActivePerl-5.20/lib/DBI/DBD/SqlEngine.pm l +ine 1589.
    #!/usr/bin/perl use strict; use Data::Dumper; use DBI; my $dbh = DBI->connect('DBI:DBM:PRO','username','password') or die "Co +uldn't connect to the database ". DBI->errstr; my $sth_action = $dbh->prepare('select distinct action_type, descripti +on from action_type ') or die 'Cannot prepare the statement'. $dbh->e +rrstr; $sth_action->execute or die 'Cannot execute the statement '. $sth_acti +on->errstr;
    I couldn't figure out what I am doing wrong. Could someone help me please.
Excel how to open existing worksheet
4 direct replies — Read more / Contribute
by AtlasFlame
on Jan 27, 2015 at 06:40

    How to write to existing worksheet?

    use Excel::Writer::XLSX; my $workbook = Excel::Writer::XLSX->new( 'sample.xlsx' ); $worksheet = $workbook->add_worksheet("new"); $worksheet->write(2, 2, 'Name'); $worksheet = $workbook->add_worksheet("old"); $worksheet->write(2, 2, 'Name'); $worksheet = $workbook->add_worksheet("latest"); $worksheet->write(2, 2, 'Name');

    How to open worksheet "new" for write again?

Object accessors with unknown data
5 direct replies — Read more / Contribute
by Amblikai
on Jan 26, 2015 at 05:43

    Hi Monks! I have a quick question with regards to building objects. My search keeps bringing up references to Moose et al, but i don't want to use an external object system. I'm practicing OOP with bog standard perl for my own education!

    With that in mind, i'm writing a program where i'm not going to know the data i have when constructing the object. In the past i've always known the name and type of each attribute so i can construct accessors and methods to check that the attribute data is correct etc.

    Now i'm stuck though! How do you write accessors for unknown attributes?

    Thanks!

New Meditations
In place editing without reading further
2 direct replies — Read more / Contribute
by trippledubs
on Jan 27, 2015 at 14:22

    In transitioning Solaris Sparc sun4u to newer sun4v architecture we found that, sometimes, the image of the old server would not install onto the new server. The image file contains 20-30 text lines describing the system that was imaged and then the image itself. This file is quite large in some cases, takes a long time to create, and is made during an outage.

    The fix, once the image is already made, is quite janky. You need to append the string 'sun4v' into the the field 'content_architectures=' at the 20th or so. The other part is you do not want to read the rest of the file. Someone came up with this and saved the day. What do you think? Was there a better approach? Is there a way to do this using command line arguments that makes sense?

RFC: automating modular classes
1 direct reply — Read more / Contribute
by Arunbear
on Jan 26, 2015 at 08:44

    Minions is yet another OOP automation module, roughly similar to Moo, but which has the addtional goal of putting Encapsulation centre stage. I wrote it because after reading How Large Does Your Project Have To Be to Justify Using Moose? (especially the comments by tye and JavaFan), I became increasingly disillusioned with the Moo(se) way of OOP (essentially OOP with no Encapsulation).

    Here is a sample that implements the fixed size queue from Re^5: The future of Perl? (that sub-thread also illustrates limitations of the Moo way of OOP)
    package FixedSizeQueue; use Minions interface => [qw( push pop size )], construct_with => { max_items => { assert => { positive_int => sub { $_[0] =~ /^\d+$/ && $_[0 +] > 0 } }, }, }, implementation => 'FixedSizeQueue::Default', ; 1; package FixedSizeQueue::Default; use Minions::Implementation has => { q => { default => sub { [ ] } }, max_size => { init_arg => 'max_items', }, }, ; sub size { my ($self) = @_; scalar @{ $self->{$__q} }; } sub push { my ($self, $val) = @_; log_info($self); push @{ $self->{$__q} }, $val; if ($self->size > $self->{$__max_size}) { $self->pop; } } sub pop { my ($self) = @_; log_info($self); shift @{ $self->{$__q} }; } sub log_info { my ($self) = @_; warn sprintf "[%s] I have %d element(s)\n", scalar(localtime), $se +lf->size; } 1;
    And a sample of usage:
    % reply -I lib 0> use FixedSizeQueue 1> my $q = FixedSizeQueue->new(max_items => 3) $res[0] = bless( { '932db126-' => 'FixedSizeQueue::__Private', '932db126-max_size' => 3, '932db126-q' => [] }, 'FixedSizeQueue::__Minions' ) 2> $q->can $res[1] = [ 'pop', 'push', 'size' ] 3> $q->push($_) for 1 .. 3 [Mon Jan 26 12:01:53 2015] I have 0 element(s) [Mon Jan 26 12:01:53 2015] I have 1 element(s) [Mon Jan 26 12:01:53 2015] I have 2 element(s) $res[2] = '' 4> $q->pop [Mon Jan 26 12:02:09 2015] I have 3 element(s) $res[3] = 1 5> $q $res[4] = bless( { '932db126-' => 'FixedSizeQueue::__Private', '932db126-max_size' => 3, '932db126-q' => [ 2, 3 ] }, 'FixedSizeQueue::__Minions' ) 6> $q->push($_) for 4 .. 6 [Mon Jan 26 12:02:55 2015] I have 2 element(s) [Mon Jan 26 12:02:55 2015] I have 3 element(s) [Mon Jan 26 12:02:55 2015] I have 4 element(s) [Mon Jan 26 12:02:55 2015] I have 3 element(s) [Mon Jan 26 12:02:55 2015] I have 4 element(s) $res[5] = '' 7> $q $res[6] = bless( { '932db126-' => 'FixedSizeQueue::__Private', '932db126-max_size' => 3, '932db126-q' => [ 4, 5, 6 ] }, 'FixedSizeQueue::__Minions' ) 8> $q->log_info() Can't locate object method "log_info" via package "FixedSizeQueue::__M +inions" at reply input line 1. 9>
    Not all Moo features are supported (for this early release I've focused on those I actually use). Important differences from Moo include
    1. Attributes can be safely accessed inside classes without the overhead of a function call
    2. As a consequence of 1., attributes need not be exposed via methods (unless there is a good reason to do so).
    3. No need to clean up animal droppings
    4. Private subroutines via the mechanism shown in Re: OO - best way to have protected methods (packages)
    5. Class methods are "class only", and object methods are "object only"
    6. No compatibility with Moose
    Feedback is much appreciated.
New Cool Uses for Perl
Alphabetize in Esperanto
1 direct reply — Read more / Contribute
by aplonis
on Jan 30, 2015 at 10:21

    A hobby of mine is translating Jack Vance into Esperanto. And yes, I have permission for this! These I distribute for free in EPub format. In each ebook I like to embed a mini linked-in dictionary to help out beginners.

    I was wanting to re-organize some standalone EPubs into one omnibus EPub. I wanted one end-of-book dictionary instead of six end-of-chapter ones. That meant re-alphabetizing hundreds of anchor links. No big deal to do it in Perl...except that it's Unicode...and Esperanto. Here's how I did it.

New Monk Discussion
CB bug: cutting off text after TAB
1 direct reply — Read more / Contribute
by LanX
on Jan 29, 2015 at 06:34
    Since I'm using a mobile client, I'm regularly struggling with CB messages which only appear shortened in "normal" CB clients but normal in CB60.

    I looked into the HTML source ... could it be that "\t" is translated to an (unbalanced) "<\td>" in the cb sidebar and the rest is chopped?

    For reproduction, posting "test\ttest" produces:

    • <dd>test    test</dd> (i.e. the original input¹) in CB60
    • <span class='content'>test</td></tr> in CB sidebar
    • <span class="content">test</span> in "Chatterbox" nodelet
    edit
    • Possible workaround: pre-filtering input with s/\t/ /g
    • Reasoning: The way browsers handle TAB is too random and the CB isn't meant for horizontal formatting anyway
    • Alternative s/\t/ &nbsp; &nbsp;/g (updatet)

    Cheers Rolf

    PS: Je suis Charlie!

    ¹) discussion posts don't seem to preserve tab in inline <c>code</c>, the HTML here will show test &nbsp; &nbsp;test

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 romping around the Monastery: (4)
As of 2015-02-01 12:41 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My top resolution in 2015 is:

















    Results (263 votes), past polls