in reply to dynamic socket communication

There is a way to write variables to the DATA section of your script, when the script exits, and you could store the current value there, and reread it everytime you start up, but it is cleaner to use the Inline::Files module. The hard way:
#!/usr/bin/perl use warnings; use strict; # The DATA filehandle is just a an open handle on the current # file. The current file is just the $0 variable (so long as # you haven't changed it) # main part of script ... my $count; while(<DATA>){ $count = $_ ; print "$count\n";} $count++; # then redo the count update: rewrite_count($count); sub rewrite_count { my $count = shift; open(SELF,"+<$0")||die $!; while(<SELF>){last if /^__END__/} truncate(SELF,tell SELF); print SELF $count; close SELF; } __END__ 1232

I'm not really a human, but I play one on earth.
Old Perl Programmer Haiku

Replies are listed 'Best First'.
Re^2: dynamic socket communication
by MidLifeXis (Monsignor) on Aug 05, 2010 at 17:46 UTC

    I would cringe if I saw this approach in production. I would be too concerned with breakage or concurrency issues trashing the file. Personally, I would feel better with an external file.

    Also allows locking down the source. The way this stands, the user running the application also has access to modify the source code.

    --MidLifeXis