Training, Open Source computer languages
PerlPHPPythonMySQLApache / TomcatTclRubyJavaC and C++LinuxCSS 
Search for:
Home Accessibility Courses Diary The Mouth Forum Resources Site Map About Us Contact
For 2023 (and 2024 ...) - we are now fully retired from IT training.
We have made many, many friends over 25 years of teaching about Python, Tcl, Perl, PHP, Lua, Java, C and C++ - and MySQL, Linux and Solaris/SunOS too. Our training notes are now very much out of date, but due to upward compatability most of our examples remain operational and even relevant ad you are welcome to make us if them "as seen" and at your own risk.

Lisa and I (Graham) now live in what was our training centre in Melksham - happy to meet with former delegates here - but do check ahead before coming round. We are far from inactive - rather, enjoying the times that we are retired but still healthy enough in mind and body to be active!

I am also active in many other area and still look after a lot of web sites - you can find an index ((here))

Posted by TedH (TedH), 21 April 2008
Hi guys:
Just a question really. In the code below (not mine - I'm learning about handling flock differently), I notice the use of a semi-colon for a write, but not in the other cases.

The code works fine, just wondering why the difference?

# Variable
$flock = "0";  # Set to to 1 for Unix

### No semi-colon for reading and on >> appends.
if ($flock) {flock(DATABASE, 2)}

### Why the semi-colon on this one? Is it becuz of the > type write?
open (DATABASE, ">".$file);
if ($flock) {flock(DATABASE, 2);}

Cheers - Ted

Posted by KevinAD (KevinAD), 21 April 2008
The semi-colon has nothing to do with the use of flock or anything else for that matter.

The last line (or in this case the only line) of a block of code: {}, does not need a semi-colon, it's optional. In my opinion, for consitancy sake you should always put one.  

Posted by KevinAD (KevinAD), 21 April 2008
Hard core perl coders will tell you to use the Fcntl module and import the flock constants into your program. I am a bit ambivalent on this issue but I tend to use Fcntl too and import the symbolic names, in some cases it might be necessary although I am not sure about that, maybe Graham knows. See the flock() function and the Fcntl module for more details.

Posted by TedH (TedH), 21 April 2008
Hi Kevin, Thanks. I usually just do a
# flock(DFILE, 2);

Then remove the comment when I put it on my live Unix server. My local testbed is Indigo perl on a Windows PC, so it's commented out there. Which is okay if there's just one, But - when there are hundreds or thousands of lines of code, with a bunch of flocks in, I figured I need a more efficient way to do it - hence the variable option.

I'll use the semi-colon as suggested.

Cheers - Ted

Posted by KevinAD (KevinAD), 22 April 2008
It was evident what you were doing by this line:

# Variable
$flock = "0";  # Set to to 1 for Unix

Been there, done that, too. You can make that dynamic:

my $flock = ($^O =~ /MSwin32/i) ? 1 : 0;

Then you don't have to comment it out and it will work on Windows and Unix/Linux.

Posted by TedH (TedH), 22 April 2008
That's neat  Thanks Kevin.

This page is a thread posted to the opentalk forum at and archived here for reference. To jump to the archive index please follow this link.

You can Add a comment or ranking to this page

© WELL HOUSE CONSULTANTS LTD., 2024: Well House Manor • 48 Spa Road • Melksham, Wiltshire • United Kingdom • SN12 7NY
PH: 01144 1225 708225 • FAX: 01144 1225 793803 • EMAIL: • WEB: • SKYPE: wellho