CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Regular Expressions:
Filename manipulation...

 



Tempus
New User

Aug 26, 2002, 10:39 AM

Post #1 of 5 (3374 views)
Filename manipulation... Can't Post

Hi, forgive me for requesting help for such simple stuff, but we do all start somewhere, eh?

Given that I've a filename ABCDEF.GHI, but don't know what letter A is or what letter G is, how do I easily replace both or either at my whim?

For example, I want to take filename ABCDEF.GHI and rename it ~BCDEF.&HI for file locking purposes, and then once I've processed the associated file, I want to rename it back to ABCDEF.GHI.

I'm able to do this with substr, but is there a more elegant way to easily do this with s// or m//???

Thanks.


Paul
Enthusiast

Aug 26, 2002, 12:30 PM

Post #2 of 5 (3374 views)
Re: [Tempus] Filename manipulation... [In reply to] Can't Post

The more elegant way is not to do it at all and use:

flock(FILEHANDLE, 2);

Wink


Tempus
New User

Aug 26, 2002, 12:47 PM

Post #3 of 5 (3371 views)
Re: [RedRum] Filename manipulation... [In reply to] Can't Post

That's as may be, but it won't work with the existing software that expects this format for locked filenames.


Paul
Enthusiast

Aug 26, 2002, 12:53 PM

Post #4 of 5 (3370 views)
Re: [Tempus] Filename manipulation... [In reply to] Can't Post

substr is probably better than a regex anyway in this case. So I'd use what you already have.


(This post was edited by RedRum on Aug 26, 2002, 12:54 PM)


davorg
Thaumaturge / Moderator

Aug 27, 2002, 1:02 AM

Post #5 of 5 (3364 views)
Re: [RedRum] Filename manipulation... [In reply to] Can't Post


In Reply To
The more elegant way is not to do it at all and use:

flock(FILEHANDLE, 2);

Wink


Magic numbers like that "2" make your code harder to understand (and probably less portable. I'd recommend using the symbolic constants from Fcntl.

Code
use Fcntl ':flock'; 

flock(FILEHANDLE, LOCK_EX) or die $!;


But you're right that using the operating system's own built-in locking is a far better idea.

--
Dave Cross, Perl Hacker, Trainer and Writer
http://www.dave.org.uk/
Get more help at Perl Monks

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives