Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw

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
Constants lists in array slices
2 direct replies — Read more / Contribute
by LanX
on Jul 20, 2018 at 07:40
    The following code is surprising me in two ways:

    use strict; use warnings; use feature 'say'; use constant FL => 17,3,16; use constant FL2 => 22,4,13; my @row= "a".."z"; my @a = (" ") x 26; @a[17,3,16] = @row[22,4,13]; say "@a"; @a = (" ") x 26; @a[FL()] = @row[FL2]; say "@a";

    It seems like constant folding isn't happening at all!!!

    • I get a warning for FL2
      Scalar value @row[FL2] better written as $row[FL2] (ignoring that its a constant _list_)
    • Deparsing the code shows that FL and FL2 are called as functions
      @a[FL()] = @row[FL2()];
    Am I missing something?

    (This is perl 5, version 16,)

    Cheers Rolf
    (addicted to the Perl Programming Language :)
    Wikisyntax for the Monastery FootballPerl is like chess, only without the dice

Perl dictionary
5 direct replies — Read more / Contribute
by dideod.yang
on Jul 19, 2018 at 20:03
    Hi monks. I am perl & python lover.. recently I made many scripy using perl.. So I want to know many functions as much as possible. Cpan give me many information about modules.. but function is not.. Do you monks have nice website? or manual? about perl function??
site_perl files
2 direct replies — Read more / Contribute
by yaklichk0719
on Jul 19, 2018 at 17:00
    Can somebody please explain me what should be in the folder perl5.10/lib/site_perl/? I have perl 5.10.1 under centOS 6.6 and it does not have site_perl. Another package that I have been been trying to run requires the presence of this path perl5.10/lib/site_perl. Where can I download files for this site_perl? Please help me to figure this out. I really appreciate it.
I need help installing DBD:Oracle and DBD
1 direct reply — Read more / Contribute
by gandolf989
on Jul 19, 2018 at 09:33

    I am trying to install DBD:Oracle and DBD so that I can write a script to clean up some attachments with our primary database, and change the pointers to show that the attachments are gone. But I ran into an issue with the above packages. I tried the initial install using cpan. but I did not have the environment variables set, so it did not compile correctly. I would like to remove and reinstall the packages, or mostly just get them working. I do have an Oracle client on the server. But I will be connecting to another server for the database.

    Can someone point me in the right direction. The server is Redhat 6.8. Thanks

    $:~/ ./ Can't load '/usr/local/lib/perl5/site_perl/5.28.0/x86_64-linux/auto/DB +I/' for module DBI: /usr/local/lib/perl5/site_perl/5.28.0/x86_6 +4-linux/auto/DBI/ undefined symbol: PL_sv_immortals at /usr/li +b64/perl5/ line 200. at /usr/local/lib/perl5/site_perl/5.28.0/x86_64-linux/ line 284 +. BEGIN failed--compilation aborted at /usr/local/lib/perl5/site_perl/5. +28.0/x86_64-linux/ line 284. Compilation failed in require at /usr/local/lib/perl5/site_perl/5.28.0 +/x86_64-linux/DBD/ line 20. BEGIN failed--compilation aborted at /usr/local/lib/perl5/site_perl/5. +28.0/x86_64-linux/DBD/ line 20. Compilation failed in require at /home/oracle/scripts/purge_proddoc_sc +ript/ line 16. BEGIN failed--compilation aborted at /home/oracle/scripts/purge_proddo +c_script/ line 16 (#1) (F) The module you tried to load failed to load a dynamic extensio +n. This may either mean that you upgraded your version of perl to one that + is incompatible with your old dynamic extensions (which is known to h +appen between major versions of perl), or (more likely) that your dynami +c extension was built against an older version of the library that i +s installed on your system. You may need to rebuild your old dynamic extensions. Uncaught exception from user code: Can't load '/usr/local/lib/perl5/site_perl/5.28.0/x86_64-linux +/auto/DBI/' for module DBI: /usr/local/lib/perl5/site_perl/5.28 +.0/x86_64-linux/auto/DBI/ undefined symbol: PL_sv_immortals at + /usr/lib64/perl5/ line 200. at /usr/local/lib/perl5/site_perl/5.28.0/x86_64-linux/ line 284 +. BEGIN failed--compilation aborted at /usr/local/lib/perl5/site_perl/5. +28.0/x86_64-linux/ line 284. Compilation failed in require at /usr/local/lib/perl5/site_perl/5.28.0 +/x86_64-linux/DBD/ line 20. BEGIN failed--compilation aborted at /usr/local/lib/perl5/site_perl/5. +28.0/x86_64-linux/DBD/ line 20. Compilation failed in require at /home/oracle/scripts/purge_proddoc_sc +ript/ line 16. BEGIN failed--compilation aborted at /home/oracle/scripts/purge_proddo +c_script/ line 16. at /home/oracle/scripts/purge_proddoc_script/ +line 16. $:~/scripts/purge_proddoc_script > cat /etc/redhat-release Red Hat Enterprise Linux Server release 6.8 (Santiago)
    #!/usr/bin/perl use strict; use warnings; use diagnostics; package purge_proddoc_script; use Getopt::Std; # use Sys::Hostname; use POSIX qw(setuid setgid); use English; use Carp; use Cwd 'abs_path'; use DBD::Oracle qw(:ora_session_modes); use DBI; use File::Basename; use IO::Handle; use Log::Log4perl qw( :easy ); use Text::Diff; local $SIG{__WARN__} = \&Carp::cluck; $SIG{__DIE__} = sub { # return if $^S; # ignore die in an eval block # Get the actual caller for the "die" and not the wrapper local $Log::Log4perl::caller_depth; $Log::Log4perl::caller_depth++; LOGDIE($_[0]); }; # possible log values: DEBUG, INFO, WARN, ERROR, FATAL my $debug_level="INFO"; # my $error_mail_list=',, vkamins@aire,'; my $error_mail_list=''; # Unbuffer STDOUT and STDERR select STDERR; $| = 1; select STDOUT; $| = 1;
