Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
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
Strange behavior with List::Util qw{first} on perl >= 5.20
5 direct replies — Read more / Contribute
by papioko
on May 26, 2015 at 16:18
    Hi monks Today when a try to run some of my work code on perl 5.20 (before that i used 5.18) i encountered a strange behavior that i can't understand. The Sample code is:
    #!/usr/bin/env perl use strict; use warnings; use List::Util qw{ first }; my %hash = ( ASD => 1, ZXC => 2, QWE => 3, TYU => 4 ); my $val = "qwe"; if(my $res = first { lc $_ eq $val } keys %hash) { print "Found: $res\n"; } else { print "Not found\n"; };
    On perl version prior 5.20 result will be "Found: QWE" (as i expected), but when i run this code on perl 5.20 and beyound, result will be "Found: qwe". What is that ? Bug? Or i missed something ?
Permission denied to module
2 direct replies — Read more / Contribute
by zdavek
on May 26, 2015 at 15:26

    We upgraded from perl 5.14.2 to perl 5.20.2 and updated most of our modules this last weekend. Our programming staff have no problems running anything but our end users are all getting messages like:

    Can't locate MIME/Lite.pm:   Permission denied at /path_to_script/msg_send.pl line 18.
    BEGIN failed--compilation aborted at /path_to_script/msg_send.pl line 18.
    
    I'm guessing something has the wrong perms but cannot track it down. MIME::Lite is installed and the permissions are:
    drwxr-sr-x  3 root common     96 May 23 12:49 lib/site_perl/
    drwxr-sr-x 56 root common   8192 May 24 11:11 lib/site_perl/5.20.2/
    drwxr-sr-x  2 root common   8192 May 23 13:16 lib/site_perl/5.20.2/MIME/
    -r--r--r--  1 root common 105117 Nov  3  2013 lib/site_perl/5.20.2/MIME/Lite.pm
    
    I'll note that every normal user of our system is in the common group. Also end users have no problems if no modules are used.

