Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

The Monastery Gates

( #131=superdoc: print w/replies, xml ) Need Help??

Donations gladly accepted

  • (Sep 10, 2018 at 22:53 UTC) Welcome new users!
If you're new here please read PerlMonks FAQ
and Create a new user.

New Questions
Special character not being captured
1 direct reply — Read more / Contribute
by Lady_Aleena
on Jun 17, 2019 at 15:06

    Hello everyone. I am having a problem with the character Ĉ in the string Ĉon Flux not being captured by the first_alpha subroutine below. A space character is being returned. This problem arose when I recently re-encoded my files from Windows-1252 to UTF-8. I am baffled. As always, I appreciate all the help I get.

    Even substr('Ĉon Flux', 0, 1) returns a space character.

    The weird thing that I found is that the string Ĉon Flux is returned when I ran the data from the file through my make_hash subroutine then ran that hash through my alpha_hash subroutine, both in the same module as first_alpha. (You can see the full module here.)

    The following is truncated output from alpha_hash.

    As I said earlier, any and all help is appreciated.

    No matter how hysterical I get, my problems are not time sensitive. So, relax, have a cookie and a very nice day!
    Lady Aleena
[Perl6] Seq iterator already consumed
1 direct reply — Read more / Contribute
by Athanasius
on Jun 16, 2019 at 22:09

    I only started learning Perl 6 within the last week, so please bear with me. :-)

    I had a script working nicely, then I added another statement (line D in the code below) and received a run-time error message like this:

    The iterator of this Seq is already in use/consumed by another Seq (you might solve this by adding .cache on usages of the Seq, or by assigning the Seq into an array)

    From the documentation I gather that I have somehow created a Seq object and then attempted to iterate it a second time. But I don’t understand where or how the Seq object is being created and used.

    I managed to pare down the code to the following SSCCE:

    use v6; my @paths = data(); my @dirs.push: $_.split('/') for @paths; # A # @dirs.perl; # B say $_.join('/') for @dirs; # C my $depth = @dirs.map(*.elems).min; # D sub data { my $text = q:to/END/; /aardvark/bison/camel/dromedary /aardvark/bison/camel/dromedary/elephant END return $text.lines; }

    Lines A, C, and D are all required to produce the error. Uncommenting line B removes the error (by caching, apparently, although I’m not sure exactly what is cached). So I have 3 questions:

    1. Where are the Seq object(s) being created and used?
    2. I tried examining the contents of @dirs using say @dirs.perl;, but that had the same effect as uncommenting line B. Is there a way to examine the contents of @dirs (like using Data::Dump in Perl5) without introducing changes?
    3. Adding line B removes the error, but feels like a kludge. What is the correct way of writing this sort of code?

    In case it matters:

    11:03 >perl6 -v This is Rakudo Star version 2019.03.1 built on MoarVM version 2019.03 implementing Perl 6.d. 12:14 >

    Thanks,

    Athanasius <°(((><contra mundum Iustus alius egestas vitae, eros Piratica,

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 ?

    Thanks

    frazap

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 CGI.pm 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.

    Thanks.
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
    Hello,
    I'm not able to fill a string as in the example below with Text::Template. Where is the mistake?
    Thanks
    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

    Hi,

    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 http://codeverge.com/perl.inline/running-inline-python-in-a-cgi-script/741065

    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' section.at ./pol +icy-lib.pl 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.

    https://metacpan.org/pod/Spreadsheet::ParseExcel::SaveParser

    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/ParseExcel.pm 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 : https://stackoverflow.com/questions/56545694/unable-to-retain-the-format-in-copying-from-one-excel-file-to-another

    #!/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 ./regexp.pl 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.
New Monk Discussion
Bookmarklet to show deeplinks in perldoc.perl.org
2 direct replies — Read more / Contribute
by LanX
on Jun 15, 2019 at 13:22
    In a reaction to link to perl documentation

    This works in the JS code works inside the console in FF and Chrome and will show hidden html-anchors ready to be cut&paste with PM markup

    javascript:(function(){ var path = location.pathname.replace(/^\//,"").replace(/\.html$/," +"); var as =document.getElementsByTagName("a"); for (i in as) { var l = as[i]; if (l.id && l.classList.length == 0 ){ var dlink = path + "#" + l.id; l.innerHTML = "<b>" + path + "#[doc://"+dlink+"]</b><br>"; + l.href = "#" + l.id } } })()

    The bold parts are generated by JS

    perlintro#[doc://perlintro#Perl-variable-types]

    Perl variable types

    Perl has three main variable types: scalars, arrays, and hashes.

    perlintro#[doc://perlintro#Scalars]

    Scalars

    A scalar represents a single value:

    you can C&P the links then into a PM post, and they'll render as:

    I still have problems putting it into a bookmark getting strange JS errors about keyword "var".

    NB: This is far from being bug-free perldoc.perl.org and PM markup have their own idiosyncrasies! But it's a start.

    Feel free to post better versions!!!

    Cheers Rolf
    (addicted to the Perl Programming Language :)
    Wikisyntax for the Monastery FootballPerl is like chess, only without the dice . test . BML

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'.

    [doc://perlfunc#open]

    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.

    Bill
Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (3)
As of 2019-06-17 22:34 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Is there a future for codeless software?



    Results (80 votes). Check out past polls.

    Notices?
    • (Sep 10, 2018 at 22:53 UTC) Welcome new users!