Migrating from Windows Server 2003
4 direct replies — Read more / Contribute
by cochise33
on Jul 19, 2018 at 08:26
    I'm running Perl on a Windows 2003 Server. The time has come to finally move to a more current version of Windows and I was wondering if you guys have any suggestions or warnings. Am I going to have any problems with Windows Server 12 or 16?

    Though I've used Perl for 20 years, I've only installed/reinstalled it or any packages like GD or some .pdf scripts a couple of times, so from that angle I'm a beginner.

    We also use MDaemon for the email part of what we do.

    Thanks for any help,

About personal function
3 direct replies — Read more / Contribute
by dideod.yang
on Jul 19, 2018 at 00:32
    Hi monks. I want to achieve using personal function with many arrays. Below script, I show you sample. According script, only print A... I want to print all of values(A B C) in @x. How can I achieve my personal function.
    my (@x,@y); @x =( "A" "B" "C"); @y =( "C" "D" "F"); &test(@x,@y): sub &test{ @test = @_[0]; print "@test\n"; }
Abuse of "or next" in expressions and "next" that returns value
5 direct replies — Read more / Contribute
by vr
on Jul 18, 2018 at 15:28

    Today I wrote a script, in which I preferred some logic expressed as 2nd fragment rather than the 1st:

    for ( $x .. $y ) { # some loop # ... skipped ... # fragment #1: next unless exists $gs_val-> { HT }; my $ht = $doc-> getValue( $gs_val-> { HT }); next unless exists $ht-> { Default }; my $df = $doc-> getValue( $ht-> { Default }); next unless exists $df-> { TransferFunction }; my $tf = $doc-> getValue( $df-> { TransferFunction }); next unless $tf eq 'Default; # ... skipped ... # fragment #2: next unless $doc-> getValue( $doc-> getValue( $doc-> getValue( $gs_val-> { HT } || next ) -> { Default } || next ) -> { TransferFunction } || next ) eq 'Default'; # ... skipped ... }

    As you see, I tried to improve the #1 with a few blank lines, but, to me, the #2 is more readable -- now, and I hope it will remain so in a year, when I have to try hard to remember what it all was about. Perhaps not everyone will agree.

    However, while experimenting and testing to see if such constructs are OK, I was surprised to find that Perl prefers even more unexpected form:

    >perl -we "for(\0,0){print${$_||next}}" 0 >perl -MO=Deparse -we "for(\0,0){print${$_||next}}" BEGIN { $^W = 1; } foreach $_ (\0, 0) { print ${next unless $_;}; } -e syntax OK >perl -we "for(\0,0){print${next unless $_}}" 0 >

    Looks like if "or next" is part of block that is supposed to return value, then Perl replaces it with "next unless" syntax. What's totally unexpected is that this "next unless" thing is actually valid and does return value.

    I can only guess that everything works the other way, in reality: "next unless" is optimized to "or next", therefore it returns value, and that for some strange reason B::Deparse shows "||next" as "next unless". That is only way this can be sane... Or is it not so? :)

