[7431] in Perl-Users-Digest
Perl-Users Digest, Issue: 1056 Volume: 8
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sun Sep 21 16:07:14 1997
Date: Sun, 21 Sep 97 13:00:24 -0700
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Sun, 21 Sep 1997 Volume: 8 Number: 1056
Today's topics:
Re: "here document" method of print erroring (Abigail)
Re: "here document" method of print erroring <rootbeer@teleport.com>
Re: Bad start on Win95 (Michael Powe)
Re: Calculating the week number <matthew.rice@ftlsol.com>
Re: Can I specify fonts? <russ@mail.org.uk>
Re: Dial-Up Networking with Perl ? <russ@mail.org.uk>
handling a non-terminating system() call <atijapan@gol.com>
Re: handling a non-terminating system() call (Martin Str|mberg)
Need a script to replace a link with the web page it po (stephen benson)
Re: Need a script to replace a link with the web page i <rootbeer@teleport.com>
Out of memory! while you still have it... (Huajun Wang)
Re: Out of memory! while you still have it... <rootbeer@teleport.com>
Perl - MS SQL server & national characters <pegit.swedmap@mbox300.swipnet.se>
Re: Perl to Java Compiler? <bgingeryNoSpAm@pLeAsEgtcs.com>
Re: perl/sqml - any help <petri.backstrom@icl.fi>
Re: perl/sqml - any help (Eric Bohlman)
Re: Question about pattern matching! (Tad McClellan)
Re: Question about pattern matching! <rootbeer@teleport.com>
Re: Regexp a Yes or No question? <russ@mail.org.uk>
rsh function gpliats@demokritos.cc.duth.gr
Setting ENV vars in perl (Michael Powe)
Re: Setting ENV vars in perl <creede@worldnet.att.net>
Re: Setting ENV vars in perl <swarren@mail.eclipse.net>
Re: Week of the Year [Was: Re: Calculating the week num (Gerben Vos)
Re: what's wrong in this function? (Jason Gloudon)
Digest Administrivia (Last modified: 8 Mar 97) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Sun, 21 Sep 1997 05:44:08 GMT
From: abigail@fnx.com (Abigail)
Subject: Re: "here document" method of print erroring
Message-Id: <EGuFxK.Ho9@nonexistent.com>
Ben Scott (jds02@ix.netcom.comNoSpam) wrote on 1482 September 1993 in
<URL: news:34249143.7531@ix.netcom.comNoSpam>:
++ hi-
++
++ I am using the "here document" style of the print command and it is not
++ working correctly for me. please lemme know if I'm doing everything
++ right or am completely off in some way. code and error follow:
++
++ code____________________________
++ print <<END_OF_TEXT;
++ a bunch of text
++ with quotes "and other stuff"
++ END_OF_TEXT
$ perl -w
print <<END_OF_TEXT;
a bunch of text
with quotes "and other stuff"
END_OF_TEXT
__END__
a bunch of text
with quotes "and other stuff"
$
Are you sure you have the above fragment? No blanks after
END_OF_TEXT? Perhaps a trailing ^M ?
Abigail
------------------------------
Date: Sun, 21 Sep 1997 07:38:15 -0700
From: Tom Phoenix <rootbeer@teleport.com>
To: Ben Scott <jds02@ix.netcom.comNoSpam>
Subject: Re: "here document" method of print erroring
Message-Id: <Pine.GSO.3.96.970921070117.21358E-100000@julie.teleport.com>
On Sat, 20 Sep 1997, Ben Scott wrote:
> Can't find string terminator "END_OF_TEXT" anywhere before EOF at
> mycgi.cgi line 68.
You have some (invisible) characters before or after the termination line,
which should contain nothing but that string and its trailing newline.
Make sure that there aren't any spaces, tabs, return characters, or
anything else before or after the tag. If you've moved the file from
machine to machine without converting line endings properly, that's likely
to be the problem. Hope this helps!
--
Tom Phoenix http://www.teleport.com/~rootbeer/
rootbeer@teleport.com PGP Skribu al mi per Esperanto!
Randal Schwartz Case: http://www.rahul.net/jeffrey/ovs/
Ask me about Perl trainings!
------------------------------
Date: Sun, 21 Sep 1997 08:12:22 -0700
From: looie@teleport.com (Michael Powe)
Subject: Re: Bad start on Win95
Message-Id: <MPG.e8ed9331bc05e1598968e@news.teleport.com>
In article <5vk0bj$qsp@bgtnsc03.worldnet.att.net>,
1dja@worldnet.att.net says...
> I am trying to teach myself Perl using Win95 and I am off to a slow
> start. I've loaded the latest self-extracting version from ActiveWare
> and when I try to call a program from a "DOS" window I get a error
> stating "This program cannot be run in DOS mode." When I try to run
> the program from a "PERL" window the program seems to run and the
> window instantly closes. Where am I going wrong? The FAQ's don't answer
> this one. (Or I can't see the answer)
One thing you can do is set your text editor to call perl &
execute your script from within the editor -- as opposed to
saving the file & exiting the editor & then running the script.
You should be able to do this with any standard text editor
oriented toward use by programmers. If you don't have one (e.g.,
you are using Notepad), try the Programmer's File Editor (PFE),
which is a freeware 32-bit MDI editor with many built-in
programming functions. PFE offers two modes of execution, one of
which will insert the output into a new document when the script
exits. Very handy for preserving error messages when the script
unexpectedly terminates, or when the script just executes and
terminates (e.g., the famous "hello, world" script).
Get PFE from
http://www.lancs.ac.uk/people/cpaap/pfe/pfefiles.htm
mp
------------------------------
Date: Sat, 20 Sep 1997 20:48:57 -0400
From: Matthew Rice <matthew.rice@ftlsol.com>
To: Dan Kogai <dankogai@dan.co.jp>
Subject: Re: Calculating the week number
Message-Id: <34246EF9.C5942D4D@ftlsol.com>
Dan Kogai wrote:
> > I need a piece of code for calculating the current week. I checked the
> > perl FAQ, but the formula there doesn't work (unless you're on a year
> > that starts with monday and don't care about the last week being
> > correct). Any help would be greatly appreciated...
>
> $thisweek = (localtime())[6];
>
> Dan the Camel Abuser
This only tells him the day of the week. Not the week of the year.
Here's what I use for counting the number of weeks. The first week
is numbered 0 and Sunday as first day of week (00..53).
$day_of_year = localtime(time())->yday;
$day_of_week = localtime(time())->wday;
$first_day_of_year = 6 - (5 + $day_of_year -$day_of_week) % 7;
$week_of_year = int(($day_of_year +$first_day_of_year -1)/7);
The first_day_of_year is the week day of Jan 1st (0..6 like wday).
Unfortunately, I read in some places that a standard first week
must have a Wednesday in it (or something like that). I also have
a feeling that I made this calculation more complex than I needed to.
--
Matthew Rice e-mail: matthew.rice@ftlsol.com
------------------------------
Date: Sat, 20 Sep 1997 23:42:40 +0100
From: Russell Odom <russ@mail.org.uk>
To: COWBYS <cowbys@aol.com>
Subject: Re: Can I specify fonts?
Message-Id: <3424515F.EE14FB37@mail.org.uk>
COWBYS wrote:
>
> Yeah, but can you do all of this if you are printing to a filehandle?
Course you can...
STDOUT (which is what 'print' goes to, unless you tell it otherwise) is
just another filehandle, which happens to be your screen most of the time,
but is the output your CGI script sends to the browser in this case.
HTH,
Russ
---------------------------------------------------------------------
--[ R u s s e l l O d o m ]---[ *NEW:* mailto:russ@mail.org.uk ]--
--[ University of York, UK ]---[ http://www.york.ac.uk/~rjo100/ ]--
---------------------------------------------------------------------
--[ FAQ maintainer, news:comp.os.ms-windows.win95.moderated ]--
---------------------------------------------------------------------
------------------------------
Date: Sun, 21 Sep 1997 15:42:02 +0100
From: Russell Odom <russ@mail.org.uk>
Subject: Re: Dial-Up Networking with Perl ?
Message-Id: <3425323A.2208FA@mail.org.uk>
batman wrote:
>
> I would like to use Win95's Dial-Up Networking (DUN) to make a connection
> to my ISP. Or if the connection is already up, then tell Perl to use
> that connection.
>
> Does anyone have an idea on how to start doing this with Perl for Windows
> 95/NT and PerlWin32 ? Any suggestions or info are appreciated. Thanks!
Perl will use the DUN connection just like any other app which uses the
internet (like your web browser, newsreader, etc.).
If you do 'Control Panel | Internet | Connection', check 'Connect to the
Internet as needed', if the connection is not already started and Perl (or
your web browser, newsreader, etc.) tries to access the internet, _Win95_
will detect this and start the connection. This is done by the OS, not
Perl or any other app.
HTH,
Russ
---------------------------------------------------------------------
--[ R u s s e l l O d o m ]---[ *NEW:* mailto:russ@mail.org.uk ]--
--[ University of York, UK ]---[ http://www.york.ac.uk/~rjo100/ ]--
---------------------------------------------------------------------
--[ FAQ maintainer, news:comp.os.ms-windows.win95.moderated ]--
---------------------------------------------------------------------
------------------------------
Date: Sun, 21 Sep 1997 20:15:59 +0900
From: Bill Wilson <atijapan@gol.com>
Subject: handling a non-terminating system() call
Message-Id: <342501EF.2E17E8C3@gol.com>
Hi
I'm trying to automate a dailup ppp session
from a perl script. I'm using system() to execute
the ppp chat session, but since chat doesn't
terminate, I can't get back into the original
perl script. Is there anyway to execute the
chat session and get back into the parent script?
Thanks,
Bill Wilson
------------------------------
Date: 21 Sep 1997 16:52:55 GMT
From: ams@ludd.luth.se (Martin Str|mberg)
Subject: Re: handling a non-terminating system() call
Message-Id: <603jd7$2fi$2@news.luth.se>
Bill Wilson (atijapan@gol.com) wrote:
: I'm trying to automate a dailup ppp session
: from a perl script. I'm using system() to execute
: the ppp chat session, but since chat doesn't
: terminate, I can't get back into the original
: perl script. Is there anyway to execute the
: chat session and get back into the parent script?
Yes, "system("chat away &");" or fork, followed by exec.
Try "man perl" and then "man perlfunc".
Right,
MartinS
------------------------------
Date: Sun, 21 Sep 1997 07:55:11 GMT
From: stephenb@scribendum.win-uk.net (stephen benson)
Subject: Need a script to replace a link with the web page it points to
Message-Id: <34241c5c.17976849@nntp.ibmpcug.co.uk>
I have a project where pages refer to notes held in other pages; what
I have to do is generate (if possible on the fly, but not necessarily)
versions for print which include these pages, expanding them inline.
if a line is an href called something with 'note' in it
follow the link
import the page, replacing the href
I've beem dabbling in Perl and Javascript, but I'[m a novoce, and I'd
appreciate tips on how to go about it, and which lang to use. I don't
mind doing it myself, but I'm flat out and I just need a starting
point, a bit of perspective. The target browser is Netscape3/4 on Win
platforms. I'm chasing info on the Win32 perl modules, but you know,
so little time.
I'd apreciate any discussion on what's the best way to approach
something like this, especially in situations where you don't have
much control over the server....
I also have to work out how to print sets/series of paragraphs in the
document, regradless what page they're on, but that's another story...
------------------------------
Date: Sun, 21 Sep 1997 07:46:47 -0700
From: Tom Phoenix <rootbeer@teleport.com>
To: stephen benson <stephenb@scribendum.win-uk.net>
Subject: Re: Need a script to replace a link with the web page it points to
Message-Id: <Pine.GSO.3.96.970921074548.21358I-100000@julie.teleport.com>
On Sun, 21 Sep 1997, stephen benson wrote:
> I have a project where pages refer to notes held in other pages; what
> I have to do is generate (if possible on the fly, but not necessarily)
> versions for print which include these pages, expanding them inline.
> I've beem dabbling in Perl and Javascript, but I'[m a novoce, and I'd
> appreciate tips on how to go about it, and which lang to use.
Use Perl; it'll be easier than doing it in Javascript (if it's even
possible in Javascript). There are modules on CPAN which can help. Good
luck!
--
Tom Phoenix http://www.teleport.com/~rootbeer/
rootbeer@teleport.com PGP Skribu al mi per Esperanto!
Randal Schwartz Case: http://www.rahul.net/jeffrey/ovs/
Ask me about Perl trainings!
------------------------------
Date: 21 Sep 1997 14:37:14 GMT
From: hw20@merhaba.cc.columbia.edu (Huajun Wang)
Subject: Out of memory! while you still have it...
Message-Id: <603beq$3fp$1@apakabar.cc.columbia.edu>
I am running a perl program that give me this Out of memory! problem.
Using ps -o rss suggests that the memory used by the program is only
about 30% of the total physical memory (at all stages) of my machine.
Basically what I am doing is merging an array of variable length (long)
strings (I did undef the ones that got merged).
Could anyone give me some hints as to what I am doing wrong? Is there a
limit of the length of strings (within an array) or some sort?
Thanks.
------------------------------
Date: Sun, 21 Sep 1997 08:20:27 -0700
From: Tom Phoenix <rootbeer@teleport.com>
To: Huajun Wang <hw20@merhaba.cc.columbia.edu>
Subject: Re: Out of memory! while you still have it...
Message-Id: <Pine.GSO.3.96.970921081532.21358R-100000@julie.teleport.com>
On 21 Sep 1997, Huajun Wang wrote:
> I am running a perl program that give me this Out of memory! problem.
That happens when Perl needs to malloc() a bigger chunk than your system
can give it. But you should make sure you're using the latest Perl, and
see what the perldiag(1) manpage suggests about your error message.
> Using ps -o rss suggests that the memory used by the program is only
> about 30% of the total physical memory (at all stages) of my machine.
Perl will use your virtual memory, if possible.
> Basically what I am doing is merging an array of variable length (long)
> strings (I did undef the ones that got merged).
When you say that you're "merging" them, do you mean that you're
concatenating them?
> Could anyone give me some hints as to what I am doing wrong?
Not without some code. :-) See if you can make a short example program
which shows the problem.
> Is there a limit of the length of strings (within an array) or some
> sort?
Only when the virtual memory runs out. Hope this helps!
--
Tom Phoenix http://www.teleport.com/~rootbeer/
rootbeer@teleport.com PGP Skribu al mi per Esperanto!
Randal Schwartz Case: http://www.rahul.net/jeffrey/ovs/
Ask me about Perl trainings!
------------------------------
Date: Sun, 21 Sep 1997 19:07:35 +0200
From: Pinne <pegit.swedmap@mbox300.swipnet.se>
Subject: Perl - MS SQL server & national characters
Message-Id: <34255457.434D@mbox300.swipnet.se>
Hi,
I'm using a Perl script to communicate with MS SQL-server,
via ISQL. That works fine, except for one thing. I can't
get our swedish national characters to show up correctly,
neither when reading from the server, nor when i pass data
to it.
I'm running Perl/isql on machine and sql-server on another
and I've checked that they both use the same charset.
This is running med nuts.
Does anyone have any ideas ?
Please reply by email.
/regards
------------------------------
Date: 21 Sep 1997 15:50:05 GMT
From: Bruce Gingery <bgingeryNoSpAm@pLeAsEgtcs.com>
Subject: Re: Perl to Java Compiler?
Message-Id: <603fnd$shb@horn.wyoming.com>
On Fri, 19 Sep 1997 12:48:40 -0400 (EDT),
in <Pine.SUN.3.96.970919121615.21608A-100000@ops.nic.mil>,
Piet Barber <pietb@nic.mil> wrote:
> I'm surprised I haven't seen more discussion about this, but here goes...
> from http://www.oreilly.com/catalog/prkunix/ --
> > By Larry Wall, Clay Irving, Nate Patwardhan, Ellen Siever, David Futato
> > & Brian Jepson
> > 1st Edition November 1997 (est.)
> > 1-56592-370-7, Order Number: 3707
> > 1700 pages (est.), $149.95, Includes 4 books & CD-ROM
> from http://www.oreilly.com/catalog/prkunix/desc.html --
[munch]
That was enough to make *me* go look. But $150 is a bit steep
to *try* something, that may just *not-work* without some kind
of VeriSign signatures. Guess I'll watch for someone else to
be the guinea pig on this one.
Bruce
------------------------------
Date: Wed, 17 Sep 1997 17:54:20 +0300
From: Petri Backstrom <petri.backstrom@icl.fi>
Subject: Re: perl/sqml - any help
Message-Id: <341FEF1C.C82@icl.fi>
Michael J Estler wrote:
>
> can anyone point me toward a perl/sqml tutorial or maybe send me some
> examples of how that code would look.
What do you mean with "perl/sgml tutorial" (they're two
different things)? Are you looking for an SGML parser
written in Perl, or something else?
Anyway...
See http://www.perl.com for Perl kits, documentation
and FAQs.
See http://www.perl.com/CPAN/ for modules for different
purposes; some might handle SGML.
See http://www.sil.org/sgml/sgml.html for one possible
starting point to SGML information.See, e.g., the link
that reads "Public SGML Software".
Besides that you could always utilize services such
as http://www.dejanews.com or http://altavista.digital.com
and search for stuff that mention "perl" and "sgml" close
to each other.
regards,
...petri.backstrom@icl.fi
ICL Data Oy
Finland
------------------------------
Date: Sun, 21 Sep 1997 16:29:28 GMT
From: ebohlman@netcom.com (Eric Bohlman)
Subject: Re: perl/sqml - any help
Message-Id: <ebohlmanEGv9t4.7uG@netcom.com>
Petri Backstrom (petri.backstrom@icl.fi) wrote:
: Michael J Estler wrote:
: >
: > can anyone point me toward a perl/sqml tutorial or maybe send me some
: > examples of how that code would look.
: What do you mean with "perl/sgml tutorial" (they're two
: different things)? Are you looking for an SGML parser
: written in Perl, or something else?
Or maybe a structured database that uses SQL as an interface and and SGML
application as a storage format? (Now writing *that* would be an
interesting class project!)
------------------------------
Date: Sun, 21 Sep 1997 09:05:03 -0500
From: tadmc@flash.net (Tad McClellan)
Subject: Re: Question about pattern matching!
Message-Id: <fi9306.fo.ln@localhost>
Tam, Kai Fai (tam1@uwindsor.ca) wrote:
: Do you guys have any clue about what the subroutine below
: is doing?
It is not a subroutine...
: while ($buf =~ /^^(.*)\n\r?([\000-\377]*)$/)
: {
: $_ = $1;
: $buf = $2;
: }
while ($buf =~ /^ # match the beginning of the string
^ # match a literal caret character
(.*) # match as many chars as possible
# (except newline)
# put the chars in $1
\n # match a newline
\r? # match an optional carriage return
([\000-\377]*) # match zero or more of any character
# (0..255 decimal)
# put the chars in $2
$ # match the end of the string
/x) # lets me put these comments here
So, if $buf has a caret as its first character, then $_ gets the first
line (sans caret and line terminating sequence), and $buf gets all of
the other lines.
The whole code block could be replaced with this single line:
$_ = $1 while $buf =~ s/^^(.*)\n\r?//g;
or, if you are really doing more stuff inside the while block:
while ($buf =~ s/^^(.*)\n\r?//g) { # non-obfuscated version of above loop
$_ = $1;
# do something with the "line" in $_
}
[ note that the usual (MS) sequence is \r\n, rather than \n\r ... ]
--
Tad McClellan SGML Consulting
tadmc@flash.net Perl programming
Fort Worth, Texas
------------------------------
Date: Sun, 21 Sep 1997 07:51:51 -0700
From: Tom Phoenix <rootbeer@teleport.com>
To: "Tam, Kai Fai" <tam1@uwindsor.ca>
Subject: Re: Question about pattern matching!
Message-Id: <Pine.GSO.3.96.970921074725.21358J-100000@julie.teleport.com>
On Sun, 21 Sep 1997, Tam, Kai Fai wrote:
> Do you guys have any clue about what the subroutine below
> is doing?
> while ($buf =~ /^^(.*)\n\r?([\000-\377]*)$/)
> {
> $_ = $1;
> $buf = $2;
> }
It's not a subroutine, but it's doing just what it says it's doing. If you
don't understand while loops, regular expressions, assignment statements,
or Perl's special variables $_ and $1, please check out the free, helpful,
ubiquitous, and voluminous Perl documentation. Once you've read the docs
and FAQs, if you still have Perl questions, please post them here. Thanks!
--
Tom Phoenix http://www.teleport.com/~rootbeer/
rootbeer@teleport.com PGP Skribu al mi per Esperanto!
Randal Schwartz Case: http://www.rahul.net/jeffrey/ovs/
Ask me about Perl trainings!
------------------------------
Date: Sun, 21 Sep 1997 17:21:18 +0100
From: Russell Odom <russ@mail.org.uk>
Subject: Re: Regexp a Yes or No question?
Message-Id: <3425497E.35F48DB9@mail.org.uk>
Matthew Cravit wrote:
>
> Seriously, though, if you're really concerned about the user typing
> random text in response to a yes/no prompt, it's probably better to
> say
>
> while ($response !~ /^yes/i) {
> print "Your response was not understood.\n";
> print "Please answer yes or no.\n";
> }
This doesn't accept 'No', and will just loop forever if the first response
(which you didn't actually get anywhere) doesn't match /^yes/i.
> if ($response =~ /^yes$/i) {
> &DoSomething;
> else {
> &DoSomethingElse;
> }
If the user inputs 'yesterday' in response to the prompt, this does
'&DoSomethingElse;', because of the $ at the end of the regexp.
Try...
print 'Are your underpants full of custard <Yes/No>? ';
chomp ($response = <STDIN>);
while ($response !~ /^(yes|no)$/i) {
print "No evasive answers allowed!\n";
print "Please answer yes or no: ";
chomp ($response = <STDIN>);
}
if ($response =~ /^yes$/i) {
print "You are a very strange person.\n";
} else {
print "Glad to hear it.\n";
}
HTH,
Russ
---------------------------------------------------------------------
--[ R u s s e l l O d o m ]---[ *NEW:* mailto:russ@mail.org.uk ]--
--[ University of York, UK ]---[ http://www.york.ac.uk/~rjo100/ ]--
---------------------------------------------------------------------
--[ FAQ maintainer, news:comp.os.ms-windows.win95.moderated ]--
---------------------------------------------------------------------
------------------------------
Date: Sun, 21 Sep 1997 12:49:03 GMT
From: gpliats@demokritos.cc.duth.gr
Subject: rsh function
Message-Id: <342516a5.1030197@news.ntua.gr>
I wonder if anyone has developed the rsh function in perl ?
- P.S.Saragiotis
- Demokritos University of Thrace
- Network Administration Centre
------------------------------
Date: Sun, 21 Sep 1997 08:38:52 -0700
From: looie@teleport.com (Michael Powe)
Subject: Setting ENV vars in perl
Message-Id: <MPG.e8edf675e6fd2ce98968f@news.teleport.com>
This is a general question -- before I set off trying to do
something that can't be done! ;-)
I want to set an env var that I can't set automatically from
within my shell via a script or shell command. Specifically, I
can't get csh to set a HOST var via the 'hostname' command. So,
my question is, can I use perl to get the value of 'hostname' and
create/setenv HOST with that value (by using %ENV, e.g.).
The project is to be able to insert a simple perl script in my
.login so that when I want to use the HOST var in my shell
scripts, it will be correctly set.
I'm not asking for someone to write the perl for me -- just if it
can be done. If it can, I'm willing to work it out myself.
BTW, I mentioned this possibility in another newsgroup & was told
that "no program can alter its own environment" -- !! But we
know that you can do <anything> with perl! ;-)
Thanks for the help.
mp
------------------------------
Date: 21 Sep 1997 16:38:55 GMT
From: "Creede Lambard" <creede@worldnet.att.net>
Subject: Re: Setting ENV vars in perl
Message-Id: <01bcc6ac$bb9f8700$ba8593cf@boris>
Unfortunately when you execute Perl you fork off a new process, and as soon
as you terminate the process (i.e. the Perl script exits) the environment
variables set within that process die with the process. I know this because
I spent some time last week fighting this. :D So I think the answer is
"no." But (forgive me if this is a dumb question) why can't you just set
this within a shell script? I think ksh would do it this way:
HOST = 'hostname'
export HOST
I don't know csh so forgive me if this won't work for you.
-- Creede
Michael Powe <looie@teleport.com> wrote in article
<MPG.e8edf675e6fd2ce98968f@news.teleport.com>...
> This is a general question -- before I set off trying to do
> something that can't be done! ;-)
>
> I want to set an env var that I can't set automatically from
> within my shell via a script or shell command. Specifically, I
> can't get csh to set a HOST var via the 'hostname' command. So,
> my question is, can I use perl to get the value of 'hostname' and
> create/setenv HOST with that value (by using %ENV, e.g.).
>
> The project is to be able to insert a simple perl script in my
> .login so that when I want to use the HOST var in my shell
> scripts, it will be correctly set.
>
> I'm not asking for someone to write the perl for me -- just if it
> can be done. If it can, I'm willing to work it out myself.
>
> BTW, I mentioned this possibility in another newsgroup & was told
> that "no program can alter its own environment" -- !! But we
> know that you can do <anything> with perl! ;-)
>
> Thanks for the help.
>
> mp
>
------------------------------
Date: Sun, 21 Sep 1997 14:37:21 -0400
From: "Stephen Warren" <swarren@mail.eclipse.net>
Subject: Re: Setting ENV vars in perl
Message-Id: <603pgm$f53@news.eclipse.net>
Michael Powe <looie@teleport.com> wrote in article
<MPG.e8edf675e6fd2ce98968f@news.teleport.com>...
> Unfortunately when you execute Perl you fork off a new process,
> and as soon as you terminate the process (i.e. the Perl script exits)
> the environment variables set within that process die with the process.
A simple way around this is to get the perl script to print out a load of
shell commands that set the variables you want and then eval the output of
the perl script:
jupiter:~> eval `perlscript`
where perlscript is e.g.:
-----
#!/usr/local/bin/perl <or wherever>
print "setenv varname=value ;\n" ; <or your shell syntax>
-----
I don't know why you can't just type setenv HOST=value from csh directly.
If it's a case of not being able to determine the value, then using a perl
script should help, assuming you can calculate the value correctly in a
perl script (and as you say, perl can do most things)
However, I have a vague feeling that csh sets the HOST variable itself and
hence may prevent the setenv command from altering it. In this case, the
above won't work, since you're just using the same shell setenv that you
can't get to work...
>Michael Powe <looie@teleport.com> wrote in article
<MPG.e8edf675e6fd2ce98968f@news.teleport.com>...
>> I want to set an env var that I can't set automatically from
>> within my shell via a script or shell command. Specifically, I
>> can't get csh to set a HOST var via the 'hostname' command. So,
>> my question is, can I use perl to get the value of 'hostname' and
>> create/setenv HOST with that value (by using %ENV, e.g.).
>> BTW, I mentioned this possibility in another newsgroup & was told
>> that "no program can alter its own environment" -- !! But we
>> know that you can do <anything> with perl! ;-)
Well, _any_ program can alter its _own_ environment (after all, that's
what setenv does in csh), but no program can alter it's _parent's_
environment (directly), which is what I guess the reply in the other group
meant...
--
-----------------------------------------------------------------
Stephen Warren, Systems Engineer, Technology House Inc., New York
mailto:swarren@techhouse.com http://www.techhouse.com/
mailto:swarren@eclipse.net http://www.eclipse.net/~swarren/
MIME, S/MIME and HTML mail are acceptable
------------------------------
Date: 21 Sep 1997 18:13:01 GMT
From: gerben@cs.vu.nl (Gerben Vos)
Subject: Re: Week of the Year [Was: Re: Calculating the week number]
Message-Id: <603o3d$s8f$1@star.cs.vu.nl>
I don't know how week numbers are calculated in the United States, but
according to the ISO standard used in most of the world, a week starts
on Monday and the first week of which four or more days fall in the new
year is week 1. This means that the first Thursday of the year always
falls in week 1, and January 1st can fall in week 52 or 53.
The code below has been adapted from some of my C code. I hope i haven't
broken anything in the conversion to Perl.
Adapt it yourself for calculating the week number of a given date.
I think you can also use Steffen Beyer's date/time module.
# Calculate the day and week on which January 1st falls.
# $weekday = 0..6 for Sunday..Saturday
# $leap is true iff $year is a leap year
$leap = isleap($year);
$weekday = ($year + $year / 4 - $year / 100 + $year / 400 - $isleap) % 7;
$weeknumber = 1;
if ($weekday >= 5)
{
$weeknumber = 53 - ($weekday == 6 && !isleap($year-1));
}
sub isleap
{
my $year = $_[0];
return ( ($year % 400 == 0) || ($year % 4 == 0 && $year % 100 != 0) )
}
g e r b e n @ c s . v u . n l . . . . . . . . . . . . G e r b e n V o s <><
Join the Coalition Against Unsolicited Commercial Email! http://www.cauce.org/
The three principal virtues of a programmer are Laziness, Impatience,
and Hubris. -- Larry Wall
------------------------------
Date: 21 Sep 1997 12:56:41 GMT
From: jgloudon@bbn.com (Jason Gloudon)
Subject: Re: what's wrong in this function?
Message-Id: <6035i9$e2h$1@daily.bbnplanet.com>
In article <342482A5.6FF7@uwindsor.ca>, Tam, Kai Fai <tam1@uwindsor.ca> wrote:
>Hi! Everyone,
>
>Do you have any idea about what's wrong in the function below,
>no matter syntax or style?
>
>
>sub award
>{
> local ($tmpflags);
>
When you say wrong what do you mean ? This compiles fine (without use strict).
If $flags is being modified, you want to say my($tmpflags) instead of local,
in order to prevent matchaction or anything else that it calls from modifying
$tmpflags. The perlsub manpage will explain the difference between my and local
> $tmpflags=$flags; $flags="g"; &matchaction; $flags=$tmpflags;
>}
>
>
>Thanks!
>
>Ken
Jason Gloudon
------------------------------
Date: 8 Mar 97 21:33:47 GMT (Last modified)
From: Perl-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 8 Mar 97)
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.
To submit articles to comp.lang.perl.misc (and this Digest), send your
article to perl-users@ruby.oce.orst.edu.
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.
The Meta-FAQ, an article containing information about the FAQ, is
available by requesting "send perl-users meta-faq". The real FAQ, as it
appeared last in the newsgroup, can be retrieved with the request "send
perl-users FAQ". Due to their sizes, neither the Meta-FAQ nor the FAQ
are included in the digest.
The "mini-FAQ", which is an updated version of the Meta-FAQ, is
available by requesting "send perl-users mini-faq". It appears twice
weekly in the group, but is not distributed in the digest.
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 V8 Issue 1056
**************************************