Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
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.

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.

Post a new question!

User Questions
WWW::Mechanize::Chrome VERY slow on xpath obtaining TDs of a TR
3 direct replies — Read more / Contribute
by ait
on Nov 25, 2022 at 07:43

    Hello ye monks!

    UPDATE: the time seems to be proportional to the number of rows. The 2-3 second timing is for a table with 450 rows and 12 columns.
    On a table with 120 rows, it's less than a second. Speculating: it would seem that relative to node xpath has some bug and may be scanning the whole table each time.

    Anybody out there have any clue why this takes 2 to 3 seconds:

    my @cells = $mech->xpath('.//td', node => $rows[$row_index]);

    Posted the issue here.
    I posted the issue here: https://github.com/libwww-perl/WWW-Mechanize/issues/362

    But answers and wisdom usually come faster in the Monastery ;-)

    If anyone knows a cheaper way to get the TDs of a TD using WWW::Mechanize::Chrome or have any other suggestion pls. do tell !

    TIA!

    --
    Alex

getting rid of UTF-8
4 direct replies — Read more / Contribute
by BernieC
on Nov 24, 2022 at 15:48
    I have a file that *should* be all ISO-latin, but the program that created it seems to sprinkle UTF-8 characters round in it. For example, the file begins

    ef bb bf 49 6d 70 6f 46 69 72 73 74 20 4e 61 6d

    later on there's

    2c 2c 2c 2c 2c 2c 2c 2c 2c 2c 2c 2c 22 ef bb bf 39 35 33 2d 31 35 31 33 0d 0a 53 63 6f 74 74 20

    And that kind of thing pops up all throughout the file. I tried "cleaning" it by running every line through

    $line = Encode::encode("ISO-8859-1", $line);

    But it didn't help. I also tried

    $text =~ s/^\xef\xbb\xbf//g ;

    It didn't help either. Is there some way to get rid of it all?

Tagging a corpus with multiple tags
1 direct reply — Read more / Contribute
by veg_running
on Nov 24, 2022 at 07:10

    Hi all, I need help adapting this code to assign multiple tags to tokens in a corpus. The code currently only prints the last tag assigned, but when I took a closer look at my tagset, I realised that the same token could have multiple tags and I would like to assign them all so that a human could check these later.

    An example of the input here:

    Abanye abahlanu balimale kanzima . Abanye abanazo izinkomo noma izimbuzi . Abaziphathi ngendlela ekhombisa ukufuna ukudlala . Abazithamundayo bathi uzimisele ngokuliphika icala . Abazi ukuthi bakhuluma ngani . abazonikwa amalungelo okudoba ezinga elincane . Ahluleke ngisho ukukuphulula umhlane njengasemihleni . Ahluleke ukuzibamba, azidedele inkaba . Ahluleke ukuzibamba uMaMthembu .

    An example of the tagset:

    icala <ZUL-SIL-0035-n> ukhalo <ZUL-SIL-0036-n> inkaba <ZUL-SIL-0037-n> inkaba <ZUL-SIL-0038-n> isisu <ZUL-SIL-0039-n> isisu <ZUL-SIL-0040-n> isibeletho <ZUL-SIL-0041-n> umhlane <ZUL-SIL-0042-n> iqolo <ZUL-SIL-0043-n> izinqe <ZUL-SIL-0044-n> umdidi <ZUL-SIL-0045-n> umphambili <ZUL-SIL-0046-n> amasende <ZUL-SIL-0047-n> inkomo <ZUL-SIL-0048-n> ubhontshisi <ZUL-SIL-0049-n> ingalo <ZUL-SIL-0050-n> ukuthi bakhuluma <ZUL-SIL-1800-n>

    An example of the output I hope to get (with a tab separating tags where two were assigned):

    Abanye abahlanu balimale kanzima . Abanye abanazo izinkomo <ZUL-SIL-0048-n> noma izimbuzi . Abaziphathi ngendlela ekhombisa ukufuna ukudlala . Abazithamundayo bathi uzimisele ngokuliphika icala <ZUL-SIL-0035-n> . Abazi ukuthi bakhuluma <ZUL-SIL-1800-n> ngani . abazonikwa amalungelo isisu <ZUL-SIL-0039-n>\t<ZUL-SIL-0040-n> ezinga +elincane . Ahluleke ngisho ukukuphulula umhlane <ZUL-SIL-0042-n> njengasemihleni +. Ahluleke ukuzibamba, azidedele inkaba <ZUL-SIL-0037-n>\t<ZUL-SIL-0038- +n> . Ahluleke ukuzibamba uMaMthembu .

    The code I currently have:

    #!/usr/bin/env perl use 5.016; use warnings; use autodie; my $corpusname = 'GFSEBcorpus.zul_selected-sentences_original'; my %words2ids; { open my $fh, '<', "$corpusname.example.tagset.txt"; while (<$fh>) { chomp; my ($text, $token) = split /\t/; $words2ids{fc $text} = $token; } } my $alt = join '|', sort { length($b) <=> length($a) } map fc, keys %words2ids; my $re = qr{(?i:($alt))}; my %found; { open my $in_fh, '<', "$corpusname.txt"; open my $out_fh, '>', "$corpusname.possible-annotation_example.txt +"; while (<$in_fh>) { s/$re/++$found{fc $1}, "$1 $words2ids{fc $1}"/eg; print $out_fh $_; } } delete @words2ids{keys %found}; { open my $fh, '>', "$corpusname.tags-not-found_example.txt"; for (sort keys %words2ids) { say $fh "$_\t$words2ids{$_}"; } }

    Thank you for the help!