SFTP for Perl on CygWin
2 direct replies — Read more / Contribute
by pcrowley203
on Jul 18, 2018 at 15:20

    I am running PERL 5.26.2 on CygWIN on Windows 10. I need to execute an sftp from Perl. The base installation of perl doesn't seem to include sftp, so I downloaded and tried to install Net::SFTP. This seems to require Net::SSH2, which I also downloaded and tried to install. That seems to require crypt.h. In attempt to get crypt.h into place, I downloaded and tried to install gcrypt-0.3. Surprisingly, that too requires (and does not include) crypt.h. So I downloaded and tried to install Crypt-GCrypt-1.26. That seems to require the library 'gcrypt'. So I downloaded and tried to install libgcrypt-1.8.3. That requires libgptg-error-1.9, which I downloaded and tried to install. That will not compile because the compiler does not like a long series of lines all of the form: { , "GPG_ERR_SOMETHING"}

    It doesn't seem like this should be so hard. Does anyone have any advice for me?

Histogram Creation
4 direct replies — Read more / Contribute
by Galahad
on Jul 18, 2018 at 11:31

    I have an array of 100 floating point values. I rounded the values to the tenths place in order to create more matches on my histogram. I was wondering how to get these values in an array and put them into a histogram. I have previously checked other posts on PerlMonks, but I end up with errors in my code. I am relatively new to programming in general and I might lack certain programming etiquette or syntax.

    use strict; use warnings; use Data::Dumper; use 5.010; use GD::Graph::histogram; use YAML; use CGI ':standard'; sub main { my $input = 'distance.txt'; unless(open(INPUT, $input)) { die "\nCannot open input\n"; } my @data; while(my $line = <INPUT>) { chomp $line; my @rounded = sprintf ("%.1f\n", $line); push @data, @rounded; my ( $filename, @data ) = @_; my $graph = new GD::Graph::histogram(400,600); $graph->set( y_label => 'Count', x_label => 'Distances', title => 'Histogram', x_labels_vertical => 1, bar_spacing => 0, shadow_depth => 1, shadowclr => 'dred', transparent => 0, ) or warn $graph->error; my $image = $graph->plot(\@data) or die $graph->error; open( IMG, '>' . $filename ) or die $!; binmode IMG; print IMG $image->png; } } main();

    These are the error messages I have been receiving.

    Subroutine main::Dump redefined at /System/Library/Perl/5.18/ li +ne 308. Use of uninitialized value $min in subtraction (-) at /Library/Perl/5. +18/GD/Graph/ line 110, <INPUT> line 1. Use of uninitialized value $max in subtraction (-) at /Library/Perl/5. +18/GD/Graph/ line 110, <INPUT> line 1. Use of uninitialized value $max in numeric le (<=) at /Library/Perl/5. +18/GD/Graph/ line 118, <INPUT> line 1. Use of uninitialized value $upper in numeric le (<=) at /Library/Perl/ +5.18/GD/Graph/ line 118, <INPUT> line 1. Use of uninitialized value $lower in addition (+) at /Library/Perl/5.1 +8/GD/Graph/ line 119, <INPUT> line 1. Use of uninitialized value $max in numeric le (<=) at /Library/Perl/5. +18/GD/Graph/ line 122, <INPUT> line 1. Use of uninitialized value in string eq at /Library/Perl/5.18/GD/Graph +/ line 42, <INPUT> line 1. Use of uninitialized value in subtraction (-) at /Library/Perl/5.18/GD +/Graph/ line 59, <INPUT> line 1. Use of uninitialized value in addition (+) at /Library/Perl/5.18/GD/Gr +aph/ line 59, <INPUT> line 1. Use of uninitialized value $filename in concatenation (.) or string at + /Users/Joshua/eclipse-workspace/PlottingPoints/Histogram line 40, <I +NPUT> line 1. No such file or directory at /Users/Joshua/eclipse-workspace/PlottingP +oints/Histogram line 40, <INPUT> line 1.

    2018-07-20 Athanasius added code tags around error messages

