[11807] in Perl-Users-Digest
Perl-Users Digest, Issue: 5407 Volume: 8
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sat Apr 17 18:07:24 1999
Date: Sat, 17 Apr 99 15:00:21 -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 Sat, 17 Apr 1999 Volume: 8 Number: 5407
Today's topics:
"mixed"-Quantifier available ? <pochmann@gmx.de>
array names same as file names <wthompso@bbn.com>
Re: array names same as file names (Larry Rosler)
Re: array names same as file names <ebohlman@netcom.com>
Re: array names same as file names <tchrist@mox.perl.com>
Re: blank form fields <cassell@mail.cor.epa.gov>
Re: Can i run cgi in Win95 of my PC ?? <tripix@tdi-net.freeserve.co.uk>
Close pipe to sendmail? (Rick Freeman)
Re: Help! I can't create an error response from this sc <cassell@mail.cor.epa.gov>
Re: How to install Perl onto a machine with no C compil <petr@datasys.cz>
ifeither--How about some feedback? <asquith@macconnect.com>
Looking for better ways of solving a pattern matching a <ianb@zedat.fu-berlin.de>
Make problem in Win95 <kenmar@ihug.co.nz>
Make problem in Win95 <kenmar@ihug.co.nz>
Re: New FAQ: How can I read in an entire file all at on <uri@home.sysarch.com>
Re: No clues to Win32::NetResource problem? <xrxoxtxhxdx@xrxoxtxhx.xnxextx>
online user groups/resources <michaeldoss@atre.net>
Parsing exported Access Text Files (Pamela Goldfarb)
Re: Parsing exported Access Text Files <not@gonna.tell>
PSI::ESP module reliability (was Re: Best books to use. <Russell_Schulz@locutus.ofB.ORG>
Q: Removing file extentions me@here.com
question about format and write (Scott Knight)
Re: reading in dir names into an array. <cassell@mail.cor.epa.gov>
Re: Splitting length instead of delimiting character? (Larry Rosler)
the FAQ -- to split or not (was Re: FAQ 1.1: What is Pe <Russell_Schulz@locutus.ofB.ORG>
Re: Wanted: some help for a perl script <ebohlman@netcom.com>
Special: Digest Administrivia (Last modified: 12 Dec 98 (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Sat, 17 Apr 1999 20:39:38 +0200
From: Stefan Pochmann <pochmann@gmx.de>
Subject: "mixed"-Quantifier available ?
Message-Id: <3718D56A.3F06@gmx.de>
Hi there,
I'd like to have a regular expression for the following problem:
It shall recognize a sequence of (unordered) tokens, but at most one of
each, like:
(a?b?c?|a?c?b?|b?a?c?|b?c?a?|c?a?b?|c?b?a?)
I'd like to write this in a shorter form like:
(a|b|c)**
means: an alternation which removes each matched token.
Is there a simple way to do that ?
--
"I hope the Red Sox win the championship,"
Stefan Pochmann
eMail: pochmann@gmx.de
WWW: http://www.student.informatik.tu-darmstadt.de/~pochmann
------------------------------
Date: Sat, 17 Apr 1999 19:54:50 GMT
From: "W. Thompson" <wthompso@bbn.com>
Subject: array names same as file names
Message-Id: <3718E70A.AF6842B7@bbn.com>
I have a directory of files: dog, armadillo, horse. It is a dynamic
directory, so that files may quietly appear or disappear at any time.
Perhaps 'moose' gets added.
I am trying to create arrays in perl that use the names of the files:
@dog, @cat, @horse, @moose (when it shows up), whose elements are the
lines from each file.
@dog = contents of file dog
@armadillo = contents of file armadillo, etc.
I want to be able to accomodate the dynamic nature of the files'
directory.
Creating a list (array) of the file names is not a problem, but how do I
create the arrays based on the filenames? Then how do I read those files
into their appropriate arrays, such that @dog's elements are the lines
from the file 'dog'? I can't seem to get the array naming to work, and
can't seem to find the right syntax to loop through the files and assign
them to their eponymous arrays.
I can, of course, do each one explicitly, but then I'm constantly having
to check for new files, or the removal of old ones. And my sense is
that I want to loop through an array to do this, but then I get confused
trying to treat a scalar as an array (or, perhaps, an array as a
scalar), and so have got quite lost in trying to solve this. I have
woven a tangled web, and I'm not even trying to deceive anybody!
Examples, or pointers to pertinent examples in the O'Reilly books (or, I
fear, the FAQ) would be appreciated.
Bill
------------------------------
Date: Sat, 17 Apr 1999 13:26:26 -0700
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: array names same as file names
Message-Id: <MPG.11828e44a6b6c2ae9898cf@nntp.hpl.hp.com>
[Posted and a courtesy copy sent.]
In article <3718E70A.AF6842B7@bbn.com> on Sat, 17 Apr 1999 19:54:50 GMT,
W. Thompson <wthompso@bbn.com> says...
> I have a directory of files: dog, armadillo, horse. It is a dynamic
> directory, so that files may quietly appear or disappear at any time.
> Perhaps 'moose' gets added.
>
> I am trying to create arrays in perl that use the names of the files:
> @dog, @cat, @horse, @moose (when it shows up), whose elements are the
> lines from each file.
This seems to be the theme of the week! You don't want to create
variable names this way. Look back over this week's postings to see
why.
Briefly: Make a hash, the keys of which are the names of the files, and
each value of which is a reference to an anonymous array, which you
populate from each file as you planned to. Then the keys() function
will list the active names, etc.
For more info and examples, read perlref and perldsc.
--
(Just Another Larry) Rosler
Hewlett-Packard Company
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: Sat, 17 Apr 1999 20:44:33 GMT
From: Eric Bohlman <ebohlman@netcom.com>
Subject: Re: array names same as file names
Message-Id: <ebohlmanFACpM9.9LI@netcom.com>
W. Thompson <wthompso@bbn.com> wrote:
: I have a directory of files: dog, armadillo, horse. It is a dynamic
: directory, so that files may quietly appear or disappear at any time.
: Perhaps 'moose' gets added.
: I am trying to create arrays in perl that use the names of the files:
: @dog, @cat, @horse, @moose (when it shows up), whose elements are the
: lines from each file.
: @dog = contents of file dog
: @armadillo = contents of file armadillo, etc.
You're barking up the wrong alley.
: I want to be able to accomodate the dynamic nature of the files'
: directory.
The way you do that is to create a hash of arrays, where the hash keys
are the file names. Back in the bad old days of Perl 4, you'd have had
to resort to the sort of trickery you're having trouble with, but Perl 5
provides real references.
: Creating a list (array) of the file names is not a problem, but how do I
: create the arrays based on the filenames? Then how do I read those files
: into their appropriate arrays, such that @dog's elements are the lines
: from the file 'dog'? I can't seem to get the array naming to work, and
: can't seem to find the right syntax to loop through the files and assign
: them to their eponymous arrays.
foreach $file (@filenames) {
open (FILE,$file) or die "couldn't open $file: $!";
@{$files{$file}}=<FILE>;
close (FILE);
}
------------------------------
Date: 17 Apr 1999 14:54:18 -0700
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: array names same as file names
Message-Id: <3718f4fa@cs.colorado.edu>
[courtesy cc of this posting sent to cited author via email]
In comp.lang.perl.misc, "W. Thompson" <wthompso@bbn.com> writes:
:I have a directory of files: dog, armadillo, horse. It is a dynamic
:directory, so that files may quietly appear or disappear at any time.
:Perhaps 'moose' gets added.
:
:I am trying to create arrays in perl that use the names of the files:
:@dog, @cat, @horse, @moose (when it shows up), whose elements are the
:lines from each file.
:
:@dog = contents of file dog
:@armadillo = contents of file armadillo, etc.
This is what, the fourth one this week? How many times do I have to
post this? Every day? Twice a day? Ever hour? Why is it that people
keep wanting to do the wrong thing?
You do *not* want the variable *NAMES* to vary. You are confused.
You want instead to use a hash of arrays.
for $critter ( qw(aardwolf armadillo ankylosaur) ) {
@{ $hash{"dog"} } = do { local @ARGV = ("$DIR/$critter"); <> };
}
--tom
=head2 How can I use a variable as a variable name?
Beginners often think they want to have a variable contain the name
of a variable.
$fred = 23;
$varname = "fred";
++$$varname; # $fred now 24
This works I<sometimes>, but it is a very bad idea for two reasons.
The first reason is that they I<only work on global variables>.
That means above that if $fred is a lexical variable created with my(),
that the code won't work at all: you'll accidentally access the global
and skip right over the private lexical altogether. Global variables
are bad because they can easily collide accidentally and in general make
for non-scalable and confusing code.
Symbolic references are forbidden under the C<use strict> pragma.
They are not true references and consequently are not reference counted
or garbage collected.
The other reason why using a variable to hold the name of another
variable a bad idea is that the question often stems from a lack of
understanding of Perl data structures, particularly hashes. By using
symbolic references, you are just using the package's symbol-table hash
(like C<%main::>) instead of a user-defined hash. The solution is to
use your own hash or a real reference instead.
$fred = 23;
$varname = "fred";
$USER_VARS{$varname}++; # not $$varname++
There we're using the %USER_VARS hash instead of symbolic references.
Sometimes this comes up in reading strings from the user with variable
references and wanting to expand them to the values of your perl
program's variables. This is also a bad idea because it conflates the
program-addressable namespace and the user-addressable one. Instead of
reading a string and expanding it to the actual contents of your program's
own variables:
$str = 'this has a $fred and $barney in it';
$str =~ s/(\$\w+)/$1/eeg; # need double eval
Instead, it would be better to keep a hash around like %USER_VARS and have
variable references actually refer to entries in that hash:
$str =~ s/\$(\w+)/$USER_VARS{$1}/g; # no /e here at all
That's faster, cleaner, and safer than the previous approach. Of course,
you don't need to use a dollar sign. You could use your own scheme to
make it less confusing, like bracketed percent symbols, etc.
$str = 'this has a %fred% and %barney% in it';
$str =~ s/%(\w+)%/$USER_VARS{$1}/g; # no /e here at all
Another reason that folks sometimes think they want a variable to contain
the name of a variable is because they don't know how to build proper
data structures using hashes. For example, let's say they wanted two
hashes in their program: %fred and %barney, and to use another scalar
variable to refer to those by name.
$name = "fred";
$$name{WIFE} = "wilma"; # set %fred
$name = "barney";
$$name{WIFE} = "betty"; # set %barney
This is still a symbolic reference, and is still saddled with the
problems enumerated above. It would be far better to write:
$folks{"fred"}{WIFE} = "wilma";
$folks{"barney"}{WIFE} = "betty";
And just use a multilevel hash to start with.
The only times that you absolutely I<must> use symbolic references are
when you really must refer to the symbol table. This may be because it's
something that can't take a real reference to, such as a format name.
Doing so may also be important for method calls, since these always go
through the symbol table for resolution.
In those cases, you would turn off C<strict 'refs'> temporarily so you
can play around with the symbol table. For example:
@colors = qw(red blue green yellow orange purple violet);
for my $name (@colors) {
no strict 'refs'; # renege for the block
*$name = sub { "<FONT COLOR='$name'>@_</FONT>" };
}
All those functions (red(), blue(), green(), etc.) appear to be separate,
but the real code in the closure actually was compiled only once.
So, sometimes you might want to use symbolic references to directly
manipulate the symbol table. This doesn't matter for formats, handles, and
subroutines, because they are always global -- you can't use my() on them.
But for scalars, arrays, and hashes -- and usually for subroutines --
you probably want to use hard references only.
--
"A well-written program is its own heaven;
a poorly-written program is its own hell."
------------------------------
Date: Sat, 17 Apr 1999 14:15:18 -0700
From: David Cassell <cassell@mail.cor.epa.gov>
Subject: Re: blank form fields
Message-Id: <3718F9E6.81F03040@mail.cor.epa.gov>
mikej wrote:
>
> Hi,
>
> I need a way of telling if someone left a form text field blank. I tried
> this:
>
> if (defined $survey_form{'comments_need_for_solutions_brochures'}) {
> $solbro_comments = $solbro_comments + 1;
> }
>
> but even when I leave that text field blank and submit the form, the
> script will see the
> defined statement as true and increment the $solbro_comments variable
> when its not
> supposed to. I only want it to increment $solbro_comments if the text
> field had
> something entered into it. Any tips?
Yes. defined() doesn't work like this on hashes and arrays. On a
hash element, it only tells you whether the value is defined. NOT
whether the key has an entry in the hash table.
If you had read the perlfunc section, it would have told you this,
and even told you what the answer is. Try using exists() instead.
Another tip: overuse of defined() leads to embarrassing glitches.
Did you know that the number 0 and the zero-length string "" are
both defined values? False, but defined.
And check into perldoc. Type 'perldoc -f defined' at your command
prompt, and enjoy one of the many benefits of a language with
extensive documentation.
David
--
David Cassell, OAO
cassell@mail.cor.epa.gov
Senior Computing Specialist phone: (541)
754-4468
mathematical statistician fax: (541)
754-4716
------------------------------
Date: Sat, 17 Apr 1999 19:00:17 +0100
From: "Wayne Keenan" <tripix@tdi-net.freeserve.co.uk>
Subject: Re: Can i run cgi in Win95 of my PC ??
Message-Id: <7faj0h$7ns$1@news7.svr.pol.co.uk>
Daniel Grisinger wrote in message ...
>some bozo with entirely too many useless characters in his name writes:
>
>> Can i run cgi in Win95 of my PC ??
>
>Yes, of course.
>
>> ( I have no Network Card, and i really do not want to buy one
>> because of this reason. )
>
>Ohhh, never mind. You can't do it without ethernet.
>
>In fact, the first thing that perl does when it is invoked by a
>webserver is verify that there is a functional ethernet card on the
>machine. If there isn't perl exits instantly with an obscure
>error message.
>
The error is usally caused by Micro$hites Personal Web server in Windoze 9x,
a patch is available from: www.apache.org
beans,
Wayne.
------------------------------
Date: Sat, 17 Apr 1999 20:35:20 GMT
From: rick@marinweb.com (Rick Freeman)
Subject: Close pipe to sendmail?
Message-Id: <3718ef04.26655491@nntp1.ba.best.com>
What are the advantages and disadvantages of closing or not closing a
pipe/filehandle to sendmail in a loop that sends a few hundred email
messages?
Rick
------------------------------
Date: Sat, 17 Apr 1999 14:30:00 -0700
From: David Cassell <cassell@mail.cor.epa.gov>
Subject: Re: Help! I can't create an error response from this script
Message-Id: <3718FD58.F4BB0670@mail.cor.epa.gov>
David Efflandt wrote:
>
> On Mon, 12 Apr 1999 23:46:59 +0100, Gareth Jones
> <gcd_jones@dial.pipex.com> wrote:
> >Is there any way of getting this script to display HTML code on an error
> >e.g. if the smtp server unavailable, rather than a blank page!
> >
> >Please Help...
>
> (snip)
> > die $!;
>
> Better to output something useful than die without warning. Many of us do
> not have access to server logs.
>
> You could create an 'error' sub and use that to print a useful html error
> message before it exits. For example if you used &error("Can't open
> socket",$!) instead of die $!, you can retrieve passed parameters from @_
> in the error sub like:
>
> my ($msg, $err) = @_;
Actually, there's an easier way. Since this is Perl, I'll bet you're
surprised by that statement. You should:
use CGI::Carp qw(fatalsToBrowser); # watch the capitals here!
die "error number 17 here ...";
Fatal errors are now echoed to the browser, in addition to the log.
So you don't need access to the server log. And the carpout()
function from the same module will echo non-fatal errors to the
filehandle of your choice.
David
--
David Cassell, OAO
cassell@mail.cor.epa.gov
Senior Computing Specialist phone: (541)
754-4468
mathematical statistician fax: (541)
754-4716
------------------------------
Date: Sat, 17 Apr 1999 20:19:34 +0200
From: Vladimir Petr <petr@datasys.cz>
Subject: Re: How to install Perl onto a machine with no C compiler
Message-Id: <3718D0B6.BD46A515@datasys.cz>
<!doctype html public "-//w3c//dtd html 4.0 transitional//en">
<html>
Look at <A HREF="http://www.bull.de">http://www.bull.de</A>. There is an AIX software archive containing
many installp packages and Perl amongst them. You can install them easily
through smit.
<p>--vp
<p>Philip Nelson wrote:
<blockquote TYPE=CITE>I've successfully built and tested Perl 5.005.03
on our development AIX server.
<p>I now want to implement the same level onto our production server, which
doesn't have a C compiler (or any development tools for that matter).
<p>Therefore I can't use the standard make based installation procedure.
<p>How should I go about putting Perl onto this server ?
<p>TIA
<p>Philip Nelson
<br>(pandp@ibm.net)
<p>Using OS/2 Warp and PMINews</blockquote>
</html>
------------------------------
Date: Sat, 17 Apr 1999 15:09:02 -0500
From: "William H. Asquith" <asquith@macconnect.com>
Subject: ifeither--How about some feedback?
Message-Id: <7faq6c$tag@enews3.newsguy.com>
All,
Working today with the following.
my ($a, $b, $c, $d, $e, $f);
while(1) {
## do some stuff
last if($a < 4 || $b < 4 || $c || < 4 || $d < 4 || $f < 4);
}
I would love to shorten the above 'last if' test with one that is shorter,
here is a suggestion.
while(1) {
## do some stuff
last ifeither($a, $b, $c, $d, $e, $f < 0); # suggested form
}
ifeither could be generalized to
ifeither($a, $b, $c, $d, $e, $f <= $value || $b, $c); # etc. . .
I know that there isn't an ifeither in Perl, but such a function would be
_very_readable_ indeed.
What other idioms do you all use for the above situation? Please comment,
maybe there are already better ways?
-wha
------------------------------
Date: Sat, 17 Apr 1999 23:54:22 +0200
From: Ian Berwick <ianb@zedat.fu-berlin.de>
Subject: Looking for better ways of solving a pattern matching and replacement task...
Message-Id: <Pine.SGI.3.96.990417232408.21073A-100000@Komma.ZEDAT.FU-Berlin.DE>
Short: is there a more elegant solution to the following problem?
Long:
I'm writing a script to translate a given text from 'human' to 'sheep' -
in other words a script which will convert all the words of a string to
something equivalent to 'baah'. Don't ask why - there's a perfectly
ludicrous reason, and I'm not going to embarrass myself by explaining it
here ;-).
The script should change the first letter of each word to 'b', the last
letter to 'h' and all letters inbetween to 'a', whereby the case of each
letter should be retained. All other characters should remain unchanged.
In the case of words with only one letter, these should become 'b'.
Thus:
"Hello World" should become "Baaah Baaah" and
"HELLO! This is a COMPuteR?" should become "BAAAH! Baah bh b BAAAaaaH?"
Below is my initial solution, which performs its ovine deeds on '$text'.
In the interests of programming efficiency, elegance etc. etc., are there
any ways of doing same which are shorter / so blindingly obvious I should
be whacking myself on my forehead etc.? Also, how can I get s/// to
recognize that the first character in the string is also the first letter
of a word?
Yours in sheepish ignorance
Ian Berwick
#!/usr/bin/perl
# Silly script to translate from Human to Sheep
$text = "Put an example 'Text' here!\n";
print $text;
# Change all chars to a/A
$text =~ s/[a-z]/a/g;
$text =~ s/[A-Z]/A/g;
# Change all word endings to h/H
$text =~ s/[a-z]([\W])/h$1/g;
$text =~ s/[A-Z]([\W])/H$1/g;
# Change beginning of all words to b/B
$text =~ s/([\W])[a-z]/$1b/g;
$text =~ s/([\W])[A-Z]/$1B/g;
# Display the result
print $text;
# Herewith ends the program
------------------------------
Date: Mon, 19 Apr 1999 03:11:22 +0800
From: Ken Mar <kenmar@ihug.co.nz>
Subject: Make problem in Win95
Message-Id: <371A2E5A.71E2955E@ihug.co.nz>
Hi all gurus,
I tried installing modules in my Win95. Performing the perl
Makefile.PL was successful but the other 3 steps just couldn't proceed.
Am I missing something? How do one do make, make install and the rest of
it in Win95?
Thanks.
-Ken
------------------------------
Date: Mon, 19 Apr 1999 03:12:18 +0800
From: Ken Mar <kenmar@ihug.co.nz>
Subject: Make problem in Win95
Message-Id: <371A2E92.80002C99@ihug.co.nz>
Hi all gurus,
I tried installing modules in my Win95. Performing the perl
Makefile.PL was successful but the other 3 steps just couldn't proceed.
Am I missing something? How do one do make, make install and the rest of
it in Win95?
Thanks.
-Ken
------------------------------
Date: 17 Apr 1999 16:31:46 -0400
From: Uri Guttman <uri@home.sysarch.com>
Subject: Re: New FAQ: How can I read in an entire file all at once?
Message-Id: <x7yajrkmz1.fsf@home.sysarch.com>
>>>>> "DG" == Daniel Grisinger <dgris@moiraine.dimensional.com> writes:
>> 2. If you are reading (or writing) from more than one file at the same
>> time, you'll probably find that reading/writing entire files is always
>> much faster than reading/writing them line by line.
DG> If you are reading from and writing to several files simultaneously
DG> you should be using 4 arg select for I/O multiplexing, you shouldn't
DG> just be reading everything into memory. Once again, the problem is
DG> that any program that requires all files to be held in memory won't
DG> scale.
select doesn't work on regular files, only on sockets, pipes and
tty's. regular files are effectively always ready for i/o so they
wouldn't block on select.
and why can't you read from multiple files line by line at the same
time? just use multiple file handles, either named or created and stored
in some structure.
slurping in whole files vs. line by line is a decision that needs to be
made knowing the maximum size of the file, how it needs to be processed,
speed of the program, etc. there is no absolute answer to which is
better. i have used both many times. in fact i have my own little set of
read_file/write_file subs to handle whole file slurping. there was a
thread about this a few months ago (maybe it was on clp.moderated).
uri
--
Uri Guttman ----------------- SYStems ARCHitecture and Software Engineering
uri@sysarch.com --------------------------- Perl, Internet, UNIX Consulting
Have Perl, Will Travel ----------------------------- http://www.sysarch.com
The Best Search Engine on the Net ------------- http://www.northernlight.com
------------------------------
Date: Sat, 17 Apr 1999 12:01:58 -0700
From: "Dave Roth" <xrxoxtxhxdx@xrxoxtxhx.xnxextx>
Subject: Re: No clues to Win32::NetResource problem?
Message-Id: <6S4S2.5468$L66.453858@news1.giganews.com>
Schorschi Decker wrote in message
<7f917n$dr0$1@birch.prod.itd.earthlink.net>...
>Dave, Chuck, Anyone...
>
>What is the solution to the issues with NetResource Module? Is anyone
>working on a replacement? I would be glad to do so, but I am sure that
>somebody in the greater Perl Community could do a better job. I just have
>not spent that much time with Perl to be ready to write a module from
>scratch (yet).
I am unaware of any fix to this. A runtime exception is indicative of
some code going off and doing something it shouldn't. Typically a pointer
has not been reset or something silly. I've seem my fair share of them. ;)
Sometimes code has to take a chance to verify, for example, that an object
is indeed valid. But even then it could be wrapped in a try/catch.
You should submit this as a bug to the guys at ActiveState. Or better
yet if you want to look at the source consider patching it yourself
and submit the patch. :)
Cheers,
dave
--
=================================================================
Dave Roth ...glittering prizes and
Roth Consulting endless compromises, shatter
http://www.roth.net the illusion of integrity
Win32, Perl, C++, ODBC, Training
rothd at roth dot net
Our latest Perl book is now available:
"Win32 Perl Programming: The Standard Extensions"
http://www.roth.net/books/extensions/
------------------------------
Date: Sat, 17 Apr 1999 13:41:37 -0700
From: Michael Doss <michaeldoss@atre.net>
Subject: online user groups/resources
Message-Id: <3718F200.75DF43AD@atre.net>
I'm looking to hire experienced perl authors, but I don't want to bother
with online resume databases, or inaccurate web searches. Does anyone
know of any resources out there where I could find perl programmers in a
central location online, that wouldn't mind hearing about job postings?
The resource doesn't need to be employment specific, just anywhere where
perl programmers hang out.
Thanks.
Michael Doss
michaeldoss@atre.net
------------------------------
Date: Sat, 17 Apr 1999 19:47:00 GMT
From: pamelag@interlog.com (Pamela Goldfarb)
Subject: Parsing exported Access Text Files
Message-Id: <3718e4dd.362734940@news.interlog.com>
I am storing an exported access table on my web server. It is an ascii
file with comma delimited fields and with strings enclosed with "".
The strings can contain commas, quotation marks, and new-lines. There
can also be blank fields.
Example (each data record, has three fields: a numeric, followed by a
string, followed by a numeric)
123, "abc", 456,
124, "first word then
newline", 888,
125, "first word ""quoted"" end
,,,", 999
I want to create a perl script that can parse this data into an array
of fields that can then be searched, processed, etc. and the outputted
to a html file.
I am having trouble constucting the appropriate parsing code. In
particular the fact that there may be multiple lines in the datafile
that make up a whole data line. Hanlding the embedded quotmation marks
and commas is also presenting difficulty.
Since this is MS Access outputted data, I would think that perl code
to do what I want already exists, can someone
point me to where I can find such code?
Thanks!
------------------------------
Date: Sat, 17 Apr 1999 17:36:22 -0400
From: "Doug Crabtree" <not@gonna.tell>
Subject: Re: Parsing exported Access Text Files
Message-Id: <7fauts$e5j$1@camel15.mindspring.com>
I am no expert, but you might want to try something like this:
#!/usr/bin/perl
@entries = qw(Num1 Str1 Num2);
open(AFILE, "< access.txt") || die print "DOH! cannot open datafile.";
print ("<TABLE><TR><TD><B>Num1</TD><TD><B>Str1</TD><TD><B>Num2</TD></TR>");
while (<AFILE>)
{
@data{@entries} = split(/~/, $_, scalar @entries);
print ("<TD>" . $data{"Num1"} . "</TD>\n");
print ("<TD>" . $data{"Str1"} . "</TD>\n");
print ("<TD>" . $data{"Num2"} . "</TD>\n");
print ("</TR>\n");
}
print ("</TABLE>");
close AFILE;
If you export this table from Access, you will be able to change what the
delimeter is. In this case I chose the ~ symbol. You could use : if you
want or whatever. This will allow your Str1 to have anything except your
delimeter.
Hope this helps some :)
Doug
Pamela Goldfarb <pamelag@interlog.com> wrote in message
news:3718e4dd.362734940@news.interlog.com...
> I am storing an exported access table on my web server. It is an ascii
> file with comma delimited fields and with strings enclosed with "".
>
> The strings can contain commas, quotation marks, and new-lines. There
> can also be blank fields.
>
> Example (each data record, has three fields: a numeric, followed by a
> string, followed by a numeric)
>
> 123, "abc", 456,
> 124, "first word then
> newline", 888,
> 125, "first word ""quoted"" end
> ,,,", 999
>
> I want to create a perl script that can parse this data into an array
> of fields that can then be searched, processed, etc. and the outputted
> to a html file.
>
> I am having trouble constucting the appropriate parsing code. In
> particular the fact that there may be multiple lines in the datafile
> that make up a whole data line. Hanlding the embedded quotmation marks
> and commas is also presenting difficulty.
>
> Since this is MS Access outputted data, I would think that perl code
> to do what I want already exists, can someone
> point me to where I can find such code?
>
> Thanks!
------------------------------
Date: Sat, 17 Apr 1999 14:38:15 -0400
From: Russell Schulz <Russell_Schulz@locutus.ofB.ORG>
Subject: PSI::ESP module reliability (was Re: Best books to use...)
Message-Id: <19990417.143815.5A6.rnr.w164w@locutus.ofB.ORG>
David Cassell <cassell@mail.cor.epa.gov> writes:
> But I [chose my name] before I was born. I used the
> alpha-alpha version of Perl's PSI::ESP module. It worked that
> once, but still isn't too reliable. :-)
You need to use the previous version; they get better the earlier you go.
--
Russell_Schulz@locutus.ofB.ORG Shad 86c
------------------------------
Date: Sat, 17 Apr 1999 20:56:29 GMT
From: me@here.com
Subject: Q: Removing file extentions
Message-Id: <3718f058.27190495@nntp.noc.netcom.net>
I have made a cgi script which will take the contents of my
website and format it into webpages on the fly but in doing so I have
come across the problem of removing extensions. The following is the
syntax used presently but I found that it will remove everything after
the first instance of the period and not the desired last.
$link =~ s/\..*//;
ex: something.zip transforms into something without the .zip
Now this isn't a problem for 99.9 percent of the files but
there are a small few that have multiple periods. In these cases the
link users see has been truncated:
ex: something 1.0.zip transforms into something missing the 1.0
Does anyone have a sly method (must be CPU friendly, some of
these directories hold 2,000 files) which will remove only the last
instance of a period and any characters following?
Thanks for any assistance,
-jeremy
jeremy.witt@cacheflow.com
------------------------------
Date: Sat, 17 Apr 1999 14:03:21 -0500
From: mknight@en.com (Scott Knight)
Subject: question about format and write
Message-Id: <mknight-1704991403210001@p11-clv-ts4.en.net>
Ok, i got a question, and if anyone would help me, it'd be awsome. I
understand how to use format and write, but i'm not getting what i want
from it. I am maintaing a database with numbers and such, and i need each
line to be the exact same lenght, which is why i chose to use format. here
is a short example of my format.
format LOG =
@<<<<<<< , @<<<<<<<<<, @<<<<
$date,$time,$temperature
.
and my log file looks something like this, again its only a short snippet
there are a lot more things that are written to the file.
"date" , "time" , "temp"
04/17 , 12:34 , 41
heres my problem.
after i write to the log file, the lines arent the same length. i want
that last feild to print spaces after 41 so that the second line is
exactly the same length as the first, but for some reason, it always jumps
to a new line after the alst variable and doesnt fill the rest of the
space with spaces. How do i fix this? I suppose i could right justify
things and it would work fine, but i would much rather keep it left
justified. Can anyone help me? A'm i describing my problem clearly enough?
Thanks in advance.
Scott Knight
------------------------------
Date: Sat, 17 Apr 1999 14:22:50 -0700
From: David Cassell <cassell@mail.cor.epa.gov>
Subject: Re: reading in dir names into an array.
Message-Id: <3718FBAA.2D87BA3A@mail.cor.epa.gov>
Earl Hood wrote:
>
> In article <37161CCB.760E121E@harris.com>, George <dscapin@harris.com> wrote:
> >I was using the command @array = <*.jpg> to read all jpg files in the
> >current directory into the array. This worked fine until I put the
> >program on a server (NT). I was developing on win98. How come this
> >command won't work on the NT server? What is another way of doing
> >this. Thank you.
>
> Look into the opendir, readdir, and closedir operators. Also
> check out the grep operator since it can be used to help extract
> specific filenames via regex.
The problem is that Win32's shell doesn't have the functionality of
the common Unix shells. You can dodge the issue by using the
File::DosGlob module - which comes with ActiveState Perl, so you
probably already have it.
HTH,
David
--
David Cassell, OAO
cassell@mail.cor.epa.gov
Senior Computing Specialist phone: (541)
754-4468
mathematical statistician fax: (541)
754-4716
------------------------------
Date: Sat, 17 Apr 1999 11:13:17 -0700
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: Splitting length instead of delimiting character?
Message-Id: <MPG.11826f095ca6dd0a9898ce@nntp.hpl.hp.com>
[Posted and a courtesy copy sent.]
Why did I get four postings of this message?
In article <3718C2EB.80CB147E@falukuriren.se> on Sat, 17 Apr 1999
19:20:43 +0200, Mats Pettersson <mats.pettersson@falukuriren.se> says...
...
> Is there som sort of '@fields = split_size /7,4,4,4.../' command in
> perl?
perldoc -f unpack
A format string like 'A7 A4 A4 A4 ...' should do what you want.
--
(Just Another Larry) Rosler
Hewlett-Packard Company
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: Sat, 17 Apr 1999 14:10:59 -0400
From: Russell Schulz <Russell_Schulz@locutus.ofB.ORG>
Subject: the FAQ -- to split or not (was Re: FAQ 1.1: What is Perl?)
Message-Id: <19990417.141059.1y7.rnr.w164w_-_@locutus.ofB.ORG>
stanley@skyking.OCE.ORST.EDU (John Stanley) writes:
> Instead of splitting the FAQs up into little pieces and stuffing them
One advantage of having them in little pieces is that followups to them,
intended to improve the FAQs, have the correct Subject: headers on them,
and are easier to distinguish.
Unfortunately, we lost that advantage with your followup. I have rectified.
--
Russell_Schulz@locutus.ofB.ORG Shad 86c
------------------------------
Date: Sat, 17 Apr 1999 19:46:13 GMT
From: Eric Bohlman <ebohlman@netcom.com>
Subject: Re: Wanted: some help for a perl script
Message-Id: <ebohlmanFACMx2.4Ey@netcom.com>
Marc Herms <marc@mercator.net> wrote:
: I have just bought a perl script for site-news and would like to make
: some changes. Because I don`t want to bother the company where I
: bougth the script, I`d like to have some help from one of you.
: If someone has some spare time and would like to help me with just
: some small things for free, please let me know.
: It4s really a small thing.
When I was a kid, I watched a short TV cartoon about a town where
everything happened backwards. I remember that I enjoyed it
tremendously, but I can only remember two scenes:
1) A bunch of people get off a train at a station. Then the station
pulls away, leaving the train sitting in the middle of nowhere.
2) Someone's house starts spurting water out all the windows. A fire
truck pulls up and sets the house on fire.
It seems to me that the logic you're using would fit quite nicely in that
town. You've paid out some of your hard-earned money for that script.
You paid that money to someone who knows more about that script than
anyone else does. As a general rule:
1) Someone who takes your money incurs certain obligations to you.
2) Someone who created a script is in a better position to tweak it than
someone who's just seen it for the first time in his life.
With all that in mind, you have somehow come to the opinion that you
would prefer that the changes be made by someone who:
1) Is under no obligation to you.
2) Isn't familiar with the script.
3) Will not be compensated for the time to become familiar with the
script and to make changes.
I'm guessing that this script is supposed to provide some facility,
possibly a critical one, on a Web site that you're responsible for.
There's a lot about the mindset of many Web designers that I can't
understand, but the desire to have a possibly critical facility under the
control of some unqualified and unobligated person goes even beyond that.
------------------------------
Date: 12 Dec 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 Dec 98)
Message-Id: <null>
Administrivia:
Well, after 6 months, here's the answer to the quiz: what do we do about
comp.lang.perl.moderated. Answer: nothing.
]From: Russ Allbery <rra@stanford.edu>
]Date: 21 Sep 1998 19:53:43 -0700
]Subject: comp.lang.perl.moderated available via e-mail
]
]It is possible to subscribe to comp.lang.perl.moderated as a mailing list.
]To do so, send mail to majordomo@eyrie.org with "subscribe clpm" in the
]body. Majordomo will then send you instructions on how to confirm your
]subscription. This is provided as a general service for those people who
]cannot receive the newsgroup for whatever reason or who just prefer to
]receive messages via e-mail.
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 5407
**************************************