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? - #!/usr/bin/perl
-
use Fcntl;
-
-
@array = (a..z);
-
srand;
-
foreach (1..5)
-
{
-
$name = int(rand scalar(@array));
-
print $array[$name];
-
splice(@array,$name,1);
-
}
-
-
print "content-type: text/perl \n\n";
- sysopen (PERL, "$name.pl", O_RDWR|O_EXCL|O_CREAT, 0755);
-
printf PERL '#!/usr/bin/perl';
-
printf PERL "\n\n";
-
printf PERL 'print "hello world!";';
-
printf PERL "\n";
-
printf PERL 'sleep(3);';
-
close (PERL);
5 2258
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? - #!/usr/bin/perl
-
use Fcntl;
-
-
@array = (a..z);
-
srand;
-
foreach (1..5)
-
{
-
$name = int(rand scalar(@array));
-
print $array[$name];
-
splice(@array,$name,1);
-
}
-
-
print "content-type: text/perl \n\n";
- sysopen (PERL, "$name.pl", O_RDWR|O_EXCL|O_CREAT, 0755);
-
printf PERL '#!/usr/bin/perl';
-
printf PERL "\n\n";
-
printf PERL 'print "hello world!";';
-
printf PERL "\n";
-
printf PERL 'sleep(3);';
-
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.
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.
$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.
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?
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.
Sign in to post your reply or Sign up for a free account.
Similar topics
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)...
|
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."',...
|
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
|
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....
|
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');"...
|
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...
|
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...
|
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...
|
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...
|
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=()=>{
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
| |