how to add slash separator in perl

lola

I have the following command

how could I add "\" (path) between v1 and bin in perl to say : c:\path\bin as v1 = c:\path

system(dirname($v1) . $bin . " " . $trinp);

could someone recommend tutorial for perl?

Thanks

pndc

You have asked a question that has multiple answers. To just put a backslash in to form a Windows path, you need to escape the backslash thus, and this will solve your direct problem:

system($v1 . "\\" . $bin . " " . $trinp);

However, there are a few refinements. Firstly, you can use Perl's interpolation to make it easier to read:

system("$v1\\$bin $trinp");

You can also use Unix-style forward slashes, as Windows understands these, and prevents so-called "backslashitis":

system("$v1/$bin $trinp");

A better way however is to use Path::Class to generate paths on any operating system.

Further, there is a potential security problem in your code that can be caused if $trinp (or any of the other variables) contains shell metacharacters such as | to pipe into another command. If you provide a list of arguments to the system() function, it will pass those directly to the command instead of the shell. You will probably also want to check if the command was successful, and do something useful (e.g. die()ing) if it failed:

system("$vi/$bin", $trinp) == 0
   or die "Couldn't run $vi/$bin: $!";

I'll leave it as an exercise for you to convert my final example to use Path::Class.

[Edited to correct misuse use of system(), which returns the status of the command that was run which is zero for success. I confused it with more common other Perl functions which return nonzero for success.]

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Java

How to add one section separator for Navigation Drawer in Android?

From Dev

Mysql find_in_set slash( / ) separator

From Dev

How to add a separator cell/uiview between cells in a UITableView?

From Dev

how to add stylesheet for separator in QCombobox

From Dev

How to create a regex that match only number and decimal separator in Perl

From Dev

How to add a trailing_slash to all urls without in Rails 4?

From Dev

How can I add a separator between tabs in a tabcontrol?

From Dev

How to add trailing slash with varnish?

From Dev

how to add a Horizontal separator for a bootstrap horizontal menu?

From Dev

Function parameter separator in Perl?

From Dev

How to change radio button place & add line separator

From Dev

How do you add a trailing slash to a PUT request in Backbone?

From Dev

How to add separator in menu items?

From Dev

How to add @ mention in response to slash commands in slack

From Dev

How to add separator at particular position inside recyclerview?

From Dev

How to add a slash or why it isn't added?

From Dev

How add a trailing slash after the port in apache URIBuilder?

From Dev

How to add Separator to Google Chrome Bookmarks Bar?

From Dev

How to add a trailing_slash to all urls without in Rails 4?

From Dev

How to add text to href after a certain slash

From Dev

How to add a delimiter/separator to a Rails block

From Dev

iOS) How to add a divider(==separator) between tabbarItems

From Dev

How to add double forward slash in a string without commenting out in Javascript?

From Dev

How to add separator every item in ListBox?

From Dev

How to add separator at particular position inside recyclerview?

From Dev

Address with hyphen or back slash separator

From Dev

How To add slash between seo friendly url in opencart

From Dev

How to add new line separator into data for oracle

From Dev

How to add a separator in a TinyMCE dropdown menu

Related Related

  1. 1

    How to add one section separator for Navigation Drawer in Android?

  2. 2

    Mysql find_in_set slash( / ) separator

  3. 3

    How to add a separator cell/uiview between cells in a UITableView?

  4. 4

    how to add stylesheet for separator in QCombobox

  5. 5

    How to create a regex that match only number and decimal separator in Perl

  6. 6

    How to add a trailing_slash to all urls without in Rails 4?

  7. 7

    How can I add a separator between tabs in a tabcontrol?

  8. 8

    How to add trailing slash with varnish?

  9. 9

    how to add a Horizontal separator for a bootstrap horizontal menu?

  10. 10

    Function parameter separator in Perl?

  11. 11

    How to change radio button place & add line separator

  12. 12

    How do you add a trailing slash to a PUT request in Backbone?

  13. 13

    How to add separator in menu items?

  14. 14

    How to add @ mention in response to slash commands in slack

  15. 15

    How to add separator at particular position inside recyclerview?

  16. 16

    How to add a slash or why it isn't added?

  17. 17

    How add a trailing slash after the port in apache URIBuilder?

  18. 18

    How to add Separator to Google Chrome Bookmarks Bar?

  19. 19

    How to add a trailing_slash to all urls without in Rails 4?

  20. 20

    How to add text to href after a certain slash

  21. 21

    How to add a delimiter/separator to a Rails block

  22. 22

    iOS) How to add a divider(==separator) between tabbarItems

  23. 23

    How to add double forward slash in a string without commenting out in Javascript?

  24. 24

    How to add separator every item in ListBox?

  25. 25

    How to add separator at particular position inside recyclerview?

  26. 26

    Address with hyphen or back slash separator

  27. 27

    How To add slash between seo friendly url in opencart

  28. 28

    How to add new line separator into data for oracle

  29. 29

    How to add a separator in a TinyMCE dropdown menu

HotTag

Archive