Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight

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
Using DBIx::Class::Schema::Loader with Oracle
No replies — Read more | Post response
by cLive ;-)
on May 27, 2022 at 20:08

    I've tried to create a DBIx Schema for an Oracle DB, but all I'm getting is the basic schema class. It's been a while since I've touched Oracle (and DBIx::Class from first principles), so I'm wondering if I'm missing something obvious.

    perl -MDBIx::Class::Schema::Loader=make_schema_at,dump_to_dir:./lib -e 'make_schema_at("My::Schema", { debug => 1 }, [ ... credentials ... ]

    On running, I just get the one module:


    I was under the impression that I would get a full schema dump of all the tables in the DB.

    Using the same credentials, I can get a $dbh and run the query

    SELECT table_name FROM all_tables ORDER BY table_name

    to get a list of all the tables, so why can't I get the Schema definitions for them? Would it be a user permission? If so, how would I check what perms my user has? At the moment, I'm going in blind and not sure what questions I need to be asking, so any insights appreciated. If I need to get a different user for this I guess I'll put in the request, but I was hoping to be able to work it out with what I have.

    Running SELECT * FROM USER_TAB_PRIVS I see a bunch of select/update/execute perms.

    Running SELECT * FROM USER_SYS_PRIVS gives me nothing.

    Running SELECT * FROM USER_ROLE_PRIVS gives me a bunch of perms (not sure what they all are just yet, only that they exist).

Exec command through ssh connexion from window
1 direct reply — Read more / Contribute
by WTem
on May 27, 2022 at 19:01

    Hi all, I would like to do a simple script that will send a command to a server through ssh from a windows machine. I am positive that the ssh connexion is established but I can't see if the command was really sent, I just got no result at all. My ref doc for doing this script: Here is my script:

    #!/usr/bin/perl -w #### Bibliothèques use strict; use warnings; use Net::SSH2; #### Variables my $ip='X.X.X.X'; my $user='user'; my $password='passwd'; #print "IMEI: "; #my $imei = <>; #chomp($imei); #my $cmd = "/opt/LSS/bin/ueadmin_cli -o delete -I $imei"; my $cmd = "ls"; # this command for testing purpose only #### Open SSH connexion and sending command my $ssh = Net::SSH2->new(); $ssh->connect("$ip") or die "SSH connexion Failed.\n"; if ($ssh->auth_password("$user","$password")) { my $chan = $ssh->channel(); $chan->exec($cmd); print while <$chan>; $chan->close(); }else {print "authentication failed.\n";} $ssh->disconnect;
