[9986] in Perl-Users-Digest
Perl-Users Digest, Issue: 3579 Volume: 8
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Aug 28 18:03:50 1998
Date: Fri, 28 Aug 98 15:01:29 -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, 28 Aug 1998 Volume: 8 Number: 3579
Today's topics:
Re: Reading a line from a file (Craig Berry)
Repeating grouped substitutions (Bill Raynor (B12349))
Simple variable manipulation question <prw@evolving.com>
Re: Trouble with getc()... <aqumsieh@tigre.matrox.com>
Re: typeglobs and references... (re: Prog Perl, p 117) (Kevin Reid)
Uploading Binary files <Jeff.Handley@SDRC.com>
what to do about syslog on win32 <rsr@rogerware.com>
Where to put my perl-scripts? <floarndt@gmx.de>
Re: why no true/false keywords? (Abigail)
Re: Win32 and Perl <JKRY3025@comenius.ms.mff.cuni.cz>
Re: Y2K Date Support (Patrick Timmins)
Re: {n} quantifier question (Craig Berry)
Re: {n} quantifier question (Mike Stok)
Special: Digest Administrivia (Last modified: 12 Mar 98 (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 28 Aug 1998 19:32:52 GMT
From: cberry@cinenet.net (Craig Berry)
Subject: Re: Reading a line from a file
Message-Id: <6s70l4$im1$4@marina.cinenet.net>
fred (passion@freemail.nl) wrote:
: I have a large ascii database file. Every line is related to a record.
: In fact: each line IS a record. So a record-number refers to a
: line-number in that file. The file is about 4 mb large.
:
: I want to create a Perl search interface to the database file.
: Of course I can use the open(FILE..) command, and read every line,
: until I reach the one I'm looking for.
:
: The question is:
:
: Is it possible to extract a line-number directly from the file? That
: way my interface will work much faster. Maybe there are other
: suggestions too?
If the records/lines are fixed-length, just multiply the desired line
number (0-base) by the record length, and seek() to it.
If the records/lines are variable-length, you have two options:
1) Just read lines until you get there, as you suggest above.
2) If the file is written seldom but read often, consider using a
different app to build an index of offsets to the beginning of
each line, or perhaps of every Nth line. Then you'd look up
the offset or nearest preceding offset in the index file, seek
to it, read a few more lines in the latter case, then grab the
line you want.
HTH...
---------------------------------------------------------------------
| Craig Berry - cberry@cinenet.net
--*-- Home Page: http://www.cinenet.net/users/cberry/home.html
| "Ripple in still water, when there is no pebble tossed,
nor wind to blow..."
------------------------------
Date: 28 Aug 1998 21:44:27 GMT
From: braynor@jupiter.kcc.com (Bill Raynor (B12349))
Subject: Repeating grouped substitutions
Message-Id: <6s78br$bfv$1@gatekeep.kcc.com>
I occasionally recieve supposedly comma delimited data with missing
comma's:
1.2,3.4 5.6,7.8 9.0
and would like to "fix it" so that it becomes comma delimited:
1.2,3.4,5.6,7.8,9.0
However:
s/(\d+\.\d*)\s+(\d+\.\d*)/\1\,\2/g;
only fixes the first one (3.4 5.6 becomes 3.4,5.6). It there any way
to force perl to change all the instances, other than:
{
$rc =s/(\d+\.\d*)\s+(\d+\.\d*)/\1\,\2/g;
redo if $rc ;
}
Thanks.
--
+-----------------------------------+----------------------------------+
| Bill Raynor |braynor@kcc.com O- |
| Kimberly Clark Corp |TEL:920/721-5973 |
| 2100 Winchester Road |FAX:920/721-2765 |
| Neenah, Wi. USA 54956 |DNRC:Minister of Standard Deviates|
+-----------------------------------+----------------------------------+
------------------------------
Date: Fri, 28 Aug 1998 15:33:25 -0600
From: Paul Worthington <prw@evolving.com>
Subject: Simple variable manipulation question
Message-Id: <35E72224.766D5207@evolving.com>
Hi - This one ought to be easy for you regular Perl
authors.
I've got variables:
$m20 = 2
$c20 = 100
$d20 = Acrobat
$m21 = 1
$c21 = 20
$d21 = Netscape
Now, when given $m20 in my script, I use substr to
get "20" from the end of it. Now that I know the
number code at the end, I want to print out
the value of $dwhatever_the_substr_returned (in this
case I want the value of $d20).
How do I put together a dollar sign (depicted as $), the
lower case letter D (depicted as d), and a variable
containing the two digit code I've extracted from the
original variable (depicted as $sub) in such a way as to
get the value of the variable I've just depicted?
I've tried lots of things, including $d$sub and
${d}${sub} and on and on and on. I've tried 8
different resources including books and web pages
and FAQs. I haven't found any answer that works,
but I gotta think this is a common thing to do and
thousands of people must have figured it out...
Help!
Much thanks in advance,
Paul Worthington
prw@evolving.com
------------------------------
Date: 28 Aug 1998 16:12:22 -0400
From: Ala Qumsieh <aqumsieh@tigre.matrox.com>
Subject: Re: Trouble with getc()...
Message-Id: <x3y67fcams9.fsf@tigre.matrox.com>
Peter Smith <psmith01@mindspring.com> writes:
>
> Trying to write a routine
> (Windows 95 with 'Perl 5.005_02 built for MSWin32-x86-object')
> which just inserts a bunch of commas into a line after certain character
> positions.
> The problem is getc() keeps returning early:
>
If you read the documentation on getc(), you would find:
=item getc FILEHANDLE
=item getc
Returns the next character from the input file attached to
FILEHANDLE, or a null string at end of file. If FILEHANDLE is
omitted, reads from STDIN. This is not particularly efficient. It
cannot be used to get unbuffered single-characters, however.
A solution is also given for UNIX-based systems. I don't know how to
get unbuffered input on winblows-based systems.
> Is there a better way - maybe by reading entire lines, then splitting
> them (hasn't worked for me either)??
yeah ..
while ($line = <IN>) {
chomp $line;
@chars = split //, $line;
foreach (@chars) {
# check your characters
}
}
or you could just check for a pattern directly
$line =~ s/\b$pat\b/$pat,/g;
or something like that.
>
> Thanks!
>
> --Peter--
> psmith01@mindspring.com
>
>
Welcome
--
Ala Qumsieh | No .. not Just Another
ASIC Design Engineer | Perl Hacker!!!!!
Matrox Graphics Inc. |
Montreal, Quebec | (Not yet!)
------------------------------
Date: Fri, 28 Aug 1998 17:44:59 -0400
From: kpreid@ibm.net (Kevin Reid)
Subject: Re: typeglobs and references... (re: Prog Perl, p 117)
Message-Id: <1degoig.ymqtq1465pj4N@slip166-72-108-119.ny.us.ibm.net>
Benjamin Low <b.d.low@unsw.edu.au> wrote:
> Is there any way of determining what a typeglob aliases to, when it is
> used as a glob for a reference?
>
> Prog Perl, 2nd ed. p117 has an example of a typeglob used to do "symbol
> table aliasing":
>
> (*a, *b) = func(\@c, \@d);
>
> sub func
> {
> local (*e, *f) = @_;
> # stuff done with @e and @f, (\@e, \@f) returned
> }
>
> In the example func assumes you're passing it refs to arrays, how can I
> tell just what *e and *f "alias" to? (Say I want to different things
> depending on whether you pass an array, scalar, etc).
First of all, you shouldn't really be using typeglobs and local; use
references and my instead:
($a, $b) = func(\@c, \@d);
sub func {
my ($e, $f) = @_;
if (ref $e eq "ARRAY") {
# do whatever with @$e & @$f
}
return ($e, $f);
}
print join ' ', @$b;
Typeglobs are not really one thing; they represent all variables with a
given name.
$a = '1';
%a = (1 => 123, 2 => 234);
foreach $type (qw(SCALAR ARRAY HASH CODE IO)) {
print 'a is ', ((*a{$type}) ? '' : 'not '), "a $type.\n";
}
--
Kevin Reid. | Macintosh.
"I'm me." | Think different.
------------------------------
Date: Fri, 28 Aug 1998 17:10:00 -0400
From: Jeff Handley <Jeff.Handley@SDRC.com>
Subject: Uploading Binary files
Message-Id: <35E71CA8.193F8915@SDRC.com>
I am trying to write a CGI script in Perl which handles a file upload
from a form. I can read in and save text files without a problem, but
when I read in binary files, they become corrupt. Has anyone done this
successfully?
Thanks in advance,
Jeff
------------------------------
Date: Fri, 28 Aug 1998 12:58:29 -0700
From: "Roger Reynolds" <rsr@rogerware.com>
Subject: what to do about syslog on win32
Message-Id: <6s726o$56g@enews1.newsguy.com>
I'm trying to use some modules, pRPC for one, which in turn try to use the
Syslog
module, which is of course not available in win32. So, what to do...
I viciously hacked sys/Syslog.pm, and removed the guts of just about all of
the methods defined, and am just printing messages to STDERR.
This allows the pRPC module to load and run (hey I am able to use
DBI:Proxy:mSQL from win32 client to solaris server, and do real queries !),
but I'm wondering if there is some better version of Syslog for win32, or
some
other general approach to working around such issues that I have missed.
Thanks to all...
============================================================
Roger S. Reynolds
email: rsr@rogerware.com rsr@softix.com
Web: http://www.rogerware.com
------------------------------
Date: Fri, 28 Aug 1998 22:50:57 +0200
From: Florian Arndt <floarndt@gmx.de>
Subject: Where to put my perl-scripts?
Message-Id: <35E71831.D8EA0F79@gmx.de>
Do you know a place to put my scripts?
Any free cgi-provider (perhaps included in homepage)?
Thanks for any answer,
Florian Arndt
------------------------------
Date: 28 Aug 1998 20:54:00 GMT
From: abigail@fnx.com (Abigail)
Subject: Re: why no true/false keywords?
Message-Id: <6s75d8$8eh$2@client3.news.psi.net>
Peter Scott (psk@euclid.jpl.nasa.gov) wrote on MDCCCXXIII September
MCMXCIII in <URL: news:6s6m3r$fhi@netline.jpl.nasa.gov>:
++ Greg Bacon (gbacon@itsc.uah.edu) wrote in article <6s4ao3$j0f$5@info.uah.edu>:
++ > That locks &some_check_sub into only being useful in scalar context
++ > because
++ >
++ > @vals = some_check_sub;
++ > if (@vals) {
++ > ...;
++ > }
++ >
++ > will break when it returns FALSE. Simple, unadorned C<return> is very
++ > useful for this type of thing.
++
++ So couldn't they just use C<wantarray>:
++
++ if (condition) {
++ return wantarray ? () : FALSE;
++ }
Because that's basically what a plain 'return;' does. It'll return
undef in scalar context, () in list context.
But that's not always what you want.
Abigail
--
perl -wleprint -eqq-@{[ -eqw\\- -eJust -eanother -ePerl -eHacker -e\\-]}-
------------------------------
Date: Fri, 28 Aug 1998 22:31:56 -0700
From: Jan Krynicky <JKRY3025@comenius.ms.mff.cuni.cz>
Subject: Re: Win32 and Perl
Message-Id: <35E7924C.3EC8@comenius.ms.mff.cuni.cz>
stevel wrote:
>
> I've been using perl for a few years now on Unix systems for various
> little scripts, etc. However, recently I've had to work at a Windows 95
> system writing various scripts. I know it's possible to control
> applications such as Excel through the OLE package on Perl. What about
> pulling up things such as dialog boxes, file browsers, etc for interactive
> use in scripts? Is it possible to do this? If so, could someone point me
> towards an online guide as to how to do this (with examples?)
>
> Thanks
>
> Steve
> stevel@gti.net
Some of teh functions are provided in package Win32.
I believe you may
use Win32;
Win32::MessageBox('Something');
not sure about the syntax.
If you want the Open/SaveAs dialogs you may use my Win32::FileOp
http://jenda.krynicky.cz/ or http://www.fmi.cz/private/Jenda
Standard BrowseForFolder dialog is suported as well.
I provides also progress and confirmation dialogs for
Moving/Copying/Deleting or Recycling.
If you want something more you should use either TK
(eithe on CPAN or by PPM or already included in your distribution)
or Win32::GUI : http://ww.divinf.it/dada/perl/
HTH, Jenda
------------------------------
Date: Fri, 28 Aug 1998 21:30:02 GMT
From: ptimmins@netserv.unmc.edu (Patrick Timmins)
Subject: Re: Y2K Date Support
Message-Id: <6s77gq$e08$1@nnrp1.dejanews.com>
In article <6s6qgm$2g1$4@client3.news.psi.net>,
abigail@fnx.com wrote:
> Patrick Timmins (ptimmins@netserv.unmc.edu) wrote on MDCCCXXIII September
> MCMXCIII in <URL: news:6s6h28$h2p$1@nnrp1.dejanews.com>:
> ++
> ++ How is it a problem with time_t (not that I am at all familiar with
time_t)?
> ++ On a 32 bit system in early 2038, the number of seconds since Jan 1, 1970
> ++ will reach 2**31. A 32 bit CPU, bus, etc will not be able to work with
> ++ anything larger. How is this a software problem, as opposed to a hardware
> ++ problem?
>
> Hmmm. Have you ever worked with a string containing more than 4 characters?
> Did it fit on the bus?
[snip]
byte by byte, yes
Patrick Timmins
U. Nebraska Medical Center
-----== Posted via Deja News, The Leader in Internet Discussion ==-----
http://www.dejanews.com/rg_mkgrp.xp Create Your Own Free Member Forum
------------------------------
Date: 28 Aug 1998 19:50:46 GMT
From: cberry@cinenet.net (Craig Berry)
Subject: Re: {n} quantifier question
Message-Id: <6s71mm$im1$5@marina.cinenet.net>
rowlands@my-dejanews.com wrote:
: Apologies if I'm being dense, but can anyone explain why
:
: "ab" =~ /(a*[^b]*b){2}/
:
: is true? I expect it to match only strings with at least two b's.
You're wrong, it's not true:
/usr2/people/cberry > perl -w
print ((("ab" =~ /(a*[^b]*b){2}/) ? 'matches' : 'fails'), "\n");
fails
What made you think otherwise?
---------------------------------------------------------------------
| Craig Berry - cberry@cinenet.net
--*-- Home Page: http://www.cinenet.net/users/cberry/home.html
| "Ripple in still water, when there is no pebble tossed,
nor wind to blow..."
------------------------------
Date: 28 Aug 1998 20:32:01 GMT
From: mike@stok.co.uk (Mike Stok)
Subject: Re: {n} quantifier question
Message-Id: <6s7441$5me@news-central.tiac.net>
In article <6s6vv8$4j1$1@nnrp1.dejanews.com>,
<rowlands@my-dejanews.com> wrote:
>Apologies if I'm being dense, but can anyone explain why
>
> "ab" =~ /(a*[^b]*b){2}/
>
>is true? I expect it to match only strings with at least two b's.
Is it true?
DB<1> print 'true' if "ab" =~ /(a*[^b]*b){2}/
DB<2> print 'true' if "abacab" =~ /(a*[^b]*b){2}/
true
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@colltech.com | Collective Technologies (work)
------------------------------
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 3579
**************************************