Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
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
Getting JSON::PP:Boolean value
1 direct reply — 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
4 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
1 direct reply — 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
2 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 => ,
Capturing output from a long-running pipeline
1 direct reply — Read more / Contribute
by wanna_code_perl
on May 23, 2017 at 12:56

    Hello monks,

    I've mostly written a Perl program that runs several external backup and file transfer programs, such as duplicity, scp, rsync, etc. Everything's fine except I'm not sure of the best way to actually execute the commands. I'll show you the relevant subroutine, then I'll get into specifics:

    # Run executable @system command, reporting name as $name If there # is an upload limit, we run through trickle(1) to limit bandwidth. sub _ext_cmd { my ($name, @system) = @_; if ($o{general}{upload}) { @system = ($o{general}{trickle}, $o{general}{trickled} ? () : '-s', -u => $o{general}{upload}, '|', @system); } say "Running name=$name, @system"; # system { $system[0] } @system[1..$#system]; # Obviously nope. say "\$?=$?"; }
match a word and delete last line
3 direct replies — Read more / Contribute
by ArifS
on May 23, 2017 at 09:26
    Hi, I am trying to match the word (sample-text) and delete previous line if has a single word that might include (digit,_,-).
    use strict; use warnings; my $filename = 'test1.txt'; open(my $fh, '<:encoding(UTF-8)', $filename) or die "Could not open file '$filename' $!"; my $line; my $flag=1; while($line=<$fh>) { if($flag == 0) { print $line; next; } if($line=~/sample-text/) { $flag=0; print $line; } }
    Content of the test1.txt
    Text_1 sample-text file Text_1 matching the 1st line matching the last line Text text_1 text-2 sample-text file text-2 matching the 1st line matching the last line
    Expected output
    sample-text file Text_1 matching the 1st line matching the last line text text_1 sample-text file text-2 matching the 1st line matching the last line
    But it only removes the 1st line, and doesn't look for other lines. Please let me know.
Authorization Negotiate Wep-Programming
3 direct replies — Read more / Contribute
by amitsq
on May 23, 2017 at 08:51
    hi,

    so i am totally new and over challenged with proxies and all that web programming, so pls bear with me. I am currently trying to access with the LWP-Modul a (https-)webpage, to fill in its form, submit it and getting the result page. While I am able to get the content of the first page with the form, the response via Post is always empty. While I am trying to recreate the request-request, i see there is following line in the request-header :

    Proxy-Authorization:"Negotiate YIIGzQYGKwYBBQUCoIIGwTCCBr2gMDAuBgkqhkiC9xIBAgIGCSqGSIb3EgECAgYKKwYBBAGCNwICHgYKKwYBBAGCNwICCqKCBoc [shorted] "  

    There is no need to log in to the website, so I got no password or username. I tried my best to find out about it, but I got no clue how i could get the Negotiate key. So i use Active perl on Windows and the LWP-Authen-Negotiate Modul is not available for Windows. Are there any other solutions?

    $param ='simpleSearchSearchForm=simpleSearchSearchForm&simpleSearchSea +rchForm%3Aj_idt379=ALLTXT&simpleSearchSearchForm%3AfpSearch=brushless ++motor&simpleSearchSearchForm%3AcommandSimpleFPSearch=Search&simpleSe +archSearchForm%3Aj_idt447=workaround&$viewState'; $request = HTTP::Request->new('POST', 'https://patentscope.wipo.int/se +arch/en/search.jsf'); $request->header('Content-Type' => 'application/x-www-form-urlencoded' +); $request->header('Referer' => "https://patentscope.wipo.int/search/en/ +search.jsf"); $request->header('Accept' => 'text/html,application/xhtml+xml,applicat +ion/xml;q=0.9,*/*;q=0.8'); $request->header('Connection' => 'keep-alive'); $request->header('Cookie' => uc $jsessionID.'; ABIW=balancer.cms41; wi +po_language=en; BSWA=balancer.bswa2'); $request->content($param); #Proxy-Authorization: Negotiate ? $response = $ua->request($request); $page = $response->decoded_content(); #empty print $page;

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?
    [perldigious]: I train for long portaging/rowing trips by carrying my kayak to the river about a half mile from my house 2-3 times a week depending on weather... but due to a lingering winter, I haven't had long to train this year.
    [erix]: Ah, I found the link for my run: 6km (and 6km back)
    [perldigious]: Also, made the unhappy discovery that the ticks have become active already this year... I really, really hate ticks.
    [Lotus1]: perldigious I found out recently that opossums are very good at killing ticks.
    Your Mother is lucky to only have to carry a kayak 15 feet to put in.
    [perldigious]: If I was given the option to remove either mosquitos or ticks from the world... I think I'd pick ticks, even though I'd guess most would go the other way.

    How do I use this? | Other CB clients
    Other Users?
    Others rifling through the Monastery: (12)
    As of 2017-05-24 13:04 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?