[13625] in Perl-Users-Digest
Perl-Users Digest, Issue: 1035 Volume: 9
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Oct 11 00:05:41 1999
Date: Sun, 10 Oct 1999 21:05:11 -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: <939614710-v9-i1035@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Sun, 10 Oct 1999 Volume: 9 Number: 1035
Today's topics:
Re: Do you now an affordable Perl editor for Windows NT <mattking@techie.com>
Re: Help - Perl regular expression question! (Ilya Zakharevich)
HELP! Why don't cookies work correctly with PERL....... <mattking@techie.com>
Re: Help! (Abigail)
Re: how to call a sub roght by form <dave@dave.org.uk>
Re: howto load modules to an ISP website? dtbaker_dejanews@my-deja.com
Re: I need some Perl help (Abigail)
Re: need csh > perl advice <reply@the.ng>
Need help making arrays. <mattking@techie.com>
Need help making arrays. <mattking@techie.com>
Re: Need help making arrays. <mattking@techie.com>
Re: Parsing Config File (Damian Conway)
Re: Passing unknown filenames as arguments to another p (Tad McClellan)
Re: Passing unknown filenames as arguments to another p (Abigail)
Re: Printing Unique fileds of a text database-help me? <jeff@vpservices.com>
Re: Printing Unique fileds of a text database-help me? <bwalton@rochester.rr.com>
s/// used on a file slurped into a scalar (David Wall)
Simple flock question <wjbell@ERASEjps.net>
Re: trouble with hash (Mark P.)
unused files script (Ace)
Re: Which Search engine script? <cumhur.ozkan@janset.com>
Re: Y2K and localtime (Abigail)
Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Thu, 7 Oct 1999 11:28:57 +0200
From: "Matt King" <mattking@techie.com>
Subject: Re: Do you now an affordable Perl editor for Windows NT
Message-Id: <7thmra$d0c$1@news.uk.ibm.com>
Why not just use the Windows notepad.exe? Works fine for me......
Matt
------------------------------
Date: 11 Oct 1999 02:57:04 GMT
From: ilya@math.ohio-state.edu (Ilya Zakharevich)
Subject: Re: Help - Perl regular expression question!
Message-Id: <7trjm0$o7e$1@charm.magnus.acs.ohio-state.edu>
[A complimentary Cc of this posting was sent to lt lindley
<lee.lindley@bigfoot.com>],
who wrote in article <7tr4u9$l58$1@rguxd.viasystems.com>:
> A backreference has a fixed length when it is actually tested.
??? How do you decide at compile time what length a backreference is
going to have?
> Could
> it not be made legal in a lookbehind? Let me rephrase. How much
> work would it take to make it legal in a lookbehind?
>
> /(fo+)(?<!k\1(?=d))/: variable length lookbehind not implemented at re line 12.
> I'm not advocating quatifiers in the lookbehind that would cause
> backtracking within the lookbehind itself.
There is no issue with backtracking at all. What is the issue is that
the only "reasonable" way to have lookbehind is to teach REx engine to
apply a REx backwards.
IIRC, I already reserved //r for backward/reversed matches (as in
/f.*ck\G/r, which should not look around at all: it could start at
pos(), and go backwards). When REx engine can do this,
variable-length lookbehind will be easy too.
Ilya
------------------------------
Date: Fri, 8 Oct 1999 22:03:54 +0200
From: "Matt King" <mattking@techie.com>
Subject: HELP! Why don't cookies work correctly with PERL.........
Message-Id: <7tlgj9$p14$1@news.uk.ibm.com>
OK. I ask a question on how to get cookies working with PERL a few days ago,
but I didn't get an answer. However, I found a working script for bother NS
and IE through an update to another question from someone else. (some link
to a site).
I downloaded the script and I have been testing it. Can someone explain what
I'm doing wrong? this makes no sence _at all_.
Why don't cookies work with PERL is the script is an ssi or link or
redirected http request????????
If I have a simple script that looks like this:
#!d:/web/perl/bin/perl.exe
$Date = "Sunday, 10-Oct-99 08:00:00 GMT";
$domain = "169.165.164.211";
$path = "/cgi-bin/";
&setCookie("user", $ENV{'REMOTE_USER'}, $Date, $path, $domain);
&setCookie("user_addr", $ENV{'REMOTE_HOST'}, $Date, $path, $domain);
print "Content-type: text/html\n\n";
print "<html><head><title>cookie test</title><body>cookie set<br>";
%cookies = &getCookies;
foreach $name (keys %cookies) {
print "\n$name = $cookies{$name}<br>";
}
print "</body></html>\n";
exit;
sub setCookie {
...
}
sub getCookies {
...
}
If I call the script *directly* with the browser the script sends the cookie
to the browser, but if I put a redirect header in a html file to point to
this scipt, or change the script into an ssi (or or or), the cookie is not
sent. There is no error from the server and the script does execute, just
the cookie is not sent. Why the difference? Same script. What do I need to
change to make this work as a ssi and a cgi?
Matt
------------------------------
Date: 9 Oct 1999 22:06:36 -0500
From: abigail@delanet.com (Abigail)
Subject: Re: Help!
Message-Id: <slrn8000lh.iq.abigail@alexandra.delanet.com>
David Efflandt (efflandt@xnet.com) wrote on MMCCXXXI September MCMXCIII
in <URL:news:slrn7vvnuk.3ul.efflandt@efflandt.xnet.com>:
**
** In what context? What you show here is a URL that ends with a filename,
** not a directory. A directory (default index) would have a trailing slash.
** However, you may not be aware of it because the webserver will usually
** redirect you to the correct URL with trailing slash.
Actually, it's neither. URL point to _resources_, not files.
http://www.something.com/anything might be mapped by the server to
a file; not necessarely named 'anything'. It might be mapped to a
directory. It could be an entry in a database. It could generate an
on-the-fly calculated response.
The assumption that URLs point to files is false.
Abigail
--
perl -MTime::JulianDay -lwe'@r=reverse(M=>(0)x99=>CM=>(0)x399=>D=>(0)x99=>CD=>(
0)x299=>C=>(0)x9=>XC=>(0)x39=>L=>(0)x9=>XL=>(0)x29=>X=>IX=>0=>0=>0=>V=>IV=>0=>0
=>I=>$r=-2449231+gm_julian_day+time);do{until($r<$#r){$_.=$r[$#r];$r-=$#r}for(;
!$r[--$#r];){}}while$r;$,="\x20";print+$_=>September=>MCMXCIII=>()'
-----------== Posted via Newsfeeds.Com, Uncensored Usenet News ==----------
http://www.newsfeeds.com The Largest Usenet Servers in the World!
------== Over 73,000 Newsgroups - Including Dedicated Binaries Servers ==-----
------------------------------
Date: Sun, 10 Oct 1999 09:53:26 +0100
From: Dave Cross <dave@dave.org.uk>
Subject: Re: how to call a sub roght by form
Message-Id: <bFMAOKkb=vlRSBABvkm=nGeuvC21@4ax.com>
On Sun, 10 Oct 1999 00:28:01 +0200, "Yuval Hamberg" <yhm@inter.net.il>
wrote:
>hi,
>I want that the user will enter his password in a cgi output like this:
><html><body>
><h1>Password?</h1><form method="POST">
><input type="hidden" name="action" value="main">
><input type="password" name="password"><br>
><input type="submit" value=" Enter ">
></form></body></html>
>
>than the cgi will do:
>if ($FORM{'action'}) { &checkpassword; }
>if ($FORM{'action'} eq "main") { &main; }
>
>But that dosent work. i lerned that i sould put this in before:
># Read and Parse Form:
>read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
>@pairs = split(/&/, $buffer);
>foreach $pair (@pairs)
> {
> ($name, $value) = split(/=/,$pair);
> $value =~ tr/+/ /;
> $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg;
> $value =~ s/<!--(.|\n)*-->//g;
> $FORM{$name} = $value;
> }
># Finished with parsing the input.
>
>But i don't know excekly what it does and not why he does it. anyway it
>still wont work...
>
>any ideas
Yes. Throw away the book that told you to write such horrible code.
Why go to all of that trouble to rewrite code that has already been
wrtiien for you. Use the CGI.pm module that has been part of the
standard Perl distribution for many years now.
For help on using CGI.pm look at the docs that have been installed on
your system using 'perldoc CGI'. For more details buy Lincoln Stein's
excellent book 'The Official Guide to Programming with CGI.pm'
hth,
Dave...
--
Dave Cross <dave@dave.org.uk>
<http://www.dave.org.uk>
------------------------------
Date: Mon, 11 Oct 1999 02:58:17 GMT
From: dtbaker_dejanews@my-deja.com
Subject: Re: howto load modules to an ISP website?
Message-Id: <7trjo4$164$1@nnrp1.deja.com>
In article <Pine.HPP.3.95a.991010185703.7619F-100000@hpplus01.cern.ch>,
"Alan J. Flavell" <flavell@mail.cern.ch> wrote
>
> perldoc -q module
-----------------
is the -q option a new thing for 5.005? I am running an older version
and my perldoc doesnt have a -q option.....
Dan
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: 10 Oct 1999 22:33:35 -0500
From: abigail@delanet.com (Abigail)
Subject: Re: I need some Perl help
Message-Id: <slrn802mk2.gep.abigail@alexandra.delanet.com>
Jonathan Stowe (gellyfish@gellyfish.com) wrote on MMCCXXXI September
MCMXCIII in <URL:news:7tqu5d$6ae$1@gellyfish.btinternet.com>:
,, On Sun, 10 Oct 1999 18:05:28 GMT Mob-Rules wrote:
,, > I have a list of names in a file and I need to know how many times each
,, > name appears and what the name is but can't figure out how to do it in
,, > Perl.
,, >
,,
,, my %filenames;
,,
,, while(<>)
,, {
,, chomp;
,, $filenames{$_}++;
,, }
,,
,, foreach (keys %filenames)
,, {
,, print $_,"\t",$filenames{$_},"\n";
,, }
Now, what's the point of chomping the name, and then adding a
newline again when printing it?
Abigail
--
perl -e '* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
/ / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / /
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % %;
BEGIN {% % = ($ _ = " " => print "Just Another Perl Hacker\n")}'
-----------== Posted via Newsfeeds.Com, Uncensored Usenet News ==----------
http://www.newsfeeds.com The Largest Usenet Servers in the World!
------== Over 73,000 Newsgroups - Including Dedicated Binaries Servers ==-----
------------------------------
Date: Sun, 10 Oct 1999 02:58:30 GMT
From: "Matt Hadder" <reply@the.ng>
Subject: Re: need csh > perl advice
Message-Id: <qhTL3.7661$Y96.70888@news.rdc2.occa.home.com>
Heh heh... I may be an enigma... I use comments extensively.
Thanks for the advice. I have programming Perl from O'Reilly... I will look
up the page you suggested. And I realize learning is the only way to get it
done correctly. And I will learn over time but... (and this is a big
but)... as it stands now I must port these scripts in the next 5 days or so.
They're starting out as csh scripts with 2000-3000 lines total. I started
after lunch Friday -- I have about 50 lines ported so far... I realize
having written that much that I was potentially causing problems for the
future manageability of the code. I just want to avoid writing a csh script
in Perl if you know what I mean.
Thanks again,
Matt
Steven Smolinski <sjs@yorku.ca> wrote in message
news:m3yadct78f.fsf@hank.yorku.ca...
> "Matt Hadder" <reply@the.ng> writes:
>
> > Is there some good documentation for avoiding pitfalls when coming from
> > another language to Perl?
>
> There are a few words in _Programming Perl_, 2nd edition, by Wall,
> Christiansen, and Scwartz (O'Reilly) page 533 (which I think is one
> must-have if you need to do serious Perl).
>
> > Does anyone have advice as to the approach to take or things to avoid
when
> > porting from csh to Purl?
>
> There is this snippet of good advice in the Perl FAQ:
>
> ------8<-------
> =head2 How can I convert my shell script to perl?
>
> Learn Perl and rewrite it. Seriously, there's no simple converter.
> Things that are awkward to do in the shell are easy to do in Perl, and
> this very awkwardness is what would make a shell->perl converter
> nigh-on impossible to write. By rewriting it, you'll think about what
> you're really trying to do, and hopefully will escape the shell's
> pipeline datastream paradigm, which while convenient for some matters,
> causes many inefficiencies.
> ------8<-------
>
> Have fun!
>
> Steve
>
> PS: On a lighter note: if you're like the shell programmers in my shop,
> please, Please, PLEASE remember that commenting your script is NOT a
> sign of weakness!!!
------------------------------
Date: Thu, 7 Oct 1999 10:54:51 +0200
From: "Matt King" <mattking@techie.com>
Subject: Need help making arrays.
Message-Id: <7thm99$9tc$1@news.uk.ibm.com>
Hi all,
I'm trying to make a simple CGI script that reads 12 different DB-File's,
stores all the information in an two arrays. Than I can send this
information to GIFgraph to get a optical display of the information.
The contence of the DB_Files will never be that same, but have the same
format. That format being in pos 0 is the 'control' word and in pos 1 is the
'count' for the 'control' word. I read in the data from the DB_File, and
then split the information to get $i (pos 0) and $data[0] (pos 1). Now I
want to take the 'control' word and compair it to the 'master' list which
has a list of all 'control' words, if the 'control' word doesn't exist, it's
added to the bottom of the list and the $data[0] is added to the totals
array in the correct position.
For example:
File 1:
John 12
Mike 7
Chris 9
File 2:
Sam 8
Mike 7
Gerry 20
Matt 3
File 4:
Tom 3
File 5:
EMPTY - No entries
File 6:
Matt 7
John 8
Chris 3
File 7:
Tom 8
File 8:
Tom 9
John 12
Mike 3
File 9:
EMPTY - No entries
File 10:
EMPTY - No entries
File 11:
Mike 7
John 20
Gerry 5
File 12:
Tom 8
Chris 15
The script woul then convert the information into something like this:
'Totals (array of arrays)'
'master' f1 f2 f3 f4 f5 f6 f7 f8 f9
f10 f11 f12
John 12 0 0 0 0 8 0 12 0 0
20 0
Mike 7 0 0 0 0 0 0 0 0 0
7 0
Chris 9 0 0 0 0 3 0 0 0 0
0 15
Sam 0 8 0 0 0 0 0 0 0 0
0 0
Mike 0 7 0 0 0 0 0 3 0 0
5 0
Gerry 0 20 0 0 0 0 0 0 0 0
0 0
Matt 0 3 0 0 0 7 0 0 0 0
0 0
Tom 0 0 0 3 0 0 8 9 0 0
0 8
I can't figure out how I can make this work. Can someone point me in the
right direction please?
Matt
------------------------------
Date: Thu, 7 Oct 1999 10:57:42 +0200
From: "Matt King" <mattking@techie.com>
Subject: Need help making arrays.
Message-Id: <7thm99$9tc$2@news.uk.ibm.com>
This is a multi-part message in MIME format.
------=_NextPart_000_0043_01BF10B2.C780E6C0
Content-Type: text/plain;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
Hi all,
I'm trying to make a simple CGI script that reads 12 different =
DB-File's,
stores all the information in an two arrays. Than I can send this
information to GIFgraph to get a optical display of the information.
The contence of the DB_Files will never be that same, but have the same
format. That format being in pos 0 is the 'control' word and in pos 1 is =
the
'count' for the 'control' word. I read in the data from the DB_File, and
then split the information to get $i (pos 0) and $data[0] (pos 1). Now I
want to take the 'control' word and compair it to the 'master' list =
which
has a list of all 'control' words, if the 'control' word doesn't exist, =
it's
added to the bottom of the list and the $data[0] is added to the totals
array in the correct position.
For example:
File 1:
John 12
Mike 7
Chris 9
File 2:
Sam 8
Mike 7
Gerry 20
Matt 3
File 4:
Tom 3
File 5:
EMPTY - No entries
File 6:
Matt 7
John 8
Chris 3
File 7:
Tom 8
File 8:
Tom 9
John 12
Mike 3
File 9:
EMPTY - No entries
File 10:
EMPTY - No entries
File 11:
Mike 7
John 20
Gerry 5
File 12:
Tom 8
Chris 15
The script woul then convert the information into something like this:
'Totals (array of =
arrays)'
'master' f1 f2 f3 f4 f5 f6 f7 f8 f9
f10 f11 f12
John 12 0 0 0 0 8 0 12 0 =
0
20 0
Mike 7 0 0 0 0 0 0 0 0 =
0
7 0
Chris 9 0 0 0 0 3 0 0 0 =
0
0 15
Sam 0 8 0 0 0 0 0 0 0 =
0
0 0
Mike 0 7 0 0 0 0 0 3 0 =
0
5 0
Gerry 0 20 0 0 0 0 0 0 0 =
0
0 0
Matt 0 3 0 0 0 7 0 0 0 =
0
0 0
Tom 0 0 0 3 0 0 8 9 0 =
0
0 8
I can't figure out how I can make this work. Can someone point me in the
right direction please?
Matt
------=_NextPart_000_0043_01BF10B2.C780E6C0
Content-Type: text/html;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META content=3D"text/html; charset=3Diso-8859-1" =
http-equiv=3DContent-Type>
<META content=3D"MSHTML 5.00.2014.210" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=3D#ffffff>
<DIV><FONT face=3DArial size=3D2>Hi all,<BR> I'm trying to make a =
simple CGI=20
script that reads 12 different DB-File's,<BR>stores all the information =
in an=20
two arrays. Than I can send this<BR>information to GIFgraph to get a =
optical=20
display of the information.<BR><BR>The contence of the DB_Files will =
never be=20
that same, but have the same<BR>format. That format being in pos 0 is =
the=20
'control' word and in pos 1 is the<BR>'count' for the 'control' word. I =
read in=20
the data from the DB_File, and<BR>then split the information to get $i =
(pos 0)=20
and $data[0] (pos 1). Now I<BR>want to take the 'control' word and =
compair it to=20
the 'master' list which<BR>has a list of all 'control' words, if the =
'control'=20
word doesn't exist, it's<BR>added to the bottom of the list and the =
$data[0] is=20
added to the totals<BR>array in the correct position.<BR><BR>For=20
example:<BR>File 1:<BR> John 12<BR> Mike 7<BR> Chris =
9<BR>File=20
2:<BR> Sam 8<BR> Mike 7<BR> Gerry 20<BR> Matt =
3<BR>File=20
4:<BR> Tom 3<BR>File 5:<BR> EMPTY - No entries<BR>File =
6:<BR> Matt 7<BR> John 8<BR> Chris 3<BR>File =
7:<BR> Tom=20
8<BR>File 8:<BR> Tom 9<BR> John 12<BR> Mike 3<BR>File=20
9:<BR> EMPTY - No entries<BR>File 10:<BR> EMPTY - No =
entries<BR>File=20
11:<BR> Mike 7<BR> John 20<BR> Gerry 5<BR>File =
12:<BR> =20
Tom 8<BR> Chris 15<BR><BR>The script woul then convert the =
information=20
into something like=20
this:<BR> &nbs=
p;  =
; =
&=
nbsp; =20
'Totals (array of=20
arrays)'<BR>'master'  =
; =20
f1 f2 f3 =20
f4 f5 f6 =20
f7 f8 f9<BR>f10 =20
f11 f12<BR> =20
John &nb=
sp; =20
12 0 0 =
0 0 8 =20
0 12 0 =20
0<BR>20 0<BR> =20
Mike &nb=
sp; =20
7 0 =
0 =20
0 0 =
0 =20
0 0 0 =20
0<BR>7 0<BR> =20
Chris &n=
bsp; =20
9 0 =
0 =20
0 0 3 =20
0 0 =
0 =20
0<BR>0 15<BR> =20
Sam &nbs=
p; =20
0 8 =
0 =20
0 0 0 =20
0 0 =
0 =20
0<BR>0 0<BR> =20
Mike &nb=
sp; =20
0 7 0 =20
0 0 =
0 =20
0 3 =
0 =20
0<BR>5 0<BR> =20
Gerry &n=
bsp; =20
0 20 0 =20
0 0 =
0 =20
0 0 =
0 =20
0<BR>0 0<BR> =20
Matt &nb=
sp; =20
0 3 0 =20
0 0 =
7 =20
0 0 =
0 =20
0<BR>0 0<BR> =20
Tom &nbs=
p; =20
0 0 0 =20
3 0 =
0 =20
8 9 =
0 =20
0<BR>0 8<BR><BR>I can't figure out how I =
can make=20
this work. Can someone point me in the<BR>right direction=20
please?<BR><BR>Matt<BR><BR><BR><BR></FONT></DIV></BODY></HTML>
------=_NextPart_000_0043_01BF10B2.C780E6C0--
------------------------------
Date: Fri, 8 Oct 1999 15:11:54 +0200
From: "Matt King" <mattking@techie.com>
Subject: Re: Need help making arrays.
Message-Id: <7tko9e$80k$1@news.uk.ibm.com>
Can someone out there help me with this? Is this at all possible with PERL?
How?
Matt
Matt King <mattking@techie.com> wrote in message
news:7thm99$9tc$1@news.uk.ibm.com...
> Hi all,
> I'm trying to make a simple CGI script that reads 12 different
DB-File's,
> stores all the information in an two arrays. Than I can send this
> information to GIFgraph to get a optical display of the information.
>
> The contence of the DB_Files will never be that same, but have the same
> format. That format being in pos 0 is the 'control' word and in pos 1 is
the
> 'count' for the 'control' word. I read in the data from the DB_File, and
> then split the information to get $i (pos 0) and $data[0] (pos 1). Now I
> want to take the 'control' word and compair it to the 'master' list which
> has a list of all 'control' words, if the 'control' word doesn't exist,
it's
> added to the bottom of the list and the $data[0] is added to the totals
> array in the correct position.
>
> For example:
> File 1:
> John 12
> Mike 7
> Chris 9
> File 2:
> Sam 8
> Mike 7
> Gerry 20
> Matt 3
> File 4:
> Tom 3
> File 5:
> EMPTY - No entries
> File 6:
> Matt 7
> John 8
> Chris 3
> File 7:
> Tom 8
> File 8:
> Tom 9
> John 12
> Mike 3
> File 9:
> EMPTY - No entries
> File 10:
> EMPTY - No entries
> File 11:
> Mike 7
> John 20
> Gerry 5
> File 12:
> Tom 8
> Chris 15
>
> The script woul then convert the information into something like this:
> 'Totals (array of
arrays)'
> 'master' f1 f2 f3 f4 f5 f6 f7 f8 f9
> f10 f11 f12
> John 12 0 0 0 0 8 0 12 0 0
> 20 0
> Mike 7 0 0 0 0 0 0 0 0 0
> 7 0
> Chris 9 0 0 0 0 3 0 0 0
0
> 0 15
> Sam 0 8 0 0 0 0 0 0 0 0
> 0 0
> Mike 0 7 0 0 0 0 0 3 0
0
> 5 0
> Gerry 0 20 0 0 0 0 0 0 0 0
> 0 0
> Matt 0 3 0 0 0 7 0 0 0
0
> 0 0
> Tom 0 0 0 3 0 0 8 9 0 0
> 0 8
>
> I can't figure out how I can make this work. Can someone point me in the
> right direction please?
>
> Matt
>
>
>
>
------------------------------
Date: 11 Oct 1999 02:43:12 GMT
From: damian@cs.monash.edu.au (Damian Conway)
Subject: Re: Parsing Config File
Message-Id: <7tris0$21v$1@towncrier.cc.monash.edu.au>
chrisf@removethis.winterlink.net (Chris Fairbanks) writes:
>I am trying to parse an apache config file to print out to a file the
>virtualwebsite:homedirectory. I have searched but cannot find anyway
>to do it. Any help would be appreciated.
Any of the parsing modules will handle this with very little effort.
Here's a solution using Parse::RecDescent...
Damian
-----------cut-----------cut-----------cut-----------cut-----------cut----------
use Parse::RecDescent;
# DEFINE FILE FORMAT AS A GRAMMAR
my $parser = Parse::RecDescent->new(<<'EOGRAMMAR');
file: bit(s)
bit: vhost | junk
vhost: '<VirtualHost' ip_addr '>'
field(s)
'</VirtualHost>'
{ my %vhost = map { %$_ } @{$item[4]};
print "$vhost{name}:$vhost{root}\n";
}
ip_addr: /\d+\.\d+\.\d+\.\d+/
field: 'ServerAdmin' m|\S+| { $return->{admin} = $item[2] }
| 'DocumentRoot' m|^(.*/)[^/\n]*| { $return->{root} = $1 }
| 'ServerName' m|\S+| { $return->{name} = $item[2] }
junk: /.*/
EOGRAMMAR
# GRAB DATA
undef $/;
my $text = <DATA>;
# PARSE IT
$parser->file($text);
__DATA__
about 50 lines of other data that needs to be skipped above this.
about 50 lines of other data that needs to be skipped above this.
about 50 lines of other data that needs to be skipped above this.
about 50 lines of other data that needs to be skipped above this.
about 50 lines of other data that needs to be skipped above this.
about 50 lines of other data that needs to be skipped above this.
about 50 lines of other data that needs to be skipped above this.
about 50 lines of other data that needs to be skipped above this.
about 50 lines of other data that needs to be skipped above this.
about 50 lines of other data that needs to be skipped above this.
about 50 lines of other data that needs to be skipped above this.
about 50 lines of other data that needs to be skipped above this.
about 50 lines of other data that needs to be skipped above this.
about 50 lines of other data that needs to be skipped above this.
about 50 lines of other data that needs to be skipped above this.
about 50 lines of other data that needs to be skipped above this.
about 50 lines of other data that needs to be skipped above this.
about 50 lines of other data that needs to be skipped above this.
#about 50 lines of other data that needs to be skipped above this.
<VirtualHost 10.1.1.2>
ServerAdmin webmaster@joebob.com
DocumentRoot /home/j/joebob/public_html
ServerName www.joebob.com
</VirtualHost>
<VirtualHost 10.1.1.3>
ServerAdmin webmaster@joe.com
DocumentRoot /home/j/joe/public_html
ServerName www.joe.com
</VirtualHost>
<VirtualHost 10.1.1.4>
ServerAdmin webmaster@bob.com
DocumentRoot /home/b/bob/public_html
ServerName www.bob.com
</VirtualHost>
------------------------------
Date: Sun, 10 Oct 1999 16:51:39 -0400
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: Passing unknown filenames as arguments to another program
Message-Id: <r8uqt7.qmr.ln@magna.metronet.com>
Steve Cresawn (scresawn@ufl.edu) wrote:
: I'm new to perl, and my question is this: I have a directory on a
perldoc -f opendir
: linux machine with hundreds of text files,
perldoc -f readdir
: whose filenames all end in
: ".seq".
perldoc perlre
perldoc -f grep
: I need to be able to create an array that holds the filenames
^^^^^^^
: for the all the files ending with .seq.
Why do you "need to"?
I don't see that you need to put them into an array, and
my code works fine without that.
: I then need to pass each of the
: files as arguments to an external program, called "blastcl3".
perldoc -f system
--------------------------
#!/usr/bin/perl -w
use strict;
my $dir = '.'; # current directory
opendir DIR, $dir or die "could not open '$dir' $!";
foreach my $fname ( grep /\.seq$/, readdir DIR) {
print "blastcl3 $fname\n"; # change to system() and *check return value*
}
closedir DIR;
--------------------------
--
Tad McClellan SGML Consulting
tadmc@metronet.com Perl programming
Fort Worth, Texas
------------------------------
Date: 10 Oct 1999 22:39:23 -0500
From: abigail@delanet.com (Abigail)
Subject: Re: Passing unknown filenames as arguments to another program
Message-Id: <slrn802muv.gep.abigail@alexandra.delanet.com>
Steve Cresawn (scresawn@ufl.edu) wrote on MMCCXXXI September MCMXCIII in
<URL:news:38010203.9637FAE3@ufl.edu>:
%% I'm new to perl, and my question is this: I have a directory on a
%% linux machine with hundreds of text files, whose filenames all end in
%% ".seq". I need to be able to create an array that holds the filenames
%% for the all the files ending with .seq. I then need to pass each of the
%% files as arguments to an external program, called "blastcl3".
Uhm, why use Perl, and why put it in an array?
Assuming blastcl3 can take multiple arguments:
ls *.seq | xargs blastcl3
But if you insist in putting it an array first:
perl -we 'map {system blastcl3 => $_} @a = <*.seq>'
Abigail
--
sub _'_{$_'_=~s/$a/$_/}map{$$_=$Z++}Y,a..z,A..X;*{($_::_=sprintf+q=%X==>"$A$Y".
"$b$r$T$u")=~s~0~O~g;map+_::_,U=>T=>L=>$Z;$_::_}=*_;sub _{print+/.*::(.*)/s}
*_'_=*{chr($b*$e)};*__=*{chr(1<<$e)};
_::_(r(e(k(c(a(H(__(l(r(e(P(__(r(e(h(t(o(n(a(__(t(us(J())))))))))))))))))))))))
-----------== Posted via Newsfeeds.Com, Uncensored Usenet News ==----------
http://www.newsfeeds.com The Largest Usenet Servers in the World!
------== Over 73,000 Newsgroups - Including Dedicated Binaries Servers ==-----
------------------------------
Date: 11 Oct 1999 02:17:27 GMT
From: Jeff Zucker <jeff@vpservices.com>
Subject: Re: Printing Unique fileds of a text database-help me?
Message-Id: <3801486D.8FFA6734@vpservices.com>
garmark wrote:
>
> [snip] say this is my database:
>
> bob::electrician::blalblabal
> jim::lawyer::blalblabal
> john::mechanic::blalblaba
> jim:elctrician::blalbala
>
> I want it to display:
>
> electrician
> bob
> jim
> lawyer
> jim
> mechanic
> john
>
> I think this uses push and hash features [snip]
Yep, my thought also. My approach would be to create a hash of
categories, an array of categories, and a hash of arrays of names. You
could then test to see if a category is in the hash of categories, if
not, put it in that hash and push it into the array of categories. Each
person would get pushed into an array which is stored in a hash that has
thier category as the key. To get the data out, you would loop through
the array of categories and for each one, print it, then loop through
the array of names in the hash for that category, printing those. This
is actually harder to explain than to do, see my code below.
> Please email. thanks
Sorry, I can't do that because I may not being doing this correctly
either, in which case someone smarter than me will undoubtedly let us
know and we can both learn something.
--
Jeff
Here's my script:
#!/usr/local/bin/perl -w
use strict;
my @jobs; # ARRAY TO HOLD UNIQUE LIST OF JOBS
my %job_listed; # HASH TO TEST IF JOB IS IN THE ARRAY
my %persons; # HASH OF ARRAYS TO HOLD PERSONS IN JOB
while(<DATA>){
my($person,$job,undef)=split /::/;
if( !$job_listed{$job} ) {
push @jobs, $job;
$job_listed{$job}=1;
}
push @{$persons{$job}}, $person;
}
for my $job( @jobs ) {
print "$job\n";
for my $person ( @{$persons{$job}} ) {
print " $person\n";
}
}
__END__
bob::electrician::blalblabal
jim::lawyer::blalblabal
john::mechanic::blalblaba
jim::electrician::blalbala
------------------------------
Date: Sun, 10 Oct 1999 23:25:32 -0400
From: Bob Walton <bwalton@rochester.rr.com>
Subject: Re: Printing Unique fileds of a text database-help me?
Message-Id: <380158AC.DAEC2040@rochester.rr.com>
garmark wrote:
>
> Hello,
> I am working on a script using a database of info seperated by "::"
> Each line has 5 fields in an array named @info.
> $info[0]=name
> $info[1]=catagoty
> and the rest are irrelivent to the problem.
>
> I want to be able to print each unique $info[1] and below it list all
> the $info[0] in the line that contain the associated $info[0].
> say this is my database:
>
> bob::electrician::blalblabal
> jim::lawyer::blalblabal
> john::mechanic::blalblaba
> jim:elctrician::blalbala
>
> I want it to display:
>
> electrician
> bob
> jim
> lawyer
> jim
> mechanic
> john
>
> I think this uses push and hash features, but i don't know a thing
> about them.
> the way I have it know the script prints:
> electrician
> bob
> lawyer
> jim
> mechanic
> john
> electrician
> jim
>
> I get the repeat "elecrician" input for $info[0].
> So like maybe
> foreach unique($info[1]) {
> print "$info0";
> }
> but that doesn't work......
...
> Blaine garrett
>
...
Blaine, try:
while(<>){
chomp;
($in0,$in1,$rest)=split /:+/,$_,3;
$in1=~s/elctrician/electrician/; #:-)
$h{$in1}.=$in0.':';
}
for $k (sort keys %h){
print "$k\n";
for(split /:/,$h{$k}){
print " $_\n";
}
}
--
Bob Walton
------------------------------
Date: Sun, 10 Oct 1999 03:06:11 GMT
From: darkon@one.net (David Wall)
Subject: s/// used on a file slurped into a scalar
Message-Id: <380002d9_1@news2.one.net>
I wrote a short script to give the FAQs in the html version of the Activestate
docs more descriptive link text. It works fine, even if it is a bit crude,
but then I started tinkering to make it shorter. The following code doesn't
work, and I'm not sure why. I used the same regular expression in the code
that worked, except that here I used s///sig instead of s///si.
Before you ask, I'm using -w and 'use strict;'. :-)
Here's the code that doesn't work:
undef $/;
open(TOC, "c:/Perl/html/perltoc.html") or die($!);
$_=<TOC>;
close TOC or die($!);
#next stmt is really all on one line, but it wraps in my newsreader.
s#(<a
href="\./lib/Pod/perlfaq\d\.html">.*)perlfaq(\d).*(</a>)#$1$faq{$2}$3#sig;
print;
%faq is a hash I built earlier in the program by extracting the <title> text
from the html version of the numbered FAQs. The keys are the numbers 1..9,
and the values are the text I want to use as link text. "Data Manipulation"
is much easier for me to figure out than "perlfaq4". :-)
perlre, perlop, and perlfunc didn't help me much, although I could easily have
overlooked something. If there's something I missed, just point me at it and
I'll figure it out -- I'll remember it better that way.
David Wall
darkon@one.net
------------------------------
Date: Sun, 10 Oct 1999 02:34:55 +0000
From: Warren Bell <wjbell@ERASEjps.net>
Subject: Simple flock question
Message-Id: <37FFFB4F.7BAA2D5F@ERASEjps.net>
If I use flock to lock files in my perl script but the machine it's
running on doesn't have flock will the script still work, just not lock
the file?
Example:
$LOCK_EX = 2;
$LOCK_UN = 8;
open (FILE, "$datafile") || die;
&lock(FILE);
@info = <FILE>;
&unlock(FILE);
close(FILE);
sub lock {
local($file)=@_;
flock($file, $LOCK_EX);
}
sub unlock {
local($file)=@_;
flock($file, $LOCK_UN);
}
Also, could I simplify this code to not have the subroutines? How would
I show the difference between locking and unlocking?
------------------------------
Date: Sun, 10 Oct 1999 01:59:07 GMT
From: mag@imchat.com (Mark P.)
Subject: Re: trouble with hash
Message-Id: <37fff29f.96382380@news.ionet.net>
On 09 Oct 1999 18:23:48 PDT, David Amann <dove@abelo.com> wrote:
>Try
> @new_answer = @{$answer{$question_number}};
>
>Hope this helps,
>-=dav
That did it! Thanks a bunch. So simple, but so hard for a beer
soaked brain.<G>
>
>
------------------------------
Date: Mon, 11 Oct 1999 02:54:39 GMT
From: kawaii_1@hotmail.com (Ace)
Subject: unused files script
Message-Id: <38015246.31468246@news-server>
Does anyone have a script that will search all of
your html files and report on which files on your server are unused?
Thanks in advance
------------------------------
Date: Sun, 10 Oct 1999 04:38:30 +0200
From: "Cumhur Ozkan" <cumhur.ozkan@janset.com>
Subject: Re: Which Search engine script?
Message-Id: <7tor35$5vb$1@defne.istanbul.edu.tr>
http://www.Best-Of-Web.com/computer/cgi_scripts_2.shtml
there are many links to web sites about prewritten cgi-scripts. you can
choose the wright one to yoour need.
But in my opinion you need 2 different perl scripts. one for html (web page)
searching and one for data base search engine to find specific company names
or details.
You may find both types of scripts easily.
regards
cumhur
Hydro wrote in message <37FDB16E.5AD2FA0E@geminis.adi.uam.es>...
>Try to use the technotrade's one at http://www.technotrade.com
>
>Mario
>
>van Weelden wrote:
>
>> I have a homepage with information of different companies. Now I want
>> to install a search engine on this homepage, but which script is the
>> best and easy to use? It must be possible to search HTML pages with
>> keywords. But it must also be possible to look for a specific company
>> name, country, etc... If you know a good script, let me know. Thanks
>> in advance! John
>
------------------------------
Date: 10 Oct 1999 21:58:47 -0500
From: abigail@delanet.com (Abigail)
Subject: Re: Y2K and localtime
Message-Id: <slrn802kir.gep.abigail@alexandra.delanet.com>
Thomas Åhlen (thomas2@dalnet.se) wrote on MMCCXXXI September MCMXCIII in
<URL:news:7tr513$sq$1@gordon.dalnet.se>:
[] I have seen this localtime usage in some scripts:
[]
[] my @_localtime = localtime(time());
[] my $date = 19000000 + $_localtime[5]*10000 + ($_localtime[4]+1)*100 +
[] $_localtime[3];
[]
[] What is the easiest way to make the above code Y2K SAFE?
I dunno. What makes you think it is *not* Y2K safe? As far as I can tell,
it's safe even when people start using years of 67 months, each having
between 27 and 93 days. Which might happen in the year 31586.
Probably the best way to keep it safe is to go into politics, and vote
no for each proposal that changes the calendar to use 100 or more
months in a year, or 100 or more days in a month.
Abigail
--
perl -wlpe '}$_=$.;{' file # Count the number of lines.
-----------== Posted via Newsfeeds.Com, Uncensored Usenet News ==----------
http://www.newsfeeds.com The Largest Usenet Servers in the World!
------== Over 73,000 Newsgroups - Including Dedicated Binaries Servers ==-----
------------------------------
Date: 16 Sep 99 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 16 Sep 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.
| NOTE: The mail to news gateway, and thus the ability to submit articles
| through this service to the newsgroup, has been removed. I do not have
| time to individually vet each article to make sure that someone isn't
| abusing the service, and I no longer have any desire to waste my time
| dealing with the campus admins when some fool complains to them about an
| article that has come through the gateway instead of complaining
| to the source.
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 V9 Issue 1035
**************************************