CGI script only works if named
1 direct reply — Read more / Contribute
by almsdealer
on May 27, 2022 at 14:19

    If I hit I see the output in browser.

    If I hit If I hit I get an error in the apache log:

    stderr from /var/www/cgi-bin/ AH01241: error spawning CGI child: exec of '/var/www/cgi-bin/' failed (Permission denied)

    Both the and have exactly the same content (for debugging reasons)

    Both the and have exactly the same owner and file permissions (chmod +a)

    I can execute the file manually like ./ and see the correct output

    My apache config looks like this:

    # # This is the main Apache HTTP server configuration file. It contains + the # configuration directives that give the server its instructions. # See <URL:> for detailed information +. # In particular, see # <URL:> # for a discussion of each configuration directive. # # See the httpd.conf(5) man page for more information on this configur +ation, # and httpd.service(8) on using and configuring the httpd service. # # Do NOT simply read the instructions in here without understanding # what they do. They're here only as hints or reminders. If you are +unsure # consult the online docs. You have been warned. # # Configuration and logfile names: If the filenames you specify for ma +ny # of the server's control files begin with "/" (or "drive:/" for Win32 +), the # server will use that explicit path. If the filenames do *not* begin # with "/", the value of ServerRoot is prepended -- so 'log/access_log +' # with ServerRoot set to '/www' will be interpreted by the # server as '/www/log/access_log', where as '/log/access_log' will be # interpreted as '/log/access_log'. # # ServerRoot: The top of the directory tree under which the server's # configuration, error, and log files are kept. # # Do not add a slash at the end of the directory path. If you point # ServerRoot at a non-local disk, be sure to specify a local disk on t +he # Mutex directive, if file-based mutexes are used. If you wish to sha +re the # same ServerRoot for multiple httpd daemons, you will need to change +at # least PidFile. # ServerRoot "/etc/httpd" # # Listen: Allows you to bind Apache to specific IP addresses and/or # ports, instead of the default. See also the <VirtualHost> # directive. # # Change this to Listen on a specific IP address, but note that if # httpd.service is enabled to run at boot time, the address may not be # available when the service starts. See the httpd.service(8) man # page for more information. # #Listen Listen 80 # # Dynamic Shared Object (DSO) Support # # To be able to use the functionality of a module which was built as a + DSO you # have to place corresponding `LoadModule' lines at this location so t +he # directives contained in it are actually available _before_ they are +used. # Statically compiled modules (those listed by `httpd -l') do not need # to be loaded here. # # Example: # LoadModule foo_module modules/ # Include conf.modules.d/*.conf # # If you wish httpd to run as a different user or group, you must run # httpd as root initially and it will switch. # # User/Group: The name (or #number) of the user/group to run httpd as. # It is usually good practice to create a dedicated user and group for # running httpd, as with most system services. # User apache Group apache # 'Main' server configuration # # The directives in this section set up the values used by the 'main' # server, which responds to any requests that aren't handled by a # <VirtualHost> definition. These values also provide defaults for # any <VirtualHost> containers you may define later in the file. # # All of these directives may appear inside <VirtualHost> containers, # in which case these default settings will be overridden for the # virtual host being defined. # # # ServerAdmin: Your address, where problems with the server should be # e-mailed. This address appears on some server-generated pages, such # as error documents. e.g. # ServerAdmin root@localhost # # ServerName gives the name and port that the server uses to identify +itself. # This can often be determined automatically, but we recommend you spe +cify # it explicitly to prevent problems during startup. # # If your host doesn't have a registered DNS name, enter its IP addres +s here. # #ServerName # # Deny access to the entirety of your server's filesystem. You must # explicitly permit access to web content directories in other # <Directory> blocks below. # <Directory /> AllowOverride none Require all denied </Directory> # # Note that from this point forward you must specifically allow # particular features to be enabled - so if something's not working as # you might expect, make sure that you have specifically enabled it # below. # # # DocumentRoot: The directory out of which you will serve your # documents. By default, all requests are taken from this directory, b +ut # symbolic links and aliases may be used to point to other locations. # DocumentRoot "/var/www/html" # # Relax access to content within /var/www. # <Directory "/var/www"> AllowOverride None # Allow open access: Require all granted </Directory> # Further relax access to the default document root: <Directory "/var/www/html"> # # Possible values for the Options directive are "None", "All", # or any combination of: # Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI M +ultiViews # # Note that "MultiViews" must be named *explicitly* --- "Options A +ll" # doesn't give it to you. # # The Options directive is both complicated and important. Please + see # # for more information. # Options Indexes FollowSymLinks # # AllowOverride controls what directives may be placed in .htacces +s files. # It can be "All", "None", or any combination of the keywords: # Options FileInfo AuthConfig Limit # AllowOverride None # # Controls who can get stuff from this server. # Require all granted </Directory> # # DirectoryIndex: sets the file that Apache will serve if a directory # is requested. # <IfModule dir_module> DirectoryIndex index.html </IfModule> # # The following lines prevent .htaccess and .htpasswd files from being + # viewed by Web clients. # <Files ".ht*"> Require all denied </Files> # # ErrorLog: The location of the error log file. # If you do not specify an ErrorLog directive within a <VirtualHost> # container, error messages relating to that virtual host will be # logged here. If you *do* define an error logfile for a <VirtualHost +> # container, that host's errors will be logged there and not here. # ErrorLog "logs/error_log" # # LogLevel: Control the number of messages logged to the error_log. # Possible values include: debug, info, notice, warn, error, crit, # alert, emerg. # LogLevel warn <IfModule log_config_module> # # The following directives define some format nicknames for use wi +th # a CustomLog directive (see below). # LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agen +t}i\"" combined LogFormat "%h %l %u %t \"%r\" %>s %b" common <IfModule logio_module> # You need to enable mod_logio.c to use %I and %O LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Ag +ent}i\" %I %O" combinedio </IfModule> # # The location and format of the access logfile (Common Logfile Fo +rmat). # If you do not define any access logfiles within a <VirtualHost> # container, they will be logged here. Contrariwise, if you *do* # define per-<VirtualHost> access logfiles, transactions will be # logged therein and *not* in this file. # #CustomLog "logs/access_log" common # # If you prefer a logfile with access, agent, and referer informat +ion # (Combined Logfile Format) you can use the following directive. # CustomLog "logs/access_log" combined </IfModule> <IfModule alias_module> # # Redirect: Allows you to tell clients about documents that used t +o # exist in your server's namespace, but do not anymore. The client + # will make a new request for the document at its new location. # Example: # Redirect permanent /foo # # Alias: Maps web paths into filesystem paths and is used to # access content that does not live under the DocumentRoot. # Example: # Alias /webpath /full/filesystem/path # # If you include a trailing / on /webpath then the server will # require it to be present in the URL. You will also likely # need to provide a <Directory> section to allow access to # the filesystem path. # # ScriptAlias: This controls which directories contain server scri +pts. # ScriptAliases are essentially the same as Aliases, except that # documents in the target directory are treated as applications an +d # run by the server when requested rather than as documents sent t +o the # client. The same rules about trailing "/" apply to ScriptAlias # directives as to Alias. # ScriptAlias "/cgi-bin/" "/var/www/cgi-bin/" </IfModule> # # "/var/www/cgi-bin" should be changed to whatever your ScriptAliased # CGI directory exists, if you have that configured. # <Directory "/var/www/cgi-bin/"> AllowOverride None Options None Require all granted </Directory> <IfModule mime_module> # # TypesConfig points to the file containing the list of mappings f +rom # filename extension to MIME-type. # TypesConfig /etc/mime.types # # AddType allows you to add to or override the MIME configuration # file specified in TypesConfig for specific file types. # #AddType application/x-gzip .tgz # # AddEncoding allows you to have certain browsers uncompress # information on the fly. Note: Not all browsers support this. # #AddEncoding x-compress .Z #AddEncoding x-gzip .gz .tgz # # If the AddEncoding directives above are commented-out, then you # probably should define those extensions to indicate media types: # AddType application/x-compress .Z AddType application/x-gzip .gz .tgz # # AddHandler allows you to map certain file extensions to "handler +s": # actions unrelated to filetype. These can be either built into th +e server # or added with the Action directive (see below) # # To use CGI scripts outside of ScriptAliased directories: # (You will also need to add "ExecCGI" to the "Options" directive. +) # #AddHandler cgi-script .cgi # For type maps (negotiated resources): #AddHandler type-map var # # Filters allow you to process content before it is sent to the cl +ient. # # To parse .shtml files for server-side includes (SSI): # (You will also need to add "Includes" to the "Options" directive +.) # AddType text/html .shtml AddOutputFilter INCLUDES .shtml </IfModule> # # Specify a default charset for all content served; this enables # interpretation of all content as UTF-8 by default. To use the # default browser choice (ISO-8859-1), or to allow the META tags # in HTML content to override this choice, comment out this # directive: # AddDefaultCharset UTF-8 <IfModule mime_magic_module> # # The mod_mime_magic module allows the server to use various hints + from the # contents of the file itself to determine its type. The MIMEMagi +cFile # directive tells the module where the hint definitions are locate +d. # MIMEMagicFile conf/magic </IfModule> #<Directory "/var/www/html"> # FallbackResource "" #</Directory> # # Customizable error responses come in three flavors: # 1) plain text 2) local redirects 3) external redirects # # Some examples: #ErrorDocument 500 "The server made a boo boo." #ErrorDocument 404 /missing.html #ErrorDocument 404 "/cgi-bin/" #ErrorDocument 402 # # # EnableMMAP and EnableSendfile: On systems that support it, # memory-mapping or the sendfile syscall may be used to deliver # files. This usually improves server performance, but must # be turned off when serving from networked-mounted # filesystems or if support for these functions is otherwise # broken on your system. # Defaults if commented: EnableMMAP On, EnableSendfile Off # #EnableMMAP off EnableSendfile on # Supplemental configuration # # Load config files in the "/etc/httpd/conf.d" directory, if any. IncludeOptional conf.d/*.conf

    Does anyone know what I might be doing wrong?