DBD::Oracle installation problem - "Can't load Oracle.dll" / "Exec format error"
1 direct reply — Read more / Contribute
by topbanana
on May 26, 2015 at 15:07
    Hi, I'm trying to install DBD::Oracle on cygwin. I am only a beginner with perl, and the whole cpan/make/build thing is entirely new to me also. So to the problem. in cpan I run: cpan[2]> install DBD::Oracle and a load of guff is spewed out. All is well until the following lines:
    t/00versions.t ................ Can't load '/home/J/.cpan/build/DBD-Or +acle-1.74-nSxxhX/blib/arch/auto/DBD/Oracle/Oracle.dll' for module DBD +::Oracle: Exec format error at /usr/ lib/perl5/5.14/i686-cygwin-threads-64int/DynaLoader.pm line 190. at t/00versions.t line 10. Compilation failed in require at t/00versions.t line 10. BEGIN failed--compilation aborted at t/00versions.t line 10. # Looks like your test exited with 8 before it could output anything. t/00versions.t ................ Dubious, test returned 8 (wstat 2048, +0x800)
    Now, I don't really know what I'm doing here because it's all new to me, but I've had a go and so far all I can say is that /home/J/.cpan/build/DBD-Oracle-1.74-nSxxhX/blib/arch/auto/DBD/Oracle/Oracle.dll does exist:
    J-PC:J >ls -l /home/J/.cpan/build/DBD-Oracle-1.74-nSxxhX/blib/arch/aut +o/DBD/Oracle/Oracle.dll -rwxr-xr-x 1 J None 721811 May 26 15:07 /home/J/.cpan/build/DBD-Oracle +-1.74-nSxxhX/blib/arch/auto/DBD/Oracle/Oracle.dll
    The failing code is in .cpan/build/DBD-Oracle-1.74-nSxxhX/t/00versions.t:
    use DBD::Oracle qw/ ORA_OCI /;
    which is called by (or perhaps vice versa) the following code in /usr/lib/perl5/5.14/i686-cygwin-threads-64int/DynaLoader.pm
    my $libref = dl_load_file($file, $module->dl_load_flags) or croak("Can't load '$file' for module $module: ".dl_error());
    So that module exists. Can anybody tell me what I can do here? By the way, I don't know what it does but I saw somebody somewhere mention ldd to check a library for links or something, so I did that:
    J-PC:J >ldd /home/J/.cpan/build/DBD-Oracle-1.74-nSxxhX/blib/arch/auto/ +DBD/Oracle/Oracle.dll ntdll.dll => /cygdrive/c/Windows/SysWOW64/ntdll.dll (0x779d000 +0) kernel32.dll => /cygdrive/c/Windows/syswow64/kernel32.dll (0x7 +72f0000) KERNELBASE.dll => /cygdrive/c/Windows/syswow64/KERNELBASE.dll +(0x75810000) ??? => ??? (0x6f640000)
    There's nothing that I can see in the cpan output that says a variable doesn't exist. Can anybody help me here? Any help is greatly appreciated as I'm totally in the dark. Thanks. ===================================================== EDIT: ===================================================== Here is some more of the cpan output, which suggests that the shared library isn't where it ought to be (although as I have said, it is where it is supposed to be, or at least, something is there):
    t/000-report-versions-tiny.t .. ok t/00versions.t ................ Can't load '/home/J/.cpan/build/DBD-Or +acle-1.74-nSxxhX/blib/arch/auto/DBD/Oracle/Oracle.dll' for module DBD +::Oracle: Exec format error at /usr/ lib/perl5/5.14/i686-cygwin-threads-64int/DynaLoader.pm line 190. at t/00versions.t line 10. Compilation failed in require at t/00versions.t line 10. BEGIN failed--compilation aborted at t/00versions.t line 10. # Looks like your test exited with 8 before it could output anything. t/00versions.t ................ Dubious, test returned 8 (wstat 2048, +0x800) Failed 2/2 subtests t/01base.t .................... 1/6 # Failed test 'install_driver' # at t/01base.t line 24. # got: 'install_driver(Oracle) failed: Can't load '/home/J/.c +pan/build/DBD-Oracle-1.74-nSxxhX/blib/arch/auto/DBD/Oracle/Oracle.dll +' for module DBD::Oracle: Exec forma t error at /usr/lib/perl5/5.14/i686-cygwin-threads-64int/DynaLoader.pm + line 190. # at (eval 11) line 3. # Compilation failed in require at (eval 11) line 3. # Perhaps a required shared library or dll isn't installed where expec +ted # at t/01base.t line 21. # ' # expected: '' # Failed to load Oracle extension and/or shared libraries # Looks like you failed 1 test of 6.
Do i need really to update perl 5 to perl 6?
7 direct replies — Read more / Contribute
by Muskovitz
on May 26, 2015 at 12:13
    Hi Monks! is it a must to update perl 5 to perl 6? There's a lot of changes in Perl 6 and also some said that learning perl 6 is like learning another language do i need really to update and learn perl 6 for future developing in perl?
Passing a file handle and two arrays to a function by reference.
5 direct replies — Read more / Contribute
by subr01
on May 26, 2015 at 09:28

    How to pass a filename or a filehandle, two arrays to a function? I have done this:

    open INPUT,"$old"; my (@arrayold,@arraynew); myfunc(*INPUT,\@arrayold,\@arraynew) sub myfunc { my ($file,@array1,@array2) = @_ ; my $j = 0; my $k = 0; while (my $line = <$file) { my($word1,$word2) = split(",",$line); $array[$j++] = $word1; $array[$k++] = $word2; } }

    As you can guess, my function reads a file which has info like:

    1,//http:abcd 2,//http:avcd

    into two arrays one containing the number and the other containing the address. I am only getting blank arrays. Am I passing it wrong? Kindly help.

Using File::Share and PerlApp
1 direct reply — Read more / Contribute
by ali0sha
on May 26, 2015 at 08:17

    I'm trying to create an application which uses a manifest.xml. Now in order to access this both while developing and using it, we can use File::Share as recommended in Using File::ShareDir in development, but I also want to be able to access it when it's packaged using PerlApp. Is my only recourse something like this? It seems inelegant, to say the least...

    use FindBin '$Bin'; use File::Share 'dist_dir'; my $result; # Get the version bound by PerlApp $result = PerlApp::extract_bound_file("manifest.xml") if defined $PerlApp::VERSION; # Get the distribution's shared files directory $result ||= dist_dir('App-SFDC', 'manifest.xml');
