Skip to content

Instantly share code, notes, and snippets.

@beppu
Created February 27, 2015 19:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save beppu/715147f5aef0b8971b10 to your computer and use it in GitHub Desktop.
Save beppu/715147f5aef0b8971b10 to your computer and use it in GitHub Desktop.
for educational purposes
#!/usr/bin/perl
use strict;
use warnings;
sub slurp {
my $file = shift;
open my $fh, '<', $file or die;
my @lines = <$fh>;
close $fh;
\@lines;
}
sub replace {
my $seed = shift;
my $lines = shift;
$lines->[int(rand(scalar @$lines))] = "$seed\n";
$lines
}
my $seed = shift;
my $file = shift;
my $lines = replace $seed, slurp($file);
print @$lines;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment