[13751] in Perl-Users-Digest
Perl-Users Digest, Issue: 1161 Volume: 9
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sat Oct 23 20:05:28 1999
Date: Sat, 23 Oct 1999 17:05:06 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <940723506-v9-i1161@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Sat, 23 Oct 1999 Volume: 9 Number: 1161
Today's topics:
Re: Card shuffling (Abigail)
Re: Card shuffling (Abigail)
Re: CGI script to start a perl script in the background (Alan Curry)
Re: CGI script to start a perl script in the background <qajurria@qajurria.cx>
Re: Comments in Perl (Abigail)
Re: Is it the list or the re? (Tad McClellan)
Re: Is it the list or the re? <lr@hpl.hp.com>
Jeff Murphy Are You Available???? <RTASHA@prodigy.net>
Re: Long menus -- any solutions? <makkulka@cisco.com>
Re: Mac text files vs PC text files -- How are they dif (David Stack)
Re: Matching an asterisk (Abigail)
Re: Off Subject : Good News Reader for Windows <makkulka@cisco.com>
Perl install prob. w/ make test <ruedas@geophysik.uni-frankfurt.de>
Picking 5 items from a random list (AcCeSsDeNiEd)
Re: Picking 5 items from a random list <qajurria@qajurria.cx>
Re: Retrieving directory contents (newbie) (GClemmons)
Re: Returning a hashref <makkulka@cisco.com>
Re: Returning a hashref (Tad McClellan)
Script Path value for Active Perl on Win32 <mudra@gnet.co.nz>
Re: SGML/HTML parsing tool (Abigail)
Re: SIMPLE scripts to help me learn??? (Max S.)
Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 23 Oct 1999 17:40:48 -0500
From: abigail@delanet.com (Abigail)
Subject: Re: Card shuffling
Message-Id: <slrn814eap.fji.abigail@alexandra.delanet.com>
Jeff Zucker (jeff@vpservices.com) wrote on MMCCXLI September MCMXCIII in
<URL:news:380DE892.7DB2E2D9@vpservices.com>:
$$
$$ This is Off-Topic, but how do the failings of Perl's random number
$$ generator compare with the failings of a typical human shuffler? Most
$$ people riffle the cards once or twice and deal. So while Perl's random
$$ generator is not up to a full random shuffle, doesn't it approach the
$$ degree of randomness found in a typical card game among humans? If it
$$ were to be truly random, wouldn't it produce very different results than
$$ found in a typical game among humans?
A shuffle algorithm based on a 32 bit random generator will produce
enough different deals to last a couple of human players a lifetime.
Even if a small subset of all possible deals will be produced.
What Knuth writes, or rather quotes, as it was Salfi that pointed it out,
is interesting, but one would do the maestro a disservice by quoting
him without thinking. Whether the ability of producing all permutations
is important or not depends; if it comes to just shuffling a deck and
play a game, it won't. If it comes to doing statistics with very large
sets (larger than for instance 2^R where R is the number of bits of
randomness), then it certainly matters.
And note that this only applies to random number generators where the next
number depends on the previous number. Throw in something like /dev/rando,
or anything else that depends on the environment, and Salfi's remarks
no longer hold.
Abigail
--
perl -we '$@="\145\143\150\157\040\042\112\165\163\164\040\141\156\157\164".
"\150\145\162\040\120\145\162\154\040\110\141\143\153\145\162".
"\042\040\076\040\057\144\145\166\057\164\164\171";`$@`'
-----------== Posted via Newsfeeds.Com, Uncensored Usenet News ==----------
http://www.newsfeeds.com The Largest Usenet Servers in the World!
------== Over 73,000 Newsgroups - Including Dedicated Binaries Servers ==-----
------------------------------
Date: 23 Oct 1999 17:56:27 -0500
From: abigail@delanet.com (Abigail)
Subject: Re: Card shuffling
Message-Id: <slrn814f85.fji.abigail@alexandra.delanet.com>
Kragen Sitaker (kragen@dnaco.net) wrote on MMCCXLI September MCMXCIII in
<URL:news:XkoP3.22432$E_1.1219502@typ11.nn.bcandid.com>:
//
// Well, I believe professional dealers are required to shuffle the deck
// six times, enough for every card to be able to be anywhere in the deck,
// but not enough to stack it very well. [I can't remember what the
// number is, though.]
//
// Ideally, every card getting shuffled -- except for the last two or
// three -- contributes one bit of entropy, because it's equally likely to
// be the left or right card. If this is the case, we have about 50 bits
// of entropy per shuffle, so we only need one shuffle to do better than
// rand(), and five shuffles to do things perfectly. [This suggests
// something is wrong with my reasoning, because we know it takes six --
// right? Or does it?]
Well, not quite. For such a shuffle, it would impossible for instance
for the top card to end up as the bottom card after only one shuffle.
And while it's true that as long as you have two stacks, there's an
about equal chance the next card will come from the left or right stack,
cards that are in the right stack will show up in the shuffled stack
in the same order; same for cards in the left stack. Hence, I would not
say "50 bits of entropy".
Take for instance a shuffle with 4 cards. Have A and B in the left deck,
and C and D in the right. You can only get 6 different decks from that:
A B C D
A C B D
A C D B
C A B D
C A D B
C D A B
while 4! == 24.
Abigail
--
echo "==== ======= ==== ======"|perl -pes/=/J/|perl -pes/==/us/|perl -pes/=/t/\
|perl -pes/=/A/|perl -pes/=/n/|perl -pes/=/o/|perl -pes/==/th/|perl -pes/=/e/\
|perl -pes/=/r/|perl -pes/=/P/|perl -pes/=/e/|perl -pes/==/rl/|perl -pes/=/H/\
|perl -pes/=/a/|perl -pes/=/c/|perl -pes/=/k/|perl -pes/==/er/|perl -pes/=/./;
-----------== Posted via Newsfeeds.Com, Uncensored Usenet News ==----------
http://www.newsfeeds.com The Largest Usenet Servers in the World!
------== Over 73,000 Newsgroups - Including Dedicated Binaries Servers ==-----
------------------------------
Date: Sat, 23 Oct 1999 22:32:13 GMT
From: pacman@defiant.cqc.com (Alan Curry)
Subject: Re: CGI script to start a perl script in the background.
Message-Id: <NHqQ3.33038$E_1.1789754@typ11.nn.bcandid.com>
In article <s14a8een85932@corp.supernews.com>,
Col <newsgroups@selectweb.co.uk> wrote:
>I load my cgi script through my browser and it then starts off a perl
>script in the background and displays some text on the page and stops.
>But the perl script is still running in the background until it finishes.
>
>I've tried both system and exec (and even placing an & after the path of
>the script) to call the perl script but the cgi script doesn't complete
The STDOUT of your script is connected to the web server. When you create a
new process, it inherits that STDOUT. The web server will not know you are
done with STDOUT until you close it. The parent process exits, so that one is
closed. But the child process still has a copy. You should close it there too.
You could put close(STDOUT); before your system(), or in the child half of
your fork(), or put >&- in your system() command line, if you are passing it
through the shell anyway. Depending on the program, you may want to pass it
/dev/null on STDOUT instead of closing it completely.
You should also give some thought to whether you really want your background
process to write its STDERR to the server log.
--
Alan Curry |Declaration of | _../\. ./\.._ ____. ____.
pacman@cqc.com|bigotries (should| [ | | ] / _> / _>
--------------+save some time): | \__/ \__/ \___: \___:
Linux,vim,trn,GPL,zsh,qmail,^H | "Screw you guys, I'm going home" -- Cartman
------------------------------
Date: 23 Oct 1999 22:37:35 GMT
From: QaJurria <qajurria@qajurria.cx>
Subject: Re: CGI script to start a perl script in the background.
Message-Id: <7utdbf$ua0$1@enterprise.cistron.net>
Col <newsgroups@selectweb.co.uk> wrote:
> I've read something about fork but haven't got a clue how to use this and
> can't find any 'dummy' guides.
Try something like this in your code:
unless($pid = fork)
{
unless(fork)
{
print "Forked in the background with pid: $$\n";
# put the code to fork here
}
}
Or check the perlfunc manfile for more about fork();
Greetz,
Jurriaan
--
/ Perl, PHP, Lite, SQL, MySQL, mSQL; / Jurriaan Kamer |
/ HTML, DHTML, JavaScript, Webdesign; / aka. QaJurria |
| Holy: / Security Consultancy. / qajurria@qajurria.cx |
| perl -e 'print $i=pack(c5,(41*2),sqrt(7056),(unpack(c,H)-2),oct(115),10);'
------------------------------
Date: 23 Oct 1999 17:59:34 -0500
From: abigail@delanet.com (Abigail)
Subject: Re: Comments in Perl
Message-Id: <slrn814fdv.fji.abigail@alexandra.delanet.com>
Martien Verbruggen (mgjv@wobbie.heliotrope.home) wrote on MMCCXLII
September MCMXCIII in <URL:news:slrn80ts0l.a5b.mgjv@wobbie.heliotrope.home>:
~~ On 20 Oct 1999 03:46:27 -0500,
~~ Abigail <abigail@delanet.com> wrote:
~~ > Alan Curry (pacman@defiant.cqc.com) wrote on MMCCXLI September MCMXCIII
~~ >
~~ > ^^ my ($width, /*$depth,*/ $height);
~~ >
~~ > my ($width, #$depth,
~~ > $height);
~~ >
~~ > One byte less on Unix, same amount of bytes on Windows.
~~
~~ Only in a file. :)
I assume you're not going to comment out stuff for things you
type interactively....
Abigail
--
sub camel (^#87=i@J&&&#]u'^^s]#'#={123{#}7890t[0.9]9@+*`"'***}A&&&}n2o}00}t324i;
h[{e **###{r{+P={**{e^^^#'#i@{r'^=^{l+{#}H***i[0.9]&@a5`"':&^;&^,*&^$43##@@####;
c}^^^&&&k}&&&}#=e*****[]}'r####'`=437*{#};::'1[0.9]2@43`"'*#==[[.{{],,,1278@#@);
print+((($llama=prototype'camel')=~y|+{#}$=^*&[0-9]i@:;`"',.| |d)&&$llama."\n");
-----------== Posted via Newsfeeds.Com, Uncensored Usenet News ==----------
http://www.newsfeeds.com The Largest Usenet Servers in the World!
------== Over 73,000 Newsgroups - Including Dedicated Binaries Servers ==-----
------------------------------
Date: Sat, 23 Oct 1999 14:23:45 -0400
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: Is it the list or the re?
Message-Id: <hfusu7.er3.ln@magna.metronet.com>
Andy Smith (asmith@hsonline.net) wrote:
: All I really want to do is pull some info from syslog.
: I'm sure there are scripts out there to do this, but
: I need the practice (badly as you can see). MYFILE is the
: sytem log, and NEWFILE a log that the info will go into.
: I am pretty sure the re is what is screwy. Perl -w tells me
: there is an error near "\s+\d+)\s+(".
: while(my $linage = <MYFILE>)
: {
:
: if (s/^\w+\s+\d+\S+\s+?/);
^^ ^
^^ ^
besides that, you are missing the BLOCK part of the if() construct.
: list($date, $time, $service) = ($linage =~
^^^^
^^^^
What is that?
: s/^(S+\s+\d+)\s+(\d{2}:\d{2}:\d{2})\s+(S+:).*?/);
^^ ^
^^ ^
s/PATTERN/REPLACEMENT/ ( s/// ) is 2-part thingie.
^^ ^ ^
^^ ^ ^
you have a couple of 1-part thingies there...
--
Tad McClellan SGML Consulting
tadmc@metronet.com Perl programming
Fort Worth, Texas
------------------------------
Date: Sat, 23 Oct 1999 16:43:15 -0700
From: Larry Rosler <lr@hpl.hp.com>
Subject: Re: Is it the list or the re?
Message-Id: <MPG.127be7f0f100ed0798a10c@nntp.hpl.hp.com>
In article <3811f89f$0$70842@news.hsonline.net> on 23 Oct 1999 18:04:15
GMT, Andy Smith <asmith@hsonline.net> says...
> All I really want to do is pull some info from syslog.
> I'm sure there are scripts out there to do this, but
> I need the practice (badly as you can see). MYFILE is the
> sytem log, and NEWFILE a log that the info will go into.
> I am pretty sure the re is what is screwy. Perl -w tells me
> there is an error near "\s+\d+)\s+(".
>
>
> while(my $linage = <MYFILE>)
> {
It is common and humane to indent code within a block like this.
> if (s/^\w+\s+\d+\S+\s+?/);
Is this line above supposed to mean something? You have posted code
that cannot compile. This is poor policy, because who wants to go
further?
> list($date, $time, $service) = ($linage =~
The above invokes a function list() as an lvalue? Unusual, I'd say.
> s/^(S+\s+\d+)\s+(\d{2}:\d{2}:\d{2})\s+(S+:).*?/);
^
Missing a backslash here, or do you really want to match a leading
string of S's?
> print(NEWFILE "$date $time $service\n");
> };
Please copy and paste well-formatted code that actually compiles and
runs. Then maybe the responses will be useful to you.
--
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: Sat, 23 Oct 1999 18:35:39 -0000
From: "Natasha Manning" <RTASHA@prodigy.net>
Subject: Jeff Murphy Are You Available????
Message-Id: <7utgrl$62qk$1@newssvr03-int.news.prodigy.com>
Jeff,
We spoke about a Perl / Sybase opening in Chicago about 3+ months ago,
are you available????>
Call me ASAP.
Mark Lewis
847-839-1900x18
------------------------------
Date: Sat, 23 Oct 1999 16:05:00 -0700
From: Makarand Kulkarni <makkulka@cisco.com>
Subject: Re: Long menus -- any solutions?
Message-Id: <38123F1C.EEEA7658@cisco.com>
Stacy Doss wrote:
> Is there any way to have a menu widget display in multiple columns?
assuming that you are talking about menu widgets in the inside
HTML forms -- you cannot change their default behaviour.
In netscape I have seen that a drop list (created using popup_menu() in
cgi.pm ) does not drop all the way down to the screen border
but instead the drop list gets a scroll bar to scroll through.
I you have too many items then srolling_list() might be
the way to go.
--
------------------------------
Date: Sun, 24 Oct 1999 02:43:16 GMT
From: musicstack@hotmail.com (David Stack)
Subject: Re: Mac text files vs PC text files -- How are they different?
Message-Id: <38127111.93696348@news.supernews.com>
Thank you and also Alan J Flavell for posting to my replies.
I am very clear on the situation now and have managed to solve the
problem thanks to all your kind information and help.
Since I never will know if the file I am parsing will be a Mac or PC
based file, I have the end user select weather he is on a Mac or PC.
This in turns set $/="\n" for PC or $/="\r" for Mac and allows the
file to be parsed one line at a time like I want.
So far it is working great for me.
Thanks again!
Dave
On Sat, 23 Oct 1999 15:58:56 -0300, Arved_37@chebucto.ns.ca (Arved
Sandstrom) wrote:
>In article <38118006.31989478@news.supernews.com>, musicstack@hotmail.com wrote:
>
>> I am stumped here. I have two text files. Both are the same ASCII
>> text file, but one was saved on a MAC and the other on a PC.
>>
>> I have FTP'ed these two files to my unix server and I now I am trying
>> to parse each file and print the first line of each file using the
>> following code:
>>
>> #!/usr/bin/perl
>>
>> open (F,"PC_file.txt");
>> $a=<F>;
>> print "$a\n\n";
>>
>> open (D,"MAC_file.txt");
>> $e=<D>;
>> print $e;
>>
>> when I run the above program, I get one line of Text with the PC
>> version of the file, but with reading the MAC text file, I get the
>> whole file printed out and not one line of text. I figured this all
>> had something to do with MACs and PCs using different end of line
>> characters, so I checked with my favorite hex editor and it ends up
>> the end of line characters are both the same for each of the two
>> different files. They are both '0D 0A'. So this leaves me
>> stumped.
>>
>> Could someone kindly tell me how to read one line text at a time with
>> a MAC text file with out reading in the whole file in? Is it
>> possible?
>>
>If both files have 0xD 0xA (CR LF) line-ends, on whatever platform you're
>looking at them on, they are PC. Unix has 0xA (LF), and Mac text files
>have 0xD (CR) line-endings.
>
>The Perl convention is that '\n' represents OS specific newline. So, if
>you haven't caught line-end conversions when saving in your favourite text
>editor (and certainly on both MacOS and Windows, the better text editors
>like Ultraedit and Alpha read and write DOS, MAC and UNIX), or when
>FTP'ing, just use something like
>
>perl -i.bak -pe 's/\015\012?/\n/g;' file > newfile
>
>to convert MAC or DOS to Unix.
>
>You can always fiddle $/ also, but I find it easier just to make sure that
>your text files arrive in the system in the proper format to start with.
>
>Arved Sandstrom
------------------------------
Date: 23 Oct 1999 18:04:30 -0500
From: abigail@delanet.com (Abigail)
Subject: Re: Matching an asterisk
Message-Id: <slrn814fn8.fji.abigail@alexandra.delanet.com>
Peter J. Kernan (pete@theory2.phys.cwru.edu) wrote on MMCCXLI September
MCMXCIII in <URL:news:slrn80s7fd.di2.pete@theory2.phys.cwru.edu>:
%% On 19 Oct 1999 22:44:11 -0500, Abigail <abigail@delanet.com> wrote:
%% .=Brett W. McCoy (bmccoy@foiservices.com) wrote on MMCCXLI September
%% .=--
%% .=-- text =~ /.*\*$/;
%% .=
%%
%% the verbosity seems like the only problem
%%
%% .=That's going to fail on "foo\nbar*" (false negative).
%% .=
%% .=It's also going to fail on "foo*\n" (false positive).
%% .=
%%
%% i dont see either failure for 5.005_02
%%
%% for ('foo\nbar*','foo*\n') {
%% print "$_: ",m/.*\*$/,"\n";
%% };
%%
%%
%% prints
%%
%% foo\nbar*: 1
%% foo*\n:
My bad. I was anchoring the .* at the beginning, but there's no ^ there.
The .* is merely pointless. As for the false positive, use "" to get
interpolation. '\n' is just a backwack followed by an n.
Abigail
--
$_ = "\x3C\x3C\x45\x4F\x54\n" and s/<<EOT/<<EOT/ee and print;
"Just another Perl Hacker"
EOT
-----------== Posted via Newsfeeds.Com, Uncensored Usenet News ==----------
http://www.newsfeeds.com The Largest Usenet Servers in the World!
------== Over 73,000 Newsgroups - Including Dedicated Binaries Servers ==-----
------------------------------
Date: Sat, 23 Oct 1999 16:28:31 -0700
From: Makarand Kulkarni <makkulka@cisco.com>
Subject: Re: Off Subject : Good News Reader for Windows
Message-Id: <3812449F.9D80765D@cisco.com>
Aaldie wrote:
> I do not like outlook news reader... suggestions on a good one ?
> maybe one written in Perl ??
www.microplanet.com
--
------------------------------
Date: Sun, 24 Oct 1999 01:58:53 +0200
From: Thomas Ruedas <ruedas@geophysik.uni-frankfurt.de>
Subject: Perl install prob. w/ make test
Message-Id: <38124BBD.1452@geophysik.uni-frankfurt.de>
Hello,
I'm installing Perl 5.005_3 on an IBM workstation running AIX 4.2 and
using the xlc C compiler. Compilation seems to be OK so far, but running
"make test" gave an error in one of the 190 tests, namely in testing
op/misc. This is a snippet of the test output:
PROG:
$a = ":="; split /($a)/o, "a:=b:=c"; print "@_"
EXPECTED:
a := b := c
GOT:
grep: 0652-033 Cannot open 0551-011.
grep: 0652-033 Cannot open Standard.
grep: 0652-033 Cannot open input.
grep: 0652-033 Cannot open is.
grep: 0652-033 Cannot open not.
grep: 0652-033 Cannot open a.
grep: 0652-033 Cannot open tty..
a := b := c
grep: 0652-033 Cannot open 0551-011.
grep: 0652-033 Cannot open Standard.
grep: 0652-033 Cannot open input.
grep: 0652-033 Cannot open is.
grep: 0652-033 Cannot open not.
grep: 0652-033 Cannot open a.
grep: 0652-033 Cannot open tty..
For the other test cases for op/misc it looks all the same, i.e. I get
this grep stuff around the expected result, but the results seems to
come anyway. I ran "make test" in an absolutely normal way (I think) on
the command line. Now, this doesn't seem to look like a serious error to
me, but I have doubts if I can "make install" now regardless to this
message or if I run the risk to have a flawed installation.
Can anybody comment on this? BTW, I would like to know if I can remove
the directory from where I installed after installation, or if I have to
keep parts of it.
Thanks in advance,
--
------------------------------------------------------------------------
Thomas Ruedas
Institute of Meteorology and Geophysics, J.W.Goethe University Frankfurt
e-mail: ruedas@geophysik.uni-frankfurt.de
http://www.geophysik.uni-frankfurt.de/~ruedas/
------------------------------------------------------------------------
------------------------------
Date: Sat, 23 Oct 1999 22:48:50 GMT
From: dillon_rm@magix.com.sg (AcCeSsDeNiEd)
Subject: Picking 5 items from a random list
Message-Id: <38123b44.2152336@news.magix.com.sg>
Hi,
I have a list of 10 items. I know how to pick one item at random. It
goes like this:
@items =
("Item1","Item2","Item3","Item4","Item5","Item6","Item7","Item8","Item9","Item10");
srand(time ^ $$);
$num = rand(@items); # Pick a Random Number
# Print Out Random Item
print "Random Item picked is: $items[$num]\n";
My question is, how do I pick 5 items at one time randomly from the
list?
I could do a while loop, but then the 5 times picked will surely have
duplicates.
Any hints?
Thanks
------------------------------
Date: 23 Oct 1999 23:15:11 GMT
From: QaJurria <qajurria@qajurria.cx>
Subject: Re: Picking 5 items from a random list
Message-Id: <7utfhv$2pl$1@enterprise.cistron.net>
AcCeSsDeNiEd <dillon_rm@magix.com.sg> wrote:
> My question is, how do I pick 5 items at one time randomly from the
> list?
> Any hints?
Build an array with the indexnumbers of the array with the items you
want to choose from. (starting with @num = (0,1,2,3,4,5,6,7,8,9);), and
pick $items[$num[$randnum]]; After every pick, change the @num, so that
the allready picked indexnumber will be erased from @num, until @num is
empty.
I apoligize for my (maybe) somewhat confusing hint, but that's because
I just got back from a party, and I guess I had enough beer =)
Greetz, Jurriaan
--
/ Perl, PHP, Lite, SQL, MySQL, mSQL; / Jurriaan Kamer |
/ HTML, DHTML, JavaScript, Webdesign; / aka. QaJurria |
| Holy: / Security Consultancy. / qajurria@qajurria.cx |
| perl -e 'print $i=pack(c5,(41*2),sqrt(7056),(unpack(c,H)-2),oct(115),10);'
------------------------------
Date: 23 Oct 1999 23:36:32 GMT
From: g@cw3.net (GClemmons)
Subject: Re: Retrieving directory contents (newbie)
Message-Id: <7utgq0$oev$1@fu-berlin.de>
acacia@online.no (Morris) wrote in
<ArlQ3.9945$7G2.56525@news1.online.no>:
>I'm wondering if anyone here knows how
>to make a script that retrieves all
>the filenames (just the names + extension)
>in a given directory...
>
You will probably get some better suggestions
but this works for me:)
if you are wanting object in a given directory
it is as simple as:
@files = <*>;
however if you need only files you could try:
while (<*>) {
push @files unless -d;
}
or if all of your files are name.extension based:
$files = <*.*>;
You might try going through the perldocs and look
for information on globbing.
Hope this helps.
-- Gordon --
------------------------------
Date: Sat, 23 Oct 1999 16:20:52 -0700
From: Makarand Kulkarni <makkulka@cisco.com>
Subject: Re: Returning a hashref
Message-Id: <381242D4.8EE5BCB0@cisco.com>
"Daniel W. Burke" wrote:
> I seem to be having a problem with the function below.
> $ret = &my_fetchash($csr);
> %data = %$ret;
> On the redhat pc, for some reason, it returns the string "1/7". I had to
> change it to this (which I actually like better),
> %data = &my_fetchhash($csr);
>
> Is there anything that would cause this difference?
yes. In the function my_fetchhash you are returning
a hash ( not ref to hash ) . This means that the
hash is "rolled out". In the first case this hash
cannot fit into the scalar $ret that you are trying
to use to catch the "rolled out" hash. The results of
getting elements from $ret which is not a hash
are meaningless.
In the second case you are not using $ret and
hence the "rolled out" elements fall into %data
directly ( and are happy)
Point to note is that we have to be careful
to note what is getting returned ( a ref
or a hash ). The return should
be of the appropriate type.
See example
use Data::Dumper ;
%data1 = &my_fetchhash1 ;
%data2 = %{&my_fetchhash2} ;
print Dumper \%data1;
print Dumper \%data2;
#returns hash
sub my_fetchhash1
{
my($ref) = { 'a', 'b', 'c', 'd' } ;
if ($ref) {
%$ref;
} else {
();
}
}
#return ref to hash
sub my_fetchhash2
{
my($ref) = { 'a', 'b', 'c', 'd' } ;
if ($ref) {
$ref;
} else {
();
}
}
--results --
$VAR1 = {
'a' => 'b',
'c' => 'd'
};
$VAR1 = {
'a' => 'b',
'c' => 'd'
};
------------------------------
Date: Sat, 23 Oct 1999 14:11:28 -0400
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: Returning a hashref
Message-Id: <gotsu7.er3.ln@magna.metronet.com>
Daniel W. Burke (dwb1@home.com) wrote:
: I seem to be having a problem with the function below. It is not acting
: consistantly between versions of perl. I wrote it, and a few scripts that
: use it pretty heavily on my home pc, which hash perl version 5.005_03. I
: took the scripts to a PC at work (redhat 5.2, which I think has 5.003 on it),
^^^^^^^^^^ ^^^^^^^
^^^^^^^^^^ ^^^^^^^
The perl that ships with redhat is from the _development_
track, not the stable track.
The first thing I do after installing redhat is to delete perl
and install the latest one from CPAN.
Why guess what version you have?
Why not just type: perl -V
and _know_ what version we are talking about, especially if
you are chasing differences between versions.
: and it behaves differently.
: This function is just to return the hashref from an open cursor to a mysql
: database.
Your my_fetchhash() below returns a hash, *not* a reference to a hash...
: On my pc, I have to do the call like this (which passes "use strict" and "-w":
: $ret = &my_fetchash($csr);
^^
^^
Please don't attempt to retype code. Use copy/paste instead.
Else you get comments about your typos instead of about your
real problem.
: %data = %$ret;
: On the redhat pc, for some reason, it returns the string "1/7".
That is what a hash is _supposed_ to do when used in a
scalar context like that. (note that that is _not_ what
a ref-to-a-hash is supposed to do. The first clue that
things are not as you expect them to be).
: I had to
: change it to this (which I actually like better),
: %data = &my_fetchhash($csr);
That is way slower because all of the hash gets pushed onto
the stack. You are losing the one of the primary advantages
of using a hashref.
: Is there anything that would cause this difference? It seems pretty odd that
: an older version operates simpler. If this is normal, is there any way I
: can test for something like this an act accordingly? This is the function.
: I think I copied it from another module and changed the name.
: sub my_fetchhash
: {
: my($self) = shift;
: my($ref) = $self->fetchrow_hashref;
: if ($ref) {
: %$ref;
^
^ here you are *de*referencing it, so you are returning
a hash, not a hash ref.
the hash will be "flattened" to a list of key/value
pairs. you return the list
don't dereference it if you don't want it dereferenced :-)
: } else {
: ();
return an empty list
: }
: }
The "else" part also looks like the original intent of this code
was to return a list, not a hashref.
If the function should always return a hashref, then I
would think it should return a reference to an empty hash,
rather than an empty list, when there were no results:
else {
return {}
}
--
Tad McClellan SGML Consulting
tadmc@metronet.com Perl programming
Fort Worth, Texas
------------------------------
Date: Sun, 24 Oct 1999 12:00:10 +1300
From: "Adam Ratcliffe" <mudra@gnet.co.nz>
Subject: Script Path value for Active Perl on Win32
Message-Id: <940719322.461226@news.win.co.nz>
Hi there,
I'm a newbie to Perl and am a little stuck with getting my scripts to
execute in my browser. Perhaps you maybe able to help?
I have just installed Active Perl on my Win 95 machine, running Personal
Webserver 4.0. The Perl interpreter works fine from a DOS Window however
when I seek to execute a script from within my browser it still directs the
output to a terminal window rather than the Browser window.
I have checked the Script Path key in the Registry and this has no value
currently assigned to it although I selected the option for Active Perl to
map to PWS.
My best guess is that I need to edit the Script Path value, any comment on
this would be most appreciated!
Thanks in advance
Adam
------------------------------
Date: 23 Oct 1999 18:11:50 -0500
From: abigail@delanet.com (Abigail)
Subject: Re: SGML/HTML parsing tool
Message-Id: <slrn814g50.fji.abigail@alexandra.delanet.com>
Jon Drukman (jsd@hudsucker.gamespot.com) wrote on MMCCXLI September
MCMXCIII in <URL:news:slrn80s74v.1vh5.jsd@hudsucker.gamespot.com>:
|| In article <slrn80rejk.fji.abigail@alexandra.delanet.com>, Abigail wrote:
|| >Christopher R. Maden (crism@exemplary.net) wrote on MMCCXLI September
|| >MCMXCIII in <URL:news:crism-2010990243160001@pm3b-12.meer.net>:
|| >;; Have you tried HTML::Parser for parsing HTML?
||
|| >Yes, I have. It's about as useful for parsing HTML as a table is
|| >to do shopping with.
|| >HTML::Parser doesn't parse, nor does it have any HTML knowledge.
||
|| i'd hate to see the pathological cases you must have to deal with.
||
|| i've been using HTML::Parser in dozens of scripts and it hasn't
|| coughed up a hairball yet. it has tackled hand generated code, as
|| well as crap from frontpage and dreamweaver with aplomb.
||
|| then again your definition of "parsing" may well be different from mine.
So, tell me, what does HTML::Parser do?
All it does is doing a call back when encountering _tokens_.
That's not parsing.
Of course, you could write a piece of software that does something
when seeing:
$i<--===>%i{&**]!!"flup fluP"
and call it a Perl parser, just because it recognizes some characters
as tokens....
Abigail
--
srand 123456;$-=rand$_--=>@[[$-,$_]=@[[$_,$-]for(reverse+1..(@[=split
//=>"IGrACVGQ\x02GJCWVhP\x02PL\x02jNMP"));print+(map{$_^q^"^}@[),"\n"
-----------== Posted via Newsfeeds.Com, Uncensored Usenet News ==----------
http://www.newsfeeds.com The Largest Usenet Servers in the World!
------== Over 73,000 Newsgroups - Including Dedicated Binaries Servers ==-----
------------------------------
Date: 23 Oct 1999 22:30:35 GMT
From: intbyte@aol.com (Max S.)
Subject: Re: SIMPLE scripts to help me learn???
Message-Id: <19991023183035.22510.00000544@ng-fi1.aol.com>
alright!
Max S.
intbyte@aol.com
http://realestateclosings.net/zd
------------------------------
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 1161
**************************************