Tk question: Dynamically disable radiobutton choices
1 direct reply — Read more / Contribute
by chafelix
on Jul 18, 2018 at 08:32

    I am creating a dialog for comparing two files. For matching purposes, the user needs to tell the program how to handle fields (for instance excel columns). Thus, the interface needs to a) specify that column i in file A corresponds to column j in file B and b) whether these matching columns are First name, last name or neither. This is important because an exact match will be performed for last name, but a first digit match will be performed on first name, e.g. 'Tim' vs. 'Timothy' should be a match. So I am adding a radiobutton for each column with the choices 'First, last and no name'. The trick is that once there is only one 'First name' and 'last name' column, so once the user has specified that this is a first name, this option should not be available to other columns.

    Apart from this, which I am not sure how to do there seem to be 2 more issues with the code below: First, the Radiobutton part seems to give a strange message Second, the Browseentry appears to be filled in the box instead of the expanding list

    use Tk; use Tk::BrowseEntry; my $top=MainWindow->new(); $top->title("Match Specifications"); my @names=('Last Name','First Name','Not a name'); my $value=2; #no name is default my $indicator=0;#start looping over names, indicator=0=>Last, 1=>first +, 2=>no name %main::A={1=>['Tim','Doe','other_info1'], 2=>['Mick','Lu','other_info_2']}; %main::B={1=>['Timothy','Doe','other_info1','moreinfo1'], 2=>['Michail','Lu','other_info_2','moreinfo2']}; $main::headers[0]=['F','L','O']; $main::headers[1]=['M','J','P','JJ']; my $fr=$top->Frame(-relief=>'sunken')->pack(-anchor=>'nw',-fill=>'both +'); my $counter0=0; my @selector; my $col=0;my $colshow=0; my @keys00=sort keys %main::A;my @keys0=(); push @keys0,$keys00[0]; push @keys0,$keys00[1]; my @keys200=sort keys %main::B; my @keys20=(); push @keys20,$keys200[0]; push @keys20,$keys200[1]; my $row1=0; foreach my $el(@{$main::headers[0]}){ my $row=0; $selector[$col]=$fr->Scrolled('BrowseEntry',-label=>$el,-variable=>\$ +main::matchhash{$col}, -browsecmd=>[\&show,$el,\@headers2,\@keys200]); my $h2cnt=0 ; my $h2cntall=0; ##### this is the part that must be repopulated dynamically foreach my $el2(@{$main::headers[1]}){ $selector[$col]->insert("end", $el2); $h2cnt++; $h2cntall++;}#foreach el2 $selector[$col]->grid(-row=>$row,-column=>$colshow); #### end of part to repopulate dynamically $row++; #row nonzero $fr->Label(-text=>$main::A{$keys0[0]}->[$col])->grid(-row=>$row,-colum +n=>$colshow);$row++; $fr->Label(-text=>$main::A{$keys0[1]}->[$col])->grid(-row=>$row,-colum +n=>$colshow);$row++; foreach my $name(@names){ $fr->RadioButton( -text=>$name,-variable=>\$indicator,-value=>$value) +->grid(-row=>$row, -column=>$colshow); $row++;} $colshow++; $row1=$row; $col++;}#foreach el ####### $fr->Button(-text=>'Run',-bg=> 'firebrick1' ,-command=>sub{ } ) +->grid(-row=>$row1,-column=>1); &MainLoop(); sub show{my $el=shift; my $rheaders=shift; my $rkeys=shift; }
Syntax Perl Version support $c = () = $a =~ /\./g
6 direct replies — Read more / Contribute
by h2
on Jul 17, 2018 at 14:02

    Hi Perl Monks, I have what is hopefully a simple question, but one I have been unable to search for due to the odd syntax of the below.

    The program I'm working on has a core requirement to work on older systems, and has a cutoff of Perl 5.008 (selected because Redhat mid 2000s release was quite late to support 5.010) or newer, though that could change in the future to either a touch earlier version, or a touch later version (but certainly never newer as max oldest than 5.010). As an aside, so far Perl 5.x has far exceeded my wildest expectations in this regard, the program is in fact working on everything! No matter how weird or arcane.

    my $a='3.4.4'; my $c = () = $a =~ /\./g; print "$c\n"

    However, my question is this: when did Perl begin supporting this type of structure?

    $c = () = $a =~ /\./g

    I've come across this several times, and I'm allured by it, it calls to me, but I have to be careful using structures that could trigger warnings or failures in old systems.

    I'd actually like to significantly expand my use of this type of structure, so besides this specific example, can anyone point me to the right search terms that describe it, that's multiple assignments of some value generated on the right side of the items? And also I believe various items that could be in the second position, (), though I'm not positive about that. And has this support been consistent since version Are there various types of this assignment that have been introduced earlier or later?

    I have the big Larry Walls Perl book, but I don't know what this is called to begin learning more about it, and what variants will be safe to use.

Using Perl XS in 5.26 fails with error loadable library and perl binaries are mismatched
3 direct replies — Read more / Contribute
by jobinjoseph121
on Jul 17, 2018 at 08:35

    We have build Perl 5.26.1 from source and used the same Perl to create a perlmodule.c file from an XS file perlmodule.xs. But when we try to execute this C code, we get the following error.
    ../perlmodule.c: loadable library and perl binaries are mismatched (got handshake key 0xe280080, needed 0xde00080)

    Previously we were using Perl 5.16 and there were no issues. Could you please let us know whether we need to rewrite the XS module for Perl 5.26. Currently we are using the same XS module which is used in Perl 5.16. I am not sure if that is creating the issue here.

    We are generating the .c files with following command.
    perl ExtUtils/xsubpp -typemap typemap -typemap ExtUtils/typemap perlmodule.xs > perlmodule.cpp

    Following is the configuration details.

    Summary of my perl5 (revision 5 version 26 subversion 1) configuration +: Platform: osname=linux osvers= archname=x86_64-linux-thread-multi uname='linux #1 mon jul 3 18:25:39 utc 2006 +x86_64 x86_64 x86_64 gnulinux ' config_args='-d -s -e -U uselargefiles -U use64bitint -U usemorebi +ts -D usemultiplicity -D usethreads -D prefix=/opt/perl/a -D installu +srbinperl=no -D useshrplib -D ccflags= -D -D man1d +ir= -D perladmin=none -D pager=/usr/bin/less -D otherlibdirs=/opt/pe +rl/a/lib/site_perl' hint=recommended useposix=true d_sigaction=define useithreads=define usemultiplicity=define use64bitint=define use64bitall=define uselongdouble=undef usemymalloc=n default_inc_excludes_dot=define bincompat5005=undef Compiler: cc='cc' ccflags ='-D_REENTRANT -D_GNU_SOURCE -fno-strict-aliasing -pipe -f +stack-protector -I/usr/local/include -D_FORTIFY_SOURCE=2' optimize='-O2' cppflags='-D_REENTRANT -D_GNU_SOURCE -fno-strict-aliasing -pipe -f +stack-protector -I/usr/local/include' ccversion='' gccversion='4.1.0 (SUSE Linux)' gccosandvers='' intsize=4 longsize=8 ptrsize=8 doublesize=8 byteorder=12345678 doublekind=3 d_longlong=define longlongsize=8 d_longdbl=define longdblsize=16 longdblkind=3 ivtype='long' ivsize=8 nvtype='double' nvsize=8 Off_t='off_t' lseeksize=8 alignbytes=8 prototype=define Linker and Libraries: ld='cc' ldflags =' -fstack-protector -L/usr/local/lib' libpth=/usr/local/lib /usr/lib64/gcc/x86_64-suse-linux/4.1.0/../.. +/../../x86_64-suse-linux/lib /usr/lib /lib/../lib64 /usr/lib/../lib64 + /lib /lib64 /usr/lib64 /usr/local/lib64 libs=-lpthread -lnsl -lgdbm -ldb -ldl -lm -lcrypt -lutil -lc -lgdb +m_compat perllibs=-lpthread -lnsl -ldl -lm -lcrypt -lutil -lc so=so useshrplib=true gnulibc_version='2.4' Dynamic Linking: dlsrc=dl_dlopen.xs dlext=so d_dlsymun=undef ccdlflags='-Wl,-E -Wl,-rpath,/opt/perl/a/lib/5.26.1/x86_64-linux-t +hread-multi/CORE' cccdlflags='-fPIC' lddlflags='-shared -O2 -L/usr/local/lib -fstack-protector' Characteristics of this binary (from libperl): Compile-time options: HAS_TIMES MULTIPLICITY PERLIO_LAYERS PERL_COPY_ON_WRITE PERL_DONT_CREATE_GVSV PERL_IMPLICIT_CONTEXT PERL_MALLOC_WRAP PERL_OP_PARENT PERL_PRESERVE_IVUV USE_64_BIT_ALL USE_64_BIT_INT USE_ITHREADS USE_LOCALE USE_LOCALE_COLLATE USE_LOCALE_CTYPE USE_LOCALE_NUMERIC USE_LOCALE_TIME USE_PERLIO USE_PERL_ATOF USE_REENTRANT_API Built under linux

    Thanks and Regards,
    Jobin Joseph
New Meditations
use Memoize;
2 direct replies — Read more / Contribute
by Anonymous Monk
on Jul 16, 2018 at 15:18
    I was porting a script to a module and noticed it kept getting slower. The script could initialize its expensive data structure once at the top and be done with it, but in order to encapsulate, the module was calling the function several times. I remembered the core module Memoize and added one line to the top of the program and now it runs fast again, 4x faster than without Memoize!
    use Memoize; memoize('some_sub');
    Only 1.5 seconds to start a program that was taking 6 seconds!
Log In?

What's my password?
Create A New User
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (10)
As of 2018-07-20 12:58 GMT
Find Nodes?
    Voting Booth?
    It has been suggested to rename Perl 6 in order to boost its marketing potential. Which name would you prefer?

    Results (431 votes). Check out past polls.