Guest User

Untitled

a guest
Jan 18th, 2019
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.63 KB | None | 0 0
  1. this
  2. is just
  3. an example.
  4.  
  5. <Hi >
  6. <this>
  7. <is just>
  8. <an example.>
  9.  
  10. Hi
  11. this
  12. is just
  13. an example.
  14. <Hi >
  15. <this>
  16. <is just>
  17. <an example.>
  18. **out.txt**
  19.  
  20. open(my $fh, "+<", "out.txt");# or die "cannot open < C:UsersdaanishsworkspaceCCoverageout.txt: $!";
  21. while(<$fh>)
  22. {
  23. $s1 = "<";
  24. $s2 = $_;
  25. $s3 = ">";
  26. $str = $s1 . $s2 . $s3;
  27. print $fh "$str";
  28. }
  29.  
  30. use Tie::File;
  31. use strict;
  32. use warnings;
  33.  
  34. my $filename = "out.txt";
  35. my @array;
  36. tie @array, 'Tie::File', $filename or die "can't tie file "$filename": $!";
  37.  
  38. for my $line (@array) {
  39. $line = "<$line>";
  40. # or $line =~ s/^(.*)$/<$1>/g; # -- whatever modifications you need to do
  41. }
  42.  
  43. untie @array;
  44.  
  45. H i / t h i s / ...
  46.  
  47. < H i > / i s / ...
  48.  
  49. my $file;
  50. { # Read the file
  51. open(my $fh, '<', $qfn)
  52. or die "Can't open "$qfn": $!n";
  53. local $/;
  54. $file = <$fh>;
  55. }
  56.  
  57. # Change the file
  58. $file =~ s/^(.*)n/<$1>n/mg;
  59.  
  60. { # Save the changes
  61. open(my $fh, '>', $qfn)
  62. or die "Can't create "$qfn": $!n";
  63. print($fh $file);
  64. }
  65.  
  66. rename($qfn, "$qfn.old")
  67. or die "Can't rename "$qfn": $!n";
  68.  
  69. open(my $fh_in, '<', "$qfn.old")
  70. or die "Can't open "$qfn": $!n";
  71. open(my $fh_out, '>', $qfn)
  72. or die "Can't create "$qfn": $!n";
  73.  
  74. while (<$fh_in>) {
  75. chomp;
  76. $_ = "<$_>";
  77. print($fh_out "$_n");
  78. }
  79.  
  80. unlink("$qfn.old");
  81.  
  82. local @ARGV = $qfn;
  83. local $^I = '';
  84. while (<>) {
  85. chomp;
  86. $_ = "<$_>";
  87. print(ARGV "$_n");
  88. }
  89.  
  90. perl -i -pe'$_ = "<$_>"' file
  91.  
  92. #!/usr/bin/perl
  93.  
  94. open(INFILE, "+<in.txt");
  95. @a=<INFILE>;
  96. seek INFILE, 0, SEEK_SET ;
  97. foreach $i(@a)
  98. {
  99. chomp $i;
  100. print INFILE "<".$i.">"."n";
  101. }
Add Comment
Please, Sign In to add comment