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

Seekers of Perl Wisdom

( [id://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
Compile perl with custom compiler path, perlbrew solution preferred
2 direct replies — Read more / Contribute
by bliako
on Jun 13, 2024 at 11:05

    Dear Monkees!

    I need to compile perl from source with custom compiler living in /usr/local/gcc82 (with subdirs bin, include, lib etc.). The reason is that I am embedding CUDA code (which is C) via Inline::C which needs this specific compiler. And XS code must be compiled with same compiler as its perl. (Indeed I get segmentation fault when doing otherwise). So I need perl compiled with this specific compiler and I am doing this on Linux.

    I prefer to let perlbrew do the compilation and installation. Is there a simple way to do it? Alternatively, I need to do it manually.

SOLVED: Get a list attributes from a given tag in Mojo::DOM
1 direct reply — Read more / Contribute
by igoryonya
on Jun 13, 2024 at 06:31
    I am learning a Mojo::UserAgent module and I've stumbled upon an issue, that I can't find an answer to on the internet and Mojo's mans.

    Here is the test code:

    #!/usr/bin/env perl use utf8; use feature 'say'; use Mojo::UserAgent; my $data = undef; #Get correct file my $cache = shift // '/tmp/cache.html'; if(-d $cache){ die("'$cache' is folder. You need to use file."); } if(-e $cache){ $data = Mojo::File->new($cache)->slurp; }else{ say 'Fetching fresh HTML'; my $ua = Mojo::UserAgent->new; my $tx = $ua->get('https://www.mojolicious.org'); die "Could not fetch! Error is ", $tx->result->code unless($tx->re +sult->is_success); $tx->result->content->asset->move_to($cache); $data = $tx->result->body; #->body is not only <body>...</body> +, but a complete loaded resource content for 1 file. } say "Tags are:\n\t", Mojo::DOM->new($data)->find('a')->map(attr=>'href +')->uniq->sort->join("\n\t");
    It works, but, is there a way to list the existing attributes from a given tag?
    I tried to find it out from Mojo:
    :DOM
    :Asset
    :Content
    and I didn't find any mentioning of attr enumeration or conversion to string.
    Is there a way to find out what tags exist on found tag?

    Something like this, probably?:

    Mojo::DOM->new($data)->find('a')->map(attr=>'*')->join("\n\t");
    I tried to enumerate with:
    my %attrs = "Tags are:\n\t", Mojo::DOM->new($data)->attr; map{ print "(%s)/(%s)\n", $_, $attrs{$_} } sort keys %attrs;
    But I only got empty hash.

    UPDATE

    OK, i've figured it out:
    my $dom = Mojo::DOM->new($data); map{ say } $dom->find('a')->first; my $attrs = $dom->find('a')->first->attr; map{ printf "(%s)/(%s)\n", $_, $attrs->{$_} } sort keys %$attrs;
Defined test creates non-empty hash value
2 direct replies — Read more / Contribute
by glendeni
on Jun 12, 2024 at 12:34

    I'd always assumed tests could never _create_ anything - they were just tests that either succeeded or failed, never actually affecting variables solely by being used. So was very surprised to recently find that use of the 'defined' test on a hash of arrays ala

    defined $hash{$name}[$integer]

    actually _created_ an empty $hash{$name} if $hash{$name} is non-existent, so is thereafter not non-existent.

    Example code:

    my %hash = ( "A" => [ 1,2 ] ) ; if ( exists $hash{"B"} ) { say "This will NOT print" ; } if ( defined $hash{"B"}[1] ) { say "This will NOT print" ; } if ( exists $hash{"B"} ) { say "This WILL print" ; }

    So the "correct" test for existence of an array element in a hash of arrays should be

    if ( exists $hash{"B"} && defined $hash{"B"}[1] )

    Would appreciate comments by those with deeper knowledge of perl than I, since I can't see how such creation is in any way beneficial - rather it can introduce problems into a script, since the first use of such a test will fail but a second same test will later succeed without the programmer intending (or expecting) any such change.

    IMHO a test should succed, or fail, or throw an error - period.

    FYI the same occurs for a test ala "$#{$hash{"B"}} > -1".

    Background: Have used perl regularly since 1998 so am experienced in perl, but never dug too deeply into it.

uninitialized value
4 direct replies — Read more / Contribute
by frank1
on Jun 12, 2024 at 04:41

    Am trying to get button to do something, and its working well.

    But how can i get rid of this error

    Use of uninitialized value in string eq at jj.pl

    if (param('btn') eq 'btn') { #Do something }
    <button type="submit" name="btn" value="btn">Do something</button>
Perl and Mysql Queries
3 direct replies — Read more / Contribute
by Milti
on Jun 10, 2024 at 13:13

    I am using Mysql 8.4 and am trying to use a form to provide info to a Perl cgi to insert data into a Mysql database table. Previous I used Mysql 5.7 and was successful with these statements:

    use DBI; print "Content-type: text/html\n\n"; use POSIX qw(strftime); $shortdate = strftime "%B %d, %Y", localtime; $Posted=$shortdate; $JobID=param('JobID'); $EmployerID=param('EmployerID'); $EmployerName=param('EmployerName'); $Title=param('Title'); $City=param('City'); $StateProvince=param('StateProvince'); $Description=param('Description'); $Function=param('Function'); $Sector=param('Sector'); $Country=param('Country'); my $dbh = DBI->connect('dbi:mysql:jobs_db','poster','posterpasswd'); my $sth =$dbh->prepare("INSERT INTO jobs (JobID,EmployerID,EmployerNam +e,Title,City,StateProvince,Description,Function,Sector,Country,Posted +) Values(?,?,?,?,?,?,?,?,?,?,?)"); $sth ->execute($JobID,$EmployerID,$EmployerName,$Title,$City,$StatePro +vince,$Description,$Function,$Sector,$Country,$Posted);
    Everything worked! Now it doesn't work. I have gotten an error message noting syntax error near my $sth=$dbh->prepare and another one indicating the use of place holders has been deprecated and cannot be used. I'm at a lost for ideas. Can anyone provide the currently acceptable way to use Perl statements to insert the data into the table? I would truly appreciate any help offered.

What's the correct and succinct way to refer to object attribute in (informal) description?
3 direct replies — Read more / Contribute
by Anonymous Monk
on Jun 10, 2024 at 04:41

    When writing to someone, I think it's perfectly OK to say e.g. "hey, have a look at HTML::Element::tag() method". But what about attributes?

    • '_tag' attribute of an instance of HTML::Element class? (too wordy)
    • $HTML_Element_obj->{'_tag'}? (is actual class name clear from instance name?)
    • HTML::Element->{'_tag'}? (short, but neither pseudocode nor correct Perl)

    (Suppose it's blessed hashref but not HTML::Element as in example above and there are no getter/setter for an attribute.)

SOLVED:how to assign 'system' to a value, and eval it.
3 direct replies — Read more / Contribute
by vincentaxhe
on Jun 09, 2024 at 10:49
    sub myrun{ ...} my $run = $condition ? 'system' : 'myrun';

    $run @args; or eval {$run @args} did not work like bash do

    what's the trick perl use about this?
Appropriate anova function in MATLAB to check PDL::Stats results?
No replies — Read more | Post response
by etj
on Jun 06, 2024 at 11:21
Comparing graph shapes or soft matching.
8 direct replies — Read more / Contribute
by tweetiepooh
on Jun 05, 2024 at 07:47

    We have multiple sets of data (row counts in Netcool), and I would like to send an alert if there is a discernable difference in those values.

    I can't simply compare the values as they can differ, but if graphed, the lines should line up or nearly line up. I can likely write code but not sure of what I am writing. I am not a maths expert. The actual values at a time could vary greatly but will shortly line up again.

Can a POST command (with a file attachment) be simulated via the terminal?
3 direct replies — Read more / Contribute
by SergioQ
on Jun 04, 2024 at 21:34

    I have a perl script that accepts a POST command from my iPhone app.

    It has two params: userid and username as well as the data from a file it is sending.

    Currently, for debugging (the perl script) I have to run my iPhone simulator, and go through a bunch of steps.

    It would be awesome if there was a way to run my perl script from the server terminal, it would be a huge time saver. Obviously I can do it with just the username and userid, but the script fails without receiving the data from the file. And obviously that's where I need to do my debugging, the data from the file.

    Is there a way to do this all from the linux terminal where my script is located?

    Thank you


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?Last hourOther CB clients
Other Users?
Others examining the Monastery: (4)
As of 2024-06-19 13:09 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?
    erzuuli‥ 🛈The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.