473,769 Members | 6,187 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

whats wrong with my code?

9 New Member
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 2320
KevinADC
4,059 Recognized Expert Specialist
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
islayer
9 New Member
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 Recognized Expert Specialist
$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
islayer
9 New Member
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 Recognized Expert Specialist
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
3470
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) Case "Authenticated" Case "CI_CODE" Case "organisation_description" Case "location_description"
3
2395
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."', '".$_POST."')"); ?> <script language="JavaScript"> <!--
4
4065
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
2464
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. ---------------------------------------------------------------------------- ---- The specified user does not exist. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more...
3
2043
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');" %>'>Need Help?</asp:HyperLink> -- mahsa
4
3544
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 whole application (its small for testing purposes) and it seems that window wraps the text, at least when I preview this post: using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing;
7
2231
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 me why? Its probably sooooooo obvious, but it is 1.19 am! Thanks. www.thunderin.co.uk/
1
7554
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 written: "std::_Container_base::_Orphan_all". What does this mean? Now some general info about whats happnening here: :this is a call to a SendMessage api, which I'm sending to my GUI window, and this call never makes it back. I have checked the GUI...
5
1721
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 statement in the for(;;) loop below, then no issue. Any help would be appreciated! function getStuff()
0
9589
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10211
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
9994
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9863
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8872
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6673
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
3959
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3562
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2815
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.