[10858] in Perl-Users-Digest
Perl-Users Digest, Issue: 4459 Volume: 8
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sat Dec 19 07:07:15 1998
Date: Sat, 19 Dec 98 04:00:21 -0800
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, 19 Dec 1998 Volume: 8 Number: 4459
Today's topics:
Re: ------What should I use as a Win32 perl interpreter <gellyfish@btinternet.com>
[Q] How do I connect to a irc server using telnet from (Andreas Gustafsson)
Re: asterisk in subroutine parameter list <gellyfish@btinternet.com>
Re: barcodes and perl <gellyfish@btinternet.com>
Re: Calling Perl from Perl? <gellyfish@btinternet.com>
Easy newbie questions (BXTC)
Re: Easy newbie questions <ebohlman@netcom.com>
Re: Ensuring only one of me is running? <gellyfish@btinternet.com>
Re: Frame question <gellyfish@btinternet.com>
Re: help with MakeMaker <gellyfish@btinternet.com>
help with system() or `` (Nikolaus Nikoll)
Re: Help: missing module <gellyfish@btinternet.com>
How do I .....? <mvenkatesh@worldnet.att.net>
Re: multi-dimensional arrays <gellyfish@btinternet.com>
Re: Nested sorting <uri@sysarch.com>
Re: numbers in base 36 <uri@sysarch.com>
Re: Perl on UNIX and Windows bjm@a2b01118.paralynx.bconnected.com
Re: Perl on UNIX and Windows (Ethan H. Poole)
Please help - CGI.pm <mikeham@samart.co.th>
Re: Please help - CGI.pm <gellyfish@btinternet.com>
Re: Reading in data from a text file <gellyfish@btinternet.com>
Re: Searching through a 10MB file (Christian M. Aranda)
Special: Digest Administrivia (Last modified: 12 Dec 98 (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 19 Dec 1998 09:18:27 -0000
From: Jonathan Stowe <gellyfish@btinternet.com>
Subject: Re: ------What should I use as a Win32 perl interpreter-----
Message-Id: <75fr13$93$1@gellyfish.btinternet.com>
On Sat, 19 Dec 1998 03:30:33 GMT Brett Summerer <summere1@pilot.msu.edu> wrote:
> Right now I use ActivePerl, because it's free. Any other
> ideas?
That is perfectly alright - unless you are going to compile your own it
is really the only version anyone would recommend now ( as long as you have
the lastest version.)
> Also, does anyone know where I can find a decent book on
> getting perl scripts to run on a NT box?
You could check out the 'books' section at <URL:http://reference.perl.com>
for some information on various books available - I wont recommend one
because I havent read any of the candidates. Also if you check out the
'Perl' category at <URL:http://www.newhoo.com/> you will find that the
editors there have found a goodly few resources devoted to Perl on Win32.
> All of the ones that I found
> are written with UNIX in mind. I do my development on Sparqs, but our
> web server is Domino on NT.
>
Ooh.
/J\
--
Jonathan Stowe <jns@btinternet.com>
Some of your questions answered:
<URL:http://www.btinternet.com/~gellyfish/resources/wwwfaq.htm>
Hastings: <URL:http://www.newhoo.com/Regional/UK/England/East_Sussex/Hastings>
------------------------------
Date: 19 Dec 1998 11:48:33 +0100
From: ante@Zeke.Update.UU.SE (Andreas Gustafsson)
Subject: [Q] How do I connect to a irc server using telnet from perl?
Message-Id: <75g0a1$576$1@Zeke.Update.UU.SE>
Keywords: perl, irc, telnet
Hi!
I'm trying to connect to my own irc-server (thus no ban
on multiple connections) using perl. How do I do it?
I've fingured that using telnet might do it,
but how do I connect using telnet from within a perl
program? And how do I send data to the connection?
IS sockets the solutions? I've no idea what sockets
is, but I've realized it has to do with networking.
Any help appreciated!
/andreas
--
=-=-=-=-=-=-=-=-=-=-=-=-=-= Ad Astra!! =-=-=-=-=-=-=-=-=-=-=-=-=-=
Me: sf-fan, philosopher, historian, dreamer...
Loves: my good friends, ale, art in many forms, dreaming...
=-=-=-=-=-=-=-=-=-=-=-=-=-=-= mail me: ante@update.uu.se /FIAWOL!
------------------------------
Date: 19 Dec 1998 11:44:23 -0000
From: Jonathan Stowe <gellyfish@btinternet.com>
Subject: Re: asterisk in subroutine parameter list
Message-Id: <75g3in$l6$1@gellyfish.btinternet.com>
On 17 Dec 1998 04:23:54 GMT mikane@shell3.ba.best.com wrote:
> What is the significance of "*" in the statement:
>
> &widgets(*foo);
>
>From the perldata manpage:
Typeglobs and Filehandles
Perl uses an internal type called a typeglob to hold an
entire symbol table entry. The type prefix of a typeglob
is a *, because it represents all types. This used to be
the preferred way to pass arrays and hashes by reference
into a function, but now that we have real references,
this is seldom needed.
Your snippet now might be written as :
&widgets(\@foo);
(Assuming that the variable in question is an array ).
/J\
--
Jonathan Stowe <jns@btinternet.com>
Some of your questions answered:
<URL:http://www.btinternet.com/~gellyfish/resources/wwwfaq.htm>
Hastings: <URL:http://www.newhoo.com/Regional/UK/England/East_Sussex/Hastings>
------------------------------
Date: 19 Dec 1998 11:32:50 -0000
From: Jonathan Stowe <gellyfish@btinternet.com>
Subject: Re: barcodes and perl
Message-Id: <75g2t2$jc$1@gellyfish.btinternet.com>
On Thu, 17 Dec 1998 01:48:04 GMT A Melton <melton@diagdata.com> wrote:
> any way to take flat ascii files,
> 1 line each and convert them to
> UPC bar codes with perl.
>
I'm pretty sure there isnt a module available from CPAN that will do this
(not to say someone hasnt written one which isnt there) - I would recommend
that you go out and get the specification for the appropriate barcode and
implement some module of your own - I'm sure there are people out there who
could use one too.
/J\
--
Jonathan Stowe <jns@btinternet.com>
Some of your questions answered:
<URL:http://www.btinternet.com/~gellyfish/resources/wwwfaq.htm>
Hastings: <URL:http://www.newhoo.com/Regional/UK/England/East_Sussex/Hastings>
------------------------------
Date: 19 Dec 1998 09:27:25 -0000
From: Jonathan Stowe <gellyfish@btinternet.com>
Subject: Re: Calling Perl from Perl?
Message-Id: <75frht$97$1@gellyfish.btinternet.com>
On Fri, 18 Dec 1998 16:13:32 -0800 Arvind Krishnaswamy <arvindk@pa.dec.com> wrote:
> Is the only way of calling one Perl script from another by using exec or
> system calls?
> If there are other ways, can the two Perl scripts communicate with each
> other (basically to send status messages such as 'Completed' etc)?
>
There are plenty of ways available to you - you might start out by reading
the perlipc manpage which outlines a variety of methods involving for
instance sockets or SysV IPC ...
/J\
--
Jonathan Stowe <jns@btinternet.com>
Some of your questions answered:
<URL:http://www.btinternet.com/~gellyfish/resources/wwwfaq.htm>
Hastings: <URL:http://www.newhoo.com/Regional/UK/England/East_Sussex/Hastings>
------------------------------
Date: Fri, 18 Dec 1998 20:38:01 -0500
From: "(BXTC)" <bxtc@forfree.at>
Subject: Easy newbie questions
Message-Id: <367B0379.F6FB6A58@forfree.at>
I have just started learning Perl and am tring to write a small program
to write html templetes from existing files. My first question is what
symbol/combination works as a wild card (*)? For instance I want to
search a string $name to see if it look like *.html Meaning does the
name end in .html whatever the filename is. I tried using it like that
but it only would detect "*.html" (one single file). Well I guess thats
it for now, I'm using Red Hat 5.1 Perl5.00404. Thanks for any help,
Bryce
--
(BXTC) ICQ# 23289202
------------------------------
Date: Sat, 19 Dec 1998 06:44:15 GMT
From: Eric Bohlman <ebohlman@netcom.com>
Subject: Re: Easy newbie questions
Message-Id: <ebohlmanF479Dr.15p@netcom.com>
(BXTC) <bxtc@forfree.at> wrote:
: I have just started learning Perl and am tring to write a small program
: to write html templetes from existing files. My first question is what
: symbol/combination works as a wild card (*)? For instance I want to
: search a string $name to see if it look like *.html Meaning does the
: name end in .html whatever the filename is. I tried using it like that
: but it only would detect "*.html" (one single file). Well I guess thats
: it for now, I'm using Red Hat 5.1 Perl5.00404. Thanks for any help,
As you've probably discovered, that's not the syntax for doing it. The
proper syntax for doing it can be found in all of the perlre manpage, and
the sections of the perlop manpage dealing with matching and substitution
operators. You may need to read them multiple times, but it's worth
doing because pattern matching is at the heart of nearly everything
you're going to do in Perl.
------------------------------
Date: 19 Dec 1998 11:17:02 -0000
From: Jonathan Stowe <gellyfish@btinternet.com>
Subject: Re: Ensuring only one of me is running?
Message-Id: <75g1ve$i4$1@gellyfish.btinternet.com>
On Tue, 15 Dec 1998 02:22:41 -0800 Steve Harris <perl@nullspace.com> wrote:
>
> Leads me to believe that atomic file locking is the
> best solution for the original posting, and just a
> good idea in general ;-) I don't know how to do this
> in Windows 95+, but I've used lockf() on UNIX systems
> with pretty good success.
>
I dont believe that flock() works on Win95. Anyhow I wouldnt recommend that
you use that platform for anything that would be considered 'Multi-user'.
/J\
--
Jonathan Stowe <jns@btinternet.com>
Some of your questions answered:
<URL:http://www.btinternet.com/~gellyfish/resources/wwwfaq.htm>
Hastings: <URL:http://www.newhoo.com/Regional/UK/England/East_Sussex/Hastings>
------------------------------
Date: 19 Dec 1998 10:57:21 -0000
From: Jonathan Stowe <gellyfish@btinternet.com>
Subject: Re: Frame question
Message-Id: <75g0qh$hu$1@gellyfish.btinternet.com>
On 14 Dec 1998 15:48:16 GMT Yue Wang <ywang@engsoc.carleton.ca> wrote:
>
> Hi,
> I have two frames, let's say frame1.html and frame2.html. And
> there's a frame2.cgi, this script is supposed to update the content of
> frame1.html. My question is if it's possible to refresh frame1.html
> without manually reload it? To be more precise, I'd like to see frame1
> changes it's content automatically when I click the submit button in
> frame2. Any suggestions? By the way, they are open side by side. thanks a
> lot!
>
If you are using CGI.pm (and it is generally recommended that you do) then
you should examine the documentation and specifically the section entitled
"Working with Netscape frames" - Somewhere out there on the 'net there also
some examples by Lincoln Stein (the author CGI.pm) which include a case like
this.
/J\
--
Jonathan Stowe <jns@btinternet.com>
Some of your questions answered:
<URL:http://www.btinternet.com/~gellyfish/resources/wwwfaq.htm>
Hastings: <URL:http://www.newhoo.com/Regional/UK/England/East_Sussex/Hastings>
------------------------------
Date: 19 Dec 1998 09:54:05 -0000
From: Jonathan Stowe <gellyfish@btinternet.com>
Subject: Re: help with MakeMaker
Message-Id: <75ft3t$bm$1@gellyfish.btinternet.com>
On Fri, 18 Dec 1998 18:57:46 -0800 Andrew Keyes <andrew.keyes@attws.com> wrote:
> Platform info:
> uname -a
> SunOS pedev 5.5.1 Generic_103640-06 sun4u sparc SUNW,Ultra-Enterprise
>
> perl -v
> This is perl, version 5.003 with EMBED
> built under solaris at Jan 31 1997 08:40:37
> + suidperl security patch
>
> This machine defaults to using gcc, however my other machine
> defaults to cc with a completely diffent set options.
> {uname} SunOS grover 4.1.3_U1 5 sun4m
>
> How does MakeMaker decide to use cc or gcc?
MakeMaker uses the information stored in Config.pm (on my system in
/usr/lib/perl5/5.00502/i686-linux) that is setup when you run the
'Configure' at the time Perl is initially compiled - it is feasible that
you could actually edit this file as you see fit, but the safest way is to
recompile your Perl giving the appropriate compiler when Configure asks for
it.
/J\
--
Jonathan Stowe <jns@btinternet.com>
Some of your questions answered:
<URL:http://www.btinternet.com/~gellyfish/resources/wwwfaq.htm>
Hastings: <URL:http://www.newhoo.com/Regional/UK/England/East_Sussex/Hastings>
------------------------------
Date: Sat, 19 Dec 1998 11:58:01 GMT
From: nikolaus.nikoll@wu-wien.ac.at (Nikolaus Nikoll)
Subject: help with system() or ``
Message-Id: <367b91f9.990726@news.wu-wien.ac.at>
hi
i am writing a nph cgi script, which calls sqlplus to push the
contents of some oracle db tables to another host, which takes about
2,3 minutes. i do it like this:
@output = `sqlplus foo/bar@www.foo.at @script`;
foreach $_ (@output) {
print;
}
this way, someone who executes this cgi script, has to wait until
sqlplus is finished, and then gets loads of sqlplus output.
is there any way to get and print the output from sqlplus (or any
other command executed from within perl) while it is still running,
which would be much more nicer for the user?
thanx
Nikolaus Nikoll
------------------------------
Date: 19 Dec 1998 11:25:22 -0000
From: Jonathan Stowe <gellyfish@btinternet.com>
Subject: Re: Help: missing module
Message-Id: <75g2f2$i7$1@gellyfish.btinternet.com>
On Thu, 17 Dec 1998 13:29:41 +0100 Thomas Ruedas <ruedas@geophysik.uni-frankfurt.de> wrote:
> Hello,
> as my first posting apparently hasn't reached the NG, I try it again:
> I have got a Perl 5 script here which uses a module Getopt::Std . This
> module is missing on my machine, and I didn't find it on CPAN; I did
> find several Getopt modules, but with other name endings. Can anybody
> tell me if I can use one them instead or, even better, where I can find
> Getopt::Std?
As Getopt::Std is in the distribution of Perl then I would suggest that
something is broken in your installation - and who knows what else might be
missing. I would suggest that you grab the latest version of Perl and
reinstall it.
/J\
--
Jonathan Stowe <jns@btinternet.com>
Some of your questions answered:
<URL:http://www.btinternet.com/~gellyfish/resources/wwwfaq.htm>
Hastings: <URL:http://www.newhoo.com/Regional/UK/England/East_Sussex/Hastings>
------------------------------
Date: 19 Dec 1998 07:29:49 GMT
From: "Muthu Muthuraj" <mvenkatesh@worldnet.att.net>
Subject: How do I .....?
Message-Id: <75fkld$d1b@bgtnsc02.worldnet.att.net>
Find out if the variable obtained from a HTML form using $FORM{'name'} where
name is the variable in the form contains only spaces and no chars/digits.
In otherwords how do I know these strings do not have any content other than
spaces or special chars.
Thanks for the help
--
Muthu
email : mvenkatesh@worldnet.att.net
------------------------------
Date: 19 Dec 1998 10:26:40 -0000
From: Jonathan Stowe <gellyfish@btinternet.com>
Subject: Re: multi-dimensional arrays
Message-Id: <75fv10$e0$1@gellyfish.btinternet.com>
On Fri, 18 Dec 1998 10:43:16 +0100 Teun <teun@bye.nl> wrote:
> Is it possible to use two- or three dimensional arrays in perl?
> what would a foreach-loop look like then?
>
You should definitely be reading the documents that others have suggested
however just for fun here is an example that demonstrates this kind of thing:
#!/usr/bin/perl
@multi_array = (
[
[ 'cat','dog','mouse'],
[ 'cod','herring','skate'],
[ 'eagle','sparrow','robin' ]
],
[
[ 'santa','elves','reindeer'],
[ 'fairy','pixie','gnome'],
[ 'giant','ogre','troll' ]
],
[
[ 'car','train','bicycle'],
[ 'boat','ship','ferry'],
[ 'rollsrskates','skateboard','parachute' ]
]
);
my ($i,$j,$k) = (0,0,0);
foreach $outer ( @multi_array )
{
foreach $middle ( @{$outer})
{
foreach $inner (@{$middle})
{
print '@multi_array',"[$i][$j][$k] = $inner\n";
$k++;
}
$k = 0;
$j++
}
$j = 0;
$i++;
}
Hope that helps
/J\
--
Jonathan Stowe <jns@btinternet.com>
Some of your questions answered:
<URL:http://www.btinternet.com/~gellyfish/resources/wwwfaq.htm>
Hastings: <URL:http://www.newhoo.com/Regional/UK/England/East_Sussex/Hastings>
------------------------------
Date: 19 Dec 1998 01:14:01 -0500
From: Uri Guttman <uri@sysarch.com>
Subject: Re: Nested sorting
Message-Id: <x7lnk4mzfa.fsf@sysarch.com>
>>>>> "BM" == Bill Moseley <moseley@best.com> writes:
BM> My situation is slightly different in that I don't know how many
BM> sort keys I have and which ones are assending and which are
BM> desending sort order until run time. Thus, the loop and the ($aa,
BM> $bb) = ($bb, $aa) swap.
why does your run time differ than anyone else's runtime? :-)
before your sort, scan all your data and build some sort structure,
maybe an array of arrays with the first sub element being the original
data and otehr sub elements being keys which sort up or down. youcan
organize those keys in some way in ths sub arrays so the compare code
know which is up and which is down. that is the common code that is doen
during the preprocessing. then the sort routine does a simple multilevel
sort on the proprocessed arrays and it doesn't have to determine whether
a key is sorted up or down e.g. key[1] is up and key[2] is down, etc.
you have to think about how little work you can make a sort compare
routine do. that is the trick to optimizing sorts, assuming a standard
higher level sort like perl's qsort. if you have more control over the
sort then the game can change, but using perl's sort the object is to
keep the compare routine as fast as possible. hence the 3 major tricks
(with many variations), schwartian transform, orchish (or-cache)
maneuver, and stringifying. all reduce the compare routine's work.
uri
--
Uri Guttman ----------------- SYStems ARCHitecture and Software Engineering
Perl Hacker for Hire ---------------------- Perl, Internet, UNIX Consulting
uri@sysarch.com ------------------------------------ http://www.sysarch.com
The Best Search Engine on the Net ------------- http://www.northernlight.com
------------------------------
Date: 19 Dec 1998 01:36:20 -0500
From: Uri Guttman <uri@sysarch.com>
Subject: Re: numbers in base 36
Message-Id: <x7iuf8mye3.fsf@sysarch.com>
>>>>> "MB" == Matthew Bafford <dragons@scescape.net> writes:
MB> Well, I looked back through my old *ha* scripts, and dug up:
MB> (minus the error checking)
and minus the bug fixes! did you ever test this with a 3 digit number? :-)
MB> sub base2dec {
MB> my %chars;
MB> @chars{(0..9, 'A'..'Z')} = (0..35);
MB> my $base = shift;
MB> my $number = reverse(shift);
MB> my $ret;
MB> my $multi = 1;
MB> for ( split //, $number ) {
MB> $ret += $chars{$_} * $multi;
MB> if ( $multi == 1 ) { $multi = $base }
MB> else { $multi *= 2 }
^^^
$multi
MB> }
MB> return $ret;
MB> }
MB> I probably would have written it differently now, but it does work. :)
no it doesn't!
it also is slower than it has to be. i didn't benchmark the changes but
i would wager that removing the reverse and using chop will beat the
split. also the if looks suspect. i think just multiplying by $multi
each time will be faster than the if. in perl, reducing perl ops is more
critical than saving a multiply. the opposite might be true in c on some
cpu's. this also handles lower case input. i wonder if ucfirst is faster
than uc for a single character value? i am too tired to hack up a
benchmark for that or my other changes. help me larry? :-)
hth,
uri
sub base2dec {
my %chars;
@chars{(0..9, 'A'..'Z')} = (0..35);
my $base = shift;
# my $number = reverse(shift);
my $number = shift;
my $ret;
my $multi = 1;
# for ( split //, $number ) {
while( $c = chop $number, length( $c ) ) {
$ret += $chars{ uc $c} * $multi;
$multi *= $multi ;
}
return $ret;
}
--
Uri Guttman ----------------- SYStems ARCHitecture and Software Engineering
Perl Hacker for Hire ---------------------- Perl, Internet, UNIX Consulting
uri@sysarch.com ------------------------------------ http://www.sysarch.com
The Best Search Engine on the Net ------------- http://www.northernlight.com
------------------------------
Date: 18 Dec 1998 22:08:13 -0800
From: bjm@a2b01118.paralynx.bconnected.com
Subject: Re: Perl on UNIX and Windows
Message-Id: <x7d85gzmsy.fsf@a2b01118.i-did-not-set--mail-host-address--so-shoot-me>
>>>>> "Mikael" == Mikael Georges <mikael.rezo@wanadoo.fr> writes:
Mikael> Hi, I'm learning PERL and I'm working on a UNIX
Mikael> workstation, but my web server is running IIS 4, I already
Mikael> know that I've to use Perl2Exe to make my CGIs working on
Mikael> this server. But Perl2Exe isn't freeware. Does anybody
Mikael> know where I can find an equivalent for Unix or Windows
Mikael> workstation ?
You do not need anything more than Perl, even on IIS.
--
Brad J. Murray "Cogito ergo am."
ActiveState Tool Corp.
------------------------------
Date: Sat, 19 Dec 1998 06:14:58 GMT
From: ehpoole@ingress.com (Ethan H. Poole)
Subject: Re: Perl on UNIX and Windows
Message-Id: <CvHe2.1416$H06.14803@news13.ispnews.com>
[Posted and Emailed] In article <3679ECAE.56A3B710@wanadoo.fr>,
mikael.rezo@wanadoo.fr says...
>
>Hi,
>
>I'm learning PERL and I'm working on a UNIX workstation, but my web
>server is running IIS 4,
>I already know that I've to use Perl2Exe to make my CGIs working on this
>server. But Perl2Exe
>isn't freeware.
>Does anybody know where I can find an equivalent for Unix or Windows
>workstation ?
You do not *have* to use Perl2Exe, just ask your provider to install Perl
(assuming they haven't already) on the server and map the *.pl extension to
the perl interpreter.
--
Ethan H. Poole | Website Design and Hosting,
| CGI Programming (Perl & C)..
========Personal=========== | ============================
* ehpoole @ ingress . com * | --Interact2Day--
| http://www.interact2day.com/
------------------------------
Date: Sat, 19 Dec 1998 19:29:49 -0800
From: Michael Hamilton <mikeham@samart.co.th>
Subject: Please help - CGI.pm
Message-Id: <367C6F2D.D0572DC4@samart.co.th>
I downloaded CGI.pm_2.46 from http://www.perl.com/CPAN-local/CPAN.html.
The readme me file says to write "/perl makefile.pm", but but when I do
an error message says "Can't locate ExtUtils/Makemaker.pm" I presume
this is another program, but I don't seem to have it. Can anyone help?
Thanks
------------------------------
Date: 19 Dec 1998 09:03:26 -0000
From: Jonathan Stowe <gellyfish@btinternet.com>
Subject: Re: Please help - CGI.pm
Message-Id: <75fq4u$8s$1@gellyfish.btinternet.com>
On Sat, 19 Dec 1998 19:29:49 -0800 Michael Hamilton <mikeham@samart.co.th> wrote:
> I downloaded CGI.pm_2.46 from http://www.perl.com/CPAN-local/CPAN.html.
> The readme me file says to write "/perl makefile.pm", but but when I do
> an error message says "Can't locate ExtUtils/Makemaker.pm" I presume
> this is another program, but I don't seem to have it. Can anyone help?
>
It would help if you told us what platform you were running Perl on.
Some versions of Perl for win32 I seem to recall dont properly work with
Makemaker but I cant remember ever having seen where it is entirely absent.
At a push (because it contains no XS components) you could copy the CGI.pm
file from the directory where you unpacked the module to some appropriate
Perl library directory.
However you really should check out the installation of Perl as it is in all
probability broken.
/J\
--
Jonathan Stowe <jns@btinternet.com>
Some of your questions answered:
<URL:http://www.btinternet.com/~gellyfish/resources/wwwfaq.htm>
Hastings: <URL:http://www.newhoo.com/Regional/UK/England/East_Sussex/Hastings>
------------------------------
Date: 19 Dec 1998 09:47:55 -0000
From: Jonathan Stowe <gellyfish@btinternet.com>
Subject: Re: Reading in data from a text file
Message-Id: <75fsob$b7$1@gellyfish.btinternet.com>
On Fri, 18 Dec 1998 17:18:07 -0800 mikej <mikej@1185design.com> wrote:
> Hi everyone,
>
> I have a script that opens a flat file database (LOG filehandle) and
> attempts to read in information on each line. The information in the log
> file looks like this:
>
<snip data>
>
> I have a form that prompts the user to type in a reference number, and
> the script is supposed to search each line of the log file to see if it
> matches the reference number to the number on the left to each line.
> Then I try to get the data on each line that matches the reference
> number they typed. It works for reading the data off the first line, but
> it wont get to the second, third, fourth lines down etc. even though I
> have it in a for each loop. Anyone know how to get it to search the
> entire list instead of only looking at the first line only? Heres the
> code in question:
>
<snip code>
I rendered your code like this for testing purpose:
#!/usr/bin/perl -w
$referenceID = $ARGV[0];
@indata = <DATA>;
my $count = 0;
#supposed to assign each line's data to these 5 variables
foreach $line (@indata)
{
chomp($line);
my ($ID, $date, $initials, $file, $description) = split(/\|/, $line);
if ($ID eq $referenceID)
{
print $line,"\n";
$count++;
}
}
print "No matches found\n" unless ($count);
__END__
17|12-18-98|mj|logo.gif|one
17|12-18-98|mj|home.gif|two
17|12-18-98|mj|employ_top.jpg|three
18|12-18-98|dp|image.jpg|image
18|12-18-98|dp|image_2.jpg|image_two
And when run and passed an argument of '17' it works as it is supposed to.
You will notice that I have changed your 'chop' for the more appropriate
'chomp'.
Of course the 'else' clause you had is not right because that will print an
error on any line that doesnt match - you should notice how I have counted
the matches and then printed a "No match" message after all of the rows
have been checked.
I can only guess that your problems lie elsewhere in your code as the basic
idea is sound (with the caveats above) although I didnt check your file
deletion.
/J\
--
Jonathan Stowe <jns@btinternet.com>
Some of your questions answered:
<URL:http://www.btinternet.com/~gellyfish/resources/wwwfaq.htm>
Hastings: <URL:http://www.newhoo.com/Regional/UK/England/East_Sussex/Hastings>
------------------------------
Date: Sat, 19 Dec 1998 10:04:49 GMT
From: christian.aranda@iiginc.com (Christian M. Aranda)
Subject: Re: Searching through a 10MB file
Message-Id: <75ftu3$8s9$1@news-2.news.gte.net>
On Sat, 19 Dec 1998 01:24:42 GMT, ced@bcstec.ca.boeing.com (Charles
DeRykus) wrote:
>
>>But isn't that interest what motivated you to make your module faster in
>>the first place? ;-)
>
>I see the problem... time being relative moves much more
>quickly as a deadline nears :)
[See timestamp of message]
Yes... that is certainly the case :) All of a sudden, there aren't
enough hours in the day!
Christian M. Aranda
Impact Innovations Group
------------------------
Decide what you want then decide
what you'll give up for it. Me?
I'll give up sleep.
------------------------------
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 4459
**************************************