in reply to Self-Modifying-Perl-Script
I wouldn't do it this way, though. It's easy to get these wrong and overwrite your program in the blink of an eye, and it's easy to use one of the DBM modules that comes with Perl and get things right. Still, it's good to know some of these techniques.#!/usr/bin/perl -w use strict; chomp(my $num = <DATA>); print "My counter is set to $num.\n"; $num++; { local *FILE; local $/ = "\n__END__"; open (FILE, "counter.pl") || die "Can't open my file for reading: +$!\n"; chomp(my $file = <FILE>); close FILE; open (FILE, ">counter.pl") || die "Can't open file for writing: $! +"; print FILE $file, "\n__END__\n$num"; close FILE; } __END__ 0
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Self-Modifying-Perl-Script
by dse (Novice) on Nov 04, 2015 at 23:26 UTC |