Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
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
Parsing .txt into arrays
3 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
Perl Tk Notebook not filling main window height
No replies — Read more | Post response
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.
Authen::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;
Wildcards for a wide array of strings?
7 direct replies — Read more / Contribute
by zarath
on May 23, 2017 at 04:01
    Heyhey!

    Perl-virgin here, be gentle, pretty please with sugar on top. + English is not my native tongue, but i pride myself in my capabilities (in written English anyways, I sound a bit like a mix of a Frenchman and a German trying to speak American).

    I have a question about the very first script I'm trying to write.

    I'm sure this will be resolved in a jiffy by the first person who bothers to read this whole thing. Will you be that person?

Backtracking in perl
3 direct replies — Read more / Contribute
by pdahal
on May 23, 2017 at 03:56
    hello monks! I was seeking for help about backtracking algorithm in perl. How can I backtrack the PubMed Abstract? Any helps are appreciated.

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 the grasshoppers chirp...

    How do I use this? | Other CB clients
    Other Users?
    Others taking refuge in the Monastery: (7)
    As of 2017-05-24 10:46 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?