[6865] in Perl-Users-Digest
Perl-Users Digest, Issue: 490 Volume: 8
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri May 16 19:17:24 1997
Date: Fri, 16 May 97 16:01:40 -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 Fri, 16 May 1997 Volume: 8 Number: 490
Today's topics:
Re: Q:Redirecting STDIN back to STDIN <rootbeer@teleport.com>
Re: Q:Redirecting STDIN back to STDIN (Even Holen)
Re: Seeding SRAND on WIN32 <jwilson@ic.ac.uk>
Sorting Associative by Values? <thomthrd@umich.edu>
Re: Sorting Associative by Values? (Mike Stok)
standard packages <jims@ss5mth44.franklin.com>
Re: standard packages (Mike Stok)
Tatum O'Neil <paulmc@radiks.net>
uninit value ? <eglamkowski@mathematica-mpr.com>
Re: uninit value ? (Mike Stok)
Re: Why Am I Getting Message About Not Returning a True (Colin Kuskie)
Win32: Manipulating ENV with a perl script <morgan.stair@software.com>
Digest Administrivia (Last modified: 8 Mar 97) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Fri, 16 May 1997 12:57:03 -0700
From: Tom Phoenix <rootbeer@teleport.com>
To: Adam Reeves <areeves@bnr.ca>
Subject: Re: Q:Redirecting STDIN back to STDIN
Message-Id: <Pine.GSO.3.96.970516125534.20078G-100000@kelly.teleport.com>
On Thu, 15 May 1997, Adam Reeves wrote:
> After doing the following statements:
>
> open(STDIN, "<&Client") or die;
> open(STDOUT, ">&Client") or die;
>
> How do you redirect STDIN back to STDIN
> and, likewise, STDOUT back to STDOUT?
You need to save the old filehandles, so that you can get back to them. An
example is given on page 193 of the new Camel book. Hope this helps!
-- Tom Phoenix http://www.teleport.com/~rootbeer/
rootbeer@teleport.com PGP Skribu al mi per Esperanto!
Randal Schwartz Case: http://www.lightlink.com/fors/
------------------------------
Date: 16 May 1997 20:04:01 GMT
From: evenh@bigblue.pvv.ntnu.no (Even Holen)
Subject: Re: Q:Redirecting STDIN back to STDIN
Message-Id: <slrn5npfdh.qei.evenh@bigblue.pvv.ntnu.no>
In article <337B3402.996@bnr.ca>, Adam Reeves wrote:
>This may sound like a dumb question, but...
Not so very dumb, but I would change the code to achieve the wanted
results...
>After doing the following statements:
>
>open(STDIN, "<&Client") or die;
>open(STDOUT, ">&Client") or die;
>
>How do you redirect STDIN back to STDIN
>and, likewise, STDOUT back to STDOUT?
I know you might do the following when rearranging stdout:
open (NEWSTDOUT, ">&Client") or die;
$OLDSTDOUT = select NEWSTDOUT;
# Do whatever you want to do...
select $OLDSTDOUT;
close NEWSTDOUT
Something rather similar to this is presented in the documentation of
perl. And if you start using objects I do think this way of thinking
(and using the return value of select) should give you a proper
solution. I do not remember how to do it with objects, but there are a
way of doing so...
Regards,
Even Holen
--
<>< Even Holen, evenh@pvv.ntnu.no, http://www.pvv.ntnu.no/~evenh/ :-)
------------------------------
Date: 16 May 1997 16:05:19 GMT
From: "Jeff Wilson" <jwilson@ic.ac.uk>
Subject: Re: Seeding SRAND on WIN32
Message-Id: <01bc6212$f3073340$1d34c69b@leicester.cc.ic.ac.uk>
Use localtime to get the time - and to seed.
--
Jeff Wilson
CCS ~ Imperial College ~
London UK
Bill Banyai <banyai@llnl.gov> wrote in article
<337A0D68.710E@llnl.gov>...
> Is there a good way to seed the random number generator on a WIN32
> platform?
>
> An associated question is how to retrieve the time; in particular,
how
> to deal with the prompt that follows the display of the time.
>
> For example:
>
> c:\time
> c:\Current time is 12:06:42.47p
> c:\Enter new time:
>
> I can extract the time to, in theory, seed SRAND, but how do I supply
a
> carriage return to kill the program.
>
> Thanks
>
------------------------------
Date: Fri, 16 May 1997 15:15:00 -0400
From: Thom Brooks <thomthrd@umich.edu>
To: Thom Brooks <thomthrd@umich.edu>
Subject: Sorting Associative by Values?
Message-Id: <Pine.SOL.3.95.970516150048.9050A-100000@breakout.rs.itd.umich.edu>
Hello. I'm a newbie with a probably very repetitive question, so I
apologize if I've posted this for the millionth time, or to the wrong
place.
Say I'm matching the number of times I see foo, bar and baz as a first
word in a string. I also want to be able to match words I don't know
about, and count how many there were, so I say something like:
open(DATA, "mydatafile");
open(OUT, ">myoutputfile");
open(OTHER, ">>other"); # append the lines of new words I didn't know
while (<DATA>)
{
$line = $_;
if (/^foo/) {$foo++;}
elsif (/^bar/) {$bar++;}
elsif (/^baz/) {$baz++;}
# easy so far. but now for misc. matching:
else
{
/^(\w+)\W+/;
print "$1\n";
if ($unmatched{$1} < 1)
{
print OTHER $line;
}
$unmatched{$1}++;
$other++;
}
}
Okay, so I've got this list of stuff I didn't know stuck in my file,
plus an Associative array with totals for each unknown word. Here's my Q:
How do I specify how to sort by the # of times unknown words in %unknown
were incremented, so I can push the answer off of a normal array 2 by 2,
to make some dumb thing like:
funk: 24
spaz: 22
hey: 13
crud: 9
whammo: 2
etc?
If anybody could be kind enough to answer this, would you cc: it to my
email, thomthrd@umich.edu, and to the newsgroup so people know my
question was answered? I don't have a lot of time to read the newsgroup
(or I probably would've seen the solution already, right? :)
thanks in advance,
Thom Brooks
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
Advanced Visualization Lab, Staff | Multimedia & HTML Programmer,
Media Union, University of Michigan | UM School of Social Work
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
7th Floor Child Life, Mott Hospital "Sure, I'll watch Barney with you.."
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
"Joy does all things without concern -- My schedule information for
for emptiness, stillness, tranquility, Spring 97 can be found at:
tastelessness, silence and non-action http://www-personal.umich.edu/
are the root of all things." ~thomthrd/schedule.html
-- Chuang Tzu
------------------------------
Date: 16 May 1997 20:39:28 GMT
From: mike@stok.co.uk (Mike Stok)
Subject: Re: Sorting Associative by Values?
Message-Id: <5ligm0$n64@news-central.tiac.net>
In article <Pine.SOL.3.95.970516150048.9050A-100000@breakout.rs.itd.umich.edu>,
Thom Brooks <thomthrd@umich.edu> wrote:
>Hello. I'm a newbie with a probably very repetitive question, so I
>apologize if I've posted this for the millionth time, or to the wrong
>place.
>
>Say I'm matching the number of times I see foo, bar and baz as a first
>word in a string. I also want to be able to match words I don't know
>about, and count how many there were, so I say something like:
>Okay, so I've got this list of stuff I didn't know stuck in my file,
>plus an Associative array with totals for each unknown word. Here's my Q:
>
>How do I specify how to sort by the # of times unknown words in %unknown
>were incremented, so I can push the answer off of a normal array 2 by 2,
>to make some dumb thing like:
> funk: 24
> spaz: 22
> hey: 13
> crud: 9
> whammo: 2
>
>etc?
Please check out the list of Frequently Asked Questions (FAQ) at
http://www.perl.com/FAQ/ or on a CPAN (comprehensive perl archive network
- master site at ftp.funet.fi in /pub/languages/perl/CPAN) site:
How do I sort a hash (optionally by value instead of key)?
Internally, hashes are stored in a way that prevents you from imposing
an order on key-value pairs. Instead, you have to sort a list of the
keys or values:
@keys = sort keys %hash; # sorted by key
@keys = sort {
$hash{$a} cmp $hash{$b}
} keys %hash; # and by value
Here we'll do a reverse numeric sort by value, and if two keys are
identical, sort by length of key, and if that fails, by straight ASCII
comparison of the keys (well, possibly modified by your locale -- see
the perllocale manpage).
@keys = sort {
$hash{$b} <=> $hash{$a}
||
length($b) <=> length($a)
||
$a cmp $b
} keys %hash;
Hope this helps,
Mike
--
mike@stok.co.uk | The "`Stok' disclaimers" apply.
http://www.stok.co.uk/~mike/ | PGP fingerprint FE 56 4D 7D 42 1A 4A 9C
http://www.tiac.net/users/stok/ | 65 F3 3F 1D 27 22 B7 41
stok@psa.pencom.com | Pencom Systems Administration (work)
------------------------------
Date: Fri, 16 May 1997 19:01:19 GMT
From: Jim Shi <jims@ss5mth44.franklin.com>
Subject: standard packages
Message-Id: <5lid7t$gn5@hideout.emanon.net>
Hi, where can I find info on how to use Perl standard packages
such as Getopt::Std etc? Thanks
------------------------------
Date: 16 May 1997 20:26:59 GMT
From: mike@stok.co.uk (Mike Stok)
Subject: Re: standard packages
Message-Id: <5lifuj$mdi@news-central.tiac.net>
In article <5lid7t$gn5@hideout.emanon.net>,
Jim Shi <jims@ss5mth44.franklin.com> wrote:
>Hi, where can I find info on how to use Perl standard packages
>such as Getopt::Std etc? Thanks
If your installation is complete then you should be able to say
$ perldoc getopt::std
Getopt::Std(3) User Contributed Perl Documentation Getopt::Std(3)
NAME
getopt - Process single-character switches with switch
clustering
getopts - Process single-character switches with switch
clustering
SYNOPSIS
use Getopt::Std;
[...]
Hope this helps,
Mike
--
mike@stok.co.uk | The "`Stok' disclaimers" apply.
http://www.stok.co.uk/~mike/ | PGP fingerprint FE 56 4D 7D 42 1A 4A 9C
http://www.tiac.net/users/stok/ | 65 F3 3F 1D 27 22 B7 41
stok@psa.pencom.com | Pencom Systems Administration (work)
------------------------------
Date: Fri, 16 May 1997 16:06:55 -0500
From: "Paul T. McNally" <paulmc@radiks.net>
Subject: Tatum O'Neil
Message-Id: <337CCC6E.3380@radiks.net>
Does anyone know when the actress and Oscar winner Tatum O'Neil
was born? I'm thinking she was born close to 3-6-62, but I knew more
when I had this bitty crush about the time Bad News Bears came out.
I need to know for it may become a vital part of my home page!!
Very important!
Thanks
Paul
--
The mind is it's own beautiful prisoner.
http://www.geocities.com/NapaValley/3343
------------------------------
Date: Fri, 16 May 1997 16:14:08 -0400
From: the count <eglamkowski@mathematica-mpr.com>
Subject: uninit value ?
Message-Id: <337CC010.4EE3@mathematica-mpr.com>
First of all, I'd like to thank everyone who has helped me to date :)
My current problem is probably quite trivial, but it is annoying me
quite a bit:
/u7/HHPP/manager> perl -w tickler
Use of uninitialized value at tickler line 233, <TMP> chunk 2.
Use of uninitialized value at tickler line 233, <TMP> chunk 2.
Use of uninitialized value at tickler line 233, <TMP> chunk 4.
Use of uninitialized value at tickler line 233, <TMP> chunk 4.
while (<TMP>) {
if ($line_number >= 45) {
print RPT "\f\n$title\t\t@td\n\n";
$line_number = 0;
} else {
@line = split /[ \n\r\f]+/;
if ($line[0] =~ /\d+/ || $line[0] eq "TODAY") { <-- line 233
if ($index ne $line[0]) {
print RPT "\n@line\n";
$index = $line[0];
}
} else {
print RPT "@line\n";
}
}
$line_number++;
}
If a given line in the input file is nothing but a new line,
would it generate this warning? The output that is generated is
definately correct despite this warning, and that is the only thing I
can think of, but I want to make sure I am not missing some subtle but
important point... (and what is this "chunk" thing?)
If this is the problem, is there any trivial way to avoid
getting the warning (other than just not using the -w switch ;)
--
Due to continuing problems with my hotmail account, any mail received
from eglamkowski@hotmail.com dated after 5/9/97 should be considered
fraudulent. I am no longer using my hotmail account, and never will
again; due to the fact that I have been unable to logon for several
days in a row, "Invalid login/password combination", I must assume my
account was hacked and the password changed.
-*-*-> Please do not send mail to, nor accept mail from <-*-*-
-*-*-> eglamkowski@hotmail.com <-*-*-
------------------------------
Date: 16 May 1997 20:59:27 GMT
From: mike@stok.co.uk (Mike Stok)
Subject: Re: uninit value ?
Message-Id: <5lihrf$okt@news-central.tiac.net>
In article <337CC010.4EE3@mathematica-mpr.com>,
the count <eglamkowski@mathematica-mpr.com> wrote:
>/u7/HHPP/manager> perl -w tickler
>Use of uninitialized value at tickler line 233, <TMP> chunk 2.
>Use of uninitialized value at tickler line 233, <TMP> chunk 2.
>Use of uninitialized value at tickler line 233, <TMP> chunk 4.
>Use of uninitialized value at tickler line 233, <TMP> chunk 4.
>
>while (<TMP>) {
> if ($line_number >= 45) {
> print RPT "\f\n$title\t\t@td\n\n";
> $line_number = 0;
> } else {
> @line = split /[ \n\r\f]+/;
> if ($line[0] =~ /\d+/ || $line[0] eq "TODAY") { <-- line 233
> if ($index ne $line[0]) {
> print RPT "\n@line\n";
> $index = $line[0];
> }
> } else {
> print RPT "@line\n";
> }
> }
> $line_number++;
>}
> If a given line in the input file is nothing but a new line,
>would it generate this warning? The output that is generated is
>definately correct despite this warning, and that is the only thing I
>can think of, but I want to make sure I am not missing some subtle but
>important point... (and what is this "chunk" thing?)
The chunk is the record number (usually line number) of the input stream
you've just read from.
You might want to say
...
}
elsif (@line = split /[ \r\n\f]+/ && $line[0] etc ) {
# @line has at least one element...
}
else {
...
}
In the debugger:
DB<1> @l = split /[ \r\n\f]+/, "\n"
DB<2> X l
@l = (
empty array
)
You might be interested in the special case where split ' ' splits on
whitespace and throws away leading & trailing stuff automatically (like
AWK)
You can also use @line in a scalar context to see how many elements it has
before trying to access the first one.
Hope this helps,
Mike
--
mike@stok.co.uk | The "`Stok' disclaimers" apply.
http://www.stok.co.uk/~mike/ | PGP fingerprint FE 56 4D 7D 42 1A 4A 9C
http://www.tiac.net/users/stok/ | 65 F3 3F 1D 27 22 B7 41
stok@psa.pencom.com | Pencom Systems Administration (work)
------------------------------
Date: 16 May 1997 08:35:32 -0700
From: colink@latticesemi.com (Colin Kuskie)
Subject: Re: Why Am I Getting Message About Not Returning a True Value?
Message-Id: <5lhus4$inl@defiant.latticesemi.com>
Keywords: require true value
In article <5lf1d4$3a3@sf18.dseg.ti.com>,
Kevin M Simonson <simonson@skopen.dseg.ti.com> wrote:
> So I took a look at what _Programming perl_ (by Wall and Schwartz,
>published by O'Reilly & Associates) had to say about "require". Experi-
>menting with what it said, I created two "perl" scripts, as shown below.
>
>,---SubSubArg--------------------------------------.
>|#!/usr/local/bin/perl |
>| |
>|sub Inner |
>|{ |
>| $Jqz = $_[0]; |
>| print "Inner called with argument /$_[0]/.\n"; |
>|} |
>`--------------------------------------------------'
I know what's wrong with your script, but I can't find it in the Camel
book. However, if you look at your perl library (/usr/local/lib/perl5
on my machine), and peek at some of the .pl files, you'll notice all of
the files have:
1;
as their last statement. And I just checked the perlfunc manpage
under require and got this little snippet:
Note that the file will not be included twice under
the same specified name. The file must return TRUE
as the last statement to indicate successful
execution of any initialization code, so it's
customary to end such a file with "1;" unless you're
sure it'll return TRUE otherwise. But it's better
just to put the "1;", in case you add more
statements.
Hope this helps,
Colin
------------------------------
Date: Fri, 16 May 1997 12:06:04 -0400
From: Morgan Stair <morgan.stair@software.com>
Subject: Win32: Manipulating ENV with a perl script
Message-Id: <337C85EC.9EC4A512@software.com>
I'd like to write a perl command line utility to manipulate my
environment variables on a WindowsNT system (i.e. I'm using the Win32
port).
The problem is that when a perl process gets run, a new process starts
with a copy of the caller's environment, and any changes to the
environment made with $ENV{"FOO"} = "BAR" type commands go away when my
perl script exits.
On a UNIX system I'd handle this with the "eval `script.pl`" syntax.
How do I solve the problem on a DOS... I mean WindowsNT box?
Morgan
--
Morgan Stair <morgan.stair@software.com>
Voice: 617-274-7000 x270
Fax: 617-674-1080
http://www.software.com
------------------------------
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 490
*************************************