Perl script to rename file,error


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Perl script to rename file,error
# 1  
Old 09-06-2010
Network Perl script to rename file,error

Code:
#!/usr/bin/perl

$FL="ch.txt";
$CFL="mytext.txt";

print "This script will rename textfiles.";
mv $FL $CFL;
print "Done.";

perl file.pl
Error:
Code:
Can't locate object method "mv" via package "ch.txt" (perhaps you forgot to load "ch.txt"?) at file.pl line 7.

# 2  
Old 09-07-2010
mv is not the rename function in Perl. use rename()
# 3  
Old 09-07-2010
Quote:
Originally Posted by frank_rizzo
mv is not the rename function in Perl. use rename()
How can i use mv command in perl script?
Or how can i use rename function in a shell script?

I want to rename all hundreds *.txt files to [1-100].txt.
# 4  
Old 09-07-2010
for Perl use rename()
for shell use the mv command

if you really want to use mv in Perl(I don't suggest this though)
Code:
`mv a b`;
or
system("mv a b");

make sure you check the return code.
# 5  
Old 09-07-2010
Quote:
Originally Posted by frank_rizzo
for Perl use rename()
for shell use the mv command

if you really want to use mv in Perl(I don't suggest this though)
Code:
`mv a b`;
or
system("mv a b");

make sure you check the return code.
Why don't you suggest this?
How can i check the return code?
# 6  
Old 09-07-2010
Quote:
Originally Posted by cola
Why don't you suggest this?
How can i check the return code?
There is no technical reason to use mv in a Perl script because the functionality is already built-in. Use the native function to avoid creating additional processes(fork).

Check the value of $?. See http://perldoc.perl.org/perlvar.html. for additional information.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Help required with a file rename shell script

Hello everyone, Posting here after a long time, been away from unix world lately and it seems I have forgotten my shell scripting completely. I have a requirement where a csv file contains following columns: Full Registration VIN Stock... (14 Replies)
Discussion started by: tayyabq8
14 Replies

2. Shell Programming and Scripting

Help with file rename script

Hello, I'm new in this shell scripting subject, I´m looking forward for someone to give me a hint or advice as to how to tackle my requirement, which is as follows: We have a Linux process that runs periodically every day, this process dumps a text file with always the same name overwriting... (2 Replies)
Discussion started by: netosv
2 Replies

3. Shell Programming and Scripting

Error while reading variable from a file in perl script

I have a file abc.ini and declared many variables in that file, one of the variable(DBname) value I am trying to read in my perl script but getting error. File abc.ini content # database name DBname =UATBOX my $ex_stat; my $cmd_output; $ex_stat = "\Qawk '/^DBname/{print... (2 Replies)
Discussion started by: Devesh5683
2 Replies

4. Shell Programming and Scripting

Command / script to partially rename file

Hi I have numerous files names product_host_result_B1000842.txt product_host_result_B1000847.txt product_host_result_C1000842.txt product_host_result_C1000848.txt etc. I need them renamed so that the 'product_host_result' becomes 'output_product_host' but the rest of the filename is... (6 Replies)
Discussion started by: Grueben
6 Replies

5. Shell Programming and Scripting

Need bash script to ping the servers and rename the output file each time the script is ran

HI, I have a file serverlist in that all host names are placed. i have written a small script #./testping #! /bin/bash for i in `cat serverlist` do ping $i >> output.txt done so now it creates a file output.txt till here fine.. now each time i run this script the output file... (4 Replies)
Discussion started by: madhudeva
4 Replies

6. HP-UX

[Solved] Unable to rename file in ftp server .Net:FTP perl

Hello All, I am trying to connect to ftp server and get the files. Also i need to rename the file in other ftp dir. rename method is not allowing me to rename the file in other dir. When i tried copy command by using net::FTP:FILE then perl says it is not installed. Can some body help me to... (2 Replies)
Discussion started by: krsnadasa
2 Replies

7. Emergency UNIX and Linux Support

File rename error

hi im new for unix, when i try to rename the file im getting error $ mv -9file.jpg 9file.jpg error is mv: invalid option --"9" Try 'mv --help' for more information. (10 Replies)
Discussion started by: gwgreen1
10 Replies

8. Shell Programming and Scripting

Script to rename zip-files with name of file

Hi, I'm desperately in search for a solution of the following problem: I have a directory full of zip-files. All these zip-files contain a single file with a name that should be used for the name of the zip-container. Anybody a good idea. I'm an absolute beginner in shell scripting - so please... (7 Replies)
Discussion started by: mark_a17
7 Replies

9. Shell Programming and Scripting

A script that will move a file to a directory with the same name and then rename that file

Hello all. I am new to this forum (and somewhat new to UNIX / LINUX - I started using ubuntu 1 year ago).:b: I have the following problem that I have not been able to figure out how to take care of and I was wondering if anyone could help me out.:confused: I have all of my music stored in... (7 Replies)
Discussion started by: marcozd
7 Replies

10. Shell Programming and Scripting

Using Perl to Rename File

Hi, Can someone help me with a perl file to rename some files please? I can do it with regular command line using the below code, but I need to include this in another script and the other script is perl. I know nothing of perl. for file in C* do newfilename=`echo $file | cut -c8-21-`... (8 Replies)
Discussion started by: bbbngowc
8 Replies
Login or Register to Ask a Question