[19122] in Perl-Users-Digest
Perl-Users Digest, Issue: 1317 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Jul 17 18:06:45 2001
Date: Tue, 17 Jul 2001 15:05:19 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <995407519-v10-i1317@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Tue, 17 Jul 2001 Volume: 10 Number: 1317
Today's topics:
Re: about image::Magick quality. <mjcarman@home.com>
Re: about image::Magick quality. <stephh@nospam.com>
Re: Advanced Sorting <ren@tivoli.com>
Re: Advice REQ for newbie <iltzu@sci.invalid>
ANNOUNCE: PDL::IO::HDF5 Released <j-cerney1@raytheon.com>
Anyone used blat.exe? <ng@spittles.freeuk.com>
Array Contents modification? <paanwa@hotmail.com>
Re: Array Contents modification? <godzilla@stomp.stomp.tokyo>
Re: Array Contents modification? <paanwa@hotmail.com>
Re: Array Contents modification? <mjcarman@home.com>
Re: Array Contents modification? (E.Chang)
Re: Array Contents modification? <godzilla@stomp.stomp.tokyo>
Re: Array Contents modification? <paanwa@hotmail.com>
Re: ARRAYS: find common values <whaidri@ford.com>
Broken WWW::Search engines ? (Mike)
Re: Broken WWW::Search engines ? (Randal L. Schwartz)
Re: Check for Dups! <iltzu@sci.invalid>
Re: easy multi-file find & replace? <iltzu@sci.invalid>
Re: error making Archive::Zip <oudendijk@home.nl>
Re: extracting a range of lines from a text file (Craig Berry)
FAQ: How can I generate simple menus without using CGI <faq@denver.pm.org>
File tutorial? <millettNOSPAM@lblueyonder.co.uk>
Re: File tutorial? <james@zephyr.org.uk>
Re: File tutorial? <stephh@nospam.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Tue, 17 Jul 2001 10:23:27 -0500
From: Michael Carman <mjcarman@home.com>
Subject: Re: about image::Magick quality.
Message-Id: <3B54586F.D8109779@home.com>
James wrote:
>
> what do u mean by saying " Subs using the named parameters via hash
> scheme will usually silently ignore params which they dont expect."?
> can u adress in detail?
The normal method of creating subroutines in Perl doesn't allow for
named or optional parameters. There is, however, a way of doing both by
using a hash to store your arguments:
sub mysub {
my %args = (
foo => 'alpha',
bar => 'beta',
baz => 42,
@_,
);
print "foo/bar/baz = $arg{foo}/$arg{bar}$arg{baz}\n";
}
This allows you to call mysub() without specifying some or all
parameters. If you don't say what foo is, it will use 'alpha' by
default. If you do specify foo, it will override the default with the
value you provide. (That's why @_ is the last thing in the declaration
of %args.) Another advantage is that you don't need to put arguments in
a particular order.
There's a slight catch, though. Because of autovivification, it's quite
possible to call mysub(quux => 'oops!'). Perl doesn't care that you
don't want an argument named quux, so it lets the call slide. Nothing in
mysub expects it though, and unless the author has taken steps to
actively look for invalid arguments the sub will most likely just ignore
them.
-mjc
------------------------------
Date: Tue, 17 Jul 2001 21:44:07 +0200
From: stephh <stephh@nospam.com>
Subject: Re: about image::Magick quality.
Message-Id: <170720012144070066%stephh@nospam.com>
> sub mysub {
> my %args = (
> foo => 'alpha',
> bar => 'beta',
> baz => 42,
> @_,
> );
>
> print "foo/bar/baz = $arg{foo}/$arg{bar}$arg{baz}\n";
> }
OK, but I do't get how you pass the values to %args. Can you write down
the line getting @_ ?
In article <3B54586F.D8109779@home.com>, Michael Carman
<mjcarman@home.com> wrote:
> James wrote:
> >
> > what do u mean by saying " Subs using the named parameters via hash
> > scheme will usually silently ignore params which they dont expect."?
> > can u adress in detail?
>
> The normal method of creating subroutines in Perl doesn't allow for
> named or optional parameters. There is, however, a way of doing both by
> using a hash to store your arguments:
>
> sub mysub {
> my %args = (
> foo => 'alpha',
> bar => 'beta',
> baz => 42,
> @_,
> );
>
> print "foo/bar/baz = $arg{foo}/$arg{bar}$arg{baz}\n";
> }
>
> This allows you to call mysub() without specifying some or all
> parameters. If you don't say what foo is, it will use 'alpha' by
> default. If you do specify foo, it will override the default with the
> value you provide. (That's why @_ is the last thing in the declaration
> of %args.) Another advantage is that you don't need to put arguments in
> a particular order.
>
> There's a slight catch, though. Because of autovivification, it's quite
> possible to call mysub(quux => 'oops!'). Perl doesn't care that you
> don't want an argument named quux, so it lets the call slide. Nothing in
> mysub expects it though, and unless the author has taken steps to
> actively look for invalid arguments the sub will most likely just ignore
> them.
>
> -mjc
--
$tephh;
Don't forget to visit http://www.grc.com/dos/grcdos.htm
------------------------------
Date: 17 Jul 2001 10:09:42 -0500
From: Ren Maddox <ren@tivoli.com>
Subject: Re: Advanced Sorting
Message-Id: <m3ae23sibt.fsf@dhcp9-161.support.tivoli.com>
On Tue, 17 Jul 2001, wyzelli@yahoo.com wrote:
> "Ren Maddox" <ren@tivoli.com> wrote in message
> news:m3d770tz3u.fsf@dhcp9-161.support.tivoli.com...
>
>> That { LIST } generates an anonymous hash reference is documented.
>
> That is probably the step I am missing, can you point me in the
> right direction? perlref at a guess which I will read later today.
Yes, perlref(1), Item #3 under "Making References". The text doesn't
come right out and say that what goes inside the curly braces is
simply a list (with an even number of elements), but the examples
include "{ @_ }", which makes it pretty evident.
--
Ren Maddox
ren@tivoli.com
------------------------------
Date: 17 Jul 2001 21:30:26 GMT
From: Ilmari Karonen <iltzu@sci.invalid>
Subject: Re: Advice REQ for newbie
Message-Id: <995405003.11451@itz.pp.sci.fi>
In article <vLG47.38494$WS4.6005383@news6-win.server.ntlworld.com>, Pete wrote:
>"Tad McClellan" <tadmc@augustmail.com> wrote in message
>news:slrn9l5uqe.5ld.tadmc@tadmc26.august.net...
>>
>> [ Please do not send stealth Cc's. It makes people angry. ]
>>
>Thanks for your forbearance. I obviously can't cut the mustard at this
>group - I can't even work out how to get to the FAQs, I only seem to get
Oh, Tad's just being slightly grumpier than usual. Usually making the
mistakes you made just gets you ignored. Not that you helped the matter
by mailing him a copy of your post and not marking it as such.
The FAQ is already on your computer. There should be a program named
"perldoc" that you can use to read it. If you're using Windows and got
your perl from ActiveState, the documentation should also be available
somewhere under your "Start" menu.
Alternatively, just point your browser to http://www.perldoc.com/
--
Ilmari Karonen -- http://www.sci.fi/~iltzu/
"Get real! This is a discussion group, not a helpdesk. You post something,
we discuss its implications. If the discussion happens to answer a question
you've asked, that's incidental." -- nobull in comp.lang.perl.misc
------------------------------
Date: Tue, 17 Jul 2001 07:10:07 -0500
From: John Cerney <j-cerney1@raytheon.com>
Subject: ANNOUNCE: PDL::IO::HDF5 Released
Message-Id: <tl8o1ld97kg18@corp.supernews.com>
PDL::IO::HDF5 has been released to CPAN. You can get it at
http://www.cpan.org/modules/by-authors/id/C/CE/CERNEY/PDL-IO-HDF5-0.1.tar.gz
>From The Man Pages:
-------------------
NAME
PDL::IO::HDF5 - PDL Interface to the HDF5 Data Format.
DESCRIPTION
This package provides an object-oriented interface for the
PDL package to the HDF5 data-format. Information on the
HDF5 Format can be found at the NCSA's web site at
http://hdf.ncsa.uiuc.edu/ .
LIMITATIONS
Currently this interface only provides a subset of the total
HDF5 library's capability.
o Only HDF5 Simple datatypes are supported. No HDF5 Compound
datatypes are supported since PDL doesn't support them.
o Only HDF5 Simple dataspaces are supported.
o Only 0-dimensional (i.e. scalar) attributes are supported.
(Support for PDLs as attributes could possibly be added
later.)
Also Included:
--------------
An experimental module for interactive viewing of HDF5 files
using perl/tk is also included. The file tkviewtest is a short
demo of this capability.
------------------------------
Date: Tue, 17 Jul 2001 20:11:52 +0100
From: Brian Spittles <ng@spittles.freeuk.com>
Subject: Anyone used blat.exe?
Message-Id: <bf39ltki7uu11g78hogaolui661so651fd@4ax.com>
Hi,
I'm trying to use blat.exe (after my host switched from Unix to NT).
Following answers given (to other questions) in other NGs, I've
constructed the following:
system qq(blat.exe "$body"
-to "$rs22->Fields(3)->{Value}"
-subject "Your squad"
-i "$from"
-body "$body");
As you can see, there's a mixture of scalars and hard-coded strings
being passed to blat. So far, nothing has appeared in my mailbox!
Any help will be gratefully accepted. If any other information is
required, just say the word.
TIA
--
Brian
I thought middle-aged spread was something to eat...
Check out the wibbler's gallery at www.wacker.clara.net/wibble
------------------------------
Date: Tue, 17 Jul 2001 14:14:45 -0400
From: "PaAnWa" <paanwa@hotmail.com>
Subject: Array Contents modification?
Message-Id: <tl904n3k9i7b6f@corp.supernews.com>
I have an array called @Booklets. Let's say the contents of the array are:
"\"AB\"," "\"BC\"," "\"CD\"," "\"DE\"," "\"EF\""
The contents are fomatted this way so that I can print the array contents to
a text file in .csv format.
I would like to take the formatting out at a certain point in my code so
that I can print this:
foreach (@Booklets)
{
print "<img src=",$_ ,".jpg> ";
}
and get a .jpg image for each item in the array.
Any suggestions?
------------------------------
Date: Tue, 17 Jul 2001 11:45:54 -0700
From: "Godzilla!" <godzilla@stomp.stomp.tokyo>
Subject: Re: Array Contents modification?
Message-Id: <3B5487E2.6646D2F8@stomp.stomp.tokyo>
PaAnWa wrote:
(snipped)
> I have an array called @Booklets. Let's say the contents of the array are:
> "\"AB\"," "\"BC\"," "\"CD\"," "\"DE\"," "\"EF\""
> Any suggestions?
Yes, write code which will at least compile.
Godzilla!
--
TEST SCRIPT:
____________
#!perl
@Array = ("\"AB\"," "\"BC\"," "\"CD\"," "\"DE\"," "\"EF\"");
print "@Array";
exit;
PRINTED RESULTS:
________________
String found where operator expected at test1.pl line 5, near ""\"AB\"," "\"BC\",""
(Missing operator before "\"BC\","?)
String found where operator expected at test1.pl line 5, near ""\"BC\"," "\"CD\",""
(Missing operator before "\"CD\","?)
String found where operator expected at test1.pl line 5, near ""\"CD\"," "\"DE\",""
(Missing operator before "\"DE\","?)
String found where operator expected at test1.pl line 5, near ""\"DE\"," "\"EF\"""
(Missing operator before "\"EF\""?)
syntax error at test1.pl line 5, near ""\"AB\"," "\"BC\",""
Execution of test1.pl aborted due to compilation errors.
*************
TEST SCRIPT:
(leading and trailing quote removed)
____________
#!perl
@Array = (\"AB\"," "\"BC\"," "\"CD\"," "\"DE\"," "\"EF\");
print "@Array";
exit;
PRINTED RESULTS:
________________
String found where operator expected at test1.pl line 5, near ""AB\"," "\"BC\",""
(Missing operator before "\"BC\","?)
String found where operator expected at test1.pl line 5, near ""\"BC\"," "\"CD\",""
(Missing operator before "\"CD\","?)
String found where operator expected at test1.pl line 5, near ""\"CD\"," "\"DE\",""
(Missing operator before "\"DE\","?)
String found where operator expected at test1.pl line 7, near "print ""
(Might be a runaway multi-line "" string starting on line 5)
(Missing semicolon on previous line?)
Array found where operator expected at test1.pl line 7, at end of line
(Do you need to predeclare print?)
String found where operator expected at test1.pl line 7, at end of line
(Missing semicolon on previous line?)
syntax error at test1.pl line 5, near ""AB\"," "\"BC\",""
Can't find string terminator '"' anywhere before EOF at test1.pl line 7.
------------------------------
Date: Tue, 17 Jul 2001 14:58:18 -0400
From: "PaAnWa" <paanwa@hotmail.com>
Subject: Re: Array Contents modification?
Message-Id: <tl92mcbikqn8b0@corp.supernews.com>
The code works fine! The array works fine.
I am trying to show what the elements for array contain.....element one
contains
"\"AB\","
If I have represented it in a manner that is both non-standard and hard to
understand I do apologize!
PAW
"Godzilla!" <godzilla@stomp.stomp.tokyo> wrote in message
news:3B5487E2.6646D2F8@stomp.stomp.tokyo...
> PaAnWa wrote:
>
> (snipped)
>
> > I have an array called @Booklets. Let's say the contents of the array
are:
> > "\"AB\"," "\"BC\"," "\"CD\"," "\"DE\"," "\"EF\""
>
> > Any suggestions?
>
>
> Yes, write code which will at least compile.
>
>
> Godzilla!
> --
>
> TEST SCRIPT:
> ____________
>
> #!perl
>
> @Array = ("\"AB\"," "\"BC\"," "\"CD\"," "\"DE\"," "\"EF\"");
>
> print "@Array";
>
> exit;
>
>
> PRINTED RESULTS:
> ________________
>
>
> String found where operator expected at test1.pl line 5, near ""\"AB\","
"\"BC\",""
> (Missing operator before "\"BC\","?)
>
> String found where operator expected at test1.pl line 5, near ""\"BC\","
"\"CD\",""
> (Missing operator before "\"CD\","?)
>
> String found where operator expected at test1.pl line 5, near ""\"CD\","
"\"DE\",""
> (Missing operator before "\"DE\","?)
>
> String found where operator expected at test1.pl line 5, near ""\"DE\","
"\"EF\"""
> (Missing operator before "\"EF\""?)
>
> syntax error at test1.pl line 5, near ""\"AB\"," "\"BC\",""
> Execution of test1.pl aborted due to compilation errors.
>
>
> *************
>
> TEST SCRIPT:
>
> (leading and trailing quote removed)
> ____________
>
> #!perl
>
> @Array = (\"AB\"," "\"BC\"," "\"CD\"," "\"DE\"," "\"EF\");
>
> print "@Array";
>
> exit;
>
>
> PRINTED RESULTS:
> ________________
>
> String found where operator expected at test1.pl line 5, near ""AB\","
"\"BC\",""
> (Missing operator before "\"BC\","?)
>
> String found where operator expected at test1.pl line 5, near ""\"BC\","
"\"CD\",""
> (Missing operator before "\"CD\","?)
>
> String found where operator expected at test1.pl line 5, near ""\"CD\","
"\"DE\",""
> (Missing operator before "\"DE\","?)
>
> String found where operator expected at test1.pl line 7, near "print ""
> (Might be a runaway multi-line "" string starting on line 5)
> (Missing semicolon on previous line?)
>
> Array found where operator expected at test1.pl line 7, at end of line
> (Do you need to predeclare print?)
>
> String found where operator expected at test1.pl line 7, at end of line
> (Missing semicolon on previous line?)
>
> syntax error at test1.pl line 5, near ""AB\"," "\"BC\",""
> Can't find string terminator '"' anywhere before EOF at test1.pl line 7.
------------------------------
Date: Tue, 17 Jul 2001 13:57:15 -0500
From: Michael Carman <mjcarman@home.com>
Subject: Re: Array Contents modification?
Message-Id: <3B548A8B.9E79B154@home.com>
PaAnWa wrote:
>
> I have an array called @Booklets. Let's say the contents of the
> array are:
> "\"AB\"," "\"BC\"," "\"CD\"," "\"DE\"," "\"EF\""
>
> The contents are fomatted this way so that I can print the array
> contents to a text file in .csv format.
>
> I would like to take the formatting out at a certain point in my
> code so that I can print [...]
>
> Any suggestions?
Yes. Don't make the formatting part of your data. Use the Text::CSV_XS
module to create your .csv file and let it do the formatting.
Text::CSV_XS isn't part of the standard distribution, so you'll have to
install it.
If you can't use Text::CSV_XS for some reason, the Text::ParseWords
module is generic enough to do this for you as well (with a little more
effort on your part).
-mjc
------------------------------
Date: Tue, 17 Jul 2001 19:19:38 GMT
From: echang@netstorm.net (E.Chang)
Subject: Re: Array Contents modification?
Message-Id: <Xns90E19C7371DC6echangnetstormnet@207.106.93.86>
"PaAnWa" <paanwa@hotmail.com> wrote in
<tl904n3k9i7b6f@corp.supernews.com>:
> I have an array called @Booklets. Let's say the contents of the
> array are: "\"AB\"," "\"BC\"," "\"CD\"," "\"DE\"," "\"EF\""
>
> The contents are fomatted this way so that I can print the array
> contents to a text file in .csv format.
Rather than keep the quotes and commas as part of the value, why not
just add them to the output when you print to the file? For example:
@Booklets = qw(AB BC CD DE EF);
foreach (@Booklets) {
print CFILE qq("$_",);
}
prints
"AB","BC","CD","DE","EF",
> I would like to take the formatting out at a certain point in my
> code so that I can print this:
>
> foreach (@Booklets)
> {
> print "<img src=",$_ ,".jpg> ";
No need to break the string - $_ will be interpolated
foreach (@Booklets) {
print "<img src=$_ .jpg> ";
}
Though it would be better to enclose the src value in quotes, Using
the qq operator eliminates the need for escaping.
foreach (@Booklets) {
print qq(<img src="$_ .jpg"> );
}
HTH
--
EBC
------------------------------
Date: Tue, 17 Jul 2001 12:53:50 -0700
From: "Godzilla!" <godzilla@stomp.stomp.tokyo>
Subject: Re: Array Contents modification?
Message-Id: <3B5497CE.CEC004E4@stomp.stomp.tokyo>
PaAnWa wrote:
> The code works fine! The array works fine.
I have not tested your code knowing your array
is FUBAR. Your array does not work fine.
> I am trying to show what the elements for array contain.....
> element one contains
> "\"AB\","
> If I have represented it in a manner that is both non-standard
> and hard to understand I do apologize!
This is not a question of "if" you did this. This is
a question of why you deliberately did this and, why
you are still deliberately doing this.
Is your brain enjoying an extended vacation?
Godzilla!
------------------------------
Date: Tue, 17 Jul 2001 16:09:14 -0400
From: "PaAnWa" <paanwa@hotmail.com>
Subject: Re: Array Contents modification?
Message-Id: <tl96rfko6r2658@corp.supernews.com>
**sigh**
Clearly my PERL abilities are FAR below yours.....perhaps this will clear
things up:
@Bklt=();
if (param('AB') ne "") {@Bklt = (@Bklt,"\"AB\",");}
My array contains 5 such elements. I need to know how to later, given a
particular condition to be true, convert (in this case) "\"AB\"," into "AB".
Is this answerable?
PAW
------------------------------
Date: Tue, 17 Jul 2001 14:53:01 -0400
From: Wali Haidri <whaidri@ford.com>
Subject: Re: ARRAYS: find common values
Message-Id: <3B54898D.12A233A5@ford.com>
Jasper, Jeff, Michael Budash, Michael Carman, Stephh,
Thank you all for your help. "grep" works faster than "foreach".
Wali Haidri wrote:
>
> I want to out put the common values in the two arrays below. Following
> code does work but it is very slow. I hope somebody can suggest a
> better way.
>
> sub get_usersByToken3{
>
> # my (@users) defined somewhere else and has a list of users.
> # my (users2) " " " " "
> my (@finalusers);
> my ($tval, $val1, $val2);
>
> # FIRST SORT BOTH ARRAYS
>
> @users = sort { uc($a) cmp uc($b) } @users;
> @users2 = sort { uc($a) cmp uc($b) } @users2;
>
> # NOW FOR EACH ELEMENT IN LIST 1, TRY TO FIND IT IN LIST 2. IF FOUND
> # PUSH IT TO AN OUTPUT ARRAY AND EXIT OUT OF THIS LOOK BACK TO THE FIRST
> # foreach LOOP.
>
> LINE:
> foreach $val1 (@users){
> foreach $val2 (@users2){
> if ( $val2 eq uc($val1) ) {
> push(@finalusers, uc($val1));
> next LINE;
> }
> }
> } # end of foreach
> return (@finalusers);
> }
>
> Please cc to my email address if possible. Thanks.
>
> Wali Haidri
> whaidri@ford.com
------------------------------
Date: 17 Jul 2001 11:52:59 -0700
From: michael_of_neb@yahoo.com (Mike)
Subject: Broken WWW::Search engines ?
Message-Id: <5a10590e.0107171052.2be446f2@posting.google.com>
Has anybody else been having problems using the following WWW::Search
modules ?
HotBot.pm
LookSmart.pm
AlltheWeb.pm
Snap.pm
Are they still working for you ? Are they working fully or only
partially ?
Another such engine, the NetFind.pm alias Aol engine, has been all but
officially dropped from support, and it would appear that there are no
rescuers on the horizon for this very important engine, even more
important as Aol scraps the Netscape search engine after buying it,
and even as Aol/Time-Warner gathers even more users with their huge
promotional methods, and their grasp of the various related markets.
The public announcement of this withdrawal of support ought to be done
shortly, but this person has been dragging his feet, to declare his
breach - for obvious reasons. (My prayers go out to him and his
consulting service organization.)
For my own purposes, and in my *spare time*, I have made an effort to
make simple generic methods for the DirectHit and Iwon engines, and,
if I am forced into doing so, I will cope with the lack of support for
these above named engines that are (sort of) without current support,
though I would rather lend my support and help to those who already
are doing this support, if there were some way I could do so with
everything else I am already responsible for.
I hope that there is a response to this request for interest. It
would further show these people how valuable their services truly are.
Thank you.
Mike
------------------------------
Date: 17 Jul 2001 14:52:58 -0700
From: merlyn@stonehenge.com (Randal L. Schwartz)
Subject: Re: Broken WWW::Search engines ?
Message-Id: <m1puazdxz9.fsf@halfdome.holdit.com>
>>>>> "Mike" == Mike <michael_of_neb@yahoo.com> writes:
Mike> Has anybody else been having problems using the following WWW::Search
Mike> modules ?
Mike> HotBot.pm
Mike> LookSmart.pm
Mike> AlltheWeb.pm
Mike> Snap.pm
Mike> Are they still working for you ? Are they working fully or only
Mike> partially ?
It's very likely that the format of the web pages has changed, as they
do frequently.
The problem with screen scraping is that it cannot usually be done
robustly.
As always, in the Perl community, the catchphrase is "patches welcome!"
print "Just another Perl hacker,"
--
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!
------------------------------
Date: 17 Jul 2001 21:20:01 GMT
From: Ilmari Karonen <iltzu@sci.invalid>
Subject: Re: Check for Dups!
Message-Id: <995402026.10461@itz.pp.sci.fi>
In article <ZXx37.54036$aE6.4616334@news1.cableinet.net>, millside wrote:
>
>I would like to protect against multiple entries being written to my flat
>file in future and was wanting a sub routine to do it.
#!/usr/bin/perl -w
use strict;
use Fcntl ':flock';
my $email = shift; # for testing purposes
open LIST, "+>> address.txt" or die $!;
flock LIST, LOCK_EX;
seek LIST, 0, 0; # start at the beginning..
my $found = 0;
while (<LIST>) {
chomp;
$found++, last if $_ eq $email;
}
if ($found) {
print "Sorry, $email is already in the database.\n";
} else {
seek LIST, 0, 2; # some systems may need this
print LIST "$email\n";
print "$email has been successfully added to the database.\n";
}
close LIST; # unlocks the file
Some notes:
* Opening with mode "+<" would work too, and would eliminate the need
for the first seek. But it would fail if the file didn't exist.
* Locking _is_ important. And you do need to obtain an exclusive lock
for the whole process. That's because as soon as you start looking
for an address, you effectively assert that the _next_ process that
will look for the same address _will_ find it already in the file.
* Using grep may in fact often be faster than manually looping over a
list, at least unless you expect an early match. But the real reason
why this code is better is that it doesn't need to read the whole
list of addresses into the memory.
* See "perldoc -f seek" for details on why the second seek may be
necessary even if the file has been opened in append mode. In any
case, it will do no harm there.
* Don't use LOCK_UN. Simply closing the filehandle will do the Right
Thing -- flush the output buffer, unlock the file and close it.
This code isn't all that slow -- running it on a 400kb word list takes
about half a second, and you're unlikely to have hundreds of thousands
of addresses in your list.
However, if you prefer the DBM approach, you could use a DBM file just
for detecting duplicate addresses, and keep the rest of the data still
in flat files. You'd still need to lock the DBM file just as above.
--
Ilmari Karonen -- http://www.sci.fi/~iltzu/
"Get real! This is a discussion group, not a helpdesk. You post something,
we discuss its implications. If the discussion happens to answer a question
you've asked, that's incidental." -- nobull in comp.lang.perl.misc
------------------------------
Date: 17 Jul 2001 16:38:11 GMT
From: Ilmari Karonen <iltzu@sci.invalid>
Subject: Re: easy multi-file find & replace?
Message-Id: <995387290.27002@itz.pp.sci.fi>
In article <yahoo_com-9BAE74.23351113072001@news1.rdc1.md.home.com>, Frank Nospam wrote:
> cberry@cinenet.net (Craig Berry) wrote:
>> find public_html -name '*.html' -exec perl -pi -e 's/foobar/fubar/' {} \;
>
>Thanks much Craig, that's exactly the syntax I needed.
> Now I ought learn what those switches mean, but I can
> get that from the man.
Note that this may be more efficient:
find public_html -name '*.html' -print0 | xargs -0 perl -pi -e 's/foobar/fubar/'
Craig's version has to launch a perl process for each file, whereas this
will feed a whole bunch of them for each perl to loop over.
(The -print0 action and the corresponding -0 option allow the command to
handle filenames with spaces and newlines in them correctly. Not all
versions of find and xargs support them -- they may be GNU specific.)
--
Ilmari Karonen -- http://www.sci.fi/~iltzu/
"Get real! This is a discussion group, not a helpdesk. You post something,
we discuss its implications. If the discussion happens to answer a question
you've asked, that's incidental." -- nobull in comp.lang.perl.misc
------------------------------
Date: Tue, 17 Jul 2001 19:06:35 GMT
From: "John DeRama" <oudendijk@home.nl>
Subject: Re: error making Archive::Zip
Message-Id: <%0057.257749$u5.5262706@zwoll1.home.nl>
Hey I don't know the answer to your problem, but can you help me with
finding modules like you use? For example the archive tar (or maybe zip, ace
or rar) modules? Where can I find other perl modules?
"Gururaj Upadhye" <gururaj@powertec.com> wrote in message
news:23c54ab6.0107170444.571d819@posting.google.com...
> I downloaded the fresh installation package (newer version) and did a
> fresh install and tried using the package and it worked!!! Thanks for
> the hints ;-)
>
> I am successful in using to generate archive file. I opened using
> winzip and I am able to see all the files. It also shows the directory
> information (or path information) of the file added. I donot want this
> information to come here. What should I be doing for this.
>
> Here is my script. I exports a directory under found in
> document_root/export/dir
> use Archive::Tar;
> use CGI::Apache qw(:standard);;
> use CGI::Carp 'fatalsToBrowser';
>
> my $query = new CGI;
> my $dir = $query->param('dir');
>
> unless ($dir){
> print 'Failed to get directory to export';
> exit;
> }
>
> my $rootdir = "$ENV{DOCUMENT_ROOT}/export";
> my $tar = Archive::Tar->new();
>
> # Open the directory to read
> opendir(DIR, "$rootdir/$dir") || warn "Temp dir empty: $dir,$rootdir";
>
> # get the list of files from the directory.
> # grep{...} removes the current and previous directory links.
> my @filelist = grep {/^[^.]/ && -f "$rootdir/$dir/$_"} readdir (DIR);
>
> # add every file
> foreach $file (@filelist)
> {
> print "$file:$rootdir/$dir/$file \n";
> $tar->add_files("$rootdir/$dir/$file");
> }
>
> # create the tar file
> $tar->write("$rootdir/$dir.tar.gz", 1);
>
> closedir (DIR);
>
> print "$rootdir/$dir.tar.gz should be the exported file\n";
> print 'SUCCESS';
------------------------------
Date: Tue, 17 Jul 2001 20:59:55 -0000
From: cberry@cinenet.net (Craig Berry)
Subject: Re: extracting a range of lines from a text file
Message-Id: <tl99qbihdsa233@corp.supernews.com>
Ren Maddox (ren@tivoli.com) wrote:
: On 16 Jul 2001, Patrick_member@newsguy.com wrote:
: > What would a perl program look like that extracts, and writes out to
: > another file, an arbitrary range of the lines? Say, lines 300,000
: > through 400,000? Does this exist already. I'm on W2000 running
: > ActiveState Perl. I've tried using the Cygnus tools (eg split,
: > csplit) and so far it seems they won't do the job.
:
: perl -ne "print if 300_000 .. 400_000"
:
: It is probably worth-while to have it quit after 400_000 rather than
: reading the rest of the file:
:
: perl -ne "print if 300_000 .. 400_000; last if $. == 400_000"
If you're going to do that, it's probably more efficient to avoid the
range operator and do a simple $. compare:
perl -ne "print if $. >= 300_000; last if $. == 400_000"
--
| Craig Berry - http://www.cinenet.net/~cberry/
--*-- "Brute force done fast enough looks slick."
| - William Purves
------------------------------
Date: Tue, 17 Jul 2001 18:17:01 GMT
From: PerlFAQ Server <faq@denver.pm.org>
Subject: FAQ: How can I generate simple menus without using CGI or Tk?
Message-Id: <xi%47.240$T3.191076352@news.frii.net>
This message is one of several periodic postings to comp.lang.perl.misc
intended to make it easier for perl programmers to find answers to
common questions. The core of this message represents an excerpt
from the documentation provided with every Standard Distribution of
Perl.
+
How can I generate simple menus without using CGI or Tk?
The http://www.perl.com/CPAN/authors/id/SKUNZ/perlmenu.v4.0.tar.gz
module, which is curses-based, can help with this.
-
Documents such as this have been called "Answers to Frequently
Asked Questions" or FAQ for short. They represent an important
part of the Usenet tradition. They serve to reduce the volume of
redundant traffic on a news group by providing quality answers to
questions that keep coming up.
If you are some how irritated by seeing these postings you are free
to ignore them or add the sender to your killfile. If you find
errors or other problems with these postings please send corrections
or comments to the posting email address or to the maintainers as
directed in the perlfaq manual page.
Answers to questions about LOTS of stuff, mostly not related to
Perl, can be found by pointing your news client to
news:news.answers
or to the many thousands of other useful Usenet news groups.
Note that the FAQ text posted by this server may have been modified
from that distributed in the stable Perl release. It may have been
edited to reflect the additions, changes and corrections provided
by respondents, reviewers, and critics to previous postings of
these FAQ. Complete text of these FAQ are available on request.
The perlfaq manual page contains the following copyright notice.
AUTHOR AND COPYRIGHT
Copyright (c) 1997-1999 Tom Christiansen and Nathan
Torkington. All rights reserved.
This posting is provided in the hope that it will be useful but
does not represent a commitment or contract of any kind on the part
of the contributers, authors or their agents.
03.14
--
This space intentionally left blank
------------------------------
Date: Tue, 17 Jul 2001 19:05:22 GMT
From: "millside" <millettNOSPAM@lblueyonder.co.uk>
Subject: File tutorial?
Message-Id: <S%%47.7669$FC5.1006165@news1.cableinet.net>
Hi,
Anyone know of an online tutorial?
I'm struggling to create a sub to prevent duplicates in my .txt file (used
for subscribed email addresses)
Thanks
--
millside
_____________
------------------------------
Date: Tue, 17 Jul 2001 20:25:03 +0100
From: James Coupe <james@zephyr.org.uk>
Subject: Re: File tutorial?
Message-Id: <FO+RewqPEJV7Ewt6@gratiano.zephyr.org.uk>
In message <S%%47.7669$FC5.1006165@news1.cableinet.net>, millside
<millettNOSPAM@lblueyonder.co.uk> writes
>Anyone know of an online tutorial?
There are many. Search Google until you find one you like.
>I'm struggling to create a sub to prevent duplicates in my .txt file (used
>for subscribed email addresses)
Read them into a hash, using each e-mail address as a hash-key.
Output all the keys to another text file.
Rename/delete as necessary.
--
James Coupe PGP Key: 0x5D623D5D
EBD690ECD7A1F
She twirled a lock of hair around her forefinger and smiled B457CA213D7E6
faintly. "Actually, I'd settle for a small Greek." 68C3695D623D5D
------------------------------
Date: Tue, 17 Jul 2001 23:25:30 +0200
From: stephh <stephh@nospam.com>
Subject: Re: File tutorial?
Message-Id: <170720012325305024%stephh@nospam.com>
Try www.perl.com, heard they have good stuff there ;-)
In article <S%%47.7669$FC5.1006165@news1.cableinet.net>, millside
<millettNOSPAM@lblueyonder.co.uk> wrote:
> Hi,
> Anyone know of an online tutorial?
> I'm struggling to create a sub to prevent duplicates in my .txt file (used
> for subscribed email addresses)
> Thanks
> --
> millside
> _____________
--
$tephh;
Don't forget to visit http://www.grc.com/dos/grcdos.htm
------------------------------
Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 6 Apr 01)
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.announce, send your article to
clpa@perl.com.
To request back copies (available for a week or so), send your request
to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
where x is the volume number and y is the issue number.
For other requests pertaining to the digest, send mail to
perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
sending perl questions to the -request address, I don't have time to
answer them even if I did know the answer.
------------------------------
End of Perl-Users Digest V10 Issue 1317
***************************************