hmm - - - something has changed in perl (from 5.34 to 5.36
4 direct replies — Read more / Contribute
by Anonymous Monk
on Nov 23, 2022 at 12:22
    Greetings A friend, now deceased, wrote a perl variant of the venerable 'cal' program so that I could have a calendar with week numbers AND be able to see some 5 years of calendar easily - - - all at once!! Except now (I only use this gift occasionally) when I tried to execute the program - - - well - - - its barfing! See first the part of the code in question:
    foreach my $arg (@ARGV) { if( $arg =~ /^-B(\d+)$/ ) { # months Before $before = $1; } elsif( $arg =~ /^-B$/ ) { $before = shift( @ARGV ); if( $before !~ /^\d+/ ) { die "Bad before argument ($before)\n"; }
    and the resultant (when I try to run the program)
    /$ /usr/local/bin/cal2.pl -B 4 Uncaught exception from user code: Bad before argument (-B)
    This were good in 5.34. I tried looking in the release notes for changes and (well - - - I'm no programmer - - - sorry) I can't spot anything that would be relevant to my issue. TIA
Reading, filtering one collumns' data, writing
1 direct reply — Read more / Contribute
by MoodyDreams999
on Nov 23, 2022 at 11:20

    (a paragraph)

    Hey, I'm basically trying to output a excel spreadsheet and filter 2 columns of data, in this code I'm trying to just start off with filtering one column of data which is phone numbers if the phone numbers aren't 10 I export it to a new sheet. I need some help, it works, doesn't filter properly filters some of the data and it seems like it splits my list in too many ways. It halves the list and then outputs some of the data but not all of the incorrect data that. (a paragraph)

    use strict; use warnings; use Excel::Writer::XLSX; use DBI; use Time::Piece; use Math::Round; ##$dbhA = DBI->connect("DBI:mysql:$VARDB_database:$VARDB_server:$VARD +B_port", "$VARDB_user", "$VARDB_pass") #or die "Couldn't connect to database: " . DBI->errstr; ##$stmt="SELECT t1.postal_code, t1.state FROM asterisk.vicidial_list +t1 inner join asterisk.vicidial_state vu on vu.state=t1.state order b +y state desc;"; #$sth = $dbhA->prepare($stmt) or die "preparing: ",$dbhA->errstr; #$sth->execute or die "executing: $stmt ", $dbhA->errstr; #$sthrows=$sth->rows; my $rowCount = 0; my $filename = "File.xlsx"; my $workbook = Excel::Writer::XLSX->new( $filename ); open(FH, "<", "Source_173_DEBT_10_31_2022_1.csv" ) or die; my $worksheet = $workbook->add_worksheet('List'); my $worksheet2 = $workbook->add_worksheet('List2'); my $format = $workbook->add_format(); $format->set_center_across(); $worksheet->set_column( 0, 0, 20 ); $worksheet->write(0, 0, "source_id" ); $worksheet->write(0, 1, "first_name" ); $worksheet->write(0, 2, "middle" ); $worksheet->write(0, 3, "last_name" ); $worksheet->write(0, 4, "address1" ); $worksheet->write(0, 5, "city"); $worksheet->write(0, 6, "state"); $worksheet->write(0, 7, "postal_code"); $worksheet->write(0, 8, "phone_number"); $worksheet->write(0, 9, "address3"); $worksheet->write(0, 10,"province"); $worksheet->write(0, 11, "email"); my $rowCount1 = my $rowCount2 = 0; while (<FH>){ my @t= split(',',<FH>); #my @ary = $t->fetchrow_array; ### if(length($t[7]) == 10) FOR one singular if statement matc +hing 10 characters # Instead of 2 statements in one for less than or Greater than + 10 > 10 || < 10 if (length($t[8]) == 10) { $worksheet2->write($rowCount1+1, 0, $t[0]); $worksheet2->write($rowCount1+1, 1, $t[1]); $worksheet2->write($rowCount1+1, 2, $t[2]); $worksheet2->write($rowCount1+1, 3, $t[3]); $worksheet2->write($rowCount1+1, 4, $t[4]); $worksheet2->write($rowCount1+1, 5, $t[5]); $worksheet2->write($rowCount1+1, 6, $t[6]); $worksheet2->write($rowCount1+1, 7, $t[7]); $worksheet2->write($rowCount1+1, 8, $t[8]); $worksheet2->write($rowCount1+1, 9, $t[9]); $worksheet2->write($rowCount1+1, 10, $t[10]); $worksheet2->write($rowCount1+1, 11, $t[11]); $rowCount1++; } else { $worksheet->write($rowCount2+1, 0, $t[0]); $worksheet->write($rowCount2+1, 1, $t[1]); $worksheet->write($rowCount2+1, 2, $t[2]); $worksheet->write($rowCount2+1, 3, $t[3]); $worksheet->write($rowCount2+1, 4, $t[4]); $worksheet->write($rowCount2+1, 5, $t[5]); $worksheet->write($rowCount2+1, 6, $t[6]); $worksheet->write($rowCount2+1, 7, $t[7]); $worksheet->write($rowCount2+1, 8, $t[8]); $worksheet->write($rowCount2+1, 9, $t[9]); $worksheet->write($rowCount2+1, 10, $t[10]); $worksheet->write($rowCount2+1, 11, $t[11]); $rowCount2++; } $rowCount++; } $workbook->close(); print $rowCount1.'-'.$rowCount2.'-'.$rowCount close(FH);
    I have a list of 10610 based on my rowCount it looks like it splits it, 5298-7-5305, I see 5298 and 7, 7 is the bad data output, but the rest is missing. I think its because I used split with file handler. I would think if the reading is the issue you could inner join the 2 data sheets
Perl script to replace xloadimage, xmessage
1 direct reply — Read more / Contribute
by teamassociated
on Nov 23, 2022 at 10:13

    I need advice on what module to experiment with to replace xloadimage and xmessage. Xloadimage simply loads images inside an Xwindow while xmessage displays messages like so. Bear in mind it has to be in my Xsession. The reason being is xloadimage and xmessage are not availble in oracle linux 8_64, at least I could not find em. Thank you!

    xloadimage -onroot -fullscreen /opt/mei-pos-tc/res/images/current.jpg xmessage -center -default okay -file $ERRORFILE
decoding a JSON object
3 direct replies — Read more / Contribute
by anautismobserver
on Nov 22, 2022 at 19:58

    This is a dumb question that is taking me hours but which a monk would solve in seconds.

    Below is code that returns a JSON object.

    use strict; use warnings; use Mojo::UserAgent; my $ua_food; my $json_food; my $url_food; $url_food = "https://api.nal.usda.gov/fdc/v1/food/170581?api_key=Oc4b +D3tFWgPAscW0R0gBRivwqEdt0N182PXCGNQO"; $ua_food = Mojo::UserAgent->new; $json_food = $ua_food->get($url_food)->res->json;

    Please tell me how to extract the values for fdcId and the various nutrient items.

    Thank you.

Dynamically determinig fstab file name
2 direct replies — Read more / Contribute
by rgren925
on Nov 22, 2022 at 19:28

    I have a script that runs on linux, solaris, hp-ux and aix.

    It uses Sys::Filesystem to get fs info. Occasionally the account this script runs under does not have read permission to the fstab file. Depending on platform, this file has different names (/etc/fstab, /etc/vfstab, etc.).

    I would like a way to dynamically determine what fstab file Sys::Filesystem is using and check upfront for readability. The doc for Sys::Filesystem says the default at runtime is $Sys::Filesystem::FSTAB but that (variable?) has no value when I try to print it.

    Any ideas?

    Thanks, Rick

I am Getting an Error like this Can't locate pathUtil.pm in @INC
4 direct replies — Read more / Contribute
by Anonymous Monk
on Nov 21, 2022 at 07:26

    I am executing one of the Perl file in "Linux OS" I am getting an error like this:

    Can't locate pathUtil.pm in @INC (you may need to install the pathUtil + module) (@INC contains: /usr/local/lib/perl5/site_perl/5.36.0/x86_64 +-linux /usr/local/lib/perl5/site_perl/5.36.0 /usr/local/lib/perl5/5.3 +6.0/x86_64-linux /usr/local/lib/perl5/5.36.0 /usr/local/lib/perl5/sit +e_perl) at pod_check.pl line 14. BEGIN failed--compilation aborted at pod_check.pl line 14 (#1) (F) You said to do (or require, or use) a file that couldn't be fo +und. Perl looks for the file in all the locations mentioned in @INC, un +less the file name included the full path to the file. Perhaps you nee +d to set the PERL5LIB or PERL5OPT environment variable to say where +the extra library is, or maybe the script needs to add the library nam +e to @INC. Or maybe you just misspelled the name of the file. See "require" in perlfunc and lib. Uncaught exception from user code: Can't locate pathUtil.pm in @INC (you may need to install the +pathUtil module) (@INC contains: /usr/local/lib/perl5/site_perl/5.36. +0/x86_64-linux /usr/local/lib/perl5/site_perl/5.36.0 /usr/local/lib/p +erl5/5.36.0/x86_64-linux /usr/local/lib/perl5/5.36.0 /usr/local/lib/p +erl5/site_perl) at pod_check.pl line 14. BEGIN failed--compilation aborted at pod_check.pl line 14.

    I have found the module like Path::Util.pm. That I have Installed But the error is not resolved. I think it is asking for the combined module like pathUtil.pm, That module I haven't found the Mcpan.org also

    So can anyone help me to solve this issue?

$^O empty in windows powershell
3 direct replies — Read more / Contribute
by WithABeard
on Nov 21, 2022 at 06:44

    When I run the following code in command prompt (cmd), I get the "MSWin32", as expected

    perl -e "print $^O;"

    But when I run the same code in powershell, I get nothing.

    The following code works though, outputting the same in both shells:

    perl -MWin32 -e "print Win32::GetOSName();"

    This outputs Win10Build 19043 (64-bit)

    Is this a bug?

    I'm using StrawberryPerl, perl version: v5.32.1 built for MSWin32-x64-multi-thread


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":


  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (4)
As of 2022-11-26 15:49 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Notices?