foreach vs. while inside a directory tranversing subroutine
3 direct replies — Read more / Contribute
by TomJerry
on May 25, 2015 at 23:25

    This is a very simple test program for traversing a directory.

    I got two versions, the only difference is listing a directory --- one uses while(<*>), the other uses foreach(). Both should work.

    However, strange things happened. The 1st is always trapped in a infinite looping, while the 2nd works well. Why?

    # 1st form sub traverse_file { my $dir = shift; if (-d $dir) { while (<$dir/*>) { traverse_file($_); } } else { print "$dir\n"; } }
    # 2nd form sub traverse_file { my $dir = shift; if (-d $dir) { my @subdirs=<$dir/*>; foreach (@subdirs){ traverse_file($_); } } else { print "$dir\n"; } }
strangeness with prototypes and 'logical defined or'?
4 direct replies — Read more / Contribute
by ed_hoch
on May 25, 2015 at 06:49

    on 5.16.2, why does

    perl -ce 'sub foo (&) {} foo {;} || 7'

    work just fine, while

    perl -ce 'sub foo (&) {} foo {;} // 7'

    gives compilation errors? this doesn't seem like a shell-escaping issue; if I copy it into a separate file, the same thing holds.

    Thanks,

    Ed

    Thanks everyone for pointing out that the interpreter's recognizing the ambiguity with the "empty pattern"!
Appending a single Scalar after a match
2 direct replies — Read more / Contribute
by SavannahLion
on May 25, 2015 at 04:36

    So I found myself updating an old script (parses oodles of HTML files). and unknowingly introduced a subtle bug.
    Here is a condensed version of the original code. The match is irrelevant.

    my $k = ''; # A bunch of junk happens to this scalar before this point my $t = "\ttest \n \n"; ($k) = $t =~ /^\s*(.*?)\s*$/g; print $k ."\n";

    Without thinking, I made a subtle change.
    my $k = ''; # A bunch of junk happens to this scalar before this point my $t = "\ttest \n \n"; ($k) .= $t =~ /^\s*(.*?)\s*$/g; print $k ."\n";

    A '1' kept getting shoved into $k. Goes without saying that I spend hours chasing this new bug down until I realized I was trying to use a list in a scalar context. So after much cursing I went and fixed the bug like thus.
    my $k = ''; # A bunch of junk happens to this scalar before this point my $t = "\ttest \n \n"; $t =~ /^\s*(.*?)\s*$/g; ($k) .= $1; print $k ."\n";

    After a fashion, I got to thinking. Is there a way to get it back to a one liner again and still append the value of $1 to $k? I tried several variations on the original but can't seem to work out a solution. My thought was something along the lines of:
    my $k = ''; # A bunch of junk happens to this scalar before this point my $t = "\ttest \n \n"; ($k) .= $($t =~ /^\s*(.*?)\s*$/g)[0]; print $k ."\n";

    I tried several variations but I can't quite seem to get it right. My gut says it should be feasible, but my brain can't quite put it together
    Any ideas?

RFC: Why Perl v5.20.2 is available for download and v5.18.2 is available on the LinuxOS repositories
3 direct replies — Read more / Contribute
by thanos1983
on May 24, 2015 at 18:37

    Hello monks,

    Today I was given the opportunity based on a really nice question on the forum Another 64-bit Perl bug. Is it fixed post 5.18? to read and found that strings longer than 2**31 bytes on 64-bits OS can only be processed in Perl v5.20.0 and afterwards, more information about that can be found here Better 64-bit support.

    allowing Perl arrays to hold more than 2**31 elements, if you have the memory available

    So my question is, since Perl v5.20.2 is a better and stable version, why the repositories still have the v5.18.2?

    Thank you for your time and effort replying to my question in advance.

    Seeking for Perl wisdom...on the process of learning...not there...yet!
