[12738] in Perl-Users-Digest
Perl-Users Digest, Issue: 148 Volume: 9
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Jul 15 01:07:37 1999
Date: Wed, 14 Jul 1999 22:05:14 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Wed, 14 Jul 1999 Volume: 9 Number: 148
Today's topics:
Re: # of days between 2 dates (again) (Iain Chalmers)
[ANNOUNCE Ima::DBI 0.09] <schwern@pobox.com>
Re: bug in vars.pm? (Tad McClellan)
Re: bug in vars.pm? <dgris@moiraine.dimensional.com>
Re: C-like #define macros in Perl <uri@sysarch.com>
Re: C-like #define macros in Perl (brian d foy)
Re: Can I do this? <richj@home.com>
Re: Can I do this? <richj@home.com>
Re: can't match $ (Tad McClellan)
Re: CGI.pm and redirect <tungyat@yahoo.com>
Re: checking Perl offline <Tim.Potter@anu.edu.au>
Re: Como ler un directorio... (Larry Rosler)
crypt() doesn't decrypt <qwerty@post.utfors.se>
Re: crypt() doesn't decrypt (Larry Rosler)
difference between my and local? <qwerty@post.utfors.se>
Re: difference between my and local? <aperrin@mcmahon.qal.berkeley.edu>
Re: difference between my and local? (Larry Rosler)
Re: file to array ? <rick.delaney@home.com>
Re: file to array ? (Matthew Bafford)
Re: file to array ? (Martien Verbruggen)
Re: Filter Websides Under WIN95/98/NT (David Whitmarsh)
help with line feeds <khowe@performance-net.com>
Digest Administrivia (Last modified: 1 Jul 99) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Thu, 15 Jul 1999 14:41:39 +1000
From: bigiain@mightymedia.com.au (Iain Chalmers)
Subject: Re: # of days between 2 dates (again)
Message-Id: <bigiain-1507991441400001@bigman.mighty.aust.com>
abigail promised:
> (there will be free rabbit stew at The Perl Conference (TPC)).
Cool! Rabbit stew! I'll book my place now, see you there :-)
big
------------------------------
Date: Wed, 14 Jul 1999 00:49:24 -0400
From: Michael G Schwern <schwern@pobox.com>
Subject: [ANNOUNCE Ima::DBI 0.09]
Message-Id: <140719990049244071%schwern@pobox.com>
Ima::DBI version 0.09 just released to CPAN. I made a major
performance improvement.
THIS IS ALPHA CODE! Its interface is still changing, and I expect the
name of the package to change soon (probably to Class::DBI).
What follows is the revision history of the module along with an
excerpt from the man page.
0.09 Tue Jul 13 23:59:56 EDT 1999
- Major performance improvement by drasticly reducing # of
calls to
DBI::connect_cached.
0.08 Wed Jun 30 16:16:16 EDT 1999
* Spaces in names of statements and database (sql_ and db_) are
now
translate to underscores.
0.07 Tue May 19 20:58:02 EDT 1999
- Cleaning up use of DBI's tainting features.
0.06 Sat May 8 03:50:34 EDT 1999
- Implements data tainting via DBI->{Taint} (Thanks, Tim!)
0.05 Tue May 4 22:08:56 EDT 1999
* code for tainting fetched data added
- taint check repaired, but still incomplete.
- manual tainting repaired, but still incomplete.
0.04 Mon May 3 22:14:02 EDT 1999
- tests added
- parts still imcomplete
- usable, I guess.
0.04pre Fri Apr 30 20:10:38 EDT 1999
* PRE RELEASE, UNTESTED
* Complete re-write from the ground up.
* Major API changes. See docs.
* taint added
* Requires DBI 1.06
* Parts still incomplete
0.03 I forget
* BROKEN BROKEN BROKEN!
0.01 Fri Apr 3 19:19:48 1998
- original version; created by h2xs 1.18
NAME
Ima::DBI - Database connection caching and organization
SYNOPSIS
# Class-wide methods.
__PACKAGE__->set_db($db_name, $data_source, $user, $password);
__PACKAGE__->set_db($db_name, $data_source, $user, $password,
\%attr);
__PACKAGE__->set_sql($sql_name, $statement, $db_name);
# Object methods.
$dbh = $obj->db_*; # Where * is the name of the db
connection.
$sth = $obj->sql_*; # Where * is the name of the sql
statement.
$rc = $obj->commit; #UNIMPLEMENTED
$rc = $obj->commit(@db_names); #UNIMPLEMENTED
$rc = $obj->rollback; #UNIMPLEMENTED
$rc = $obj->rollback(@db_names); #UNIMPLEMENTED
$obj->clear_db_cache; #UNIMPLEMENTED
$obj->clear_db_cache(@db_names); #UNIMPLEMENTED
$obj->clear_sql_cache; #UNIMPLMENTED
$obj->clear_sql_cache(@sql_names); #UNIMPLMENTED
$obj->DBIwarn;
$dbh->clear_cache; #UNIMPLEMENTED
# Modified statement handle methods.
$rv = $sth->execute;
$rv = $sth->execute(@bind_values);
$rv = $sth->execute(\@bind_values, \@bind_cols);
$row_ref = $sth->fetch;
@row = $sth->fetch;
$row_ref = $sth->fetch_hash;
%row = $sth->fetch_hash;
$rows_ref = $sth->fetchall;
@rows = $sth->fetchall;
$rows_ref = $sth->fetchall_hash;
@tbl = $sth->fetchall_hash;
$sth->clear_cache; #UNIMPLEMENTED
DESCRIPTION
Ima::DBI attempts to organize and facilitate caching and more
efficient use of database connections and statement handles.
One of the things I always found annoying about writing large
programs with DBI was making sure that I didn't have duplicate
database handles open. I was also annoyed by the somewhat
wasteful nature of the prepare/execute/finish route I'd tend to
go through in my subroutines. The new DBI->connect_cached and
DBI->prepare_cached helped alot, but I still had to throw around
global datasource, username and password information.
So, after a while I grew a small library of DBI helper routines
and techniques. Ima::DBI is the culmination of all this, put
into a nice(?), clean(?) class to be inherited from.
Why should I use this thing?
Ima::DBI is a little odd, and it's kinda hard to explain. So
lemme explain why you'd want to use this thing...
* Consolidation of all SQL statements and database information
No matter what, embedding one language into another is
messy. DBI alleviates this somewhat, but I've found a
tendency to have that scatter the SQL around inside the Perl
code. Ima::DBI allows you to easily group the SQL statements
in one place where they are easier to maintain (especially
if one developer is writing the SQL, another writing the
Perl). Alternatively, you can place your SQL statement
alongside the code which uses it. Whatever floats your boat.
Database connection information (data source, username,
password, atrributes, etc...) can also be consolidated
together and tracked.
Both the SQL and the connection info are probably going to
change alot, so having them well organized and easy to find
in the code is a Big Help.
* Holds off opening a database connection until necessary.
While Ima::DBI is informed of all your database connections
and SQL statements at compile-time, it will not connect to
the database until you actually prepare a statement on that
connection.
This is obviously very good for programs that sometimes
never touch the database. It's also good for code that has
lots of possible connections and statements, but which
typically only use a few. Kinda like an autoloader.
* Easy integration of the DBI handles into your class
Ima::DBI causes each database handle to be associated with
your class, allowing you to pull handles from an instance of
your object, as well as making many oft-used DBI methods
available directly from your instance.
This gives you a cleaner OO design, since you can now just
throw around the object as usual and it will carry its
associated DBI baggage with it.
* Honors taint mode
It always struck me as a design deficiency that tainted SQL
statements could be passed to $sth->prepare(). For example:
# $user is from an untrusted source and is tainted. $user =
get_user_data_from_the_outside_world; $sth = $dbh-
>prepare('DELETE FROM Users WHERE User = $user'); Looks
innocent enough... but what if $user was the string "1 OR
User LIKE %". You just blew away all your users, hope you
have backups.
Ima::DBI turns on the DBI->connect Taint attribute so that
all DBI methods will no longer accept tainted data. See the
DBI manpage for details.
* Taints returned data
Databases should be like any other system call. Its the
scary Outside World, thus it should be tainted. Simp.
Ima::DBI turns on DBI's Taint attribute on each connection.
This feature is overridable by passing your own Taint
attribute to set_db as normal for DBI. See "Taint" in the
DBI man page for details.
* Encapsulation of some of the more repetative bits of everyday DBI
usage
I get lazy alot and I forget to do things I really should,
like using bind_cols(), or rigorous error checking. Ima::DBI
does some of this stuff automatic, other times it just makes
it more convenient.
* Encapsulation of DBI's cache system
DBI's automatic handle caching system is relatively new,
some people aren't aware of its use. Ima::DBI uses it
automatically, so you don't have to worry your pretty little
head about it.
* Sharing of database and sql information amongst inherited classes
Any SQL and connections created by a class is available to
its children via normal method inheritance.
* Convenience and orthoganality amongst statement handle methods
It always struck me odd that DBI didn't take much advantage
of Perl's context sensitivity. Ima::DBI redefines some of
the various fetch methods to fix this oversight; it also
adds a few new methods for convenience.
* Guarantees one connection per program.
One program, one database connection (per database user).
One program, one prepared statement handle (per statement,
per database user). That's what Ima::DBI enforces. Extremely
handy in persistant environments (servers, daemons,
mod_perl, FastCGI, etc...)
* Encourages use of bind parameters and columns
Bind parameters are safer and more efficient than embedding
the column information straight into the SQL statement. Bind
columns are more efficient than normal fetching. Ima::DBI
pretty much requires the usage of the former, and eases the
use of the latter.
Why shouldn't I use this thing.
* It's all about OO
Although it is possible to use Ima::DBI as a stand-alone
module as part of a function-oriented design, its generally
not to be used unless integrated into an object-oriented
design.
* Overkill for small programs
* Overkill for programs with only one or two SQL statements
* Overkill for programs that only use their SQL statements once
Ima::DBI's caching will probably prove to be an unecessary
performance hog if you never use the same SQL statement
twice.
EXAMPLE
package Foo;
use base qw(Ima::DBI);
# Set up database connections (but don't connect yet)
__PACKAGE__->set_db('Users', 'dbi:Oracle:Foo', 'admin', 'passwd');
__PACKAGE__->set_db('Customers', 'dbi:Oracle:Foo', 'Staff',
'passwd');
# Set up SQL statements to be used through out the program.
__PACKAGE__->set_sql('FindUser', <<"SQL", 'Users');
SELECT *
FROM Users
WHERE Name LIKE ?
SQL
__PACKAGE__->set_sql('ChangeLanguage', <<"SQL", 'Customers');
UPDATE Customers
SET Language = ?
WHERE Country = ?
SQL
# rest of the class as usual.
package main:
$obj = Foo->new;
eval {
# Does connect & prepare
my $sth = $obj->sql_FindUser;
# bind_params, execute & bind_columns
$sth->execute(['Likmi%'], [\($name)]);
while( $sth->fetch ) {
print $name;
}
# Uses cached database and statement handles
$sth = $obj->sql_FindUser;
# bind_params & execute.
$sth->execute('%Hock');
@names = $sth->fetchall;
# connects, prepares
$rows_altered = $obj->sql_ChangeLanguage->execute(qw(es_MX mx));
};
unless ($@) {
# Everything went okay, commit the changes to the customers.
$obj->commit('Customers');
}
else {
$obj->rollback('Customers');
warn "DBI failure: $@";
}
AUTHOR
Michael G Schwern <schwern@pobox.com>
WHAT IS THIS?
This is Ima::DBI, a perl module. Please see the README that comes with
this distribution.
HOW DO I INSTALL IT?
To install this module, cd to the directory that contains this README
file and type the following:
perl Makefile.PL
make
make test
make install
To install this module into a specific directory, do:
perl Makefile.PL PREFIX=/odinstall man page, if available.
Requires:
Carp::Assert 0.05 and up
DBI 1.07 and up
------------------------------
Date: Wed, 14 Jul 1999 17:32:39 -0400
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: bug in vars.pm?
Message-Id: <nlvim7.dbk.ln@magna.metronet.com>
John M. Dlugosz (john@dlugosz.com) wrote:
: In the standard pragmatic module vars.pm, I see:
: if ($sym =~ tr/A-Za-Z_0-9//c) {
: now since the ordinal of 'a' is greater than the ordinal of 'Z' (lower-case
: letters follow capitals), the range a-Z is empty. From the context, I take
: suppose this should have been a-z, not a-Z,
Looks like a bug to me.
: in an effort to check for
: strings containing anything that's not a letter number or underscore.
in an effort to check for characters that are not allowed in
Perl "identifiers" (names).
: Also, what is the benifit of using tr/// with an empty replacement string
So the target string does not get modified...
just like it says in the documentation (perlop.pod) for tr///
"If the REPLACEMENTLIST is empty, the SEARCHLIST is replicated."
So you already knew that.
: (which does nothing but returns a count of chars matching the source string)
^^^^^
^^^^^ hmmm. there's a handy search term...
But note the tr///c option (complement).
So it counts characters that are NOT in the list, as it says in
the documentation (perlop.pod) for tr///.
So you already knew that too.
If it counts more than zero, then it is "time for a more-detailed
check-up" of the symbol being matched against. :-)
: instead of the more common s// ?
so the "equivalent" s/// would be
$sym =~ s/([^A-Za-Z_0-9])/$1/g;
tr/// is waaaaaay faster.
use Benchmark; # and see for yourself!
: Is this a technique we should all be
: using?
You betcha!
But all of the conscientious Perl programmers already knew about it.
So you already knew that too (so, where *is* your tr/// question?).
Because they saw the constant mentions of the fine Perl FAQ that
some fine perl guru(s) have spent lots and lots of time compiling,
and thought they ought to have a look at them from time to time.
They wouldn't want to ignore those gurus magnificent effort, and
make them feel like idiots for spending so much time so that
everybody can ask the questions yet again, and get a one-off
answer from *one* dude on Usenet instead of getting an answer
that has been scrutinized by *thousands* of Perl Experts the
world over.
So they already knew about all of this, having read Perl FAQ part 4:
"How can I count the number of occurrences of a
substring within a string?"
Even if they hadn't yet found the time to check _all_ of the FAQs,
when they wanted to *count* something, they would have tried:
perldoc -q count
And found the above mentioned Frequently Asked Question.
[ Sorry for my tone. Nothing personal. Occasionally I have to vent.
But I don't see any of your questions about tr/// and "count"ing
that aren't readily answered in the standard docs.
I'm sure you just missed them when you checked before posting.
]
--
Tad McClellan SGML Consulting
tadmc@metronet.com Perl programming
Fort Worth, Texas
------------------------------
Date: 14 Jul 1999 22:59:35 -0600
From: Daniel Grisinger <dgris@moiraine.dimensional.com>
Subject: Re: bug in vars.pm?
Message-Id: <m3yagiik3s.fsf@moiraine.dimensional.com>
tadmc@metronet.com (Tad McClellan) writes:
<snip>
> [ Sorry for my tone. Nothing personal. Occasionally I have to vent.
Me, too
You are completely out-of-line.
0- The poster had obviously read the docs, he understood both _what_
was happening and _how_ it was happening. He just didn't get
_why_ it was being done that particular way.
I don't know about you, but I'd much rather answer questions
about why things are done than about how they are done. How
is readily available from any decent reference, why is often
a function of experience. One of those we can reasonably
demand from posters, the other we can't.
1- His confusion was made worse by the fact that he had stumbled
across an actual bug in perl. Think about, that's bound to
throw you off. If there's one place that I expect to find
well-written perl code it's in the core perl distribution.
2- After deciding that he had probably found a bug in perl he
didn't go rushing off to p5p waving his hands and screaming
his head off. Instead he came here to verify that it was a
an actual bug. That's something that I guarantee you every
subscriber to p5p appreciates.
I understand people being frustrated by the constant flow of basic
questions that could be answered with just a cursory inspection of the
documentation. But this guy did not deserve this in any way.
He had done _everything_ that we could possibly have asked him to
but was still confused. Those are exactly the circumstances in
which people should be coming here for help.
And those are exactly the circumstances in which we should be acting
like helpful, respectful adults, not like spoiled teenagers having a
dick-size competition.
*plonk*
dgris
--
Daniel Grisinger dgris@moiraine.dimensional.com
perl -Mre=eval -e'$_=shift;;@[=split//;;$,=qq;\n;;;print
m;(.{$-}(?{$-++}));,q;;while$-<=@[;;' 'Just Another Perl Hacker'
------------------------------
Date: 15 Jul 1999 00:01:43 -0400
From: Uri Guttman <uri@sysarch.com>
Subject: Re: C-like #define macros in Perl
Message-Id: <x7u2r6muhk.fsf@home.sysarch.com>
>>>>> "A" == Abigail <abigail@delanet.com> writes:
A> -- Can I define macros like in C language?
A> Yes, but that's a seldomly used technique, and not very useful in
A> Perl. Use the -P switch.
normally i would agree that macros makes little sense in perl. i
probably would never use them in production code since you may not have
control over the cpp and it will slow things down. but i found a very
good use for -P in a sort benchmark system i am creating. see the thread
in moderated (-P is in the title) from a couple of weeks ago.
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
"F**king Windows 98", said the general in South Park before shooting Bill.
------------------------------
Date: Wed, 14 Jul 1999 23:16:24 -0500
From: brian@pm.org (brian d foy)
Subject: Re: C-like #define macros in Perl
Message-Id: <brian-1407992316240001@34.bloominton-01rs13-14rt.il.dial-access.att.net>
In article <378ca933.80071166@iitb>, hiwi1krg@iitb.fhg.de wrote:
>I am trying to write a Perl script that can print messages in several
>languages. I have put all text strings to separate file (lang.pl). The
>text strings have parts that change in run-time. When I try to print
>them from my script, the variable part of the string either doesn't
>show at all or shows as "This is directory: $working_dir" depending of
>which combination of single and double quotes I use in every place.
although everyone has answered your literal question by telling you
to use the preprocessor, that's probably not what you want. you might
consider storing all of your messages in a separate file (one per
language) where each message is referred to by the same name in
each file. you just load the appropriate langauge file for the
situation, and there you go. no preprocessing or other hoops in your
main script other than choosing the right file to use.
--
brian d foy
CGI Meta FAQ <URL:http://www.smithrenaud.com/public/CGI_MetaFAQ.html>
Perl Monger Hats! <URL:http://www.pm.org/clothing.shtml>
------------------------------
Date: Thu, 15 Jul 1999 03:58:13 GMT
From: Joan Richards <richj@home.com>
Subject: Re: Can I do this?
Message-Id: <378D5BFD.5AA0E368@home.com>
That's cool!!! Do you happen to know if there is something that will give me
output similar to the "netstat -in" and "vmstat"?
Andrew Allen wrote:
> Joan Richards (richj@home.com) wrote:
> : So, in a nutshell, how can I access (through perl) the data structures
> : or whatever that keeps the information for the 'df' command and use them
> : in my own proggie?
>
> A cursory glance at the CPAN module list
>
> http://www.perl.com/modules/00modlist.long.html
>
> reveals:
>
> File::Df
> Filesys::Df
> Filesys::DiskFree
>
> which appears useful.
>
> Andrew
------------------------------
Date: Thu, 15 Jul 1999 04:31:16 GMT
From: Joan Richards <richj@home.com>
Subject: Re: Can I do this?
Message-Id: <378D63BB.FEC29156@home.com>
To further clairy what I'm looking for beyond the 'df' command. I'm also
looking for something that will provide me with some sort of cpu utilization
stats, and network throughput. Are there modules or scripts out there that
are already doing this?
Andrew Allen wrote:
> Joan Richards (richj@home.com) wrote:
> : So, in a nutshell, how can I access (through perl) the data structures
> : or whatever that keeps the information for the 'df' command and use them
> : in my own proggie?
>
> A cursory glance at the CPAN module list
>
> http://www.perl.com/modules/00modlist.long.html
>
> reveals:
>
> File::Df
> Filesys::Df
> Filesys::DiskFree
>
> which appears useful.
>
> Andrew
------------------------------
Date: Wed, 14 Jul 1999 17:42:24 -0400
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: can't match $
Message-Id: <080jm7.dbk.ln@magna.metronet.com>
Michael Graham (mgraham@gwemail.ryerson.ca) wrote:
: i'd like to match a dollar sign, however using the following expression
: m/[$]/
^^
^^ that is a Perl special variable ($PERL_VERSION)
: i get error
: /[5.00502/: unmatched [] in regexp at format1.pl line 19,
: <TEXTFILE> chunk 8.
So you have an unmatched [] in regexp at format1.pl line 19...
:-)
: i've also tried to match $ by its ascii number
: m/[\036]/
That isn't the ASCII number for the dollar sign (36 decimal).
036 is an _octal_ number (because it starts with a zero) in Perl.
So that tries to match control-^ (decimal 30).
: this produces no errors but doesn't match anything
So you didn't happen to have the right strange control symbol
in your string, heh, heh.
: there must be a way to match the $ symbol with a regular expression -
: please enlighten me,
m/[\$]/
Now it is not a variable, it is a literal dollar sign character.
So you might as well go back to
m/\$/
no need for a character class.
--
Tad McClellan SGML Consulting
tadmc@metronet.com Perl programming
Fort Worth, Texas
------------------------------
Date: Thu, 15 Jul 1999 04:08:13 GMT
From: "Winter" <tungyat@yahoo.com>
Subject: Re: CGI.pm and redirect
Message-Id: <N8dj3.2630$n5.54749@news1.rdc2.on.home.com>
don't print anything before $q->redirect. expecially $q->header
oronet Tech - Joshua Scott <> wrote in message
news:378D33CA.5D210771@oro.net...
> I am using the redirect in the CGI.pm. For some reason I get this error
> at the browser:
>
> Status: 302 Found Uri: http://www.oro.net Location: http://www.oro.net
> Content-type: text/html
>
> Any insights would be greatly appreciated.
>
> =============================================================
> Josh Scott 272.0799
> oronet Technician http://www.oro.net/~jscott
------------------------------
Date: 15 Jul 1999 13:48:06 +1000
From: Tim Potter <Tim.Potter@anu.edu.au>
Subject: Re: checking Perl offline
Message-Id: <6y7lo2fua1.fsf@acronym.anu.edu.au>
aml@world.std.com (Andrew M. Langmead) writes:
[...]
> There is no reason any software developer has to debug code with print
> statements any more. Even the embedded design people have their
> simulators and in circuit emulators (and for this kind of work, it
> isn't debugging with print statements, but by toggling I/O ports)
You can still debug a hell in an embedded environment using only print
statements. I've only had to break out the logic analyser to debug
bootstrap routines. Simulators and emulators are usually quite
expensive beasts as well.
I haven't been bothered to learn the perl debugger because I've never
needed to! All my problems can usually be fixed with use strict, perl
-w and print statements. (-:
Tim.
--
Tim Potter, System Admin/Programmer "Disco Stu doesn't advertise"
Advanced Computational Systems CRC, RSISE Bldg Australian National University,
Canberra 0200, AUSTRALIA Ph: +61 2 62798813 Fax: +61 2 62798602
------------------------------
Date: Wed, 14 Jul 1999 21:45:17 -0700
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: Como ler un directorio...
Message-Id: <MPG.11f7073181bee869989ccd@nntp.hpl.hp.com>
[Posted and a courtesy copy sent.]
In article <378CCBB9.43B3C028@alumnos.utfsm.cl> on Wed, 14 Jul 1999
13:41:13 -0400, Rodrigo <rcortes@alumnos.utfsm.cl> says...
> Se puede hacer en perl que un script lea un directorio y guarde en un
> arreglo los nombres de todos los archivos que existen en dicho
> directorio??
> De ser asi... como se puede hacer???
Maybe the wiseguys who answered your question with Swedish gibberish and
Finnish are not aware that sometimes a post in one's native language may
be more intelligible than an attempt at English. Especially if it is a
language that Babelfish can help at translating.
My main objection to your post is that you did it in two newsgroups
separately, without using the crossposting capabilities of your
newsreader. If
X-Mailer: Mozilla 4.51 [en] (WinNT; I)
can't handle that, then you should invest in a proper newsreader.
As to the substance of your question: You can use opendir, readdir, and
grep to get whatever names you want out of a directory into an array.
What the conditions for grep should be I cannot tell, because I don't
know what you mean by an 'archive'. If you mean simply a file, then
this will do:
my $dir = '/path/to/directory';
opendir DIR, $dir or die "Couldn't open '$dir'. $!\n";
my @array = grep -f "$dir/$_", readdir DIR;
> Por favor envien sus respuestas a roco3d@softhome.net
If that's what you want, then you can set the 'Reply-to:' header to
that. I'm too lazy to do other than send a copy to your posting
address.
> Muchas gracias...
De nada.
--
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: Wed, 14 Jul 1999 04:27:07 +0200
From: "Dr. Who" <qwerty@post.utfors.se>
Subject: crypt() doesn't decrypt
Message-Id: <378BF57B.E4428EA2@post.utfors.se>
what's the point in encrypting someting that is decryptable?
.. or is there really a way? :)
------------------------------
Date: Wed, 14 Jul 1999 21:24:44 -0700
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: crypt() doesn't decrypt
Message-Id: <MPG.11f702617e80972b989ccc@nntp.hpl.hp.com>
In article <378BF57B.E4428EA2@post.utfors.se> on Wed, 14 Jul 1999
04:27:07 +0200, Dr. Who <qwerty@post.utfors.se> says...
> what's the point in encrypting someting that is decryptable?
> .. or is there really a way? :)
Do you *ever* read the documentation before posting? Which part of the
result of `perldoc -f crypt` did you not understand?
--
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: Wed, 14 Jul 1999 04:11:43 +0200
From: "Dr. Who" <qwerty@post.utfors.se>
Subject: difference between my and local?
Message-Id: <378BF1DF.9AFA4FC@post.utfors.se>
..perldoc tells the same about those functions ..
.. what's differs chop from chomp?
------------------------------
Date: Wed, 14 Jul 1999 20:30:53 -0700
From: Andrew J Perrin <aperrin@mcmahon.qal.berkeley.edu>
Subject: Re: difference between my and local?
Message-Id: <378D55ED.4A8FDA27@mcmahon.qal.berkeley.edu>
Dr. Who wrote:
> ..perldoc tells the same about those functions ..
no it doesn't.perldoc -f my
perldoc -f local
perldoc perlsub
> .. what's differs chop from chomp?
perldoc -f chompperldoc -f chop
HTH!
ap
--
-------------------------------------------------------------
Andrew Perrin - NT/Unix/Access Consulting -
aperrin@mcmahon.qal.berkeley.edu
I'M LOOKING FOR ANOTHER EXPERIENCED ACCESS
DEVELOPER - CONTACT ME IF INTERESTED.
http://www.geocities.com/SiliconValley/Grid/7544/
-------------------------------------------------------------
------------------------------
Date: Wed, 14 Jul 1999 21:20:57 -0700
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: difference between my and local?
Message-Id: <MPG.11f70184df345823989ccb@nntp.hpl.hp.com>
In article <378BF1DF.9AFA4FC@post.utfors.se> on Wed, 14 Jul 1999
04:11:43 +0200, Dr. Who <qwerty@post.utfors.se> says...
> ..perldoc tells the same about those functions ..
> .. what's differs chop from chomp?
substr('chomp', 3, 1) = '';
What did you not understand after doing `perldoc -f chop` and
`perldoc -f chomp`?
--
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: Thu, 15 Jul 1999 02:24:02 GMT
From: Rick Delaney <rick.delaney@home.com>
Subject: Re: file to array ?
Message-Id: <378D4611.16C58390@home.com>
[posted & mailed]
stu7@usa.net wrote:
>
> Is there a single PERL function which writes a file (by line)
> to an array ?
This is a FAQ, but you probably haven't seen it yet.
<Tom C>
=head2 How can I read in an entire file all at once?
The customary Perl approach for processing all the lines in a file is to
do so one line at a time:
open (INPUT, $file) || die "can't open $file: $!";
while (<INPUT>) {
chomp;
# do something with $_
}
close(INPUT) || die "can't close $file: $!";
This is tremendously more efficient than reading the entire file into
memory as an array of lines and then processing it one element at a time,
which is often -- if not almost always -- the wrong approach. Whenever
you see someone do this:
@lines = <INPUT>;
You should think long and hard about why you need everything loaded
at once. It's just not a scalable solution. You might also find it
more fun to use the the standard DB_File module's $DB_RECNO bindings,
which allow you to tie an array to a file so that accessing an element
the array actually accesses the corresponding line in the file.
On very rare occasion, you may have an algorithm that demands that
the entire file be in memory at once as one scalar. The simplest solution
to that is:
$var = `cat $file`;
Being in scalar context, you get the whole thing. In list context,
you'd get a list of all the lines:
@lines = `cat $file`;
This tiny but expedient solution is neat, clean, and portable to all
systems that you've bothered to install decent tools on, even if you are
a Prisoner of Bill. For those die-hards PoBs who've paid their billtax
and refuse to use the toolbox, or who like writing complicated code for
job security, you can of course read the file manually.
{
local(*INPUT, $/);
open (INPUT, $file) || die "can't open $file: $!";
$var = <INPUT>;
}
That temporarily undefs your record separator, and will automatically
close the file at block exit. If the file is already open, just use this:
$var = do { local $/; <INPUT> };
</Tom>
--
Rick Delaney
rick.delaney@home.com
------------------------------
Date: Thu, 15 Jul 1999 02:38:46 GMT
From: *@dragons.duesouth.net (Matthew Bafford)
Subject: Re: file to array ?
Message-Id: <slrn7oqgkm.1ju.*@dragons.duesouth.net>
stu7@usa.net, thinking with his hands, posted the following to
comp.lang.perl.misc:
: Is there a single PERL function which writes a file (by line)
: to an array ?
@array = <FILE>;
perldoc -f readline
HTH,
--Matthew
------------------------------
Date: Thu, 15 Jul 1999 03:00:09 GMT
From: mgjv@comdyn.com.au (Martien Verbruggen)
Subject: Re: file to array ?
Message-Id: <Z8cj3.246$9t5.7479@nsw.nnrp.telstra.net>
In article <7mjdjm$1vf$1@nnrp1.deja.com>,
stu7@usa.net writes:
> Is there a single PERL function which writes a file (by line)
> to an array ?
It's so trivial that one would hardly want a 'single function':
# open your file for reading
my @lines = <FILEHANDLE>;
# close again.
In case you don't know how any of that works, and you really can't be
bothered reading documentation:
Using builtins:
sub fta
{
open(FOO, shift) || die "$!";
my @foo = <FOO>;
close(FOO);
return @foo;
}
(The above can be done with a little less code by localising the file
handle, so you don't have to explicitly close)
Using a module:
use FileHandle;
sub fta { my $fh; ($fh = new FileHandle(shift)) ? <$fh> : die "$!" }
Or if you don't care too much about nice error handling, IOW if you
are absolutely certain you can read the file and it exists:
use FileHandle;
sub fta { new FileHandle(shift)->getlines }
HTH,
Martien
PS. Please, next time, put in some effort and read the documentation.
If you have done so, tell us what you tried, and how it isn't doing
what you want it to do.
--
Martien Verbruggen |
Interactive Media Division | That's funny, that plane's dustin'
Commercial Dynamics Pty. Ltd. | crops where there ain't no crops.
NSW, Australia |
------------------------------
Date: Thu, 15 Jul 1999 02:25:24 GMT
From: david.whitmarsh@dial.pipex.com (David Whitmarsh)
Subject: Re: Filter Websides Under WIN95/98/NT
Message-Id: <378e21fa.14463762@news.dial.pipex.com>
anton.kramer.erlenmoos@t-online.de wrote:
>
>Who can help me?
>I should filter websides before they are displayed
>by the browser.
>For excample:
>URL: www.yahoo.de
>filtering: 'shopping'
>if the webside contains -shopping- I should
>change the URL f.e. to 'www.wal-mart.com'
>Do you know a solution ?
If you are asking what I think you are asking, you can translate URLs
by using apache as a proxy server and installing and configuring
mod_rewrite. See http://ww.apache.org/ for details and documentation
on apache and http://dspace.dial.pipex.com/david.whitmarsh/ for how I
configured my laptop.
David
************************************
David Whitmarsh
remove "spamtrap." from email address before replying
Sparkle Computer Co Ltd
Sybase C C++ perl UNIX NT
************************************
------------------------------
Date: Thu, 15 Jul 1999 00:17:15 -0300
From: "Kevin Howe" <khowe@performance-net.com>
Subject: help with line feeds
Message-Id: <Yjcj3.8405$j3.43963@tor-nn1.netcom.ca>
Is there a way to convert UNIX lines feeds to NT and vice versa using Perl?
------------------------------
Date: 1 Jul 99 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 1 Jul 99)
Message-Id: <null>
Administrivia:
The Perl-Users Digest is a retransmission of the USENET newsgroup
comp.lang.perl.misc. For subscription or unsubscription requests, send
the single line:
subscribe perl-users
or:
unsubscribe perl-users
to almanac@ruby.oce.orst.edu.
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 V9 Issue 148
*************************************