Perl quoting file names




















A module is just a set of related functions in a library file, i. At the terminal I can test it out:. So now I have a distribution with a module containing a different package name, how well does it work with the CPAN toolchain? The indexer requires that a distribution has a module with a matching package name in it.

This makes sense as it discourages users from uploading conflicting package names into different distributions. So this works:. As conventions go, using the same package and module name is useful and recommended.

Especially if the code is going to be shared via CPAN or otherwise. This article was originally posted on PerlTricks. David is the editor of Perl. It wastes less of your time, and it wastes less of our time. Having a pair of parentheses or even one parenthesis in a file name of itself doesn't cause any trouble if the name is quoted sufficiently.

As I noted, double quotes are adequate for this specific file name and a good many others, even ones containing special characters ; as ikegami noted , there are other names that will cause problems.

Specifically, names containing dollar signs, back quotes or double quotes will cause grief with double quotes; names containing single quotes will cause grief with single quotes. Ikegami also notes that there is a module, String::ShellQuote , which is designed to deal with these problems. It is not a Perl core module so you would have to install it yourself, but using it would be sensible if you have to deal with any perverse name that the user might throw your way. I'm not clear what strings can't be safely quoted; the documentation doesn't elaborate on the issue.

Stack Overflow for Teams — Collaborate and share knowledge with a private group. Create a free Team What is Teams? Collectives on Stack Overflow. Learn more. Open file with special characters in file name in Perl Ask Question. Asked 6 years, 4 months ago. Active 6 years, 4 months ago.

Viewed 1k times. Improve this question. San San 5 5 silver badges 15 15 bronze badges. There shouldn't be any problem. Can you show the code you use? Usernames and passwords should be retrieved from configuration files or from environment variables. It defines a set of methods, variables and conventions that provide a standard database interface.

Other languages have created similar universal interfaces for working with databases. The DBI is also responsible for the dynamic loading of drivers, error checking and handling, providing default implementations for methods, and many other non-database specific duties.

The DBI dispatches method calls to the appropriate database driver. The database drivers are supplied by database vendors. In this tutorial, we work with the MariaDB database. The connect method is used to establish a connection to the database. The disconnect method is used to close the database connection. The connect method establishes a database connection to the requested data source.

It returns a database handle object if the connection succeeds. We use the disconnect method to terminate the connection. It is a string that tells DBI what kind of driver it should load and the location of the database to which the connection is going to be created. The dsn starts always with the dbi: substring.

Then we have the driver name. In our case the driver name is MariaDB. The third part is the database name. We work with testdb throughout this tutorial. The final parameter is a reference to hash, in which we can set attributes to alter the default settings of a connection.

For example the RaiseError attribute can be used to force errors to raise exceptions rather than return error codes. The HandleError attribute can be used to provide a subroutine which is called in case of error. The AutoCommit attribute sets or unsets the autocommit mode.

In case the connection fails, this message is displayed and the script is aborted. The ping method attempts to determine if the database server is live.

It tries to connect to the database in a "reasonably efficient way". We specify the datasource name. We do not specify the database name, since in this example we are only checking the availability of the server. The connect method establishes a database connection, or session, to the requested datasource.

At the end we call disconnect to terminate the connection. We check the returned value with die. The first parameter is the data source name. In the string we specify the database driver and the database name. The second parameter is the user name.

The third parameter is the user password. Unlike the MariaDB driver, Pg requires the database name in its datasource. In the example, we set the DSN to an empty string. The statement returns a single data unit. By default, each of the DBI methods returns an error code; we check the code with the die method.

The PrintError attribute can be used to force errors to generate warnings using warn in addition to returning error codes in the default way. We set it to 0 to avoid duplicate error messages. We are generating our own errors with die. The connection attributes are passed as the fourth optional parameter to the connect. The prepare method prepares an SQL statement for later execution.



0コメント

  • 1000 / 1000