472,980 Members | 1,700 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

whats wrong with my code?

can someone tell me what is wrong with the bold code? i am just learning perl. the program should create a perl file with a random name (5 letters, followed by a number), but the name is always just the number. whats wrong with my code?

Expand|Select|Wrap|Line Numbers
  1. #!/usr/bin/perl
  2. use Fcntl;
  3.  
  4. @array = (a..z);
  5. srand;
  6. foreach (1..5) 
  7. {    
  8. $name = int(rand scalar(@array));    
  9. print $array[$name];    
  10. splice(@array,$name,1);    
  11. }
  12.  
  13. print "content-type: text/perl \n\n";
  14. sysopen (PERL, "$name.pl", O_RDWR|O_EXCL|O_CREAT, 0755);
  15. printf PERL '#!/usr/bin/perl';
  16. printf PERL "\n\n";
  17. printf PERL 'print "hello world!";';
  18. printf PERL "\n";
  19. printf PERL 'sleep(3);';
  20. close (PERL);
Nov 9 '07 #1
5 2258
KevinADC
4,059 Expert 2GB
can someone tell me what is wrong with the bold code? i am just learning perl. the program should create a perl file with a random name (5 letters, followed by a number), but the name is always just the number. whats wrong with my code?

Expand|Select|Wrap|Line Numbers
  1. #!/usr/bin/perl
  2. use Fcntl;
  3.  
  4. @array = (a..z);
  5. srand;
  6. foreach (1..5) 
  7. {    
  8. $name = int(rand scalar(@array));    
  9. print $array[$name];    
  10. splice(@array,$name,1);    
  11. }
  12.  
  13. print "content-type: text/perl \n\n";
  14. sysopen (PERL, "$name.pl", O_RDWR|O_EXCL|O_CREAT, 0755);
  15. printf PERL '#!/usr/bin/perl';
  16. printf PERL "\n\n";
  17. printf PERL 'print "hello world!";';
  18. printf PERL "\n";
  19. printf PERL 'sleep(3);';
  20. close (PERL);
While your code is a bit awkward, it seems to work for me. $name is a random string of 5 letters followed by a number.
Nov 10 '07 #2
While your code is a bit awkward, it seems to work for me. $name is a random string of 5 letters followed by a number.
$name is a random string of 5 letters followed by a number, but at least for me, the files created lack the 5 letters. i tried adding a print "$name" and it printed 5 letters and a number though.
Nov 12 '07 #3
KevinADC
4,059 Expert 2GB
$name is a random string of 5 letters followed by a number, but at least for me, the files created lack the 5 letters. i tried adding a print "$name" and it printed 5 letters and a number though.

I have no idea why your system will not create a file with the letters and numbers. Maybe someone else will be able to shed some light on this odd problem.
Nov 13 '07 #4
I have no idea why your system will not create a file with the letters and numbers. Maybe someone else will be able to shed some light on this odd problem.
well thanks anyway, i'll try running it in ubuntu, since i am currently using windows xp. you said it did work on your system? and what os are you running?
Nov 13 '07 #5
KevinADC
4,059 Expert 2GB
well thanks anyway, i'll try running it in ubuntu, since i am currently using windows xp. you said it did work on your system? and what os are you running?

I didn't actually check to see if the code created a file. I only printed the random strings out to the screen. I assume it would create a file with the random string, I can't see any reason why it would not. I tested the code on my old windows 98 test server.
Nov 14 '07 #6

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

Similar topics

6
by: Colin Steadman | last post by:
I have created a function to kill all session variables that aren't in a safe list. This is the function - Sub PurgeSessionVariables For Each Item In Session.Contents Select Case Trim(Item)...
3
by: Chris Geerdink | last post by:
combo with PHP. what is wrong with the Javascript? else { include("mysql.php"); $query1 = mysql_query("INSERT INTO gbook (naam, email, text) VALUES ('".$_POST."', '".$_POST."',...
4
by: asdf | last post by:
Hello! Can someone tell me whats wrong with this piece of code: Option Compare Database Option Explicit Sub retrieve() Dim rst As ADODB.Recordset Dim i As Integer
1
by: aa | last post by:
When I am reading from local disk (d:), everithing is OK, but then I am reading from map disk I am geting the this error. Whats wrong. Thanks Server Error in '/Extra' Application....
3
by: mahsa | last post by:
Hi do you know whats wrong with this code? <asp:HyperLink id="HLink_Help" runat="server" NavigateUrl='<%# "javascript:window.open('comments.aspx?id=1,width=500,height=600, scrollBars=yes');"...
4
by: blah | last post by:
Hello everyone, Ive been trying to get my application to "click" on a button in another application using SendMessage, Ive gotten this far but Im not sure whats wrong with this code, here is the...
7
by: Mike Barnard | last post by:
It's a simple test... VERY SIMPLE. But... In an external stlyesheet some attributes don't show. With the same styles cut and pasted to the test internally it works as expected. Anyone tell...
1
by: Abubakar | last post by:
Hi, In my application, Some of my thread gets stuck somewhere. The vs2k5 debugging "Thread" window shows that stuck thread and I can I dentify it. In its Name column the following text is...
5
by: hiqu | last post by:
This issue is driving me nuts and not able to figure out whats wrong. I've this code in my firefox extension. Firefox always hangs and reports the script is busy. if I introduce a break...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
0
tracyyun
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
2
by: giovanniandrean | last post by:
The energy model is structured as follows and uses excel sheets to give input data: 1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
1
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
3
by: nia12 | last post by:
Hi there, I am very new to Access so apologies if any of this is obvious/not clear. I am creating a data collection tool for health care employees to complete. It consists of a number of...
0
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...
4
by: GKJR | last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...

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.