Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
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
Hash user input
3 direct replies — Read more / Contribute
by Nansh
on May 24, 2017 at 13:14

    Hello I have two hash say %hash1 and %hash2

    %hash1 and %hash2 these hash contains some keys and values

    I need to give these hash as a user input

    my %hash_input=@_; my %hash_input2=@_;
    can i take two hash as a user input like i mentioned above??? Thanks in Advance.
Best way to sum an array?
9 direct replies — Read more / Contribute
by Anonymous Monk
on May 24, 2017 at 11:06
    How do I pick the "best way" to do something? In particular, I want the fastest way, using the fewest resources, to sum up the values in an array of arbitrary length. I could do it in a loop with a bucket, I could do it recursively, I could do it with a join and an eval, etc. What's the "best" way? Is there a "better" way? How do I measure? How do I pick?
    # Iterative sub SumArryItr { my $agg = 0; $agg += $_ for @_; return $agg } # Recursive use feature 'current_sub'; sub SumArryRcs { 1==@_?$_[0]:1>@_?die:shift(@_)+__SUB__->(@_) } # Eval Trick sub SumArryEvl { eval join "+", @_ } # Test my @array = ( -249, 0, 74, 65, 80, 72 ); print "Sum: ", join( ", ", @array ), "\n"; print "Itr: ", SumArryItr( @array ), "\n"; print "Rcs: ", SumArryRcs( @array ), "\n"; print "Evl: ", SumArryEvl( @array ), "\n";
    merci
XML-LibXML-2.0129 installation issues
2 direct replies — Read more / Contribute
by Brat
on May 24, 2017 at 10:44
    I installed the latest libxml perl library XML-LibXML-2.0129 after downloading it from cpan. my installation did not seem to have gone fine.
    perl Makefile.PL FORCE=1 PREFIX=/app/localapps/perl/lib LIB=/app/localapps/perl/lib enable native perl UTF8 running xml2-config...failed The installed version of libxml2 FORCED 2.9.4 is not compatible with XML::LibXML (and probably buggy)! You may continue at your own risk using 'perl Makefile.PL FORCE=1', bu +t: - don't expect XML::LibXML to build or work correctly! - don't report errors! - don't send patches! Check the README file for more information on versionsthat are tested +with XML::LibXML Checking for ability to link against xml2...yes Generating a Unix-style Makefile Writing Makefile for XML::LibXML Writing MYMETA.yml and MYMETA.json

    The issue with the installation is that I cannot find Node.pm. Not sure How I can fix this. Please help. what am I missing?

Getting JSON::PP:Boolean value
2 direct replies — Read more / Contribute
by cormanaz
on May 24, 2017 at 08:42
    Good Day bros. I have some values in a json file parsed with mod JSON that have values JSON::PP:Boolean. How do I process these to get the true/false value? If I just assign them to another variable they are undef.
extract column data
3 direct replies — Read more / Contribute
by bigup401
on May 24, 2017 at 07:35

    am trying to extract data from column. but am only getting the first lastname am not getting the reset. i only get john

    +----------+ | lastname | +----------+ | john | | Doe | | Jones | | Smith | +----------+
    my $sth = $dbh->selectrow_array("SELECT lastname FROM dbase"); $dbh->disconnect; #its ok with array @data = $sth1; print @data;
Parsing .txt into arrays
6 direct replies — Read more / Contribute
by Fshah
on May 24, 2017 at 05:32

    Hi there, I have a large log file in .txt format which has several pages (each page has different format,with different colums pertaining to different fields) I want to separate each column into an array so that it can be used to process later ,how do I do this I have a picture of how log file looks let me know if u need it, Thanks in advance

    place and year data: 67 _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ |no.| name | age | place | year | |_ _|_ _ _ _|_ _ _ | _ _ _ | _ _ | |1 | sue |33 | NY | 2015 | |2 | mark |28 | cal | 2106 | work and language :65 _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ |no.| name | languages | proficiency | time taken| |_ _| _ _ _| _ _ _ _ _ |_ _ _ _ _ _ _| _ _ _ _ _ | |1 | eliz | English | good | 24 hrs | |2 | susan| Spanish | good | 13 hrs | |3 | danny| Italian | decent | 21 hrs | Position log | | |Pos |value | |bulk|lot| prev| newest| |# |Locker|(dfg) |(no) |nul|val |Id | val |val | ----------------------------------------------------------- | 0| 1| 302832| -11.88| 1| 0|Pri| 16| 0| | 1| 9| 302836| 11.88| 9| 0|Pri| 10| 0| | 2| 1| 302832| -11.88| 5| 3|Pri| 14| 4| | 3| 3| 302833| 11.88| 1| 0|sec| 12| 0| | 4| 6| 302837| -11.88| 1| 0|Pri| 16| 3|

    I want these columns into an array with name as given in the table containing values as in the table. thank you.

