Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
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
Checking Variable for Not Null
5 direct replies — Read more / Contribute
by dirtdog
on May 27, 2015 at 10:49

    Hi Monks, Can anyone tell me if the following 2 statements would be equivalent as far as checking that a variable is not null.

    next unless ! $ex_date; next unless !defined($ex_date);

    Basically, i would like to go to the next record if the variable $ex_date is null. any help is much appreciated. thanks Tony

Data Move
2 direct replies — Read more / Contribute
by PilotinControl
on May 27, 2015 at 09:36

    Good Morning Monks!
    The sub routine code posted below does what I want except it copies all lines over to a new file instead of one line based on its unique key. What the code does is remove a line from one file however it copies All lines instead of the updated line to the new file. What am I missing? The update code works as it updates a record. What my focus is on is moving that updated line from the original cardata.txt to the updatedcardata.txt Thanks in advance!

    use strict; use warnings; use File::Copy;

    UPDATE
    This is the code that calls the sub below just for clarification

    my ($rcid,$car,$owner); print "\nSelect Value To Edit: "; chomp(my $enter=<STDIN>); if ($enter) { if ($enter) { print "\nEnter New Value: "; chomp(my $new_value=<STDIN>); if ($new_value) { if ($enter == 1) { update_record_now($rcid,$new_value,$owner); } elsif ($enter == 2) { update_record_now($rcid,$car,$new_value); } } } } sub update_record_now { my ($rcid,$car,$owner) = @_; open my $infile, '<','cardata.txt' or die $!; open my $outfile, '>', 'cartemp.txt' or die $!; while (<$infile>) { s/^$rcid\:.*/$rcid\:$car\:$owner/g; print $outfile $_; } my $pinfile = "cardata.txt"; my @data; { open(my $data_file_handle, '<', "$pinfile") or die("Can't open file: $ +pinfile"); @data = <$data_file_handle>; close($data_file_handle); close $pinfile; } chomp(@data); open(my $out_file_handle,'>', $pinfile) or die("Can't open file: $pinf +ile"); foreach my $line_from_file ( @data ) { my @field = split( /\:/, $line_from_file ); next if( $field[0] == $rcid ); print $out_file_handle $line_from_file, "\n"; } close $pinfile; close $out_file_handle; close $infile; close $outfile; move 'cartemp.txt', 'updatedcardata.txt'; } __DATA__ 1:Chevy:Bob 2:Ford:Tom 3:Fiat:Dave
How smart is 'seek $fh, $pos, 0'?
3 direct replies — Read more / Contribute
by Monk::Thomas
on May 27, 2015 at 08:36
    Hello

    If the filehandle is at position X and I want to go to position Y: Does 'seek $fh, $pos, 0' rewind to the begin and then skip ahead to $pos or does it optimize automatically and just moves from the current position to the intended position?

    In other words:

    a) Does it actually make a difference if I calculate the difference and use 'seek $fh, $delta, 1' or if I simply use 'seek $fh, $abs, 0'?

    b) Is there a difference between going back (Y<X) and skipping ahead (Y>X)?

Heap structure for lookup?
5 direct replies — Read more / Contribute
by BrowserUk
on May 27, 2015 at 04:13

    If you have 150e6 64-bit values to store for efficient lookup, perl's hashes(~14GB) and arrays(~5GB) are very expensive of memory, and a bitmap is out of the question.

    The array is feasible, but to do lookups (binary search) requires it be sorted, and that's quite expensive for this size of array, even when using one of salva's in-place, XS modules.

    The values are generated at runtime, and discarded at program end, so DBs are pointless. Even an in-memory sqlite DB which stores numbers as strings is off the cards.

    I'm going to have to drop into Inline::C for this for both space and performance reasons.

    A straight C array of 64-bit ints is ~1.2GB which is fine; but again sorting it so I can to O(logN) lookups is expensive.

    I keep thinking about heaps (or Beaps or B-heaps or other variations), structures that "order" the values as they are inserted; but once built, can any of them be used for efficient (O(logN) or better) lookup?

    Wikipedia isn't giving me much on the subject of lookup/searches.


    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
Strange behavior with List::Util qw{first} on perl >= 5.20
6 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"!
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 contemplating the Monastery: (5)
As of 2015-05-28 05:10 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

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









    Results (548 votes), past polls