Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

Re: Need to change directory string.

by toolic (Bishop)
on Jan 02, 2013 at 16:20 UTC ( [id://1011306]=note: print w/replies, xml ) Need Help??


in reply to Need to change directory string.

Here's one way using s///:
use warnings; use strict; my $dir_str = "test/home/players/demo//thumbs/super.jpg"; $dir_str =~ s{//+}{/}g; print "$dir_str\n"; __END__ test/home/players/demo/thumbs/super.jpg

UPDATE: fixed typo. Thanks Athanasius

Replies are listed 'Best First'.
Re^2: Need to change directory string.
by Athanasius (Archbishop) on Jan 02, 2013 at 16:36 UTC

    Well, this produces .../demothumbs/..., but the OP states that he wants .../demo/thumbs/.... So a small amendment is needed:

    2:29 >perl -wE "$d = 'test/home/players/demo//thumbs/super.jpg'; $d = +~ s[/{2,}][/]g; say $d;" test/home/players/demo/thumbs/super.jpg 2:34 >

    Hope that helps,

    Athanasius <°(((><contra mundum Iustus alius egestas vitae, eros Piratica,

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (5)
As of 2024-03-19 06:23 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found