codetoad.com
  ASP Shopping CartForum & BBS
  - all for $20 from CodeToad Plus!
  
  Home || ASP | ASP.Net | C++/C# | DHTML | HTML | Java | Javascript | Perl | VB | XML || CodeToad Plus! || Forums || RAM 
Search Site:
Search Forums:
  Problem in perl scripting.  sagarbsa at 10:41 on Friday, September 26, 2008
 

Hii,

I am creating a perl script to read a text and remove the ' at the end of each line only. But I am not getting any sucess. The text file is as follows.

exec ''sp_prepexec'
exec ''sp_prepexec'
exec ''sp_prepexec'
exec ''sp_prepexec'
exec ''sp_prepexec'

Request your help to solve the same in perl.

Thanks in Advance

  Re: Problem in perl scripting.  S_Flex at 13:21 on Friday, September 26, 2008
 

This script will get the content from the file and edit it as needed.
I like to use file lock( flock() since its good practice ) and sysopen for reading and writing.

# Start
use strict;
use warnings;
use Fcntl qw(:DEFAULT :flock);

# File to edit
my $path_file = '/home/some/path/text.txt';

# get file content
sysopen(FH, $path_file, O_RDONLY) or die($!);
flock(FH, LOCK_EX);
my @content = <FH>;
close(FH);

# Overwrite file with new content
sysopen(FH, $path_file, O_WRONLY | O_TRUNC) or die($!);
flock(FH, LOCK_EX);
foreach my $line (@content) {
if ($line =~ m/\'\n/i) {
# remove ' from the end
$line =~ s/\'\n//g;
# print new stuff
print FH $line, "\n";
}
else {
# no edit needed
print FH $line;
}
}
close(FH);
# End

Any questions?








CodeToad Experts

Can't find the answer?
Our Site experts are answering questions for free in the CodeToad forums
//








Recent Forum Threads
•  Re: Problem in perl scripting.
•  Re: ridding of beginning/ending spacebars in each element of a list.
•  Excel to XML
•  DHTML tutorials?
•  The Ballarat Airline Company (BAC)
•  Re: Problem to declare global variable in Object oriented perl
•  Issue with Javascript between web servers
•  Not Allowing Copying from Site
•  Re: dereferenceing a string to a constant name


Recent Articles
ASP GetTempName
Decode and Encode UTF-8
ASP GetFile
ASP FolderExists
ASP FileExists
ASP OpenTextFile
ASP FilesystemObject
ASP CreateFolder
ASP CreateTextFile
Javascript Get Selected Text


© Copyright codetoad.com 2001-2008