How can I set a bit to 0 ?
9 direct replies — Read more / Contribute
by bartender1382
on May 26, 2022 at 12:09

    I feel silly asking this, but...

    I know how to set bits, and check for them. What I don't know how to do, nor find on Google,is turn off a specific bit whether it is set or not.

    my $stats = 0; $stats = upload | getTicket | downLoading; printCLine($stats);

    Yes, I can reset every bit minus the one I want, but that feels kludgy

In my perl script one of the variable it is giving an extra dot.
6 direct replies — Read more / Contribute
by Anonymous Monk
on May 25, 2022 at 03:05

    How to remove the . in the generated string

    my $file = shift;

    For the above variable it is giving an output like this "./root/git/common/crt_del/cert/DEFAULT.pem"

    I want to remove the "." before the /root for that can i use like this $file =~ s{.}{}g or any other way is there to remove that dot in the string

Purpose of =~ and = in this statement
1 direct reply — Read more / Contribute
by sherab
on May 23, 2022 at 13:29

    Monks, I come seeking wisdom and am confused by a statement I see.... I inherited a perl code project, and this statement in this foreach loop is confusing me... $chapter will end up being something like "5","7", and "11V"....

    foreach my $chapter (.....){ ( $chapter =~ /5/ ) and ( $chapter = 5 ); ...... ...... }
    The second part of the "and" seems to be assigning "5" to $chapter but I'm normally used to the first part as being "If $chapter matches 5 then do something". Please accept my apologies ahead of time because this may be crazy simple but what is this statement doing?
