[9644] in Perl-Users-Digest
Perl-Users Digest, Issue: 3238 Volume: 8
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Jul 23 18:07:47 1998
Date: Thu, 23 Jul 98 15:00:27 -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 Thu, 23 Jul 1998 Volume: 8 Number: 3238
Today's topics:
[Q] Multiplexing STDOUT to already opened Filehandle( <mishra.aditya@emeryworld.com>
autoflush not working <biztech@jps.net>
Checking to see if packages exist volodya@my-dejanews.com
Re: Checking to see if packages exist <jdporter@min.net>
comp.lang.perl.extreme (Michael J Gebis)
Database help for newbie <kwang@biogate.com>
Re: Database help for newbie <jdporter@min.net>
Re: dumb questions Re: Problem with DBD::Oracle <kucerar@hhmi.org>
Re: has anyone attempted a script that can replicate it pittelli@my-dejanews.com
hashes in perl <neilf@echelon.ca>
Re: hashes in perl <jason.holland@dial.pipex.com>
Re: hashes in perl (Craig Berry)
Re: hashes in perl (Larry Rosler)
Re: hashes in perl (Josh Kortbein)
Re: hashes in perl <mishra.aditya@emeryworld.com>
Re: hashes in perl (Larry Rosler)
Re: Help - Need disclaimer for code/exe in pTK and p2xs (Greg Bacon)
Re: HELP! Hash of refs to objects <jdporter@min.net>
Re: How to know the number of hash items without runnin <dgris@rand.dimensional.com>
Re: Is there a better way to do this? <jdporter@min.net>
Re: Is there a better way to do this? <Richard@waveney.demon.co.uk>
Re: is there a isNumber($aString) function? <ckuskie@cadence.com>
Re: Last Name First... <jdporter@min.net>
Re: Last Name First... (Al Gordon)
Re: Multiple Key Sort <jdporter@min.net>
Re: parsing question (Craig Berry)
Re: parsing question <minich@globalnet.co.uk>
Re: parsing question <jdporter@min.net>
Re: passing data from a form to another cgi app <featheredfrog@geocities.com>
Re: Perl Beautifier Home Page <zenin@bawdycaste.org>
Re: perl setup problems <Eric.Zylberstejn@wanadoo.com>
Re: References as strings <JKRY3025@comenius.ms.mff.cuni.cz>
sprintf and decimals jrector@my-dejanews.com
Re: sprintf and decimals (Larry Rosler)
Re: sprintf and decimals (Craig Berry)
Re: STUMPED!!! (perl trivia) <jhi@alpha.hut.fi>
subs in separate files? <melinda@acm.org>
Re: Sybperl script fails to exit after last line meadore@my-dejanews.com
Re: Sybperl script fails to exit after last line meadore@my-dejanews.com
Re: Sybperl script fails to exit after last line meadore@my-dejanews.com
What's the status of COPE? <kucerar@hhmi.org>
Special: Digest Administrivia (Last modified: 12 Mar 98 (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Thu, 23 Jul 1998 13:46:19 -0700
From: "Mishra Aditya" <mishra.aditya@emeryworld.com>
Subject: [Q] Multiplexing STDOUT to already opened Filehandle(s)
Message-Id: <6p87ej$1ara@news.cnf.com>
I need to multiplex output from STDOUT to already opened file handles under
SunOs 5.5.1
I looked at perlipc which recommends using Comm.pl.I can't use that
solution.
I don't want to fork and manage output from child processes either.
I tried using IO::Tee which did not work for me because it appears to be a
perl abstraction only.
I want to do the equivalent of freopen in perl.
If this is not possible directly , does anybody know the equivalent ioctl
call I have to do to tie the stdout stream to other open streams.
Thanks in advance
Adi
------------------------------
Date: Thu, 23 Jul 1998 14:59:27 -0700
From: "JPS.Net Corp Tech" <biztech@jps.net>
Subject: autoflush not working
Message-Id: <35B7B23F.265336A1@jps.net>
I have a program that reads from a TCP socket. My problem is that by
default the socket file descriptor is buffered and so my script waits
forever while reading from the socket. I have tried the following three
lines to unbuffer the file descriptor (the file descriptor is called
"SD"):
# Gives the message: Can't locate object method "autoflush" via package
"IO::Handle" at /usr/home/bweir/public_html/cgi-bin/mail2.pl line 93.
autoflush SD 1;
# Gives the message: Can't locate object method "autoflush" via package
"IO::Handle" at /usr/home/bweir/public_html/cgi-bin/mail2.pl line 93.
SD->autoflush(1);
# No error messages but the file descriptor is still buffered
select((select(SD), $|)[0]);
At the top of my perl script is
use FileHandle;
Any help on this would be greatly appreciated.
Thanks,
Ben Weir
JPS.Net Biztech Support/Programmer
------------------------------
Date: Thu, 23 Jul 1998 19:50:09 GMT
From: volodya@my-dejanews.com
Subject: Checking to see if packages exist
Message-Id: <6p845h$evq$1@nnrp1.dejanews.com>
Is there a way to check whether a certain package directory exists. For
example, I can use the code like this to check if a package exists: eval
"use Sys::Hostname"; warn $@ if $@ to see if Sys::Hostname is defined.
But how do I check if Sys is a valid package directory?
Please email,
Thanks,
- Vladimir
-----== Posted via Deja News, The Leader in Internet Discussion ==-----
http://www.dejanews.com/rg_mkgrp.xp Create Your Own Free Member Forum
------------------------------
Date: Thu, 23 Jul 1998 20:47:16 GMT
From: John Porter <jdporter@min.net>
Subject: Re: Checking to see if packages exist
Message-Id: <35B7A2E5.49AA@min.net>
volodya@my-dejanews.com wrote:
>
> But how do I check if Sys is a valid package directory?
for ( @INC ) {
-d "$_/Sys" and print "$_/Sys\n";
}
--
John Porter
------------------------------
Date: 23 Jul 1998 20:33:03 GMT
From: gebis@albrecht.ecn.purdue.edu (Michael J Gebis)
Subject: comp.lang.perl.extreme
Message-Id: <6p86lv$56n@mozo.cc.purdue.edu>
PERL!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
--
Mike Gebis gebis@ecn.purdue.edu mgebis@eternal.net
------------------------------
Date: Thu, 23 Jul 1998 14:23:05 -0500
From: Kent Wang <kwang@biogate.com>
Subject: Database help for newbie
Message-Id: <35B78D99.BEE7C4FE@biogate.com>
i would like to somehow manage a text database, that i can add to,
delete entries, and edit. anybody know how?
------------------------------
Date: Thu, 23 Jul 1998 20:41:24 GMT
From: John Porter <jdporter@min.net>
Subject: Re: Database help for newbie
Message-Id: <35B7A185.22BE@min.net>
Kent Wang wrote:
>
> i would like to somehow manage a text database, that i can add to,
> delete entries, and edit. anybody know how?
Sure: use perl.
Oh, you mean more specific than that?
O.k., use open(), <>, print(), and close().
--
John Porter
------------------------------
Date: Thu, 23 Jul 1998 17:31:21 -0400
From: Richard J Kucera <kucerar@hhmi.org>
Subject: Re: dumb questions Re: Problem with DBD::Oracle
Message-Id: <35B7ABAD.4A3AC174@hhmi.org>
Yeah, I know now...and only Oracle comes close to delivering on that
type 4 network driver I mentioned earlier
(even though it's "free" we can't forget that it's not really free as
long as so much remains proprietary
and single source...even Sun still reserves all rights to java and JDK
source etc etc...Oracle has a huge
investment in Java, which is probably why they wanted to make such a
nice driver "free").
-R
John D Groenveld wrote:
> It would be great if SQLNet was an open standard protocol, its not.
> It would be great if Oracle provided the full Perl distribution
> and latest DBI/DBD::Oracle with OWAS, it doesn't.
> John
> groenveld@acm.org
------------------------------
Date: Thu, 23 Jul 1998 21:40:34 GMT
From: pittelli@my-dejanews.com
Subject: Re: has anyone attempted a script that can replicate itself and then run the copy?
Message-Id: <6p8aki$mlj$1@nnrp1.dejanews.com>
Just like creating a new script and running it: after creating the file,
'require' it. Or if not sure if it'll run ok, do an eval "require
'script.name'";
-Randy
In article <6p680f$3ab$4@nswpull.telstra.net>,
mgjv@comdyn.com.au (Martien Verbruggen) wrote:
> In article <6p5p5u$qes$1@nnrp1.dejanews.com>,
> jhestyr@my-dejanews.com writes:
> > text
>
> By lack of meaningful content, We'll just use the subject:
>
> Subject: has anyone attempted a script that can replicate itself
> and then run the copy?
>
> yes.
>
> Martien
> --
> Martien Verbruggen |
> Webmaster www.tradingpost.com.au | That's funny, that plane's dustin'
> Commercial Dynamics Pty. Ltd. | crops where there ain't no crops.
> NSW, Australia |
>
-----== Posted via Deja News, The Leader in Internet Discussion ==-----
http://www.dejanews.com/rg_mkgrp.xp Create Your Own Free Member Forum
------------------------------
Date: Fri, 24 Jul 1998 04:00:03 -0400
From: "Neil Frenette" <neilf@echelon.ca>
Subject: hashes in perl
Message-Id: <6p84s3$buq$1@nntp2.uunet.ca>
When I write a key-value pair to a hash, then write another
key-value pair to the same hash, same key, different value.
Which value gets stored in the hash ???
------------------------------
Date: Thu, 23 Jul 1998 21:31:41 +0000
From: Jason Holland <jason.holland@dial.pipex.com>
To: Neil Frenette <neilf@echelon.ca>
Subject: Re: hashes in perl
Message-Id: <35B7ABBD.554E0A50@dial.pipex.com>
Neil Frenette wrote:
>
> When I write a key-value pair to a hash, then write another
> key-value pair to the same hash, same key, different value.
>
> Which value gets stored in the hash ???
The last one overwrites the previous one.
Note: I use this technique to delete duplicate array members, like this:
sub uniq {
my @array = shift;
my %hash;
foreach ( @array ) {
$hash{$_} = 1;
}
@array = undef;
foreach ( keys( %hash ) ) {
if( $hash{$_} ) {
push( @array, $_ );
}
}
return(1);
}
Every time you assign to a hash element, the previous data is destroyed.
Bye!
--
sub jasonHolland {
my %hash = ( website =>
'http://dspace.dial.pipex.com/jason.holland/',
email => 'jason.holland@dial.pipex.com' );
}
------------------------------
Date: 23 Jul 1998 20:29:37 GMT
From: cberry@cinenet.net (Craig Berry)
Subject: Re: hashes in perl
Message-Id: <6p86fh$igp$4@marina.cinenet.net>
Neil Frenette (neilf@echelon.ca) wrote:
: When I write a key-value pair to a hash, then write another
: key-value pair to the same hash, same key, different value.
:
: Which value gets stored in the hash ???
Have you tried it? Easy enough to do by experiment:
perl -we '$a{b}=1; $a{b}=2; print $a{b}'
prints 2, as one would expect; the last value assigned to the key replaces
any previous ones.
If you need to hold onto all values, I'd suggest using an array-reference
as the hash key's value, and push new values onto it:
perl -we 'push @{$a{b}}, 1; push @{$a{b}}, 2; print "@{$a{b}}"'
prints '1 2', as the array refered to by the hash key's value now has
these two elements.
---------------------------------------------------------------------
| Craig Berry - cberry@cinenet.net
--*-- Home Page: http://www.cinenet.net/users/cberry/home.html
| Member of The HTML Writers Guild: http://www.hwg.org/
"Every man and every woman is a star."
------------------------------
Date: Thu, 23 Jul 1998 13:28:51 -0700
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: hashes in perl
Message-Id: <MPG.10213ce181187ff7989741@nntp.hpl.hp.com>
[Posted to comp.lang.perl.misc and a copy sent to Neil Frenette
<neilf@echelon.ca>.]
In article <6p84s3$buq$1@nntp2.uunet.ca> on Fri, 24 Jul 1998 04:00:03 -
0400, Neil Frenette <neilf@echelon.ca> says...
> When I write a key-value pair to a hash, then write another
> key-value pair to the same hash, same key, different value.
>
> Which value gets stored in the hash ???
Try it and see.
--
Larry Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: 23 Jul 1998 20:35:38 GMT
From: kortbein@iastate.edu (Josh Kortbein)
Subject: Re: hashes in perl
Message-Id: <6p86qq$am6$1@news.iastate.edu>
Neil Frenette (neilf@echelon.ca) wrote:
: When I write a key-value pair to a hash, then write another
: key-value pair to the same hash, same key, different value.
: Which value gets stored in the hash ???
Try it out and see.
$hash{'test'} = 666;
$hash{'test'} = 333;
print $hash{'test'}, "\n";
Josh
--
__________________________________________
She had heard all about excluded middles;
they were bad shit, to be avoided.
- Thomas Pynchon
------------------------------
Date: Thu, 23 Jul 1998 13:47:48 -0700
From: "Mishra Aditya" <mishra.aditya@emeryworld.com>
Subject: Re: hashes in perl
Message-Id: <6p87hc$1aro@news.cnf.com>
Same key new value in hash
Adi
------------------------------
Date: Thu, 23 Jul 1998 13:46:38 -0700
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: hashes in perl
Message-Id: <MPG.102141082dcc17fb989743@nntp.hpl.hp.com>
[Posted to comp.lang.perl.misc and a copy sent to Jason Holland
<jason.holland@dial.pipex.com>.]
In article <35B7ABBD.554E0A50@dial.pipex.com> on Thu, 23 Jul 1998
21:31:41 +0000, Jason Holland <jason.holland@dial.pipex.com> says...
...
> Note: I use this technique to delete duplicate array members, like this:
>
> sub uniq {
> my @array = shift;
> my %hash;
> foreach ( @array ) {
> $hash{$_} = 1;
> }
> @array = undef;
> foreach ( keys( %hash ) ) {
> if( $hash{$_} ) {
> push( @array, $_ );
> }
> }
> return(1);
> }
Instead, one could use one of the approaches in perlfaq4: "How can I
extract just the unique elements of an array?" which have the triple
advantages of being correct, much shorter, and much faster.
Hints:
1. Have you tried this with an input array that has more than one
element?
2. What is the purpose of returning 1 and abandoning the computed array?
--
Larry Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: 23 Jul 1998 20:14:35 GMT
From: gbacon@cs.uah.edu (Greg Bacon)
Subject: Re: Help - Need disclaimer for code/exe in pTK and p2xstd(aka perl2exe)
Message-Id: <6p85jb$i3h$2@info.uah.edu>
In article <6p80eo$b6t$1@nnrp1.dejanews.com>,
chuckkovacs@my-dejanews.com writes:
: I've written a useful pTk program, a alarm/reminder thingy.
: 1) written in pTk and available as a .pl
: 2) compiled with p2xstd beta (aka perl2exe)
:
: I would like to distibute both for free, but what sort
: of disclaimer/legal mumbo-jumbo do I need to include?
IMHO, Perl's Artistic License makes a fine prototype.
Greg
--
open(G,"|gzip -dc");$_=<<EOF;s/[0-9a-f]+/print G pack("h*",$&)/eg
f1b88000b620f22320303fa2d2e21584ccbcf29c84d2258084
d2ac158c84c4ece4d22d1000118a8d5491000000
EOF
------------------------------
Date: Thu, 23 Jul 1998 20:34:44 GMT
From: John Porter <jdporter@min.net>
Subject: Re: HELP! Hash of refs to objects
Message-Id: <35B79FF5.1443@min.net>
Richard Hakim wrote:
>
> %hash = (
> 'GLOBAL' => new Global,
> );
>
> Then, I want to call a function process() which is part of the global
> class. But when I try to do
>
> $hash{GLOBAL}->process(), of course, it bails.
That should work.
But is there something you didn't tell us?
Like, what else is inside the %hash = ( ... ) list?
Because the 'new' method gobbles up everything after it; it
doesn't stop at the first comma. So if you had something like this:
%hash = (
'foo' => new Global,
'GLOBAL' => new Global,
'bar' => new Global,
);
then %hash contains only one key -- 'foo' -- and its value is the
result of
Global->new( 'GLOBAL', Global->new( 'bar', Global->new() ) );
which is probably not what you meant.
--
John Porter
------------------------------
Date: Thu, 23 Jul 1998 21:52:30 GMT
From: Daniel Grisinger <dgris@rand.dimensional.com>
Subject: Re: How to know the number of hash items without running loop.
Message-Id: <6p8an0$76d$1@rand.dimensional.com>
[posted to comp.lang.perl.misc and mailed to the cited author]
In article <35B76F37.349F1B47@nortel.com>
Michael Bowler <mkbowler@nortel.com> wrote:
>That probably should be: $numitems = $#hkeys + 1;
>as $#<array> returns the last valid index of an array which is one less than the
>number of elements in the array.
More correctly, the above approach should be-
$numitems = $#hkeys + 1 - $[;
This will correct for the situation of $[ being a value
other than 0.
Regards,
Daniel
--
Daniel Grisinger dgris@perrin.dimensional.com
"No kings, no presidents, just a rough consensus and
running code."
Dave Clark
------------------------------
Date: Thu, 23 Jul 1998 20:22:28 GMT
From: John Porter <jdporter@min.net>
Subject: Re: Is there a better way to do this?
Message-Id: <35B79D15.3ED2@min.net>
Richard Proctor wrote:
>
That's mighty application-specific. So you're the expert!
Suggegtion #1: Have you considered using HTML::Parse?
Suggestion #2:
> $Warn=$^W;$^W=0;
> $USPrice = $1;
> $OtherPrice = $2;
> $OnePrice = $3;
> $^W=$Warn;
This would be much better as
{ local $^W; # =undef, same effect as =0.
$USPrice = $1;
$OtherPrice = $2;
$OnePrice = $3;
} # restore previous value of $^W.
--
John Porter
------------------------------
Date: Thu, 23 Jul 1998 21:57:28 +0100
From: Richard Proctor <Richard@waveney.demon.co.uk>
Subject: Re: Is there a better way to do this?
Message-Id: <ant232028345Rr9i@waveney.demon.co.uk>
In article <35B79D15.3ED2@min.net>, John Porter
<URL:mailto:jdporter@min.net> wrote:
> Richard Proctor wrote:
> >
>
> That's mighty application-specific. So you're the expert!
Yes this bit of code is, most of the script is general purpose. It only
calls the code in this subroutine for a dealing with a particular site.
>
> Suggegtion #1: Have you considered using HTML::Parse?
>
Yes, but it did not really do what I wanted. I want to operate on the
fly, some of the pages are on the large size and its friendlier to start
sending material on to end users as soon as possible. Most of the HTML I
leave alone, I add my own header and trailer to the pages, otherwise its
mainly links and prices that get modified.
> Suggestion #2:
>
> > $Warn=$^W;$^W=0;
> > $USPrice = $1;
> > $OtherPrice = $2;
> > $OnePrice = $3;
> > $^W=$Warn;
>
> This would be much better as
>
> { local $^W; # =undef, same effect as =0.
> $USPrice = $1;
> $OtherPrice = $2;
> $OnePrice = $3;
> } # restore previous value of $^W.
>
I had half considered doing it that way, I probably will.
--
Richard@waveney.demon.co.uk
for$i(0..23){$b=0;for(0..4){($b*=2)+=hex(substr(
"0ec1cac5a6a902458844802541b078",2*$_+($i>>3)*10,2))>>($i&7)&1};print
chr($b?$b+($l?96:64):32);$l=$b}
------------------------------
Date: Thu, 23 Jul 1998 14:05:25 -0700
From: Colin Kuskie <ckuskie@cadence.com>
To: Abigail <abigail@fnx.com>
Subject: Re: is there a isNumber($aString) function?
Message-Id: <Pine.GSO.3.96.980723134713.19858K-100000@pdxmail.cadence.com>
On 23 Jul 1998, Abigail wrote:
> sub is_a_number {
> {map {$_ => 1} 0 .. 0x7FFFFFFF} -> {+shift};
> }
That is honestly the funniest piece of perl code that I've seen in
a long time. I've learned a lot about perl by reverse engineering your
signatures, so I thought that I'd type it in and run some benchmarks
just for fun. Of course, first I syntax checked it, not realizing
that perl would generate the list in order to check it...
So I stared at it for a while and modified the upper bits to a slightly
more friendly value and tried it again and it doesn't compile using
perl5.004_04.
For some reason perl doesn't seem to like your anonymous hash. When I
expand it out to a more clear syntax:
sub is_a_number {
$a = map {$_ => 1} 0 .. 0x7FF;
$a->{+shift};
}
it works just fine. You didn't actually send that poor, clueless,
neophyte code that would run out of memory AND doesn't work, did you?
Colin
------------------------------
Date: Thu, 23 Jul 1998 20:39:04 GMT
From: John Porter <jdporter@min.net>
Subject: Re: Last Name First...
Message-Id: <35B7A0F9.71CF@min.net>
John Porter wrote:
>
> if ( $a[1] =~ /,/ ) { $a[1] = "$' $`"; }
woops, those indexes should be 2, not 1.
--
John Porter
------------------------------
Date: Thu, 23 Jul 1998 20:52:51 GMT
From: al@ioa.com (Al Gordon)
Subject: Re: Last Name First...
Message-Id: <35b7a28d.3886703@news.a-o.com>
Thank you! This looks like exactly what I'm looking for. :)
On 23 Jul 1998 19:37:13 GMT, cberry@cinenet.net (Craig Berry) wrote:
>Al Gordon (al@ioa.com) wrote:
>: I have a text tab-delimeted file that follows a format something like
>: this:
>:
>: field 1<tab>field 2<tab>field 3<tab> ... etc.
>
>OK, so (leaving out the trivial code to open the input and output files,
>and loop over the lines of input) the first step is to do
>
> my @fields = split /\t/;
>
>on each line to split the fields into array elements.
>
>: The third field contains names of businesses and individuals.
>: Businesses might be something like: "Joe Smith Corp." (without the
>: quotes) and individuals are listed like "Smith, Joe" or "Smith, Joe
>: W." (again, without the quotes).
>:
>: I need to convert the "lastname, firstname" formatted text in the file
>: to "firstname lastname" (both without quotes). The business names in
>: the third field will not contain commas (or at least I hope they
>: don't).
>
>OK, so we're talking about $fields[2]. Here's how I'd write it:
>
> $fields[2] =~ s/(.*?)\s*,\s+(.*)/$2 $1/;
>
>If there's no comma in the field, this is a no-op; otherwise, it reverses
>the chunks before and after a comma (and its surrounding whitespace).
>
>Then you'd just print out the transformed data, rejoined into the original
>tab-separated format:
>
> print join "\t", @fields;
>
>You can actually do this without splitting and joining, but the regex
>involved gets much hairier. I'd suggest this as a good, easy to
>understand approach unless you're going to run this thing often on huge
>files.
>
>---------------------------------------------------------------------
> | Craig Berry - cberry@cinenet.net
> --*-- Home Page: http://www.cinenet.net/users/cberry/home.html
> | Member of The HTML Writers Guild: http://www.hwg.org/
> "Every man and every woman is a star."
------------------------------
Date: Thu, 23 Jul 1998 20:13:22 GMT
From: John Porter <jdporter@min.net>
Subject: Re: Multiple Key Sort
Message-Id: <35B79AF2.7084@min.net>
Michael Maraist wrote:
>
> @dest_list = sort {
> return $_ if ( $_ = $a->[ $key1 ] <=> $b->[ $key1 ];
> return $_ if ( $_ = $a->[ $key2 ] <=> $b->[ $key2 ];
> ...
> return $a->[ $keyn ] <=> $b->[ $keyn ];
> } @obj_list;
Blech. Do this:
@dest_list = sort {
$a->[ $key1 ] <=> $b->[ $key1 ]
or $a->[ $key2 ] <=> $b->[ $key2 ]
or ...
or $a->[ $keyn ] <=> $b->[ $keyn ]
} @obj_list;
--
John Porter
------------------------------
Date: 23 Jul 1998 20:08:59 GMT
From: cberry@cinenet.net (Craig Berry)
Subject: Re: parsing question
Message-Id: <6p858r$igp$3@marina.cinenet.net>
Larry Rosler (lr@hpl.hp.com) wrote:
: Use the $\ variable (see the perlvar manpage for details). You can either
: set it to "" to eliminate empty paragraphs ("abc\n\n\n\ndef", for
: instance, gets treated as two paragraphs and not three), or "\n\n" to
: accept empty paragraphs.
That should actually be $/, the input record separator; $\ is the output
record separator. This is a typo in the faq.
---------------------------------------------------------------------
| Craig Berry - cberry@cinenet.net
--*-- Home Page: http://www.cinenet.net/users/cberry/home.html
| Member of The HTML Writers Guild: http://www.hwg.org/
"Every man and every woman is a star."
------------------------------
Date: Thu, 23 Jul 1998 21:49:30 +0100
From: "Martin" <minich@globalnet.co.uk>
Subject: Re: parsing question
Message-Id: <6p87lu$bun$1@heliodor.xara.net>
Hi, try:
open(INF, "myfile.dat");
@indata = <INF>;
close(INF);
foreach $indata (@indata) {
$_ = $indata;
if ( /=/) {
($name, $value) = split(/=/, $indata);
}
elsif ( /^[MTWFS]/) {
$firstline = "$indata";
}
else {
#The whole record has been read in. Now do what you
#Want with it. (See altered file format below) It is in the
#form $namea = $valuea and $nameb = $valueb etc.
#The time stamp and date info are in $firstline and you
#could insert extra code in the elsif loop to manipulate
#this.
}
}
Hope this helps, please test run it first on a copy of the file
so you don't lose the info. Please e-mail me to tell me if it
works as I haven't had time to test it. It should though.
Martin
> namea = valuea
> nameb = valueb
------------------------------
Date: Thu, 23 Jul 1998 21:04:04 GMT
From: John Porter <jdporter@min.net>
Subject: Re: parsing question
Message-Id: <35B7A6D4.246E@min.net>
Martin wrote:
>
> Hi, try:
>
> open(INF, "myfile.dat");
> @indata = <INF>;
> close(INF);
>
> foreach $indata (@indata) {
> $_ = $indata;
> if ( /=/) {
> ($name, $value) = split(/=/, $indata);
> }
> elsif ( /^[MTWFS]/) {
> $firstline = "$indata";
> }
> else {
> #The whole record has been read in.
> }
> }
1. you didn't check the return value of open().
you must *always* do that. No but's.
2. unless you have some specific need to store the entire
input file in memory at once, it's better to while()
over it instead of foreach(). You'll notice the
difference as the files get larger.
3. bizarre mixing of $_ and $indata. $_ was sufficient for
the task.
4. you already did a split( /=/, $_, 2 ) when you did a
if ( /=/ )
so use the results, rather than splitting again.
5. superfluous quoting:
> $firstline = "$indata";
In summary:
my $filename = "myfile.dat";
open INF, "< $filename" or die "open $filename: $!";
my $firstline;
my %hash;
while (<INF>) {
chomp;
if ( /^[MTWFS]/ ) {
$firstline = $_;
%hash = ();
}
elsif ( /=/ ) {
$hash{ $` } = $';
}
# &c.
}
close INF;
6. But you don't cleanly handle the case where the last line
of input is the last "name = value" line of the last
record.
7. One should just use $/ for this kind of thing.
--
John Porter
------------------------------
Date: Thu, 23 Jul 1998 16:39:29 -0400
From: "Michael D. Hofer" <featheredfrog@geocities.com>
Subject: Re: passing data from a form to another cgi app
Message-Id: <35B79F81.51A@geocities.com>
Jeoff Micalizzi wrote:
>
> Does anyone know how to take data from a browser based form, pass it to
> another cgi app and parse the results?
>
> Thanks,
> Jeoff Micalizzi
> jeoff@geocities.com
Maybe I'm being dense, but isn't this just a matter of adding an
ACTION="url of the other cgi app" to the <form> tag? Even denser, I
don't see how this is a perl issue... Oh yeah:
use CGI;
.
.
.
print $query->start_form(-action=>'url of the other cgi app');
[?]
--
Cian ua'Lochan /mka/ Michael D. Hofer
No Unsolicited Commercial Email: $500.00/Item for proofreading!
I'm not a medievalist - I just play one on weekends!
http://www.geocities.com/SoHo/Lofts/9800/
------------------------------
Date: 23 Jul 1998 21:24:58 GMT
From: Zenin <zenin@bawdycaste.org>
Subject: Re: Perl Beautifier Home Page
Message-Id: <901229690.52022@thrush.omix.com>
John Porter <jdporter@min.net> wrote:
>snip<
: What? Included in the editor? What kind of system are you on?
X on FreeBSD.
: DOS?
: On MS Windows, X Window, and Mac, the fonts are in the system, not
: the application.
True, fonts are in the system. However, applications are free
to add fonts to the system. There is no reason an editor can't
ship with its own font, on any system. Even without root (or
similar) access to install.
Even under X, if the application is installed under a user's
directory it can still have its own font and just include
it in the search path.
--
-Zenin (zenin@archive.rhps.org) From The Blue Camel we learn:
BSD: A psychoactive drug, popular in the 80s, probably developed at UC
Berkeley or thereabouts. Similar in many ways to the prescription-only
medication called "System V", but infinitely more useful. (Or, at least,
more fun.) The full chemical name is "Berkeley Standard Distribution".
------------------------------
Date: Thu, 23 Jul 1998 23:21:50 +0200
From: Eric Zylberstejn <Eric.Zylberstejn@wanadoo.com>
To: "A. Nelson" <mbane@s-crim1.dl.ac.uk>
Subject: Re: perl setup problems
Message-Id: <35B7A96E.2F73AC16@wanadoo.com>
Hello,
A. Nelson wrote:
>
> Hello,
> I need help successfully compiling the source code for
> perl5.
> [...]
> opt/gnu/lib/gcc-lib/sparc-sun-solaris2.5/2.7.2/include/sys/param.h:187: warnind
So you are compiling on Solaris.
Never had any problem compiling on Solaris 2.5.1 or 2.6 with either gcc or
Sun's workshop C 4.2.
I suggest you :
* check you have installed the Solaris latest recommended patches ;
* upgrade to gcc version 2.8.1 (especially if you are running 2.6).
Eric.pl
------------------------------
Date: Thu, 23 Jul 1998 22:03:52 -0700
From: Jan Krynicky <JKRY3025@comenius.ms.mff.cuni.cz>
Subject: Re: References as strings
Message-Id: <35B815B8.3932@comenius.ms.mff.cuni.cz>
Michael Maraist wrote:
>
> > I am trying to store references as strings, and then later dereference
> > them. THis far, I have not succeded. Perhaps someone could give me an
> > advice.
> >
> > For example, if I do like this:
> >
> > $a = "string";
> > $ref_to_a = \$a;
> > $string_ref_to_a = "$ref_to_a";
> >
> > $string_ref_to_a upon being printed looks something like
> > SCALAR(0x9f29c), but
> > it can not be dereferenced. Is there a way to convert the "stringed"
> > reference back into a hard reference, or some other way to get to the
> > data in that location without using the real reference variable?
>
> Just out of curiousity, why would you want/need to do so. Personally,
> I'd think it was cool to be able to access real memory locations as in
> C, but can't think of any real value in doing so in a scripting
> language.
>
> Hmm. Maybe you could write a C extension for it.
OK, this is most probably not his reason, but I have one.
It's related to Interpolation.pm module.
This module ties a hash to a function so that every time
you ask for a value of some "key" in the hash the function
gets called and you get the result.
The problem is, that since hash keys may be only strings, as soon as you
try to pass a reference as the "key", the reference gets stringified
and you cannot get back to the value.
use Interpolation foo => sub { my $ref = $_[0]; $$ref + 1};
$x = 23;
print "\thello $foo{\$x} wordl\n";
will give you
hello 1 world
instead of
hello 24 world
Anyway I don't think there is an easy solution.
You could search all packages looking for a variable with the same
address,
but that would be terribly inefficient and it would not work always.
Eg. if it was an anonymous reference or if the variable already got
garbagecollected.
Jenda
------------------------------
Date: Thu, 23 Jul 1998 20:05:19 GMT
From: jrector@my-dejanews.com
Subject: sprintf and decimals
Message-Id: <6p851v$fvo$1@nnrp1.dejanews.com>
When I use the following code to round decimals to integers my result is 0
when the variable is 0.8. How can I get it to round to 1?
$t = sprintf("%.0f",$number);
-----== Posted via Deja News, The Leader in Internet Discussion ==-----
http://www.dejanews.com/rg_mkgrp.xp Create Your Own Free Member Forum
------------------------------
Date: Thu, 23 Jul 1998 13:36:06 -0700
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: sprintf and decimals
Message-Id: <MPG.10213e918f833a4d989742@nntp.hpl.hp.com>
[Posted to comp.lang.perl.misc and a copy sent to jrector@my-dejanews.com
<jrector@my-dejanews.com>.]
In article <6p851v$fvo$1@nnrp1.dejanews.com> on Thu, 23 Jul 1998 20:05:19
GMT, jrector@my-dejanews.com <jrector@my-dejanews.com> says...
> When I use the following code to round decimals to integers my result is 0
> when the variable is 0.8. How can I get it to round to 1?
>
> $t = sprintf("%.0f",$number);
You deserve congratulations for doing it right. However...
Print $number immediately before this. If it is indeed 0.8, install a
version of perl that works. I have checked it in 5.002 and 5.004 with no
problems.
--
Larry Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: 23 Jul 1998 20:46:24 GMT
From: cberry@cinenet.net (Craig Berry)
Subject: Re: sprintf and decimals
Message-Id: <6p87f0$igp$5@marina.cinenet.net>
jrector@my-dejanews.com wrote:
: When I use the following code to round decimals to integers my result is 0
: when the variable is 0.8. How can I get it to round to 1?
:
: $t = sprintf("%.0f",$number);
perl -we '$number=0.8; $t = sprintf("%.0f",$number); print $t'
gets me 1, not 0. This is with perl version 5.004_04. What version do
you have?
---------------------------------------------------------------------
| Craig Berry - cberry@cinenet.net
--*-- Home Page: http://www.cinenet.net/users/cberry/home.html
| Member of The HTML Writers Guild: http://www.hwg.org/
"Every man and every woman is a star."
------------------------------
Date: 24 Jul 1998 00:13:12 +0300
From: Jarkko Hietaniemi <jhi@alpha.hut.fi>
Subject: Re: STUMPED!!! (perl trivia)
Message-Id: <oeeu348nudz.fsf@alpha.hut.fi>
adtp@cix.compulink.co.uk ("Advent Dtp") writes:
> or: (assumes padding exists)
>
> $y = substr $x,0,index ($x,"\0");
Why assume?
$y = substr $x,0,index ("$x\0","\0");
--
$jhi++; # http://www.iki.fi/~jhi/
# There is this special biologist word we use for 'stable'.
# It is 'dead'. -- Jack Cohen
------------------------------
Date: Thu, 23 Jul 1998 21:45:41 GMT
From: "Quinn,M" <melinda@acm.org>
Subject: subs in separate files?
Message-Id: <35B7B13D.918D61FF@acm.org>
Novice question:
How do I put subrouotines (functions) into
separate files? I have learned to call functions
(subs) that are in the SAME file, but I cannot
figure out how to put subs in separate files.
I've tried "use", "require", etc. No luck.
The following works in the SAME file - how can I
make the subroutine work if it is in a SEPARATE FILE
IN THE SAME DIRECTORY?
==== file: subtry ========
#!/usr/bin/perl -w
print ("=== subtry BEFORE calling subtry2 ==\n);
$MVAR = "SOMETHING";
subtry2($MVAR);
print ("=== subtry AFTER calling subtry2 ==\n");
sub subtry2 {
my $Stuff = $_[0];
print ("This stuff is $Stuff \n");}
================EOF=============================
If anyone can refer me to pages in "Learning Perl" or
"Programming Perl" or on-line Perl documentation,
I'd be grateful.
Please also reply by e-mail. Thank you.
Melinda Quinn melinda@acm.org
}
------------------------------
Date: Thu, 23 Jul 1998 20:54:30 GMT
From: meadore@my-dejanews.com
Subject: Re: Sybperl script fails to exit after last line
Message-Id: <6p87u6$j9t$1@nnrp1.dejanews.com>
I am having the same problem on AIX4.2.1 and AIX4.3.1. I am running
perl5.004_04 and sybperl 2.09. Some of our scripts hang (only some times)
after the die or exit has been called. These same scripts work fine using
perl 5.003 and an earlier version of sybperl.
In article <6o01o2$24n$1@nnrp1.dejanews.com>,
tonyprideaux@my-dejanews.com wrote:
> I've written a small Sybperl script which I run from Cron throughout the day.
> However, occasionally, after it has executed the last lines in the script,
> the process goes into a cpu loop and has to be terminated with a kill -9. The
> last three lines are: print LOG "Goodbye world!!\n"; close LOG; exit 0;
>
> The print statement executes everytime so it is getting to the end.
>
> I'm running this on AIX 4.1.4 with Perl 5.004 and Sybperl 2. Has anyone got an
> idea as to why my script is sometimes looping when it should be exiting?
>
> -----== Posted via Deja News, The Leader in Internet Discussion ==-----
> http://www.dejanews.com/rg_mkgrp.xp Create Your Own Free Member Forum
>
-----== Posted via Deja News, The Leader in Internet Discussion ==-----
http://www.dejanews.com/rg_mkgrp.xp Create Your Own Free Member Forum
------------------------------
Date: Thu, 23 Jul 1998 20:54:32 GMT
From: meadore@my-dejanews.com
Subject: Re: Sybperl script fails to exit after last line
Message-Id: <6p87u8$ja0$1@nnrp1.dejanews.com>
I am having the same problem on AIX4.2.1 and AIX4.3.1. I am running
perl5.004_04 and sybperl 2.09. Some of our scripts hang (only some times)
after the die or exit has been called. These same scripts work fine using
perl 5.003 and an earlier version of sybperl.
In article <6o01o2$24n$1@nnrp1.dejanews.com>,
tonyprideaux@my-dejanews.com wrote:
> I've written a small Sybperl script which I run from Cron throughout the day.
> However, occasionally, after it has executed the last lines in the script,
> the process goes into a cpu loop and has to be terminated with a kill -9. The
> last three lines are: print LOG "Goodbye world!!\n"; close LOG; exit 0;
>
> The print statement executes everytime so it is getting to the end.
>
> I'm running this on AIX 4.1.4 with Perl 5.004 and Sybperl 2. Has anyone got an
> idea as to why my script is sometimes looping when it should be exiting?
>
> -----== Posted via Deja News, The Leader in Internet Discussion ==-----
> http://www.dejanews.com/rg_mkgrp.xp Create Your Own Free Member Forum
>
-----== Posted via Deja News, The Leader in Internet Discussion ==-----
http://www.dejanews.com/rg_mkgrp.xp Create Your Own Free Member Forum
------------------------------
Date: Thu, 23 Jul 1998 21:00:03 GMT
From: meadore@my-dejanews.com
Subject: Re: Sybperl script fails to exit after last line
Message-Id: <6p888j$jql$1@nnrp1.dejanews.com>
I am having the same problem with perl5.004_04 and sybperl 2.09 on aix 4.2.1
and 4.3.1. A script of ours hangs about 50% of the time after the die or
exit has been called. The script uses Sybase:CTlib, and is usually called as
a cgi program (but also hangs sometimes from the command line).
This script works just fine with perl5.003 and a much earlier version of
sybperl.
In article <6o01o2$24n$1@nnrp1.dejanews.com>,
tonyprideaux@my-dejanews.com wrote:
> I've written a small Sybperl script which I run from Cron throughout the day.
> However, occasionally, after it has executed the last lines in the script,
> the process goes into a cpu loop and has to be terminated with a kill -9. The
> last three lines are: print LOG "Goodbye world!!\n"; close LOG; exit 0;
>
> The print statement executes everytime so it is getting to the end.
>
> I'm running this on AIX 4.1.4 with Perl 5.004 and Sybperl 2. Has anyone got an
> idea as to why my script is sometimes looping when it should be exiting?
>
> -----== Posted via Deja News, The Leader in Internet Discussion ==-----
> http://www.dejanews.com/rg_mkgrp.xp Create Your Own Free Member Forum
>
-----== Posted via Deja News, The Leader in Internet Discussion ==-----
http://www.dejanews.com/rg_mkgrp.xp Create Your Own Free Member Forum
------------------------------
Date: Thu, 23 Jul 1998 17:33:17 -0400
From: Richard J Kucera <kucerar@hhmi.org>
Subject: What's the status of COPE?
Message-Id: <35B7AC21.77F31C11@hhmi.org>
It seems pretty quiet lately...
Dumb question: what can I do with it? Write an object whose methods
are Perl?
TIA
-R
------------------------------
Date: 12 Jul 98 21:33:47 GMT (Last modified)
From: Perl-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Special: Digest Administrivia (Last modified: 12 Mar 98)
Message-Id: <null>
Administrivia:
Special notice: in a few days, the new group comp.lang.perl.moderated
should be formed. I would rather not support two different groups, and I
know of no other plans to create a digested moderated group. This leaves
me with two options: 1) keep on with this group 2) change to the
moderated one.
If you have opinions on this, send them to
perl-users-request@ruby.oce.orst.edu.
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 3238
**************************************