Gossamer Forum
Home : General : Perl Programming :

Is this the only way?

Quote Reply
Is this the only way?
Tongue
I`m opening a counter file, reading from it, adding one to the value, writing the new value back to the counter file.

Is this the only way, do I have to open it twice, can the file be opened once for reading and overwriting I tried using + but it just appends rather than overwrites.
Code:
open (ENQID, "<$enq_id_file_name") or &cgierr("error in get_defaults. unable to open unique enquiry file: $enq_id_file_name.\nReason: $!");
if ($db_use_flock) { flock(ENQID, 1); }

$enqid_default = <ENQID> + 1; # Get next ENQID number

open (ENQID, ">$enq_id_file_name") or &cgierr("error in get_defaults. unable to open unique enquiry file: $enq_id_file_name.\nReason: $!");
if ($db_use_flock) { flock(ENQID, 2); }

print ENQID $enqid_default;

close ENQID;

I`m using $enqid_default further down..

thanks.

chmod
Quote Reply
Re: [chmod] Is this the only way? In reply to
Did you try +< ?

If so, you'd want:

open (ENQID, "+>$enq_id_file_name") ...
Quote Reply
Re: [Paul] Is this the only way? In reply to
open (ENQID, "+>$enq_id_file_name")

ends up with no value in the count file.

open (ENQID, "+<$enq_id_file_name")

appends the incremented value to the existing value in the count file, started as 5 is now 56

weird ain`t it, I would have thought perl would have a file open operator that allowed read and overwrite.


cheers

chmod
Quote Reply
Re: [chmod] Is this the only way? In reply to
+> :

Read = Yes
Write = Yes
Append = No
Creates = Yes
Truncates Existing Data = Yes

Try

+>>

Last edited by:

Paul: Apr 13, 2002, 5:24 AM
Quote Reply
Re: [Paul] Is this the only way? In reply to
nope..
+>> pulls the value ok but doesn`t wright it back in.

chmod
Quote Reply
Re: [chmod] Is this the only way? In reply to
Thats annoying me now. I dragged out my old perl book and it tells you what each should do like:

>
<
<+

etc....and Im sure one of them should work. Hm....
Quote Reply
Re: [chmod] Is this the only way? In reply to
See:

http://www.perldoc.com/...--How-can-I-do-this-

Cheers,

Alex
--
Gossamer Threads Inc.

Last edited by:

Alex: Apr 13, 2002, 11:17 AM
Quote Reply
Re: [Alex] Is this the only way? In reply to
So are +< and +> working properly then because according to my perl book they should work for this?

Maybe I misunderstood my book.

Last edited by:

Paul: Apr 13, 2002, 11:24 AM
Quote Reply
Re: [Paul] Is this the only way? In reply to
if I`m reading the page correctly that you put up Alex then I assume this cannott be done as none seam to be for read and overwrite.

http://www.perldoc.com/...ite-it-wipes-it-out-

cheers anyway, thanx Paul.

chmod