Perl-opening a file then copying files


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Perl-opening a file then copying files
# 1  
Old 04-21-2010
Perl-opening a file then copying files

Good morning guys!!

Im still practicing with Perl and now Im trying to open a file, and copy its contents to another file. Them I want to remeove the information out of the orginal file after it is copied over.

The flow should be messages-->messages1-->messages2.

Kind of like a log rotator.

Here is what I have:
Code:
#!/usr/local/bin/perl
$username = "rgoforth"
$filename = "/home/".$username."/messages";
$mess = "/home/".$username."/messages"/messages";
$mess1 = "/home/".$username."/messages"/messages.1";
$mess2 = "/home/".$username."/messages"/messages.2";
$mess3 = "/home/".$username."/messages"/messages.3";
$mess4 = "/home/".$username."/messages"/messages.4";

if (-e $filename){
        open (FILE, ">$mess") or die $!;
        print (FILE $mess1);
        close (FILE);
}else{
        print "Error: $filename doesn't exist\n";

But I cant seem to get past the strings. I have been looking at it for a while and I thought it might help to have some experts look at it.

Thanks
in advance!!

Ben

Last edited by pludi; 04-21-2010 at 02:01 AM..
# 2  
Old 04-21-2010
where are you opening a file for read ? normally that should be using <.

where are you going through the file to read ? normally that should be using while.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

PERL - Copying ONLY files from one dir to another

I'm writing a Perl script which has its 1st step as to copy files from one directory to another directory. The Source directory has got files with extension, without extension, directories etc. But I want to copy ONLY files with no extension. The files with extensions and directories should not get... (2 Replies)
Discussion started by: jhamaks
2 Replies

2. Shell Programming and Scripting

Perl : copying only the latest file to other directory

In linux.. In a directory there are 3 files which I want to copy only the latest file (ls -ltr myfiles*.txt|tail -1) to other directory in perl? Could anyone please help me with the code? Regards, J (1 Reply)
Discussion started by: scriptscript
1 Replies

3. Shell Programming and Scripting

Printing a message in file without opening it in perl

Hello friends, i have a perl script as below ... for (0 ..$#values) { ##want to print some message here in Report.txt file print `find /abc/xyz/pqr/$values" -type f -ls` >> Report.txt } I am able to get output of print `find /abc/xyz/pqr/$values" -type f -ls` >> Report.txt in... (2 Replies)
Discussion started by: harpal singh
2 Replies

4. UNIX for Dummies Questions & Answers

Opening a file in perl

Hi I need to open a file if a condition(for example a if a regular expression) is met. How do i do this ? open (file) if (some regex)..... (3 Replies)
Discussion started by: manutd
3 Replies

5. Shell Programming and Scripting

KSH: Opening Files based on a file list

I'd like to grep files for key words using korn shell, and compile the actual contents (not just file name) of those files that contain a combination of those grepped key words into one repository file for reference. However, I'm stuck at the combining part. Here's what I have thus far: egrep... (5 Replies)
Discussion started by: drumminfool91
5 Replies

6. Shell Programming and Scripting

Opening File names with spaces inside it !- PERL

I developed a perl code..And the excerpt from it is given below... open(HANDLE,$cmp_path) ; #reading the xml file from the file path while($file_path = <HANDLE>) I have list of XML files to read from a folder. It has some spaces inside the name of the file...I used "\"... (2 Replies)
Discussion started by: gameboy87
2 Replies

7. Shell Programming and Scripting

Opening Mulitple files using For loop in Perl

Hi All, I have a total of ten file to open in the Perl script and i am using a for loop to open each file and capture some strings inside each file. Unfortunately, i encounter the below syntax error. I think there should be something wrong with this term reports_${counting}_${_}.txt but i do... (4 Replies)
Discussion started by: Raynon
4 Replies

8. Shell Programming and Scripting

Opening Files and checking contents in Perl

Hi All, I need some expert help in performing the following in Perl. I have a code below but it doesn;t seem to work. Can any expert give me some advice? Below are the requirements 1) Open numerous files assigned to an array @FILES. Note that the files are always named with the term... (7 Replies)
Discussion started by: Raynon
7 Replies

9. Shell Programming and Scripting

perl - copying files

Folks, here is my code: I am a serious newbie, why doesn't this make copies of my files? I dont get any errors, the files are just not created. Your help is appreciated #!/usr/bin/perl use File::Copy; $PWD = `pwd`; $REPORTDIR = "/usr/local/tripwire/tfs/report"; chdir $REPORTDIR;... (1 Reply)
Discussion started by: BG_JrAdmin
1 Replies

10. UNIX for Dummies Questions & Answers

Copying files from file to another

How do I copy one file from one unix file to another??? I'm new at this, please help.. (3 Replies)
Discussion started by: Tevin
3 Replies
Login or Register to Ask a Question