Code Newbie
News     Forums     Search     Members     Sign Up    

My Code Newbie
Username

Password

Articles/Snippets
ASP Classic
ASP.NET
C
C#
C++
HTML / CSS
Java
Javascript
Linux / BSD
Perl
PHP
Python
Ruby
SQL
VB 6
VB.NET

C.N. Friends
  Planet Rome

Link to Us!
Code Newbie
  Code Newbie
    forums
Old 01-31-2006, 10:06 AM   #1 (permalink)
fabbasey
Recruit
 
Join Date: Mar 2005
Posts: 10
fabbasey is on a distinguished road
Exclamation Perl

Hi Every one,
I am trying to write a code that should move the file from one folder to another folder in PERL. Its really very urgent. Please tell me how I can write the code for that.
If someboday can help me out I would really appreciate that.

Thanks!!!
fabbasey is offline   Reply With Quote
Old 01-31-2006, 11:12 AM   #2 (permalink)
redhead
Newbie
 
redhead's Avatar
 
Join Date: Jun 2002
Location: Denmark
Posts: 1,696
redhead is on a distinguished road
How about this:
Code:
#!/usr/bin/perl
use File::Copy;
move($oldfile, $newfile)
    or die "move failed: $!";
OR if you want all the things done by hand, and not use some fancy library function
Code:
#!/usr/bin/perl
open(IN,  "< $oldfile")                     or die "can't open $oldfile: $!";
open(OUT, "> $newfile")                     or die "can't open $newfile: $!";

$blksize = (stat IN)[11] || 16384;          # preferred block size?
while ($len = sysread IN, $buf, $blksize) {
    if (!defined $len) {
        next if $! =~ /^Interrupted/;       # ^Z and fg
        die "System read error: $!\n";
    }
    $offset = 0;
    while ($len) {          # Handle partial writes.
        defined($written = syswrite OUT, $buf, $len, $offset)
            or die "System write error: $!\n";
        $len    -= $written;
        $offset += $written;
    };
}

close(IN);
close(OUT);
unlink($oldfile) or die "Can't unlink $oldfile: $!";
Naturaly you can change the $oldfile/$newfile with whatever you'd parsed as arguments.. I assume you know how to fetch arguments parsed to your program.
Else read up on the Perl cookbook, happy reading
__________________
Don't worry Ma'am, We're university students, We know what We're doing.
-----
If you pull the pin, Mr.Grenade would no longer be your friend.
-----
01000111 01101111 00100000 01000011 00100000 00100001
redhead is offline   Reply With Quote
Old 02-01-2006, 03:20 AM   #3 (permalink)
teknomage1
Jack of all trades
 
teknomage1's Avatar
 
Join Date: Feb 2005
Location: Los Angeles
Posts: 596
teknomage1 is on a distinguished road
Send a message via AIM to teknomage1
And of course if you're using perl on unix you can just
Code:
system("mv $oldfile $newfile");
or
Code:
my $mv_output = `mv $oldfile newfile`; #note those are backticks not single quotes!
__________________
Stop intellectual property from infringing on me
teknomage1 is offline   Reply With Quote
Old 02-04-2006, 04:28 PM   #4 (permalink)
computer geek47
Registered User
 
Join Date: Feb 2006
Posts: 8
computer geek47 is on a distinguished road
I feel so stupid that i cant understand a word you people say!Oh well...everyone has to start somewhere.
computer geek47 is offline   Reply With Quote
Old 02-04-2006, 04:35 PM   #5 (permalink)
sde
Moderator
 
sde's Avatar
 
Join Date: May 2002
Location: us.ca
Posts: 4,475
sde is on a distinguished road
Quote:
Originally Posted by computer geek47
everyone has to start somewhere.
indeed
sde is offline   Reply With Quote
Old 02-04-2006, 05:22 PM   #6 (permalink)
computer geek47
Registered User
 
Join Date: Feb 2006
Posts: 8
computer geek47 is on a distinguished road
*gasp*

No way!!I use that word and nobody else does!!
computer geek47 is offline   Reply With Quote
Old 02-05-2006, 12:55 AM   #7 (permalink)
sde
Moderator
 
sde's Avatar
 
Join Date: May 2002
Location: us.ca
Posts: 4,475
sde is on a distinguished road
Quote:
Originally Posted by computer geek47
No way!!I use that word and nobody else does!!
indeed, (c) 1995-2006, sde

sorry, if i print this disclaimer, i have the rights to this intellectual property. you now owe me money for each time you have used the word in the last 11 years.
sde is offline   Reply With Quote
Old 02-05-2006, 01:03 AM   #8 (permalink)
teknomage1
Jack of all trades
 
teknomage1's Avatar
 
Join Date: Feb 2005
Location: Los Angeles
Posts: 596
teknomage1 is on a distinguished road
Send a message via AIM to teknomage1
Wait a minute there Mike, my patent on single word agreements of univeral truisms clearly trumps your (c). Luckily for you I'll license it to you for 50% of your "indeed" revenues in royalties.
__________________
Stop intellectual property from infringing on me
teknomage1 is offline   Reply With Quote
Old 02-05-2006, 10:47 AM   #9 (permalink)
computer geek47
Registered User
 
Join Date: Feb 2006
Posts: 8
computer geek47 is on a distinguished road
Ya I dont do law.Im just here for the code.You can have your word.I have a new one!
perhaps, (c) 0-2006
computer geek47 is offline   Reply With Quote
Old 02-05-2006, 11:12 AM   #10 (permalink)
redhead
Newbie
 
redhead's Avatar
 
Join Date: Jun 2002
Location: Denmark
Posts: 1,696
redhead is on a distinguished road
Hey Computer geek, welcome here at CodeNewbie, don't be afraid to ask any form of question, as I'm sure we will be capable of providing you with an answer.
__________________
Don't worry Ma'am, We're university students, We know what We're doing.
-----
If you pull the pin, Mr.Grenade would no longer be your friend.
-----
01000111 01101111 00100000 01000011 00100000 00100001
redhead is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
My first Perl script. Admin All Other Coding Languages 2 05-19-2005 11:09 AM
{perl} HTTP Error Code Response gty All Other Coding Languages 2 09-08-2004 11:09 AM


All times are GMT -8. The time now is 02:02 PM.


Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.0.0 RC8





Copyright © 2000-2008, Milano Interactive
Web Hosting provided by Portal 360 Web Hosting