Cleaning %PATH% with WinBatch
5 direct replies — Read more / Contribute
by LanX
on May 22, 2022 at 12:36

    NB: Not off-topic!

    I'm trying to build a one-click solution to switch between various Perl versions on Win for my colleagues.

    Using portableshell.bat from strawberries portable versions works very good so far.

    It will basically add the needed PATHs in %PATH%

    C:\perls\strawberry-perl-\perl\site\bin;C:\perls\strawberry-perl-\perl\\bin;C:\perls\strawberry-perl-\c\bin;C:\Windows\system32;... etc

    To make this even more idiot proof (talking about me not my colleagues ;) I'd like to purge all older entries from PATH C:\perls\*;

    My BAT-Shell knowhow is limited, I was only able to find a weak solution by replacing C:\perls\ with a dummy DISABLED to "sabotage" those entries, but it'll keep ugly artifacts in the PATH. (I doubt this will insert much of a performance penalty)

    So is there a good way to delete those older entries?

    (off course I could spawn a perl one-liner, but the basic idea of BAT is to keep the delay minimal)


    Cheers Rolf
    (addicted to the Perl Programming Language :)
    Wikisyntax for the Monastery

    PS: Yes I know about berrybrew, and I will look into it. But for the time being we need to extend this solution to support ActiveState too.

LWP and Mechanize
3 direct replies — Read more / Contribute
by perlmike
on May 21, 2022 at 15:34

    I used to use LWP and Mechanize to download files from the internet, but they stopped working today. Does anyone know what's going on? Thanks!

    use strict; use warnings; use LWP::UserAgent(); my $ua = LWP::UserAgent->new(timeout => 10); $ua->env_proxy; my $response = $ua->get(' +/2019/QTR1/master.idx'); open(OUT, ">" . "master") or die "Cannot open master"; if ($response->is_success) {print OUT $response->decoded_content; } else {die $response->status_line;} close OUT;
