473,320 Members | 2,052 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

create copy, random filename of itself

Hello,

I am rather new at pearl, but I am a fast learner.

So, I have been sitting up here, all night, trying to make a script that:

Reads it's name, copies itself to the same folder, but with a random name with a .html suffix(I have my apache configure to handle .html as CGI).

My code is here, this is the small batch I left for you to see, and It doesn't work.

http://kuratkull.pastebin.com/862554
You are welcome to submit fixes and suggestion there :)

Thank you.
Jan 19 '07 #1
3 2718
KevinADC
4,059 Expert 2GB
Do you have Data::Random installed? I've never even heard of that module but thats no surprise, there are so many perl modules. But this is really easy to do without that module.

Expand|Select|Wrap|Line Numbers
  1. #!/usr/bin/perl
  2. use strict;
  3. use warnings;
  4. print "Content-type: text/html\n\n";
  5. use File::Copy;
  6. my @length = (3..20);
  7. my @set = ('a'..'z','A'..'Z','0'..'9');
  8. my $key2 = $ENV{SCRIPT_NAME};
  9. my $rand_name = '';
  10. my $length = $length[rand @length];
  11. for(0..$length){
  12.    $rand_name .= $set[rand @set];
  13. }
  14. $rand_name .= '.html';    
  15. print $rand_name;
  16. my $filetobecopied = "rando2.html";
  17. copy($filetobecopied, $rand_name) or die "File cannot be copied.";
  18. chmod 0666, $rand_name;
  19.  
ten runs produced this output:

LTHbsX.html
RTMvPRX.html
obVmyxbPlp8lnyeZAVI.html
ExYicXiGh9n03bq.html
uEOMOhHdlv0QPF.html
uIiF2orJK2u.html
jSfdXEG06cuVQ.html
A5Tfy32wt0YB.html
XokxahaECjvqEge8SjjW.html
5dDfE.html


In your code this line has an error:

Expand|Select|Wrap|Line Numbers
  1. chmod $0666, '@newfile';
$0666 should be 0666

next time post your code here, asking people to go to another site to see that little bit of code is not necessary and just makes it harder to help you.
Jan 19 '07 #2
wow, thx for such a detailed answer :)

Next time, I will do as you told me.

Thanks again.
Jan 19 '07 #3
KevinADC
4,059 Expert 2GB
personally if it were me I might just use "time" for the filename instead of that random name stuff:

Expand|Select|Wrap|Line Numbers
  1. #!/usr/bin/perl
  2. use strict;
  3. use warnings;
  4. print "Content-type: text/html\n\n";
  5. use File::Copy;
  6. my $key2 = $ENV{SCRIPT_NAME};
  7. my $filetobecopied = "rando2.html";
  8. my $new_name = time . '.html';
  9. copy($filetobecopied, $new_name) or die "File cannot be copied.";
  10. chmod 0666, $new_name;
  11.  
might work for your purposes, might not.
Jan 19 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

15
by: alanbe | last post by:
Greetings I am making a flashcard type application to help me in my TCP/IP protocols test. My instructor will test us periodically on how a device or networking function relates to the OSI...
5
by: Sybren Stuvel | last post by:
Hi people, I'm creating a program that can solve and create Sudoku puzzles. My creation function needs to make a lot of copies of a puzzle. Until now, I used copy.deepcopy(), but that's too...
8
by: kp87 | last post by:
I am a little bit stuck .... I want to play a bunch of soundfiles randomly, but i want to give each soundfile a rating (say 0-100) and have the likelihood that the file be chosen be tied to its...
6
by: windandwaves | last post by:
Hi Folk Some of my clients asked me to create "fancy emails" for them (aka html formatted emails). I know how to make a nice html document, but I had trouble creating a simple way to provide...
5
by: Michael Sperlle | last post by:
Is it possible? Bestcrypt can supposedly be set up on linux, but it seems to need changes to the kernel before it can be installed, and I have no intention of going through whatever hell that would...
12
by: Jim Michaels | last post by:
I need to generate 2 random numbers in rapid sequence from either PHP or mysql. I have not been able to do either. I get the same number back several times from PHP's mt_rand() and from mysql's...
23
by: sandy | last post by:
I need (okay, I want) to make a dynamic array of my class 'Directory', within my class Directory (Can you already smell disaster?) Each Directory can have subdirectories so I thought to put these...
3
by: bluez | last post by:
I want to design a webpage where user can search the data from the database and list out the related records. Each of the record got a delete button which allow user to delete the record. ...
4
by: Masta | last post by:
Hello Group. I have a directory with 3000 ".jpg" named like this: 1234_01.jpg 1234_09.jpg 1234_11.jpg 1234_12.jpg 2341_01.jpg 2341_05.jpg
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.