Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re^2: Search & Replace repeating characters

by g_speran (Scribe)
on Apr 23, 2020 at 12:45 UTC ( [id://11115943]=note: print w/replies, xml ) Need Help??


in reply to Re: Search & Replace repeating characters
in thread Search & Replace repeating characters

not an X-Y Problem. So that I can properly give an example of what I was trying to accomplish, I just assigned c:\\temp\\\\ to the variable $ScriptDir. in actuality, $ScriptDir gets its value from the terminal input from the end user $ScriptDir=<STDIN>; So I am trying to plan for the end user entering slashes and correct it
  • Comment on Re^2: Search & Replace repeating characters

Replies are listed 'Best First'.
Re^3: Search & Replace repeating characters
by Corion (Patriarch) on Apr 23, 2020 at 12:47 UTC

    I think you need to make your solution either smarter or not as helpfull, because Windows file paths are allowed to start with \\ in UNC notation. For example, this is a valid UNC filepath:

    \\servername\c$\foo.txt
Re^3: Search & Replace repeating characters
by Marshall (Canon) on Apr 29, 2020 at 08:38 UTC
    Ok. Now I understand this better.
    Use the command prompting loop to reject invalid syntax of the input.
    Below I reject input lines that have a double // or \\.
    use strict; use warnings; my $dir; while ( (print "enter directory; "), $dir=<STDIN> and $dir =~ /\\\\|\/ +\//g) { print "invalid directory syntax... double ", '// or \\\\', " not al +lowed!\n"; } $dir =~ s/^\s*|\s*$//g; #remove leading and trailing spaces print "INPUT LOOP says $dir\n"; __END__ C:\Monks>perl CommandLoopNoDoubleSlash.pl enter directory; C:\\x invalid directory syntax... double // or \\ not allowed! enter directory; D:\x\temp// invalid directory syntax... double // or \\ not allowed! enter directory; C://x invalid directory syntax... double // or \\ not allowed! enter directory; C:/X INPUT LOOP says C:/X
    Now it is also possible perhaps have a sub that prompts for a valid directory and that sub continues to loop until a valid directory is entered. I would return a file handle from that sub. In that sort of case, the sub tries to open the dir name that the user entered and it works or it doesn't. Loop until the openddir() works. Remember to allow for leading and trailing whitespace for all command line entries.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11115943]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chilling in the Monastery: (7)
As of 2024-04-24 10:49 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found