Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot

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
Sort alphabetically from file
6 direct replies — Read more / Contribute
by edujs7
on Jun 14, 2019 at 09:19
    Hi folks, hoping someone can help me. I trying to sort alphabetically from a file that contains several rows with numbers and words - I need to sort them based on the word column. Below an idea of what the file contains.
    1 2 3 delta 1 2 3 apricot 1 2 3 charlie 1 2 3 bravo 1 2 3 echo 1 2 3 fox
    My struggle is that I cannot make it work so that it sorts alphabetically but only on the last column (words. Any advise will be greatly appreciated. Thanks so much My problem is
Accessing javascript variable from perl
2 direct replies — Read more / Contribute
by frazap
on Jun 14, 2019 at 07:53
    I have a javascript file that contains a bunch of variables.
    var leg = { aa: "a label", ab: "another label", .... }; var map = { aa : ["R1"], ab : ["AA1"], ac : ["AA1", "AA2"], .... }; var monorows = [ ["R6", "c", "1", "CB16", "CB15" ... codes that are listed in map], ... ];
    I want to check that these variables are coherent, eg all codes in map are also in monorows, etc. In a first step, I copied the javascript variables in a perl script, changed the syntax to have json data instead of javascript syntax and could run my checks:
    use JSON; use Data::Dump "dd"; my $leg_str =<<'END'; { "aa": "label1", "ab": "label2", ... "er": "last label" } END my $leg = decode_json($leg_str);
    Now, I would like to automatize the import step. I tried this:
    use WWW::Mechanize::PhantomJS; my $js = WWW::Mechanize::PhantomJS->new(); $js->get_local("my_js_file.js"); #print $js->content; I get the content ok here. my ($val, $type) = $js->eval_in_page('function(){JSON.stringify(leg);} +');
    But this just return in $val the function is have sent... What am I missing ? is there a way to have this working ?



Perl parsing of multipart content
4 direct replies — Read more / Contribute
by jeclark2006
on Jun 13, 2019 at 21:02

    There are a number of examples of creating multipart form data for sending to a HTTP server.

    I found very few, server side parsing examples. This ranged from getting a message that is delisted in the standard perl suite, to finding an HTTP::MultiPartParser library function, etc.

    However when using the latter, HTTP::MultiPartParser functions, a 'boundary' pattern was required to be given when creating the object.

    So, upon receiving content, how does one find the 'boundary' to then use HTTP::MultiPartParser to then parse the file?

    Could someone point me to an example where perl is used to receive the file selected via the multipart form, and then parsed out to filename, and file content segments.

gene location
3 direct replies — Read more / Contribute
by nica
on Jun 12, 2019 at 09:38
    I need to extract from a gbff:
    gene complement(<5504..>6553) /locus_tag="OT_ostta02g00030" /old_locus_tag="Ot02g00030" /db_xref="GeneID:9832574"
    the GeneID related to its coordinates $start = 5504 $stop = 6553 There are a lot of genes so I want to make a loop I use Perl for my code, you can see below a part of it (extracting the numbers) but it doesn't work.
    $infile = "GCF.gbff"; $outfile = "a1.txt"; open(IN, $infile) or die "Failed to open $infile\n"; open (OUT, ">$outfile") or die "Failed to open $outfile\n"; $n=0; while ($line = <IN>) { chomp ($line); $line =~ s/\r$//; if ( $line =~ /<\d+..>\d+/ ) { ++$n; my ($start, $stop) = ($1, $2); print OUT "$start, $stop, $header"; } } print STDERR"$n"; sub header { @geneID = split /\s+/, $start, $stop; $header = "$fastaprompt$geneID[1]"; } close (IN); close (OUT);
Filling a string with Text::Template
1 direct reply — Read more / Contribute
by Anonymous Monk
on Jun 12, 2019 at 05:22
    I'm not able to fill a string as in the example below with Text::Template. Where is the mistake?
    use strict; use Text::Template; my $user_info = 'u1'; my $site = 'a'; my $string = './{$user_info}.{$site}.txt'; my $template = Text::Template->new(TYPE =>'STRING',SOURCE=>$string); $string = $template->fill_in({site=>$site,user_info=>$user_info}); print "$string\n";
Passing compilation options through to cpan/cpanm
3 direct replies — Read more / Contribute
by ondohotola
on Jun 12, 2019 at 05:04


    Something similar has been asked here before, but It wasn't solved

    Of late, the XCode command line tools on Mojave MacOs do not remember the default framework path, which i can however pass to cc by adding -F /Library/Frameworks.

    I can of course edit the Makefile.PL, but I would rather prefer to pass it from the command line, because it scales better

    Any Ideas?

    greetings, el

using Inline Python with CGI
3 direct replies — Read more / Contribute
by garima3003
on Jun 12, 2019 at 03:43
    I was going through a post on

    Unfortunately i ended up getting into the same situation.
    I am new to perl and python and through a cgi calling a perl script and python code is embedded in Perl script.

    Tried the same code but still no luck.
    Below is the code :

    #---------------------------- # Defining The constants #--------------------------- *SUBMIT = \'submit'; *TRUE = \1; *FALSE = \0; *DISABLED = \'DISABLED'; sub store_policy() { print "Started\n"; use Inline::Python qw(py_new_object py_call_method); use Inline Python => 'DATA', DIRECTORY => '/usr/local/webmin/gehc_password_management/_Inli +ne/'; Inline->init(); print "\nGoing to create Object\n"; my $obj = py_new_object("gehc_password_management","gehc_password_mana +gement","passwordManagement"); #print "hello".py_call_method($obj,"testPrint")."\n"; print("\nCreated the Object"); #my $flag = $obj->getPasswordConfigFilePath(); #print($flag); print "\nClosed"; } 1; # Return true, required for libraries __DATA__ __Python__ from passwordChangeNew import PasswordManagement as passwordManagement
    and getting the below error:
    Started HTTP/1.0 500 Perl execution failed Server: MiniServ/1.840 Date +: Tue, 11 Jun 2019 22:58:49 GMT Content-type: text/html; Charset=iso- +8859-1 Connection: close Error - Perl execution failed Marker '__Python__ from passwordChangeNew import PasswordManagement as + passwordManagement ' does not match Inline 'Python' ./pol line 36.
    Can somebody please help ?

    Need it as asap

%{^CAPTURE}, %{^CAPTURE_ALL} and %- don't produce expected output
1 direct reply — Read more / Contribute
by vr
on Jun 11, 2019 at 13:39
    use strict; use warnings; use Data::Dump 'dd'; my $s = "a aa aaa aaaa"; $s =~ /(?<a>a+) (?<a>a+) (?:(?<a>a+)bbb)?/; dd \@{^CAPTURE}; # all captured groups dd $+{a}; # leftmost defined "a" dd ${^CAPTURE}{a}; # ditto dd $-{a}; # all defined "a"'s groups dd ${^CAPTURE_ALL}{a}; # ditto __END__ ["a", "aa"] # correct "a" # correct undef ["a", "aa", undef] "a"

    Documentation is not very verbose about new %{^CAPTURE}, %{^CAPTURE_ALL} variables, they are listed as if they are English synonyms to old %+ and %-, but they are obviously not, they look plain wrong to me.

    The "aaa" was deleted from @{^CAPTURE} array (or was not even added to begin with), when rightmost cluster failed to match, and deleted as array element from @{$-{a}}, but the $#{$-{a}} was not changed from wrong 2 to expected 1, hence unexpected undefined element in @{$-{a}}.

    Update: Actually, w/r/t %-, re-reading the docs, there's no phrase "all defined "a"'s groups" as I stated above.

    To each capture group name found in the regular expression, it associates a reference to an array containing the list of values captured by all buffers with that name (should there be several of them), in the order where they appear.

    Yes, they say "all buffers with that name", but can undef be said to be "captured"? Can failed sub-expression "capture"? It's ambiguous.

    Update 2: Mixing these "CAPTURE" things is broken:

    #dd \@{^CAPTURE}; dd \%{^CAPTURE};

    is OK, but un-commenting 1st line results in empty unblessed hash in the 2nd.

Unable to retain the format in copying from one excel file to another
2 direct replies — Read more / Contribute
by nemadepsn
on Jun 11, 2019 at 10:30

    I want to copy content from one excel file to another retaining the format too. Here by format I mean fill color, border, bold, italic, etc. I have written a code for this where I extract the value and format number from one excel file and simply write in the other excel sheet. I have referred the following link for that.

    The problem is that it is not retaining the format. I think the problem is that the format number is not universal which means that a format number means two different things in two different excel files. When I run this code I get the error

    Use of uninitialized value in hash element at /pkg/qct/software/perl/5.18.0_test/lib/site_perl/5.18.0/Spreadsheet/ line 2383.

    According to me, it means that the extracted format number doesn't mean anything to other file. Please let me know solution to this problem

    Basically what my problem is that I have modified two xls file using Spreadsheet::ParseExcel::SaveParser and I want to merge those two xls files using Perl. Please suggest a way of merging two xls files using Perl in any other way such that formatting is retained. Please suggest non-Perl way too using some other coding language.

    This question has been cross-posted on stackoverflow :

    #!/usr/bin/perl use strict; use warnings; use Spreadsheet::ParseExcel; use Spreadsheet::ParseExcel::SaveParser; # Open an existing file with SaveParser my $parser = Spreadsheet::ParseExcel::SaveParser->new(); my $template = $parser->Parse('template.xls'); my $parser1 = Spreadsheet::ParseExcel::SaveParser->new(); my $template1 = $parser1->Parse('test_perl.xls'); my $worksheet11 = $template->worksheet(0); $template1->AddWorksheet('New Data'); my $worksheet22 = $template1->worksheet(0); my $cellz; my $valua;my $format_number; for (my $i = 0; $i < 400; $i++) { for (my $j = 0; $j < 20; $j++) { $cellz = $worksheet11->get_cell( $i, $j ); if($cellz){ $valua = $cellz->unformatted(); $format_number = $cell +z->{FormatNo}; $worksheet22->AddCell($i, $j, $valua,$format_number); } } } my $workbook; $workbook = $template1->SaveAs('newfile1.xls');
regexp "?" delimiter
4 direct replies — Read more / Contribute
by cmic
on Jun 11, 2019 at 09:54
    The following code (using Perl 5.24 on Debian) yields this error:
    syntax error at ./ line xx, near "if ?"
    my ($DICT, $first, $last); open $DICT, "<", "/usr/share/dict/words"; while (<$DICT>) { #FIXME $first = $1 if ?(^neuro.*)?; # <- syntax error here $last = $1 if /(^neuro.*)/; } close $DICT; print "first : $first, last : $last \n"; print "-" x 10, "\n"; #
    Is it a deprecated usage of the "?" delimiter ?
    Or what ?
    -- cmic. Life helps. Perl Too.
LWP get Cookies for API
3 direct replies — Read more / Contribute
by abs52
on Jun 11, 2019 at 07:54

    Hi All,
    I am trying to use LWP ( i dont mind using something else ) to do some posts and get from a website API

    But i am failing at the first step.

    According to their docs you need to login with your broswer, get the cookie AUTH_TOKEN and get the and then use that output for the curl command authorization. Is there way to do this in perl ?
    The curl would look like

    curl -X GET "<URL> -H "accept: application/json" -H "authorization:<to +ken>"
    and my LWP looks like
    my $cookies = HTTP::Cookies->new(); my $ua = LWP::UserAgent->new( cookie_jar => {} ); $req -> authorization_basic ( 'cloud-bespoke' ); my $rc = REST::Client->new( { useragent => $ua } ); my $headers = {Content-type => 'application/json'}; my $client = REST::Client->new( { useragent => $ua }); my $res = $client->POST('URL', '{"username": "username, "password":"password"}', {"Content-type" => ' +application/json'}); chkerr($client->responseCode()); print $client->responseContent(); print "\n" . $cookies->as_string;
    Thanks a

improving speed in ngrams algorithm
8 direct replies — Read more / Contribute
by IB2017
on Jun 11, 2019 at 06:37

    Given string with text, I need to create n-grams of predefined lengths. I came up with the following. Any suggestions on how to improve it (being speed an important factor in my process?). The sentence, i.e. the array will contain typically 5-15 elements.

    use strict; use warnings; my $sentence = "this is the text to play with"; my @string = split / /, $sentence; my $ngramWindow_MIN = 2; my $ngramWindow_MAX = 3; for ($ngramWindow_MIN .. $ngramWindow_MAX){ my $ngramWindow=$_; my $sizeString = (@string) - $ngramWindow; foreach (0 .. $sizeString){ print "START INDEX: $_ :"; print "@string[$_..($_+$ngramWindow-1)]\n"; } }
New Monk Discussion
link to perl documentation
2 direct replies — Read more / Contribute
by BillKSmith
on Jun 15, 2019 at 11:08

    In a recent post, I wanted to reference the perl documentation for the open function. The following code links to the right page, but does not go the section on 'open'.



    Am I overlooking some detail in the FAQ. (I am not even going to try to create a link to this today)

    I believe that this example is typical of several links that I have posted. The same solution will probably apply to all of them, but lets concentrate on this one for now.

Log In?

What's my password?
Create A New User
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (6)
As of 2019-06-15 22:31 GMT
Find Nodes?
    Voting Booth?
    Is there a future for codeless software?

    Results (76 votes). Check out past polls.