Been a long day with 'real life' issues I've been trying to use Perl to help me pretend they didn't happen... here's a base test I was thinking.
#!perl -T use Test::More tests => 9; use File::Copy qw(copy); use Tie::File; my $f = 't/sample.data'; my $wf = 't/write_sample.data'; copy($f, $wf); tie my @wfh, 'Tie::File', $wf; for (@wfh){ if (/sub seven/){ $_ =~ s/seven/xxxxx/; } } untie @wfh; #1 eval { open my $wfh, '<', $wf or die "Can't open test written file $wf: $!"; }; ok (! $@, "copy of test sample file ok" ); open my $wfh, '<', $wf or die $!; #2 eval { open my $fh, '<', $f or die "Can't open original test file $f: $!"; }; ok (! $@, "can open orig test file after tie/untie/copy" ); my @wf = <$wfh>; my @f = <$fh>; my $count = scalar @f; my @changes; #3 for (0..$count){ if ($wf[$_] and $wf[$_] ne $f[$_]){ push @changes, $wf[$_]; } } is ( scalar(@changes), 1, "search/replace does the right thing, in the + right spot" ); #4 eval { close $fh; }; ok (! $@, "no problem closing the original test read file" ); close $fh; #5 eval { close $wfh; }; ok (! $@, "no problem closing the test write file" ); close $wfh; #6 eval { unlink $wf }; ok (! $@, "no problem deleting the test write file" ); #7 eval { open my $wfh, '<', $wf or die "Can't open $wfh: $!"; }; ok ($@, "after unlink of test write file, it can't be opened" ); #8 is (@changes, 1, "search_replace on one line replaces only one line" ) +;
In reply to Re: "Unescaped left brace in regex is deprecated"
by stevieb
in thread "Unescaped left brace in regex is deprecated"
by stevieb
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |