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 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? - #!/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.
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.
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?
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.
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)
Case "Authenticated"
Case "CI_CODE"
Case "organisation_description"
Case "location_description"
|
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">
<!--
|
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.
----------------------------------------------------------------------------
----
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...
|
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
| |
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;
|
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/
|
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...
|
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()
|
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...
|
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...
| |
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,...
|
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...
|
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...
|
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();...
|
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
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
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...
| |