Solved

some easy question.

Posted on 2000-03-29
6
156 Views
Last Modified: 2010-03-05
1.what's mean about this section?

open(LIST,"$file");
if ($lock){                <---?
flock(LIST, $lock);        <---?

2.and

print qq~
0
Comment
Question by:li_fang
6 Comments
 
LVL 19

Expert Comment

by:Kim Ryan
Comment Utility
If $lock is true ( > 0), get a lock on the file handle LIST. Lock modes are:

$LOCK_SH = 1;
$LOCK_EX = 2;
$LOCK_NB = 4;
$LOCK_UN = 8;

qq means  print the followong literla string, don't understand the ~



0
 
LVL 10

Expert Comment

by:makerp
Comment Utility
# some crude ways to lock a section of critical code
my $FILEH;

sub lockSection()
{
      open(FILEH,$com."common/lockfile.lk") or die("cannt open the lock file : ".$!);
      flock(FILEH,2) or die("cannt lock the file : ".$!);
}

sub unlockSection()
{
      flock(FILEH,8) or die("cannt unlock file : ".$!);
      close(FILEH);
}
0
 
LVL 10

Expert Comment

by:makerp
Comment Utility
sorry i meant to edit that code before submitting..
0
How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

 
LVL 16

Accepted Solution

by:
maneshr earned 20 total points
Comment Utility


ABOUT flock(LIST, $lock);


Operating systems vary greatly in the type and reliability of locking techniques available. Perl tries hard to give you something
that works, even if your operating system uses its own underlying technique.

The flock function takes two arguments: a filehandle and a number representing what to do with the lock on that filehandle or the Lock mode.

The different Lock modes are:

$LOCK_SH  = 1      #  Shared lock (for reading)
$LOCK_EX  = 2      #  Exclusive lock (for writing)
$LOCK_NB  = 4      #  Non-blocking request (don't stall)
$LOCK_UN  = 8      #  Free the lock (careful!)

Flocking files is like putting up a stoplight at an intersection. It works only if people pay attention to whether the light is red or
green  - or yellow in the case of a shared lock. The red light doesn't stop traffic; it merely signals that traffic should stop. A
desperate, ignorant, or rude person will still go flying through the intersection no matter what the light says. Likewise, flock
only blocks out other flockers  - not processes trying to do I/O. Unless everyone is polite, accidents can (and will) happen.

=================================================
ABOUT if ($lock){


Checks if a lock has already been set (ie $lock contains a value greater tha zero)


Hope that helps
0
 
LVL 10

Expert Comment

by:makerp
Comment Utility
mmmmmm

well put maneshr.. good analogy
0
 

Author Comment

by:li_fang
Comment Utility
Thanks for you help!

(And I don't know how to give the points to more than one people,so thanks for teraplane.
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

I have been pestered over the years to produce and distribute regular data extracts, and often the request have explicitly requested the data be emailed as an Excel attachement; specifically Excel, as it appears: CSV files confuse (no Red or Green h…
There are many situations when we need to display the data in sorted order. For example: Student details by name or by rank or by total marks etc. If you are working on data driven based projects then you will use sorting techniques very frequently.…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now