[17588] in Perl-Users-Digest
Perl-Users Digest, Issue: 5008 Volume: 9
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Dec 1 11:10:56 2000
Date: Fri, 1 Dec 2000 08:10:14 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <975687014-v9-i5008@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Fri, 1 Dec 2000 Volume: 9 Number: 5008
Today's topics:
Re: Perl string converter (Anno Siegel)
Re: proc::daemon question <hl198@doc.ic.ac.uk>
Re: Random password generator (Tad McClellan)
Reading file into array. <johngros@Spam.bigpond.net.au>
Re: Reading file into array. <johngros@Spam.bigpond.net.au>
Re: Reading file into array. (Tad McClellan)
Re: regex not matching (Tad McClellan)
sorting a file... texasreddog@my-deja.com
Re: Space near the middle (Abigail)
Re: txt files getting denied. <johngros@Spam.bigpond.net.au>
Re: txt files getting denied. (David Wall)
Re: txt files getting denied. (Rafael Garcia-Suarez)
Re: URL Get targeting HTTPS . . . <jboes@eoexchange.com>
Re: Using Curses <wombat@virtualdan.com>
Re: Using goto (Tad McClellan)
Re: What is a Junior Perl Programmer? <bowman@montana.com>
Re: why could't i do something like this? <johngros@Spam.bigpond.net.au>
Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 1 Dec 2000 14:35:48 -0000
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Perl string converter
Message-Id: <908d04$q9t$1@lublin.zrz.tu-berlin.de>
Abigail <abigail@foad.org> wrote in comp.lang.perl.misc:
>On Fri, 01 Dec 2000 04:34:52 GMT, Bob Walton (bwalton@rochester.rr.com) wrote in comp.lang.perl.misc <URL: news:<3A272B18.56A2F095@rochester.rr.com>>:
>++ designpixs@my-deja.com wrote:
>++ >
>++ > I want to be able to pass in a string of any size
>++ > and return an integer. The return value is
>++ > always unique to the string passed in. (i.e.
>++ > pass in TEST returns 3452, pass in TESTS returns
>++ > 234532) The return value MUST be a unique value
>++ > to the value passed in. If I pass in TEST and
>++ > get 1234 and the later pass in TEST I should get
>++ > 1234.
>++ ...
>++ > Drew
>++ ...
>++ What you're asking for is technically infeasible. There are a *lot* of
>++ strings "of any size" out there, and only a relative handful of integer
>++ values. For example, a 100000-character string has 2**800000 possible
>++ values (which is probably more than the number of electrons in the
>++ universe), while a standard integer has only 2**32 possible values. I
>++ suppose you could use the Math::BigInt package to represent a unique
>++ number for each such string, but then why not just use the string
>++ itself, since there would be a 1:1 relationship anyway?
>
>Well, 18457123481273012315713645734592745983749171023827156175619 is a
>perfectly valid integer. Perl might not be able to do arithmetic with
>it, but it doesn't have a problem storing it in a scalar.
>
>Here's a trivial function that uniquely maps any string to an integer:
>
> sub str2int {join "" => map {sprintf "%03d" => ord} split // => shift}
The way I understand the OP it is not required that the mapping from
strings to numbers be defined a priori (before having seen the strings
to be mapped). It will probably be enough to assign a new number to
every new string and recognize old strings. This is trivially
achieved with a hash:
{ # scope for private variables
my $next_num = 0; # next index to use
my %num_tab; # save known associations here
sub enum_string {
my $str = shift;
$num_tab{ $str} = $next_num++ unless defined $num_tab{ $str};
$num_tab{ $str};
}
}
Anno
------------------------------
Date: Fri, 01 Dec 2000 12:48:52 +0000
From: Hilkiah Lavinier <hl198@doc.ic.ac.uk>
Subject: Re: proc::daemon question
Message-Id: <3A279E34.425F5EBA@doc.ic.ac.uk>
Thank you for your reply. I tried commenting out print but nothing
seemed to happen, when I looked in the / directory I saw the files
'newfile' and 'file'. I forget that when u run a daemon, it changes the
current working directory to /.
So I guess it is working.
Thank you for your advice otherwise I wouldn't have looked at the
program anytime soon.
Hilkiah
David Efflandt wrote:
>
> On Thu, 30 Nov 2000 11:43:54 +0000, Hilkiah Lavinier <hl198@doc.ic.ac.uk> wrote:
> >Hi, I'm trying to get the following program to work while running as a
> >daemon. It's quite silly but I need to figure this out in order to get
> >the real program running. It works fine if i comment the line with
> >Proc::Daemon::Init; but when I leave this line uncommented (so the
> >programs runs in the background as a Daemon, the files don't get
> >created.
> >
> >Here is the source code:
> >
> >#!/usr/bin/perl -w
> >#daemon.plx
> >
> >#use warnings;
> >use strict;
> >use Proc::Daemon;
> >use Carp;
> >
> >Proc::Daemon::Init;
> >
> >print "hi";
> >system("touch newfile");
> >`touch file`;
>
> What happens if you comment out the 'print "hi"'? Where do you expect
> that to print to when running as a daemon? It likely hangs or dies at
> that point.
>
> --
> David Efflandt efflandt@xnet.com http://www.de-srv.com/
> http://www.autox.chicago.il.us/ http://www.berniesfloral.net/
> http://cgi-help.virtualave.net/ http://hammer.prohosting.com/~cgi-wiz/
--
..\ /.. HILKIAH G. LAVINIER, [aka ¥eL10W]
...\/... 9 Earl's Court Square
.._||_.. London, SW5 9BY
./ ||... HILKIAH@YAHOO.COM HL198@DOC.IC.AC.UK
.\_||_.. Tel : # 0796 807 8247 (CELL) ICQ # 8978201
...||... FAX : 0870 133 8705 uk or 1 603 697 8299 usa
------------------------------
Date: Fri, 1 Dec 2000 09:31:34 -0500
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: Random password generator
Message-Id: <slrn92fdi6.8ne.tadmc@magna.metronet.com>
simbean@my-deja.com <simbean@my-deja.com> wrote:
>In article <9078fv$c6h$1@nnrp1.deja.com>,
>I am still learning. But I would appreciate advice about how to create
>better [cleaner] code. :)
>
>
>my @all =
>('1', '2', '3', '4', '5', '6', '7', '8', '9', '0', 'A', 'B', 'C', 'D', '
>E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S'
>, 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f', 'g',
>'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v
>', 'w', 'x', 'y', 'z');
Yuck!
(and how come you have zero coming _after_ nine?
Zero comes before one.
)
my @all = ( '1' .. '9', '0', 'A' .. 'Z', 'a' .. 'z');
>srand (time | $$);
"In fact, it's usually not necessary to call `srand' at all"
But you surely already know that, because it is in the description
for the function that you are using.
perldoc -f srand
You do read the descriptions for the functions that you use, don't you?
>my $p, $z, $value;
You should ask perl for all of the help that you can get.
You do that by enabling warnings.
You should enable warnings on every single Perl program that
you ever write:
#!/usr/bin/perl -w
That would have pointed out to you that the statement above
is not doing what you probably think it is doing.
Reading the description of my() would also have pointed out
what is wrong with the above.
perldoc -f my
You do read the descriptions for the functions that you use, don't you?
>while(length($p)<6)
Space characters are not a scarse resource. Feel free to use as
many as you like to make your code easier to read:
while( length($p) < 6 )
--
Tad McClellan SGML consulting
tadmc@metronet.com Perl programming
Fort Worth, Texas
------------------------------
Date: Fri, 01 Dec 2000 11:55:07 GMT
From: "John Boy Walton" <johngros@Spam.bigpond.net.au>
Subject: Reading file into array.
Message-Id: <vkMV5.586$xW4.4437@news-server.bigpond.net.au>
This is the best I could come up with but $_ should be $_[$somevalue] where
can I get the value perl would be using as it creates @_?
#!e:/millenium programs/perl/bin/perl
$path = "C:/Program Files/G6FTP/";
$file = $path."Users.ini";
open BOGUS,"$file";
$array = 0;
while (@_ = <BOGUS> ){
$line = $_;
if ($line =~ /\[/){
$flag = "set";
$counter = 0;
}elsif (/^\n/){
$flag ="not set";
print $data[$array[$counter]];
print $data[$array[2]];
$temp = $data[$array[2]];
$temp =~ s/Login=//;
if ({time-$temp}/86400<31){
$array++;
}
}elsif ($flag eq "set"){
$data[$array[$counter]] = $line;
$counter++;
}
}
------------------------------
Date: Fri, 01 Dec 2000 12:20:02 GMT
From: "John Boy Walton" <johngros@Spam.bigpond.net.au>
Subject: Re: Reading file into array.
Message-Id: <SHMV5.625$xW4.4784@news-server.bigpond.net.au>
I think I got it with for ($i =0; $i <@_; $i++)
"John Boy Walton" <johngros@Spam.bigpond.net.au> wrote in message
news:vkMV5.586$xW4.4437@news-server.bigpond.net.au...
> This is the best I could come up with but $_ should be $_[$somevalue]
where
> can I get the value perl would be using as it creates @_?
>
> #!e:/millenium programs/perl/bin/perl
> $path = "C:/Program Files/G6FTP/";
> $file = $path."Users.ini";
> open BOGUS,"$file";
> $array = 0;
> while (@_ = <BOGUS> ){
> $line = $_;
> if ($line =~ /\[/){
> $flag = "set";
> $counter = 0;
> }elsif (/^\n/){
> $flag ="not set";
> print $data[$array[$counter]];
> print $data[$array[2]];
> $temp = $data[$array[2]];
> $temp =~ s/Login=//;
> if ({time-$temp}/86400<31){
> $array++;
> }
> }elsif ($flag eq "set"){
> $data[$array[$counter]] = $line;
> $counter++;
> }
>
> }
>
>
>
------------------------------
Date: Fri, 1 Dec 2000 09:49:28 -0500
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: Reading file into array.
Message-Id: <slrn92fejo.8ne.tadmc@magna.metronet.com>
John Boy Walton <johngros@Spam.bigpond.net.au> wrote:
>This is the best I could come up with but $_ should be $_[$somevalue] where
>can I get the value perl would be using as it creates @_?
>
>#!e:/millenium programs/perl/bin/perl
#!perl -w
use strict;
>$path = "C:/Program Files/G6FTP/";
Don't use double quotes when you don't need double quotes.
my $path = 'C:/Program Files/G6FTP/';
>open BOGUS,"$file";
Don't use double quotes when you don't need double quotes.
Always, yes *always*, check the return value from open():
open BOGUS, $file or die "could not open '$file' $!";
>while (@_ = <BOGUS> ){
The input operator in list context (which is what you have above)
reads _all_ of the input at once.
Then perl needs to do a conditional test on @_ to decide if
it should execute the while body. If you read any lines at
all, then @_ will be "true" and the body will execute.
Back to the top of the loop. @_ becomes empty (because BOGUS
is at the end-of-file because you already read up to EOF on
the first iteration).
When @_ is empty, the condition evaluates to false, and
the loop body does not execute.
This loop with *always* execute one time. It is a non-looping loop!
> $line = $_;
> if ($line =~ /\[/){
No need to copy it, you can use the elements of @_ directly:
if ($_[0] =~ /\[/){
> $flag = "set";
> $counter = 0;
> }elsif (/^\n/){
That matches against the $_ variable, but your code never put
anything into that variable!
perl would have told you about that if you could have been
troubled to ask it to help you find common mistakes by
turning on warnings.
> if ({time-$temp}/86400<31){
Space characters are not a scarce resource, feel free to use as
many as you like to make your code easier to read:
if ( (time - $temp) / 86400 < 31 ) {
--
Tad McClellan SGML consulting
tadmc@metronet.com Perl programming
Fort Worth, Texas
------------------------------
Date: Fri, 1 Dec 2000 08:56:47 -0500
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: regex not matching
Message-Id: <slrn92fbgv.8ne.tadmc@magna.metronet.com>
Wyzelli <wyzelli@yahoo.com> wrote:
>Had an interesting situation recently where a regex failed to match, when I
>thought it should.
So you need to examine 2 things then: the pattern, and the string.
Did you print out the string that you are trying to match against?
>I wrote a short script to parse this and not print the $0.00 lines,
>The regex to skip the $0.00 lines was /\$0\.00$/ Which failed to match.
>
>To get it to work, I had to use m/\$0\.00$/.
I cannot duplicate that behavior.
Can you make a complete program that we can run that displays
what you have described?
My attempt prints "matched":
-----------------------------
#!/usr/bin/perl -w
use strict;
$_ = 'C Around to it aroundto $0.00';
# ^^
# better not be in a "double quotish" context if we don't
# want that variable to be interpolated...
if ( /\$0\.00$/ )
{ print "matched\n" }
else
{ print "No match\n$_\n" }
-----------------------------
>I thought the m was optional when the regex delimiter was a slash.
It is. Let's see some (complete) code.
--
Tad McClellan SGML consulting
tadmc@metronet.com Perl programming
Fort Worth, Texas
------------------------------
Date: Fri, 01 Dec 2000 14:09:07 GMT
From: texasreddog@my-deja.com
Subject: sorting a file...
Message-Id: <908bds$5rt$1@nnrp1.deja.com>
Hi,
I have a calendar script on our servers that contains a text file of
events. The file looks like this:
#id|datestamp|label|description
29|20001206|Holiday Party|Location ???
30|20001225|Christmas Day|Office Closed
31|20001226|Christmas Holiday|Office Closed
33|20001227|Out Of Office|Joe Blow - Vacation
34|20001228|Out Of Office|Joe Blow - Vacation
35|20010101|New Years Day|Office Closed
36|20001207|Annual Stockholders Meeting |10:00am
37|20001201|Jane Doe - doctor's appt|11:00 doctor's appt.
I want to be able to sort this file by id & datestamp, because the e-
mail script that I wrote for this just reads this file and mails out
the events in this order, so the last two events in December are shown
after the January events. When I sort the file, it should look like
this before the e-mail goes out:
#id|datestamp|label|description
29|20001201|Jane Doe - doctor's appt|11:00 doctor's appt.
30|20001206|Holiday Party|Location ???
31|20001207|Annual Stockholders Meeting |10:00am
32|20001225|Christmas Day|Office Closed
33|20001226|Christmas Holiday|Office Closed
34|20001227|Out Of Office|Joe Blow - Vacation
35|20001228|Out Of Office|Joe Blow - Vacation
36|20010101|New Years Day|Office Closed
I have a script that I started working on to do this. It appears to
work for the first out of place event, but I don't think it will work
for all events, because some people may append events to this file that
are earlier than this. Here is what my script looks like so far:
#!/usr/bin/perl
# open input and output files
$infile = '/u1/httpd/cgi-bin/calendar/calendar_events.txt';
$outfile1 = '/u1/httpd/cgi-bin/calendar/temp1.txt';
$outfile2 = '/u1/httpd/cgi-bin/calendar/temp2.txt';
open(IN, $infile) || die "Cannot open $infile\n";
open(OUT1, ">$outfile1") || die "Cannot open $outfile1\n";
# write to output file
$cnt = 0;
while(<IN>){
@parts = split(/\|/, $_);
$parts[$cnt+1] = int($parts[$cnt+1]);
push(@junk, @parts);
}
if($junk[0] eq "#id") {
print OUT1 "#id|datestamp|label|description\n";
}
for($x=4; $x<=$#junk; $x=$x+4) {
if($junk[$x+5] eq "") {
print OUT1 "$junk[$x]|$junk[$x+1]|$junk[$x+2]|$junk[$x+3]";
} else {
if($junk[$x+5] < $junk[$x+1]){
print OUT1 "$junk[$x+4]|$junk[$x+5]|$junk[$x+6]|$junk[$x+7]";
for($y=$x+8; $y<=$#junk; $y=$y+4) {
print OUT1 "$junk[$y]|$junk[$y+1]|$junk[$y+2]|$junk
[$y+3]";
}
print OUT1 "$junk[$x]|$junk[$x+1]|$junk[$x+2]|$junk[$x+3]";
close(OUT1);
system("mv $outfile1 $infile");
exit;
} else {
print OUT1 "$junk[$x]|$junk[$x+1]|$junk[$x+2]|$junk[$x+3]";
}
}
}
exit;
Can someone help me, by putting in some code for this to make this work?
If anyone knows of a better sort solution than this, let me know.
Thanks, Ken
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: 1 Dec 2000 11:07:35 GMT
From: abigail@foad.org (Abigail)
Subject: Re: Space near the middle
Message-Id: <slrn92f1jn.bha.abigail@tsathoggua.rlyeh.net>
On Fri, 1 Dec 2000 05:22:57 -0500, Jeff Pinyan (jeffp@crusoe.net) wrote in comp.lang.perl.misc <URL: news:<Pine.GSO.4.21.0012010452190.5826-100000@crusoe.crusoe.net>>:
++ >
++ >Question: is there a neat way to find that splitting point (a space)
++ >near the middle of the string? Can it be done with regexes?
++
++ my $string = "external diameter in mm";
++ my $half = int(length($string)/2);
++
++ $string =~ s/( ?)([^ ]*)(?<=^.{$half})([^ ]*)( ?)/
++ length($2) < length($3) ? "\n$2$3$4" : "$1$2$3\n"
++ /e;
So, you either get rid of $1 or of $4? ;-)
Abigail
------------------------------
Date: Fri, 01 Dec 2000 12:03:59 GMT
From: "John Boy Walton" <johngros@Spam.bigpond.net.au>
Subject: Re: txt files getting denied.
Message-Id: <PsMV5.600$xW4.4561@news-server.bigpond.net.au>
You are right Michael I was trying to read. I was hoping to open in
read/write mode as I want to write to the file after some processing. I have
read the Manpage this morning, previously I was relying on some books I have
that did not explain all the ">" and "+>" flags, so I was copying from
examples I felt most closely matched what I was attempting. While I now
"know" I still stuffed it only just five minutes ago and wiped a file I
wanted to read.
> At any rate, John, you don't seem to have a good grasp specifying file
> modes with open(). Study the open() manpage (perldoc -f open) to get a
> better understanding.
>
> -mjc
------------------------------
Date: 30 Nov 2000 16:32:54 -0500
From: darkon@one.net (David Wall)
Subject: Re: txt files getting denied.
Message-Id: <8FFCA07E2darkononenet@206.112.192.118>
helgi@NOSPAMdecode.is (Helgi Briem) wrote in
<3a266ea6.271936944@news.itn.is>:
>On Thu, 30 Nov 2000 07:05:49 GMT, "John Boy Walton"
><johngros@Spam.bigpond.net.au> wrote:
>
>>I created some text files and ran a script against them and I keep
>>getting permission denied. Here is the script.
[snip, although possibly I should have commented on always checking the
return value(s) of system calls like open() and opendir() (Hi Tad!)]
>>I have made no permission changes to them yet they stopped being
>>accessible to my scripts. Does anyone know what I did to trigger this?
>>
>I dare say you have to close the file before
>you try unlinking it.
>
>I'm to lazy to check for myself.
I'm not. You do have to close a file before you unlink it, at least under
Windows NT. Linux doesn't seem to care.
--
David Wall
darkon@one.net
------------------------------
Date: Fri, 01 Dec 2000 16:02:37 GMT
From: rgarciasuarez@free.fr (Rafael Garcia-Suarez)
Subject: Re: txt files getting denied.
Message-Id: <slrn92fiue.i7r.rgarciasuarez@rafael.kazibao.net>
David Wall wrote in comp.lang.perl.misc:
> helgi@NOSPAMdecode.is (Helgi Briem) wrote in
> <3a266ea6.271936944@news.itn.is>:
>
> >I dare say you have to close the file before
> >you try unlinking it.
> >
> >I'm to lazy to check for myself.
>
> I'm not. You do have to close a file before you unlink it, at least under
> Windows NT. Linux doesn't seem to care.
It's perfectly legal under Linux (and other unix flavors as well) to
unlink a file that is open. Unlinking modifies the filesystem to delete
the reference from the directory containing the file to the file inode.
Note that this does not imply the deletion of the file itself: several
directory entries may refer to the same inode. This trick is sometimes
used by a program to get a private temporary file on disk: the unlinked
open file remains accessible only by this program, through the use of
its filehandle. Once the filehandle is closed, the file is deleted from
the disk.
--
# Rafael Garcia-Suarez / http://rgarciasuarez.free.fr/
------------------------------
Date: Fri, 01 Dec 2000 10:13:39 -0500
From: "Jeff Boes" <jboes@eoexchange.com>
Subject: Re: URL Get targeting HTTPS . . .
Message-Id: <3a27c1a3$0$30011$44a10c7e@news.net-link.net>
Unless my newsreader has been taken over by the Illuminati, I think ameen
@ dausha . net babbled:
> How would I go about accessing HTTPS in Perl? In a discussion today with
> some peers I was told it was impossible in Perl without using an
> unreliable hack.
>
>
> Ben Wilson (a.k.a. Ameen, Last of the Dausha)
> ____________________________
> -"Ever heard of Aristotle . . . Plato . . . Socrates?!"
Not to be too much of a smartass, but I couldn't resist:
"Ever heard of Yahoo ... Google ... Altavista?!"
Google turned up several references when fed 'perl lwp https', mostly
pointing to Crypt::SSLeay. I don't know if that's the preferred method
nowadays, but it's certainly a start. Note: my personal experience with
this module indicates that it *must* be installed natively (not just
copied to the target machine) because it has compiled (C) code inside.
--
Jeff Boes <jboes@eoexchange.com> Tel: (616) 381-9889 x.18
Sr. Software Engineer, EoExchange, Inc. http://www.eoexchange.com/
Search, Monitor, Notify. http://www.eomonitor.com/
------------------------------
Date: Fri, 01 Dec 2000 14:31:40 GMT
From: Dan Cardamore <wombat@virtualdan.com>
Subject: Re: Using Curses
Message-Id: <gDOV5.33437$3u1.8143693@news3.rdc1.on.home.com>
Thanks for the reply.
I'm just using ls --color as an example. Since this will be a shell I'd
have to be able to run anything. From your reply it sounds as though I'd be
better off not using curses since it will probably create incompatibilities
with the run programs and be too much of a hassle. Is there another toolkit
that can do the same type of functionality as Curses without this problem?
Dan
Chris Fedde <cfedde@fedde.littleton.co.us> wrote:
> In article <zDFV5.30114$3u1.7441945@news3.rdc1.on.home.com>,
> Dan Cardamore <wombat@virtualdan.com> wrote:
>>Hi all,
>>I'm trying to use Curses to make a perl shell which can execute
>>system commands as well. I'd like to use Curses because I can
>>do some cool GUI stuff if I use it. The problem is that I can't
>>use it to execute things like "ls --color" since that will return
>>some special terminal color codes.
>>
>>Is there a way to have curses display the screen in two: top part
>>being non-curses, and the bottom half being curses? Or is there a
>>better way to execute commands like this and get them to display
>>nicely.
>>
> One way to do this is to just do the colorization yourself. That
> is when someone asks for a directory you just opendir and do the
> colorization directly as you loop through the display. The other
> method would be to build a parsing tree indexed by the ANSI escape
> sequences using TERM::ANSIColor and match what 'ls --color' returns
> to what is in the parse tree.
> --
> This space intentionally left blank
--
________________________________________________________________
Dan Cardamore wombat@proudly.ca http://www.proudly.ca
GnuPGP Key: mailto:wombat@proudly.ca?subject=sendpgpkey
Mail Filter: mailto:wombat@proudly.ca?subject=mailfilter
My current project can be found at http://www.collaboffice.com
________________________________________________________________
------------------------------
Date: Fri, 1 Dec 2000 08:12:49 -0500
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: Using goto
Message-Id: <slrn92f8uh.8ne.tadmc@magna.metronet.com>
Shawn Smith <SPAM_loginprompt@yahoo.com> wrote:
>
>I am fresh out of school
Did school include the software life-cycle and where the costs
of software are apportioned?
>Some of the scripts have goto statements. What I have read is that
>goto's slow down the scripts because goto's cause Perl to compile the
>scripts on every run.
Where did you read that? It is a load of errr, stuff.
perl (not Perl) compiles your scripts on every run regardless
of whether there are gotos or not.
>I thought that the scripts got interpreted. Can
>someone explain this or direct me to the proper docs?
To find out how perl runs, consult the misleadingly named Perl doc:
perldoc perlrun
>Also, to justify removing the goto's I must show that it will improve
^^^^
>the efficiency of the scripts.
Doesn't your managment make business decisions based on cost
versus benefits?
Many PHBs will understand if you talk to them about money
rather than about software constructs :-)
It will cost them more money to pay your salary while you remove
the gotos than they are likely to save by having the program
take several more milliseconds to run.
So don't present your case based on "it will run faster",
because that does not clearly save money.
>I can't just say hey these are not
>cool.
Say:
"Three quarters of the cost of software over its lifetime is
due to maintenance (new features, bug fixes) labor."
"gotos make code very hard to maintain and modify."
"If we don't remove the gotos, we will be wasting time
(i.e. money) every time we need to change the software."
"So we could save a lot of money by removing the gotos."
"Should I go do that for us?"
:-)
>The goto's are (so far, I have only read 3 of a dozen scripts)
>being used when an error occurs. Thus, only on rare occasions do the
>goto's get used.
gotos have their place. Bailing out on fatal errors is the most
classic example of one of the rare places where gotos _might_
be OK.
But in Perl code, you can bail by calling die() or exit() (or
a subroutine that in turn calls one of those), so gotos aren't
often needed for "fatal errors".
--
Tad McClellan SGML consulting
tadmc@metronet.com Perl programming
Fort Worth, Texas
------------------------------
Date: Fri, 1 Dec 2000 07:18:20 -0700
From: "bowman" <bowman@montana.com>
Subject: Re: What is a Junior Perl Programmer?
Message-Id: <RlOV5.315$9s6.1692@newsfeed.slurp.net>
Craig Berry <cberry@cinenet.net> wrote
>
> But as in his use of 'you' in the first clause, I think the intent here is
> to say 'become mid-to-senior in other languages, and then tackle Perl'.
> Which you can actually make a case for, I think.
I definitely agree with that. Perl reminds me of one of those movies that
make
sly references to every movie back to Tom Edison's first talkie. The flick
may
still be enjoyable if you aren't a walking encyclopedia of motion picture
history,
but you certainly are missing 90% of the in jokes. (NOTE: generic 'you' in
use)
------------------------------
Date: Fri, 01 Dec 2000 11:51:12 GMT
From: "John Boy Walton" <johngros@Spam.bigpond.net.au>
Subject: Re: why could't i do something like this?
Message-Id: <QgMV5.580$xW4.3945@news-server.bigpond.net.au>
I don't know perl seems to be able to do some weird things like that. You
would never know if you did not try.
"Joe" <mantisman@usa.net> wrote in message
news:907u74$82$1@imsp026.netvigator.com...
> sorry guys for i asked a silly question
>
> <simbean@my-deja.com> ¼¶¼g©ó¶l¥ó news:907t5d$re1$1@nnrp1.deja.com...
> >
> >
> > > if ( for (@links){
> > > $base = 'http://www.quamnet.com/fcgi-bin/c/';
> > > $k = $base . $_;
> > > $content[$i] = $quamnet ->FetchURL($k);
> > > $i = $i + 1;
> > > }){
> > > print "ok for retrieving files";
> > > }
> > > else{
> > > print "there is a problem : $!";
> > > }
> > I think the problem is, that you don't get a boolean from the statement
> > in the if-braces.
> >
> > Just a thought ... ;)
> >
> >
> > Ciao,
> > SimBean.
> >
> >
> > Sent via Deja.com http://www.deja.com/
> > Before you buy.
>
>
------------------------------
Date: 16 Sep 99 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 16 Sep 99)
Message-Id: <null>
Administrivia:
The Perl-Users Digest is a retransmission of the USENET newsgroup
comp.lang.perl.misc. For subscription or unsubscription requests, send
the single line:
subscribe perl-users
or:
unsubscribe perl-users
to almanac@ruby.oce.orst.edu.
| NOTE: The mail to news gateway, and thus the ability to submit articles
| through this service to the newsgroup, has been removed. I do not have
| time to individually vet each article to make sure that someone isn't
| abusing the service, and I no longer have any desire to waste my time
| dealing with the campus admins when some fool complains to them about an
| article that has come through the gateway instead of complaining
| to the source.
To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.
To request back copies (available for a week or so), send your request
to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
where x is the volume number and y is the issue number.
For other requests pertaining to the digest, send mail to
perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
sending perl questions to the -request address, I don't have time to
answer them even if I did know the answer.
------------------------------
End of Perl-Users Digest V9 Issue 5008
**************************************