Perl Tk Notebook not filling main window height
3 direct replies — Read more / Contribute
by madhusudhan_s
on May 24, 2017 at 05:14

    In the perl tk code below, i use a create_tab subroutine to create several tabs (tk notebooks)

    As the number of tabs grew i had a need to add a main window scroll bar using mw->Scrolled which would help me move to other tabs beyond the view of main window.

    The addition of this scroll bar now makes my tabs not fill the main window height completely while it fits the main window width.

    Would any of you monks be able to let me know what is wrong with my code which causes the vertical fit issue and how to solve it?

    #!/usr/bin/perl use Tk; use strict; require Tk::NoteBook; require Tk::LabEntry; require Tk::Scrollbar; our $mw = MainWindow->new; $mw->geometry("800x1000"); my $canvas = $mw->Scrolled('Canvas', -scrollbars => "s")->pack(-fill = +> 'both', -expand => 1); $mw->withdraw(); $mw->Popup; # Create the NoteBook and add pages our $n = $canvas->NoteBook(-dynamicgeometry => 'true')->pack( -fill=>' +both', -expand=>1); $n->pack( -expand => "yes", -fill => "both", -side => "top" ); for ( 1 .. 20 ){ my $title = "mytab $_"; $_ = create_tab("$title"); } ### embed the notebook widget into the canvas my $nb_in_canvas = $canvas->createWindow( 0, 0, -window => $n, -anchor + => 'nw' ); $canvas->update; ### the whole notebook is larger than what can be initially displayed ### so we'll have to sroll it later on in the program $canvas->configure( -scrollregion => [0,0,$n->reqwidth,$n->reqheight]) +; sub create_tab { my $tabname = shift; my $tn = $n->add($tabname, -label => $tabname, -underline => 0); my $t = $tn->Scrolled("Text", -scrollbars => "e", -wrap => 'none') +->pack(-expand => 1, -fill => 'both'); $t->tagConfigure ('bold', -font => [ -size => 0, -weight => 'bold' + ]); return $t; } MainLoop;
Regex Minimal Quantifiers
3 direct replies — Read more / Contribute
by pr33
on May 24, 2017 at 00:41

    Hello Monks,

    Can any one please explain me the below code ? Isn't the minimal quantifier(.*?) in this case be supposed to match 'I have ' for the first capture and then from number 2 till end of the string for second capture $2 . The O/p returns nothing for $1 and $2 .

    Here is my code

    #!/usr/bin/perl use warnings; use strict; ############### my $str = "I have 2 numbers: 53147"; my @pats = qw { (.*?)(\d*) }; foreach my $pat (@pats) { printf "%-12s ", $pat; if ( $str =~ /$pat/ ) { print "<$1> <$2>\n"; } else { print "FAIL\n"; } }

    $ ./regex.pl

    (.*?)(\d*) <> <>

Iterate multiple arrays with added text
3 direct replies — Read more / Contribute
by Bman70
on May 23, 2017 at 15:44
    Hi, I'm looking at another ten hours of troubleshooting (sucks to not know much Perl!), so I thought I would ask. I have several arrays, @title, @author, @date, each of which have multiple elements. I need to output all the elements (several hundred) organized as:
    Title: "title from array" Author: "author from array" Date: "Date from array"
    In my searching the closest I got was another perlmonks thread:
    while (@title, @author, @date) { print join ': ', map shift @$_ // 'NULL', \@title, \@author, \@dat +e; print "\n"; }
    This gets all the information out, but not formatted right. Would I be able to add the text and newlines to this code, or should I use something entirely different? I realize it could probably be done with hashes but currently it's in arrays so hoping that can work. Thanks!
sending to multiple addressess
2 direct replies — Read more / Contribute
by bigup401
on May 23, 2017 at 12:56

    how can i send message to multiple addresses without showing cc, bcc emails to recipients. i want something like php mailer.

    any idea

    $msg = MIME::Lite->new( To => ,

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 examining the Monastery: (3)
    As of 2017-05-28 03:46 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?