Another 64-bit Perl bug. Is it fixed post 5.18?
4 direct replies — Read more / Contribute
by BrowserUk
on May 24, 2015 at 07:38

    The regex engine silently fails to process strings longer than 2**31 bytes on 64-bits perl's upto and including v5.18.4:

    $x = "the quick brown fox\n"; $x x= 107374182; print length $x;; 2147483640 + ### 8 bytes less than 2^31. $n=0; ++$n while $x =~ m[^.*$]mg; print $n;; + ### finds all the lines. 107374182 $x .= "the straw that broke the camel's back\n"; print length $x;; + ### Add another line that pushes the length a few bytes over 2^ +31 2147483678 $n=0; ++$n while $x =~ m[^.*$]mg; print $n;; + ### and it silently fails to find any of them. 0

    Before I raise a perlbug, does this fail on later perls? Does it fail on non-windows perls?

    If its been fixed already, which version did the fix happen?

    Thanks.


    With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority". I'm with torvalds on this
    In the absence of evidence, opinion is indistinguishable from prejudice. Agile (and TDD) debunked
Threads From Hell #2: How To Search A Very Huge File [SOLVED]
4 direct replies — Read more / Contribute
by karlgoethebier
on May 23, 2015 at 16:04

    Hi all,

    for learning purposes i started to think about how to parse search a very huge file using the multithreading capabilities of Perl.

    As i like trivial examples, i started out with something trivial and created some huge file at first:

    karls-mac-mini:monks karl$ ls -hl very_huge.file -rw-r--r-- 1 karl karl 2,0G 23 Mai 19:38 very_huge.file karls-mac-mini:monks karl$ tail very_huge.file Lorem ipsum kizuaheli Lorem ipsum kizuaheli Lorem ipsum kizuaheli Lorem ipsum kizuaheli Lorem ipsum kizuaheli Lorem ipsum kizuaheli Lorem ipsum kizuaheli Lorem ipsum kizuaheli Lorem ipsum kizuaheli nose cuke karl karls-mac-mini:monks karl$ wc -l very_huge.file 100000001 very_huge.file

    By RTFM i figured out this using MCE::Grep:

    #!/usr/bin/env perl use strict; use warnings; use MCE::Grep; use Data::Dump; use Time::HiRes qw (time); MCE::Grep::init( { max_workers => 4 } ); my $start = time; open( my $fh, '<', 'very_huge.file' ); my @result = mce_grep { /karl/ } $fh; close $fh; printf "Took %.3f seconds\n", time - $start; dd \@result; __END__ karls-mac-mini:monks karl$ ./huge.pl Took 29.690 seconds ["nose cuke karl\n"]

    Good old grep performs very much better easily:

    karls-mac-mini:monks karl$ time grep karl very_huge.file nose cuke karl real 0m2.563s user 0m2.176s sys 0m0.309s

    I don't know if this trivial exercise is peinlich parallel, but i'm wondering how to:

    • do this "by hand" (without using MCE::Grep)
    • ...and improve the performance

    Thank you very much for any hint and best regards,

    Update:

    Edit: Striked out nonsense.

    Ouch! Perhaps more RTFM would have helped:

    PID Prozessname Benutzer % CPU Physikal. Speic Virt. S +peicher 1065 perl karl 12,7 10,3 MB 2, +33 GB 1068 perl karl 83,7 3,9 MB 2, +33 GB 1069 perl karl 84,6 3,9 MB 2, +33 GB 1070 perl karl 83,5 3,9 MB 2, +33 GB 1071 perl karl 84,0 3,9 MB 2, +33 GB

    Edit 2: Renamed the thread

    Update 3: Many thanks to marioroy and BrowserUk for their patience and their contributions to this interesting thread.

    Karl

    «The Crux of the Biscuit is the Apostrophe»

New Meditations
Perl monks vs other sites
1 direct reply — Read more / Contribute
by f77coder
on May 23, 2015 at 23:09
    Hello All,

    I wasn't sure where to post this, so apologies if this is not the place.

    I wanted to say how great Perl Monks is at helping out noobs compared with knuckle dragging neanderthals at place like stack overflow. People here are generally orders of magnitude nicer.

    Cudos to the site.

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 wandering the Monastery: (15)
As of 2015-05-27 12:38 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    In my home, the TV remote control is ...









    Results (532 votes), past polls