Advanced perl help in windows


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Advanced perl help in windows
# 1  
Old 06-22-2011
Advanced perl help in windows

Hi guys,
Im trying to write a perl code to do the following task.

prerequisites:-
1) some media files(say boys.mp3 or gaga.mpeg or snoop.flv) is located in C:\videos\
2) The perl code is also located in same location C:\videos\

when I execute this perl code, it should ask for a number say 100 or 200 or even 5000 for variable n and a filename that is located in C:\videos\
and then it should duplicate that file n number of times and rename all the files with some random filenames.

Say if snoop.flv is given and n=5 then it should duplicate 5 times and rename it
eg:-
aksjg.flv
ojregnos.flv
aeofasjdavsf.flv
wajgtoih.flv
lkfj.flv


please provide your input guys

thanks
# 2  
Old 06-22-2011
What have you tried so far?
# 3  
Old 06-22-2011
Quote:
Originally Posted by getmmg
What have you tried so far?
Code:
#!/usr/bin/perl 
use File::Copy;

 $filetobecopied = "myhtml.html.";
while(n<500)
{
$random_generated_name = Generate a random string here

 $newfile = $random_generated_name".html."; 
copy($filetobecopied, $newfile) or die "File cannot be copied.";
random_generated_name = " ";
}




This is basic outline.. But I did not start coding this.


Last edited by radoulov; 06-22-2011 at 09:04 AM.. Reason: Code tags.
# 4  
Old 06-22-2011
How about this

Code:
 
use strict;
print "Enter File Name: ";
my $fileName = <STDIN>;
chomp($fileName);
print "Enter Number: ";
my $no = <STDIN>;
chomp($no);
if(-e $fileName)
{
        $fileName=~/(\.\w+)$/;
        my $extn = $1;
        for(my $i=0;$i<$no;$i++)
        {
                my $randFile = &genRandString();
                $randFile .= $extn;
                my $cmd = qq@cp $fileName $randFile@;
                system($cmd);
        }
}
else
{
        print "$fileName not exits\n";
}

sub genRandString
{
        my @cha=('a'..'z','A'..'Z');
        my $string;
        $string.= $cha[rand @cha] foreach(1..10);
        return $string;
}

This User Gave Thanks to getmmg For This Post:
# 5  
Old 06-22-2011
This might work fine with Linux... But not in windows... Because windows doesn't know about "cp"

---------- Post updated at 06:01 PM ---------- Previous update was at 05:56 PM ----------

Its working now

I replaced cp with copy(file1, file2 ) using the File::Copy module.

Thanks getmmg.
Login or Register to Ask a Question

Previous Thread | Next Thread

8 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

perl script to traceroute an IP from windows

I am writing a perl code(windows) to traceroute IP address and to print the output. I had executed the below code which was taken from cpan modules #!C:/perl/bin/perl.exe use Net::Traceroute; $tr = Net::Traceroute->new(host=> "google.com"); if($tr->found) { my $hops = $tr->hops; if($hops... (4 Replies)
Discussion started by: giridhar276
4 Replies

2. Windows & DOS: Issues & Discussions

Windows Advanced Options Menu

I dual boot between Windows XP and Linux Mint. I am trying to get the Windows Advanced Options Menu to show up. Normally you would press f8 to make this happen when your computer is booting. With a dual boot it makes it way more complicated. If you press f8 when your computer first starts it does... (3 Replies)
Discussion started by: cokedude
3 Replies

3. UNIX for Dummies Questions & Answers

How to Perl Code in Windows?

I got this perl code for solaris from tyler_durden Please help me to run the same on windows as i am unable to install date::calc program on unix perl -F, -M"Date::Calc qw(Add_Delta_DHMS)" -lane ' if ($ARGV eq "file2") { $os{$F} = $F.join($F, unpack("A2A2",$F)); } else { ... (1 Reply)
Discussion started by: ssantoshss
1 Replies

4. UNIX for Dummies Questions & Answers

Need help configuring Active Perl on Windows Vista.: Perl Scripting on Windows

Hi All, Need help configuring Active Perl on Windows Vista. I am trying to install Active Perl on Windows Vista. The version of Active Perl i am trying to install is : ActivePerl 5.10.1 Build 1006 After installing it through cmd, When i try to run perl -v to check the version, i get the... (2 Replies)
Discussion started by: Vabiosis
2 Replies

5. Shell Programming and Scripting

FTP From UNIX to WINDOWS Using PERL

Hi All, I have to write a PERL script in which I have to FTP results from UNIX to Windows Desktop. How can I do this using PERL? Thanks (1 Reply)
Discussion started by: kunal1514
1 Replies

6. Shell Programming and Scripting

Perl for Unix & Windows

Hi Even though this is unix forum, iam posting this thread as iam not sure of which forum should i post this too. I understand perl can be used in unix environment and i have used the same for automation of my processes. Eg: Open a file search the text string replace the text string close... (9 Replies)
Discussion started by: kenkanya
9 Replies

7. Shell Programming and Scripting

sending mail using perl through windows

Hi all this is the code which i tried executing in windows environment to send a test mail. # Perl script to send mail on deliver complete. package SendMail; use Config; use Mail::Send; @ISA = qw(Mail::Send); sub open { my $me = shift; my $how; # How to send mail my $notused; my... (13 Replies)
Discussion started by: victorvvk
13 Replies

8. Windows & DOS: Issues & Discussions

Anyone know any good perl compilers for windows ?

Does anyone know of a Good perl compiler for windows ? i have searched google.com and a few other search engines but they havent turned up anything good. Any and all help would be appreciated (3 Replies)
Discussion started by: JeZzTeR
3 Replies
Login or Register to Ask a Question