- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: Move function + Perl
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Discussions
Discussions
Discussions
Forums
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-22-2007 09:17 PM
тАО03-22-2007 09:17 PM
Move function + Perl
++++++++++++++++Script+++++++++++++++++++++++++
#!/usr/bin/perl
use File::Copy;
open ('FILE', "/var/atul/file");
@file=
close (FILE);
$a=0;
#$temp=$#file;
#for ($i=0;$i<=3;$i++) {
foreach $file (@file) {
#move '/var/atul/atul1/atul2/$file[$a]', '/var/atul/' or die "move failed: $!";
$old = "/var/atul/atul1/atul2/$file[$a]";
$new = "/var/atul/$file[$a]";
#move $old,$new;
print "$old";
print "$new";
move $old,$new or die "move failed: $!";
$a++;
}
+++++++++++++++++++++++++++++++++++++++++++++++++
here what i am doing is taking file name from one location through variable and then putting the value of that variable in move function to move a file of same name to another location. Now thing is when i am giving print command its giving me proper file name but if i am using move function its taking that variable as filename and operation get failed.
This is error message:
+++++++++++++++++++++++++++++++++++++++++
/var/atul/atul1/atul2/file1
/var/atul/file1
Unsuccessful stat on filename containing newline at /usr/lib/perl5/5.8.0/File/Copy.pm line 185.
Unsuccessful stat on filename containing newline at /usr/lib/perl5/5.8.0/File/Copy.pm line 189.
Unsuccessful stat on filename containing newline at /usr/lib/perl5/5.8.0/File/Copy.pm line 190.
Unsuccessful stat on filename containing newline at /usr/lib/perl5/5.8.0/File/Copy.pm line 205.
Unsuccessful stat on filename containing newline at /usr/lib/perl5/5.8.0/File/Copy.pm line 92.
Unsuccessful open on filename containing newline at /usr/lib/perl5/5.8.0/File/Copy.pm line 119.
move failed: No such file or directory at test.pl line 16.
+++++++++++++++++++++++++++++++++++++++++++++++
its clear that its taking "$file[$a]" as file name not the value of this variable when using move. So please let me know how can i move a file in this case.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-22-2007 09:22 PM
тАО03-22-2007 09:22 PM
Re: Move function + Perl
Doesn't look like bad code to me.
Looks like use File::Copy; is not finding the library or doesn't have permissions to execute it.
SEP
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-22-2007 09:39 PM
тАО03-22-2007 09:39 PM
Re: Move function + Perl
How about
chomp @file;
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-22-2007 09:44 PM
тАО03-22-2007 09:44 PM
Re: Move function + Perl
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-22-2007 10:25 PM
тАО03-22-2007 10:25 PM
Re: Move function + Perl
Of course the chomp () does the trick, but your code is flacky in many ways.
#!/usr/bin/perl
# Hmm, start using:
# use strict;
# use warnings;
use File::Copy;
# First arg should NOT be quoted!
#open ('FILE', "/var/atul/file");
my $file = "/var/atul/file";
open my $fh, "<", $file or die "$file: $!";
#@file=
chomp (my @file = <$h>);
# close (FILE);
close $fh;
for (@file) {
# Huh? You changed the code to not use $a, and now you use it?
# $old = "/var/atul/atul1/atul2/$file[$a]";
my $old = "/var/atul1/atul2/$_";
# $new = "/var/atul/$file[$a]";
my $new = "/var/atul/$_";
# Diagnostics should go to STDERR
print STDERR "$old\n";
print STDERR "$new\n";
move $old, $new or die "move failed: $!";
}
BTW You should still consider upgrading your perl
Enjoy, Have FUN! H.Merijn