Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- this
- is just
- an example.
- <Hi >
- <this>
- <is just>
- <an example.>
- Hi
- this
- is just
- an example.
- <Hi >
- <this>
- <is just>
- <an example.>
- **out.txt**
- open(my $fh, "+<", "out.txt");# or die "cannot open < C:UsersdaanishsworkspaceCCoverageout.txt: $!";
- while(<$fh>)
- {
- $s1 = "<";
- $s2 = $_;
- $s3 = ">";
- $str = $s1 . $s2 . $s3;
- print $fh "$str";
- }
- use Tie::File;
- use strict;
- use warnings;
- my $filename = "out.txt";
- my @array;
- tie @array, 'Tie::File', $filename or die "can't tie file "$filename": $!";
- for my $line (@array) {
- $line = "<$line>";
- # or $line =~ s/^(.*)$/<$1>/g; # -- whatever modifications you need to do
- }
- untie @array;
- H i / t h i s / ...
- < H i > / i s / ...
- my $file;
- { # Read the file
- open(my $fh, '<', $qfn)
- or die "Can't open "$qfn": $!n";
- local $/;
- $file = <$fh>;
- }
- # Change the file
- $file =~ s/^(.*)n/<$1>n/mg;
- { # Save the changes
- open(my $fh, '>', $qfn)
- or die "Can't create "$qfn": $!n";
- print($fh $file);
- }
- rename($qfn, "$qfn.old")
- or die "Can't rename "$qfn": $!n";
- open(my $fh_in, '<', "$qfn.old")
- or die "Can't open "$qfn": $!n";
- open(my $fh_out, '>', $qfn)
- or die "Can't create "$qfn": $!n";
- while (<$fh_in>) {
- chomp;
- $_ = "<$_>";
- print($fh_out "$_n");
- }
- unlink("$qfn.old");
- local @ARGV = $qfn;
- local $^I = '';
- while (<>) {
- chomp;
- $_ = "<$_>";
- print(ARGV "$_n");
- }
- perl -i -pe'$_ = "<$_>"' file
- #!/usr/bin/perl
- open(INFILE, "+<in.txt");
- @a=<INFILE>;
- seek INFILE, 0, SEEK_SET ;
- foreach $i(@a)
- {
- chomp $i;
- print INFILE "<".$i.">"."n";
- }
Add Comment
Please, Sign In to add comment