Capture a non-printable char and test what it is
2 direct replies — Read more / Contribute
by almsdealer
on May 21, 2022 at 10:03

    Good morning,

    Can anyone tell me how I would capture a non-printable character from STDIN and test what the character is?

    Specifically, I want to test if the escape key has been pressed.

    Trying to build a console based text editor.

The wonders of Test::More
2 direct replies — Read more / Contribute
by syphilis
on May 21, 2022 at 09:29

    Have a laugh at this piece of brilliance:
    C:\>perl -MMath::MPFR -MTest::More -e "cmp_ok(Math::MPFR->new(2), '!=' +, Math::MPFR->new(2), 'test for blow up'); done_testing();" not ok 1 - test for blow up # Failed test 'test for blow up' # at -e line 1. Operation "eq": no method found, left argument in overloaded package Math::MPFR, right argument in overloaded package Math::MPFR at C:/perl-5.3 +4.0/site/lib/Test/ line 1006. A context appears to have been destroyed without first calling release +(). Based on $@ it does not look like an exception was thrown (this is not + always a reliable test) This is a problem because the global error variables ($!, $@, and $?) +will not be restored. In addition some release callbacks will not work prop +erly from inside a DESTROY method. Here are the context creation details, just in case a tool forgot to c +all release(): File: -e Line: 1 Tool: Test::More::cmp_ok Here is a trace to the code that caused the context to be destroyed, t +his could be an exit(), a goto, or simply the end of a scope: Context destroyed at C:/perl-5.34.0/site/lib/Test/ line 1006 +. eval {...} called at C:/perl-5.34.0/site/lib/Test/ l +ine 1006 Test::Builder::cmp_ok(Test::Builder=HASH(0x24eaa60), Math::MPF +R=SCALAR(0x86b998), "!=", Math::MPFR=SCALAR(0x33cf88), "test for blow + up") called at C:/perl-5.34.0/site/lib/Test/ line 511 Test::More::cmp_ok(Math::MPFR=SCALAR(0x86b998), "!=", Math::MP +FR=SCALAR(0x33cf88), "test for blow up") called at -e line 1 Cleaning up the CONTEXT stack... # Tests were run but no plan was declared and done_testing() was not s +een. # Looks like your test exited with 255 just after 1.
    Note that the problem arises at C:/perl-5.34.0/site/lib/Test/ line 1006.
    It's not the test failure that's an issue - pretty obviously, that test should fail.
    It's the ensuing fatal over-the-top blowup that's my main concern.
    Here's the actual section of the Test::Builder code that blows up:
    ... unless($ok) { $self->$unoverload( \$got, \$expect ); if( $type =~ /^(eq|==)$/ ) { $self->_is_diag( $got, $type, $expect ); } elsif( $type =~ /^(ne|!=)$/ ) { no warnings; my $eq = ($got eq $expect || $got == $expect) ## LINE 1006 ...
    The evaluation of $got eq $expect is bound to be interesting if $got is an object and the 'eq' operator has not been overloaded

    Anyway ... my question is "what is the bug ?"
    Is it that 'eq' overloading has not been provided ? (Providing such overloading successfully works around the problem.)
    Is it that Test::More (or Test::Builder) should not be assuming that 'eq' has been overloaded ?
    Or has Test::Builder tried (and failed) to account for this possibility. I'm looking at $self->$unoverload( \$got, \$expect ) in the above snippet from, and wondering what that might be intended to do.

    With math objects, I've never felt the need to be able to compare $obj eq $str. If I need to do that I just make use of the overloaded stringification and compare "$obj" eq $str.

    I'm interested to hear thoughts on what is the "correct" way to deal with this issue.


Add your question
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?

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

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (2)
As of 2022-05-28 13:24 GMT
Find Nodes?
    Voting Booth?
    Do you prefer to work remotely?

    Results (99 votes). Check out past polls.