Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re: Why I can't remove trailing slash

by kennethk (Abbot)
on Apr 19, 2013 at 15:44 UTC ( #1029541=note: print w/ replies, xml ) Need Help??


in reply to Why I can't remove trailing slash

Because you never call the main subroutine.

use strict; use warnings; sub main { my $path = "\\\\127.0.0.1\\c\$\\bak\\"; $path =~ s/\\$//; print __FILE__.__LINE__." path $path\n"; return; } main();
or even better
use strict; use warnings; my $path = <<'EOT'; \\127.0.0.1\c$\bak\ EOT $path =~ s/\\$//; printf "%s %s path %s\n", __FILE__, __LINE__, $path;

Unlike C or Java, you don't need a main subroutine; the script just runs in the order it's written, like a shell script. Note as well that I had to escape your $ since " interpolates - you were inserting $\ into your $path assignment. If you'd actually run your subroutine, you would have gotten a warning.


#11929 First ask yourself `How would I do this without a computer?' Then have the computer do it the same way.


Comment on Re: Why I can't remove trailing slash
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (18)
As of 2015-07-30 20:18 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (273 votes), past polls