Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"

Re: Why cant regex parse this string?

by moritz (Cardinal)
on Jul 12, 2012 at 13:57 UTC ( #981404=note: print w/replies, xml ) Need Help??

in reply to Why cant regex parse this string?

$filename is a string, but if you use it in a regex, it is interpreted as a regex. So all sorts of characters (like parenthesis, for example) have a special meaning. To prevent that, use s/\Q$filename\E//. See perlre for more information.

But, you are already using the URI module, why do you do all those path manipulations yourself? $url->path gives you the path, which is the URL without schema or domain name, so you don't have to manually remove that from the original URL. Or path_segments, which gives you the different parts of the path delimited by slashes:

# untested: my @path_chunks = $url->path_segments; pop @path_chunks; # remove the last one, which is the file name my $dir = $song{dir} = join '/', @path_chunks;

(Updated to use $uri->path_segments, daxim++, and s/shift/pop/, johngg++)

Replies are listed 'Best First'.
Re^2: Why cant regex parse this string?
by jayto (Acolyte) on Jul 12, 2012 at 14:08 UTC
    Thank you, that is what I suspected the problem was, but i wasn't sure how to fix it. I also used URI->path() instead of those lines of regex that i had before. Thanks again!

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://981404]
[ambrus]: (either on just one screen or two screens). this is necessary because
[ambrus]: overhead slide plus blackboard is inconvenient because the lighting conditions are different and they require separate areas you can't quickly repartition, and typing on keyboard is faster and more convenient than writing on a blackboard
[Corion]: (b) would be cool. I've thought about this doing Pod editing, and even simply regenerating/live updating the browser makes things much more interactive
[ambrus]: modern computers have way enough processing power to allow this, at least for geeks who are willing to spend a few weeks to learn a tricky new user interface like vim
[Corion]: ambrus: Well, for mathematical notation, I find blackboard much more convenient than a computer. But when inserting text or moving text around, the computer wins obviously
[ambrus]: But either of these is a big problem in practice, so I'd need to spend like thirty years of my life to solve (a) and five more years to solve (b)
[ambrus]: Corion: yes, CURRENTLY the blackboard is more convenient
[ambrus]: and it's not like I want to ban blackboards anyway
[ambrus]: you already have blackboards and a canvas for projector or overhead transparencies (or positive film slide projector, not used for maths) canvas in the same lecture halls today, and switch in a few minutes between presentations,
[ambrus]: they're only difficult to use together.

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (10)
As of 2017-09-26 10:21 GMT
Find Nodes?
    Voting Booth?
    During the recent solar eclipse, I:

    Results (293 votes). Check out past polls.