Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
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
occurence of repeated numbers group
4 direct replies — Read more / Contribute
by satya02
on Jul 19, 2018 at 09:42

    Please help me in finding occurence of repeated numbers group.

    Example input:

    1 2 5 9

    1 2 5 10

    4 5 10 12

    5 9 10 11

    output:-

    1 2 repated 2 times

    2 5 repeated 2 times

    5 10 repeated 3 times

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 11.2.0.4 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

    $:~/ ./runMyPerlScript.pl Can't load '/usr/local/lib/perl5/site_perl/5.28.0/x86_64-linux/auto/DB +I/DBI.so' for module DBI: /usr/local/lib/perl5/site_perl/5.28.0/x86_6 +4-linux/auto/DBI/DBI.so: undefined symbol: PL_sv_immortals at /usr/li +b64/perl5/DynaLoader.pm line 200. at /usr/local/lib/perl5/site_perl/5.28.0/x86_64-linux/DBI.pm line 284 +. BEGIN failed--compilation aborted at /usr/local/lib/perl5/site_perl/5. +28.0/x86_64-linux/DBI.pm line 284. Compilation failed in require at /usr/local/lib/perl5/site_perl/5.28.0 +/x86_64-linux/DBD/Oracle.pm line 20. BEGIN failed--compilation aborted at /usr/local/lib/perl5/site_perl/5. +28.0/x86_64-linux/DBD/Oracle.pm line 20. Compilation failed in require at /home/oracle/scripts/purge_proddoc_sc +ript/purge_proddoc_script.pl line 16. BEGIN failed--compilation aborted at /home/oracle/scripts/purge_proddo +c_script/purge_proddoc_script.pl 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/DBI.so' for module DBI: /usr/local/lib/perl5/site_perl/5.28 +.0/x86_64-linux/auto/DBI/DBI.so: undefined symbol: PL_sv_immortals at + /usr/lib64/perl5/DynaLoader.pm line 200. at /usr/local/lib/perl5/site_perl/5.28.0/x86_64-linux/DBI.pm line 284 +. BEGIN failed--compilation aborted at /usr/local/lib/perl5/site_perl/5. +28.0/x86_64-linux/DBI.pm line 284. Compilation failed in require at /usr/local/lib/perl5/site_perl/5.28.0 +/x86_64-linux/DBD/Oracle.pm line 20. BEGIN failed--compilation aborted at /usr/local/lib/perl5/site_perl/5. +28.0/x86_64-linux/DBD/Oracle.pm line 20. Compilation failed in require at /home/oracle/scripts/purge_proddoc_sc +ript/purge_proddoc_script.pl line 16. BEGIN failed--compilation aborted at /home/oracle/scripts/purge_proddo +c_script/purge_proddoc_script.pl line 16. at /home/oracle/scripts/purge_proddoc_script/purge_proddoc_script.pl +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='bbyrd@aires.com, ASayed@aires.com, vkamins@aire +s.com, RKatru@aires.com'; my $error_mail_list='bbyrd@aires.com'; # Unbuffer STDOUT and STDERR select STDERR; $| = 1; select STDOUT; $| = 1;
Migrating from Windows Server 2003
3 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,

    Steve
Use Protocol::WebSocket::Client in HTTPS mode?
1 direct reply — Read more / Contribute
by larrymcp
on Jul 19, 2018 at 02:55

    I need to communicate with a Websockets server that expects HTTPS. I'm doing some initial tests using the wsconsole example script that comes with Protocol::WebSocket::Client.

    When the script connects to the server on port 443, the server responds:

        400 Bad Request
        The plain HTTP request was sent to HTTPS port

    It appears that for some reason the wsconsole script is not using HTTPS, even though I did preface the URL with "wss://" and I did specify port 443. Is there something I need to do, some parameter I need to specify, to tell it to use HTTPS when communicating with the server?

    Thanks very much!

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"; }
Spreadsheet::read how to get error?
1 direct reply — Read more / Contribute
by gsd4me
on Jul 18, 2018 at 17:32

    All

    I have a program that writes some data into a spreadsheet, which I want to then analyse again to produce some HTML output. The latter part works in testing but putting the whole lot together has raised an interesting problemette. Code replicated below. My debugging is showing that $gOutWorkbook has a value of "undef" upon return from ReadData, and I have no means of knowing why the workbook is not being (re-)opened to be read, when I have populated it with data previously (not shown here)

    So: can I find out the reason *why* the workbook is not being opened properly? (ie some error value from somewhere) I have even put a 10 second delay before I attempt the open, to allow the OS to 'settle down' after closing the file, post writing to it but that doesn't help at all All other variables have relevant and correct values associated with them at the crucial point in the software. Previous ReadData calls work in other parts of the software suite, so it is only this section that is letting me down.

    # Re-open as a read only # Read in the workbook and all its data $gOutWorkbook = ReadData ($lOutputFileName); $gOutWorksheet = $gOutWorkbook->[$gOutWorkbook->[0]{sheet}{"my +Sheet"}];
Abuse of "or next" in expressions and "next" that returns value
4 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 2.9.0.0 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/CGI.pm li +ne 308. Use of uninitialized value $min in subtraction (-) at /Library/Perl/5. +18/GD/Graph/histogram.pm line 110, <INPUT> line 1. Use of uninitialized value $max in subtraction (-) at /Library/Perl/5. +18/GD/Graph/histogram.pm line 110, <INPUT> line 1. Use of uninitialized value $max in numeric le (<=) at /Library/Perl/5. +18/GD/Graph/histogram.pm line 118, <INPUT> line 1. Use of uninitialized value $upper in numeric le (<=) at /Library/Perl/ +5.18/GD/Graph/histogram.pm line 118, <INPUT> line 1. Use of uninitialized value $lower in addition (+) at /Library/Perl/5.1 +8/GD/Graph/histogram.pm line 119, <INPUT> line 1. Use of uninitialized value $max in numeric le (<=) at /Library/Perl/5. +18/GD/Graph/histogram.pm line 122, <INPUT> line 1. Use of uninitialized value in string eq at /Library/Perl/5.18/GD/Graph +/histogram.pm line 42, <INPUT> line 1. Use of uninitialized value in subtraction (-) at /Library/Perl/5.18/GD +/Graph/histogram.pm line 59, <INPUT> line 1. Use of uninitialized value in addition (+) at /Library/Perl/5.18/GD/Gr +aph/histogram.pm 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

sorting and merging in perl
2 direct replies — Read more / Contribute
by Sekhar Reddy
on Jul 18, 2018 at 10:41

    Hello Monks,

    GoodEvening

    Can any one help me on this, How this can be done in perl

    Thank you very much in advance

    I have 4 different Scenarios, I have listed down, and i have also written how my hash should store

    STRUCTURE OF MY DATA below(with Header, last two fields are date fields in yyyymmdd format):

    A1,B1,ACTDATE,DEACTDATE

    7900724666,200906888,20180406,20180411

    7900724666,200906888,20180416,20180522

    7900724666,200906888,20180601,20180720

    For the above content(A1), i want to store in hash like this==>A1,B1 of MIN ACTDATE:B1 of MAX DEACTDATE,MIN ACTDATE,MAX DEACTDATE

    For the above example, ==>7900724666,200906888:200906888,20180406,20180720

    7900724677,200906871,20180101,20180228

    7900724677,200906872,20180301,20180330

    7900724677,200906873,20180401,20180420

    For the above content(A1), i want to store in hash like this==>7900724677,200906871:200906873,20180101,20180420

    7900724688,200906881,20180101,20180228

    7900724688,200906881,20180303,20180330

    7900724688,200906882,20180404,20180430

    7900724688,200906883,20180508,20180620

    For the above content(A1), i want to store in hash like this==>7900724688,200906881:200906883,20180101,20180620

    7900724699,200906891,20180101,20180228

    7900724699,200906891,20180303,20180330

    7900724699,200906892,20180404,20180430

    7900724699,200906893,20180508,

    For the above content(A1), i want to store in hash like this==>7900724699,200906891:NULL,20180101,NULL


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!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • 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
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            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 all is quiet...

    How do I use this? | Other CB clients
    Other Users?
    Others having an uproarious good time at the Monastery: (3)
    As of 2018-07-19 18:00 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?
      It has been suggested to rename Perl 6 in order to boost its marketing potential. Which name would you prefer?















      Results (414 votes). Check out past polls.

      Notices?