Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
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
When i am installing an Digest::SHA1 module i am getting an error like this so anyone can help on this.
2 direct replies — Read more / Contribute
by Anonymous Monk
on May 16, 2022 at 10:16

    When i am installing an Digest::SHA1 module i am getting an error like below

    sudo perl Makefile.PL Checking if your kit is complete... Looks good ExtUtils::MM_Unix::tool_xsubpp : Can't find xsubpp at /usr/local/share +/perl5/ExtUtils/MM_Unix.pm line 3903.
HSV/HSL in SVG?
2 direct replies — Read more / Contribute
by BernieC
on May 16, 2022 at 07:01
    I'm doing some graphics hacking with the SVG module and it works great.. but... RBG is a bit of a crude color hammer. Is there a way to do HSL or HSV color selection with the SVG module?
replacing literals with constants
4 direct replies — Read more / Contribute
by hexcoder
on May 14, 2022 at 05:02
    Hello dear monks,

    in my latest project I wanted to replace hard coded literals with constants.
    In one case there was a simple loop, which used an expression with a constant for the terminal range value.
    Here i stumbled upon an unexpected behavior.
    Can someone shed some light on what is going on?

    Thanks a lot!

    This test program

    use strict; use warnings; sub ten { 10 } print "9 .. 10 - 1 without constant\n"; for my $i (9 .. 10 - 1) { print $i, "\n"; } print "-> expected\n\n"; print "9 .. 10 - 1 with constant()\n"; for my $i (9 .. ten() - 1) { print $i, "\n"; } print "-> expected\n\n"; print "9 .. 10 - 1 with constant\n"; for my $i (9 .. ten - 1) { print $i, "\n"; } print "-> unexpected\n\n"; print "9 .. 10 with constant\n"; for my $i (9 .. ten) { print $i, "\n"; } print "-> expected\n\n";
    (run with Strawberry Perl 5.26.2) yields:
    9 .. 10 - 1 without constant 9 -> expected 9 .. 10 - 1 with constant() 9 -> expected 9 .. 10 - 1 with constant 9 10 -> unexpected 9 .. 10 with constant 9 10 -> expected
    It seems literals cannot simply be replaced by defined constants, which i consider rather unfortunate.
How to grep for values & see the keys?
4 direct replies — Read more / Contribute
by misterperl
on May 13, 2022 at 09:23
    I've never figured out a concise way to do this. I have a hash and I want to seek certain values, and ALSO see the keys for those values, like:
    DB<1> x grep /cat/, values %h
    I see my values, but I ALSO want to see each corresponding key. Obviously it's a simple matter to write a for(){} to do this, but I'm thinking there is some elusive grep that can do it using the hash in list context? Oh maybe "each"..

    My spidey sense says it in there somewhere.. Happy Friday the 13th team Perl!

Cant get a clean 5.34 Perl built...
1 direct reply — Read more / Contribute
by misterperl
on May 13, 2022 at 09:09
    I'm on attempt like 4 now. Problem is, wherever I build it (.) , @INC ends up with a bunch of ./.cpan/build/ entries. But the README , etc, doesn't state to build in any certain location so its perplexing. After the build, I do:
    DBG> x @INC
    and about half the entries are .cpan . And worse- I read these are built into the binaries so they can't be adjusted out.

    I'm not doing anything odd - just the steps in the README.

    Help please!

Is mod_perl going the way of the dinosaur?
8 direct replies — Read more / Contribute
by Polyglot
on May 12, 2022 at 06:13

    I've looked everywhere--been stumped on this for over a day already: I thought it would be simple to install mod_perl.so into the Apache 2.4 setup...but it was not to be. Searching here and elsewhere online, it is unclear whether mod_perl itself is being phased out of existence. FastCGI, no longer downloadable from some servers (phased out already), seems to be promoted here; but I am left wondering where one obtains it?

    A friend wants to run my scripts on his Windows computer. I haven't been a Windows user in over 10 years, but thought it should be doable. I installed MySQL, Apache24, and Strawberry Perl, being careful to configure them along the way. But that's just where the problem was...it seems to be an impossible combination on a Windows 11 platform.

    First, there was no 'mod_perl.so'. In attempting to compile this from the source tarball I found online (had to install WinRAR just to unpack it), I was unable to compile mod_perl owing to lack of 'make'. I downloaded a heap of stuff from Microsoft (over 8 GB) just trying to get their 'make' program among all of the other C++ development tools they wanted to feed me. And when I finally had 'nmake', it failed to compile anything on one error after another. Looking online, I was not alone. No site has a compiled version, and it's not possible to compile one. After many hours of pure frustration, I tried to substitute a packaged arrangement instead: XAMPP. So, I uninstalled everything, then installed XAMPP, which is supposed to have it all. But, even after starting the apache and mysql services, and making sure perl was in the path, I still saw code displayed in the browser instead of it's getting executed.

    Turns out, XAMPP provided no mod_perl either. None.

    And then I find threads here discussing whether mod_perl is even needed anymore? The future of mod_perl

    If one chooses not to use mod_perl, what other option is there to get a script to actually run under Apache 2.4?

    Blessings,

    ~Polyglot~

I have to change my libxml version or not?
2 direct replies — Read more / Contribute
by Anonymous Monk
on May 12, 2022 at 03:19

    The libxml2 version and the perl version are different in my Pc so can i change my libxml2 version or no need

    libxml2 version

    /usr/lib/libxml2.so.2 /usr/lib/libxml2.so.2.9.1 /usr/lib64/libxml2.so.2 /usr/lib64/libxml2.so.2.9.1

    Perl Version

    This is perl 5, version 16, subversion 3 (v5.16.3) built for x86_64-li +nux-thread-multi (with 39 registered patches, see perl -V for more detail) Copyright 1987-2012, Larry Wall Perl may be copied only under the terms of either the Artistic License + or the GNU General Public License, which may be found in the Perl 5 source ki +t. Complete documentation for Perl, including FAQ lists, should be found +on this system using "man perl" or "perldoc perl". If you have access to + the Internet, point your browser at http://www.perl.org/, the Perl Home Pa +ge.
Help with Creating a Table from array ref I parsed in
4 direct replies — Read more / Contribute
by perlynewby
on May 12, 2022 at 02:57

    Hello Monks, I need help understanding how to format some text. I opted for an array since I do not know how to add multiple values to key in a hash. Clearly, I do not understand how to manipulate the array of elements to create a table equally align.

    desired output, name of probe on the left side then all (x,y) coords and units on the right:

    MM_STD_gate -61.771653 -45.472441 mils + -1569.000000 -1155.000000 micro +ns RFN_a -91.102362 68.307087 mils + -2314.000000 1735.000000 micro +ns RFN_b -62.165354 68.307087 mils + -1579.000000 1735.000000 micron +s RFN_c -51.417322 68.307087 mils + -1306.000000 1735.000000 micro +ns
    #!/usr/bin/perl #use strict; use warnings; use Data::Dumper; my @records; my @col; my ($probe, $x_coord, $y_coord, $mils, $micron); my $infile= 'coord.txt'; open (DATA,'<',$infile) or die "could not open the $infile: $!"; while (<DATA>) { chomp; my @col = split " ", $_; push @records, \@col; } #print Dumper(\@col, @records); for (\@col){ print join("\t",$col{$records[0]}, $col{$records[1]}, $col{$record +s[2]}, $col{$records[3]}); } #this for loop doesn't work

    DATA can be presented in unalign format

    __DATA__ MM_STD_gate -61.771653 -45.472441 mils -1569.000000 -1155.000000 microns RFN_a -91.102362 68.307087 mils + -2314.000000 1735.000000 microns RFN_b -62.165354 68.307087 mils + -1579.000000 1735.000000 microns RFN_c -51.417322 68.307087 mils + -1306.000000 1735.000000 + microns
warning! -- Why?
5 direct replies — Read more / Contribute
by jwkrahn
on May 11, 2022 at 23:37
    sub process_variables { my ( $value, $remove_undef ) = @_; $value =~ s/ (?<! \\ ) \$ \{ ( .*? ) \} / defined $variable{ $1 } ? $variable{ $1 } : defined $remove_undef && $remove_undef # for if statements, any variable that is not defined, # we simple convert to 0 ? '0' # This could be an option that is used later, save # it so we don't warn if this option is not one of # ktests options. And put back the origin piece. : ( $used_options{ $1 } = 1 and "\${$1}" ) /exg; return $value; }

    The code above produces the warning message:
    Found = in conditional, should be == at file line n.
    If I change:
    ( $used_options{ $1 } = 1 and "\${$1}" )
    To:
    do { $used_options{ $1 } = 1 and "\${$1}" }
    I still get the same warning message.

    But obviously the message is wrong because there is no = in conditional.

    $ perl -v This is perl 5, version 24, subversion 1 (v5.24.1) built for x86_64-li +nux-gnu-thread-multi (with 90 registered patches, see perl -V for more detail) Copyright 1987-2017, Larry Wall Perl may be copied only under the terms of either the Artistic License + or the GNU General Public License, which may be found in the Perl 5 source ki +t. Complete documentation for Perl, including FAQ lists, should be found +on this system using "man perl" or "perldoc perl". If you have access to + the Internet, point your browser at http://www.perl.org/, the Perl Home Pa +ge.
Is there a way to make a JSON out of multiple records from MySQL?
1 direct reply — Read more / Contribute
by bartender1382
on May 10, 2022 at 22:57

    I am trying to transfer data from MySQL, over to an app in Swift.

    I use the following code when I have to send over just ONE record:

    This creates a hash of every field in my table

    sub reader { foreach my $rows (@$data) { my %GenericData; @GenericData{ @rawFields } = @$rows; # NOTE added push @rawRecords, \%GenericData; } return \@rawRecords;

    Then I encode the JSON like so, so I can send it over as HTTP DATA

    my $rows = reader($mysqlFilename); ...in reader my $json = encode_json($hashref, { lastname => JSON_TYPE_STRING, firstname => JSON_TYPE_STRING, age => JSON_TYPE_INT} ); ...and I return $json which is the single record.

    However, I am now pulling more than one record, and I wondered if it's possible to export multiple records to JSON?


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 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 taking refuge in the Monastery: (5)
As of 2022-05-26 18:40 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Do you prefer to work remotely?



    Results (93 votes). Check out past polls.

    Notices?