Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much

Re: convert windows path

by Tyke (Pilgrim)
on Nov 06, 2001 at 14:12 UTC ( #123541=note: print w/replies, xml ) Need Help??

in reply to convert windows path

Try $var =~ tr!\\!/!;

But if you're using ActiveState Perl then be aware that the built-in operators and functions understand slashes in all directions anyway.

Replies are listed 'Best First'.
Re: Re: convert windows path
by Anonymous Monk on Nov 06, 2001 at 14:23 UTC
    $var =~ tr!\\!/! didn't work - this just split out the \ slashes. the problem seems to be that the forward slashes in the variable are not interpreted as such so c:\dir would not work whereas we know c:\\dir would be interpreted as c:\dir and would work. i think i need to find a way of returning the path from my html form with \\ instead of \ each time. i wonder if has an ability to convert paths?
      If I'm right in my guess about what you're trying to do, then the answer is "yes, does do it all for you". That's to say, if you're dealing with form input from a form that has a tag like <INPUT TYPE="FILE" NAME="FILENAME"> then if you do
      my $fh = param('FILENAME'); while (<$fh>) { do_stuff_with($_); # manipulate the file line by line } will deal with the path in the appropriate way - at least, that's been my experience when receiving input from browsers on Windows systems and processing it on a Linux system.

      (BTW you might want to use the upload() method, but as this comes only with later versions of I mention the old-fashioned way, in case you are stuck with an annoying ISP.) does the thinking so you can spend more time drinking beer :)

      George Sherston
        i've think i have confused the situation, the problem is some browsers submit the full path whereas some submit just the filename. when the full path is submitted i can't work out how to get the filename out. eg filename from c:\somedir\file.ext. perl doesn't let me search & replace those \ slashes when they are on their own.
      I'm not sure I understand the problem.
      What does your variable really contain? What is the length of c:\dir? 5 or 6? Can you post a snippet?

      If you need a way to escape special characters you can use the quotemeta built-in.

      I don't use CGI so I'm afraid that I can't help you there.

Re:{2} convert windows path
by jeroenes (Priest) on Nov 06, 2001 at 16:20 UTC
    Didn't you want to say: $var =~ tr!\\!/!s;

    Update ...oops, apparently not what was wanted. It's just that in my unix eye the double slash at the beginning looks so ugly.

      That would change \\machine\dir\file to /machine/dir/file which wasn't what the original poster wanted (the way I read the question anyway).

      Update Sorry jeroenes must've posted at the same moment. BTW, my first take was to agree with you. I hadn't even considered adding it. It was only while replying that I saw it wouldn't work.

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (7)
As of 2023-02-08 20:19 GMT
Find Nodes?
    Voting Booth?
    I prefer not to run the latest version of Perl because:

    Results (43 votes). Check out past polls.