[18548] in Perl-Users-Digest
Perl-Users Digest, Issue: 716 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Apr 19 09:31:29 2001
Date: Thu, 19 Apr 2001 06:31:10 -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: <987687070-v10-i716@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Thu, 19 Apr 2001 Volume: 10 Number: 716
Today's topics:
Re: Premature end of script headers? <bart.lateur@skynet.be>
Re: Premature end of script headers? <iltzu@sci.invalid>
Re: Premature end of script headers? <urael@craavaxvynzcv.arg>
Re: Premature end of script headers? (Gwyn Judd)
Re: Premature end of script headers? (Eric Bohlman)
Printing while simultaneously using CGI.pm and Mail::In <pr1@club-internet.fr>
Processing all files in directory <taka@yarn.demon.co.uk>
Re: Processing all files in directory (Gwyn Judd)
Re: Processing all files in directory (Garry Williams)
Re: Processing all files in directory nobull@mail.com
Re: Processing all files in directory <bart.lateur@skynet.be>
Re: Processing all files in directory (Chris Ball)
Re: Processing all files in directory <bart.lateur@skynet.be>
Re: Processing all files in directory (Chris Ball)
Re: Proper way to export Vars <dan@nospam_dtbakerprojects.com>
Re: Q : Why out of memory? (Richard J. Rauenzahn)
Re: reading a specific paragraph <graham.wood@iona.com>
Re: Reading one character through a socket (Tassilo von Parseval)
Re: Reading one character through a socket (Tassilo von Parseval)
Re: Recursive directory listing <root@novastar.dtdns.net>
RegExp for parsing HTML table entries <christian.weyer@eyesoft.de>
regular expression question <whitetiger@pinc.com>
Regular Expressions (again) <s.warhurst@rl.ac.uk>
Re: Regular Expressions (again) nobull@mail.com
Re: Regular Expressions (again) (Tad McClellan)
Re: Returning 2 arrays from a sub (E.Chang)
Re: Returning 2 arrays from a sub <bcoon@sequenom.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Tue, 17 Apr 2001 14:11:08 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: Premature end of script headers?
Message-Id: <mqjodtgoep8dcqer8a5nturfdpb3opbpge@4ax.com>
Preston Price wrote:
>I have this really easy script that looks like this:
>#!/usr/local/bin/perl
>
>use strict;
>use CGI qw(:standard);
>use CGI::Carp qw(fatalsToBrowser);
>
>print header;
>print start_html('upload test');
>my $filename = param('file_name');
>print qq ($filename);
>
>I dont know why I am getting this error:
>got any ideas?
The "Premature end of script headers" is something you get most often
when the script simply fails to compile. It could be something as simple
as the fact that module CGI::Carp isn't present. Check throuh telnet, if
you can, or wrap some test stuff in a simple no-brain CGI script, a bit
like:
print "Content-type: text/plain\n\n";
open STDERR, ">&STDOUT";
eval "use CGI::Carp; print 'OK'" or print "eval failed: $@\n";
--
Bart.
------------------------------
Date: 17 Apr 2001 16:22:04 GMT
From: Ilmari Karonen <iltzu@sci.invalid>
Subject: Re: Premature end of script headers?
Message-Id: <987523817.21331@itz.pp.sci.fi>
In article <urael-9B1A07.21084817042001@news.metropolis.net.au>, Henry wrote:
>In article <9bbgd7$fcu$1@kestrel.csrv.uidaho.edu>, "Preston Price"
><pric3596@cs.uidaho.edu> wrote:
>
>> #!/usr/local/bin/perl
>>
>> use strict;
>> use CGI qw(:standard);
>> use CGI::Carp qw(fatalsToBrowser);
>>
>> print header;
>> print start_html('upload test');
>> my $filename = param('file_name');
>> print qq ($filename);
>>
>> I dont know why I am getting this error:
>> got any ideas?
>
>Sometimes this helps:
>
>$query = new CGI;
>print $query->header;
That's odd, because it shouldn't help anything at all. Besides, your
code wouldn't work in the original poster's script, since you haven't
declared $query with "my" or "use vars".
I'd suggest the original poster should try running his script from the
command line and see what happens. He should also check that the file
is executable by the webserver, and that the path to perl on the first
line is really correct.
I would also generally suggest putting "use CGI::Carp" before any of the
other "use" statements, since any errors before it won't get sent to the
browser. But I doubt that's relevant to the problem at hand.
There are more useful features in CGI::Carp than just fatalsToBrowser.
Particularly carpout() and in newer versions warningsToBrowser() are
very much worth looking into.
--
Ilmari Karonen - http://www.sci.fi/~iltzu/
Please ignore Godzilla / Kira -- do not feed the troll.
------------------------------
Date: Wed, 18 Apr 2001 03:56:44 +0930
From: Henry <urael@craavaxvynzcv.arg>
Subject: Re: Premature end of script headers?
Message-Id: <urael-843488.03564418042001@news.metropolis.net.au>
In article <987523817.21331@itz.pp.sci.fi>, Ilmari Karonen
<usenet11429@itz.pp.sci.fi> wrote:
>> Sometimes this helps:
>>
>> $query = new CGI;
>> print $query->header;
>
> That's odd, because it shouldn't help anything at all.
Agreed, but _sometimes_ it does. I don't know why, but sometimes I'll
get premature end of script errors, and the above sorts it out.
> Besides, your
> code wouldn't work in the original poster's script, since you haven't
> declared $query with "my" or "use vars".
Hmmm, yes, well. 'perldoc CGI' never makes mention of that. And when
the examples in the docs generate compile-time-errors, use strict; is
the first thing to get shut off in favour of progress.
> I would also generally suggest putting "use CGI::Carp" before any of the
> other "use" statements, since any errors before it won't get sent to the
> browser.
Out of curiosity, would the following be a 'acceptable' approach?
-
BEGIN {
use CGI::Carp qw(carpout fatalsToBrowser);
carpout(STDOUT);
}
use CGI qw(:standard);
...
-
Henry.
------------------------------
Date: Tue, 17 Apr 2001 20:34:31 GMT
From: tjla@guvfybir.qlaqaf.bet (Gwyn Judd)
Subject: Re: Premature end of script headers?
Message-Id: <slrn9dpe2v.4bg.tjla@thislove.dyndns.org>
In article <urael-843488.03564418042001@news.metropolis.net.au>,
Henry <urael@craavaxvynzcv.arg> wrote:
>> Besides, your
>> code wouldn't work in the original poster's script, since you haven't
>> declared $query with "my" or "use vars".
>
>Hmmm, yes, well. 'perldoc CGI' never makes mention of that. And when
>the examples in the docs generate compile-time-errors, use strict; is
>the first thing to get shut off in favour of progress.
perldoc 'strict' does though.
--
Gwyn Judd (print `echo 'tjla@guvfybir.qlaqaf.bet' | rot13`)
I can't tell you how many shows I've done with full-blown migraine
headaches.
-Jonathan Taylor Thomas
------------------------------
Date: 18 Apr 2001 00:18:54 GMT
From: ebohlman@omsdev.com (Eric Bohlman)
Subject: Re: Premature end of script headers?
Message-Id: <9bimhe$p13$1@bob.news.rcn.net>
Henry <urael@craavaxvynzcv.arg> wrote:
> Hmmm, yes, well. 'perldoc CGI' never makes mention of that. And when
> the examples in the docs generate compile-time-errors, use strict; is
> the first thing to get shut off in favour of progress.
"When I smell smoke and I'm looking for the source, the smoke detectors
are the first thing to get shut off in favor of progress."
Seriously, many of the errors that using strict will detect are the kind
that result from typos. And when you have a piece of code that you've
typed in from a well-reviewed source like the Perl documentation, guess
what the most likely kind of errors are going to be? That's right, typos.
The perl interpreter is trying to help you by issuing those error
messages. Being too macho to accept that kind of help is a *major*
barrier to becoming a good programmer (as is believing that your
programming mistakes reflect badly on you personally; good programmers
assume that they will make mistakes, and therefore check carefully for
them, something that's very hard to do if mistakes reflect blows to your
ego).
------------------------------
Date: Tue, 17 Apr 2001 09:48:47 +0200
From: Philippe de Rochambeau <pr1@club-internet.fr>
Subject: Printing while simultaneously using CGI.pm and Mail::Internet.pm
Message-Id: <3ADBF55F.89DAF52@club-internet.fr>
Hello,
When you use Mail::Internet in a regular Perl script, you can simply
type print $mail->send('smtp'...) to send an email message. If you
insert emailing code in a CGI script, which filehandle should you print
to, in the case of the Mail::Internet object? Certainly not STDOUT since
it is already used by CGI.
Many thanks.
Philippe de Rochambeau
wwphi
#!/usr/bin/perl
use CGI;
my $query = new CGI;
print $query->header;
print $query->start_html('test');
use Mail::Internet;
use strict;
my $head = Mail::Header->new;
$head->add(From => 'vichy@127.0.0.1' );
$head->add(BCC => 'vichy2@127.0.0.1' );
$head->add(BCC => 'georges@127.0.0.1' );
$head->add(BCC => 'postmaster@127.0.0.1' );
$head->add(Subject => 'Hello there');
my $body = "Hello World";
my $mail = Mail::Internet->new(Header => $head, Body => $body, Modify =>
1 );
print $mail->send('smtp', Server => '127.0.0.1' );
print $query->end_html;
------------------------------
Date: 17 Apr 2001 10:10:13 +0100
From: Paul the Nomad <taka@yarn.demon.co.uk>
Subject: Processing all files in directory
Message-Id: <87k84jhoy2.fsf@euterpe.yarn.demon.co.uk>
I want to process all the files in a directory in date order (latest
first). So I needed to get a list of files in the directory - 'ls -t'
would do it. I've ended up doing it like this, is there a better way?
opendir (DIR, $article_dir) or die "can't open $article_dir, $!";
@articles = readdir(DIR);
closedir (DIR);
@articles = sort { (stat($b))[10] cmp (stat($a))[10] }
map {$article_dir . $_}
grep {!/^\./ && !/~$/ && !/^\#/} @articles;
# Note, I don't want 'dot' files, backup files or emacs auto-save files
foreach $file (@articles) {
do stuff
}
Cheers....
--
-----------
Paul
http://www.seditiousdiaries.com/Donald10.html
------------------------------
Date: Tue, 17 Apr 2001 12:42:15 GMT
From: tjla@guvfybir.qlaqaf.bet (Gwyn Judd)
Subject: Re: Processing all files in directory
Message-Id: <slrn9doidc.2h1.tjla@thislove.dyndns.org>
In article <87k84jhoy2.fsf@euterpe.yarn.demon.co.uk>,
Paul the Nomad <taka@yarn.demon.co.uk> wrote:
>I want to process all the files in a directory in date order (latest
>first). So I needed to get a list of files in the directory - 'ls -t'
>would do it. I've ended up doing it like this, is there a better way?
Well, you might want to try working the GRT or ST into that sort
routine, but really I think you are better off doing:
chomp(@articles = `ls -t`);
--
Gwyn Judd (print `echo 'tjla@guvfybir.qlaqaf.bet' | rot13`)
It takes a smart husband to have the last word and not use it.
------------------------------
Date: Tue, 17 Apr 2001 12:48:43 GMT
From: garry@ifr.zvolve.net (Garry Williams)
Subject: Re: Processing all files in directory
Message-Id: <slrn9doetb.763.garry@zfw.zvolve.net>
On 17 Apr 2001 10:10:13 +0100, Paul the Nomad <taka@yarn.demon.co.uk> wrote:
>
> I want to process all the files in a directory in date order (latest
> first). So I needed to get a list of files in the directory - 'ls -t'
> would do it. I've ended up doing it like this, is there a better way?
>
> opendir (DIR, $article_dir) or die "can't open $article_dir, $!";
>
> @articles = readdir(DIR);
>
> closedir (DIR);
>
> @articles = sort { (stat($b))[10] cmp (stat($a))[10] }
> map {$article_dir . $_}
> grep {!/^\./ && !/~$/ && !/^\#/} @articles;
Why not pre-compute the sort key before passing the list to sort like
the FAQ? (perlfaq4, "How do I sort an array by (anything)?")
(I assumed that $article_dir ends with a `/' from your code.)
my @articles = map { $_->[0] }
sort { $a->[1] <=> $b->[1] }
map { ["$article_dir$_", -M "$article_dir$_"] }
grep { !/^\./ && !/~$/ && !/^\#/ }
readdir(DIR);
--
Garry Williams
------------------------------
Date: 17 Apr 2001 18:09:26 +0100
From: nobull@mail.com
Subject: Re: Processing all files in directory
Message-Id: <u9lmozihbt.fsf@wcl-l.bham.ac.uk>
Bart Lateur <bart.lateur@skynet.be> writes:
> nobull@mail.com wrote:
> >I'd probably do a Swartzian transform to avoid calling stat() so often
> >(see FAQ for details).
>
> Or the orcish manouvre: cache the file dates in a hash.
Not much in it really:
print "Directory has ",scalar(@articles)," entries\n";
timethese(1000, {
simple => sub {
@sorted = sort { (stat($b))[10] <=> (stat($a))[10] }
map { "$article_dir$_" }
grep {!/^\./ && !/~$/ && !/^\#/} @articles;
},
Swartz => sub {
@sorted = map { $_->[0] }
sort { $b->[1] <=> $a->[1] }
map { [ "$article_dir$_" , (stat "$article_dir$_")[10] ] }
grep {!/^\./ && !/~$/ && !/^\#/} @articles;
},
orcish => sub {
my %date;
@sorted = sort { ($date{$b} ||= (stat($b))[10]) <=>
($date{$a} ||= (stat($a))[10]) }
map { "$article_dir$_" }
grep {!/^\./ && !/~$/ && !/^\#/} @articles;
}
});
Directory has 213 entries
Benchmark: timing 1000 iterations of Swartz, orcish, simple...
Swartz: 23 wallclock secs (18.50 usr + 3.52 sys = 22.02 CPU) @ 45.41/s (n=1000)
orcish: 22 wallclock secs (19.02 usr + 2.20 sys = 21.22 CPU) @ 47.13/s (n=1000)
simple: 87 wallclock secs (60.24 usr + 20.64 sys = 80.88 CPU) @ 12.36/s (n=1000)
--
\\ ( )
. _\\__[oo
.__/ \\ /\@
. l___\\
# ll l\\
###LL LL\\
------------------------------
Date: Tue, 17 Apr 2001 15:16:29 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: Processing all files in directory
Message-Id: <adnodt4e33fgp52rbp0hkrb7prj326qrr1@4ax.com>
nobull@mail.com wrote:
>> I want to process all the files in a directory in date order (latest
>> first). So I needed to get a list of files in the directory - 'ls -t'
>> would do it. I've ended up doing it like this, is there a better way?
>
>> @articles = readdir(DIR);
>
>> @articles = sort { (stat($b))[10] cmp (stat($a))[10] }
>> map {$article_dir . $_}
>> grep {!/^\./ && !/~$/ && !/^\#/} @articles;
>
>I'd probably do a Swartzian transform to avoid calling stat() so often
>(see FAQ for details).
Or the orcish manouvre: cache the file dates in a hash.
my %date;
@articles = sort { ($date{$b} ||= (stat($b))[10]) <=>
($date{$a} ||= (stat($a))[10]) }
grep {!/^\./ && !/~$/ && !/^\#/} @articles;
>Also change 'cmp' to '<=>' as the number of seconds since 1/1/1970
>will reach 1000000000 quite soon now.
True.
Also note that one can use an -X operator instead of the stat() call.
--
Bart.
------------------------------
Date: Thu, 19 Apr 2001 10:52:56 GMT
From: chris@spoon.pkl.net (Chris Ball)
Subject: Re: Processing all files in directory
Message-Id: <slrn9dtgs8.ni4.chris@pkl.net>
nobull@mail.com wrote:
>Also change 'cmp' to '<=>' as the number of seconds since 1/1/1970
>will reach 1000000000 quite soon now.
Sorry; I'm sleep-deprived and being slow. Why does this matter?
Thanks,
~C.
--
Chris Ball.
chris@printf.net | http://printf.net/
finger: choric@compsoc.man.ac.uk
--
------------------------------
Date: Thu, 19 Apr 2001 11:08:22 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: Processing all files in directory
Message-Id: <4qhtdts4mr7bse00k9ee3kdtpmo26eiqqk@4ax.com>
Chris Ball wrote:
>>Also change 'cmp' to '<=>' as the number of seconds since 1/1/1970
>>will reach 1000000000 quite soon now.
>
>Sorry; I'm sleep-deprived and being slow. Why does this matter?
Because, to take just the first few digits of the numbers, if you
compare 99 to 100 as text, 100 will come before 99.
--
Bart.
------------------------------
Date: Thu, 19 Apr 2001 12:42:07 BST
From: chris@spoon.pkl.net (Chris Ball)
Subject: Re: Processing all files in directory
Message-Id: <slrn9dtjoc.odg.chris@pkl.net>
In article <4qhtdts4mr7bse00k9ee3kdtpmo26eiqqk@4ax.com>, Bart Lateur wrote:
>>Sorry; I'm sleep-deprived and being slow. Why does this matter?
>
>Because, to take just the first few digits of the numbers, if you
>compare 99 to 100 as text, 100 will come before 99.
Of course. Apologies. A better question would have been 'Why would anyone
code a numerical comparison using cmp()?' ;-)
~C.
--
Chris Ball.
chris@printf.net || http://printf.net/
finger: choric@compsoc.man.ac.uk
--
------------------------------
Date: Thu, 19 Apr 2001 12:16:35 GMT
From: Dan Baker <dan@nospam_dtbakerprojects.com>
Subject: Re: Proper way to export Vars
Message-Id: <3ADED5DB.C28B2D02@nospam_dtbakerprojects.com>
Bryan Coon wrote:
> implement a global variables file, so those working on the project can just set up that file with their local information.
-------------------------
I dunno how proper it is, but I do this by creating a config.pl that
makes the assignments, and then "require"-ing it in the scripts that
need the global variables. (Make sure the last line is
1;
so that it compiles correctly....)
The problem with my approach is that I get warnings if I use a variable
only once... not an error, but junks up the ERRLOG. I guess I would also
be interested in learning a more proper way to have all my "global"
hardcoded assignments in a script that could be included in other
scripts without errors.
Dan
------------------------------
Date: 18 Apr 2001 17:45:43 GMT
From: nospam@hairball.cup.hp.com (Richard J. Rauenzahn)
Subject: Re: Q : Why out of memory?
Message-Id: <987615943.27595@hpvablab.cup.hp.com>
mjd@plover.com (Mark Jason Dominus) writes:
>
>In article <9b1rfa$a8u$1@trsvr.tr.unisys.com>,
>Gregory K. Deal <gregory.deal@unisys.com> wrote:
>>I'm running perl 5.5 on an HP J5000 with 4GB real memory and 6GB swap. I get
>>an "out of memory" error. Yet, the memory image of the program right before
>>dying is ~960MB. At this point, there was 1500MB real memory and 2080MB
>>virtual memory in use.
>
>Many systems have a per-process memory limit enforced by the system.
>Look into the 'limit' or 'ulimit' command in your shell.
And some systems also have it enforced in the kernel:
$ grep max.siz /stand/system
maxdsiz 0X40000000
maxssiz 0X08000000
maxtsiz 0X08000000
You probably need to bump maxdsiz.
[Followups set to comp.sys.hp.hpux]
Rich
--
Rich Rauenzahn ----------+xrrauenza@cup.hp.comx+ Hewlett-Packard Company
Technical Consultant | I speak for me, | 19055 Pruneridge Ave.
Development Alliances Lab| *not* HP | MS 46TU2
ESPD / E-Serv. Partner Division +--------------+---- Cupertino, CA 95014
------------------------------
Date: Thu, 19 Apr 2001 11:33:36 +0100
From: "Graham Wood" <graham.wood@iona.com>
Subject: Re: reading a specific paragraph
Message-Id: <9bmevo$ogf$1@spider.iona.com>
R. Utterback <rutterba@cisco.com> wrote in message
news:987635656.128256@sj-nntpcache-3...
> All,
>
> Reading a file, I have a string I want to extract. The string is within
> parens, and the line starts with 'Comp:'. It can look like any of the
> following, followed by at least one blank line:
>
> 1) Comp: some_string (the_string_I_want)
>
> 2) Comp: some_string (the_string
> _I_want)
>
> 3) Comp: some_string
> (the_string
> _I
> _want)
>
> (etc.)
>
> I have tried using $/ to set the input record separator and do this:
>
> $/ = "";
> while (<INFILE>) {
> if (/Comp:/) {
> $_ =~ s/\n//g; #remove any newlines
> $string = ($_ =~ /\((.*)\)/);
> }
> }
>
> The problem is, some of the files I am working with have the stinkin ^M at
> the end of each line, which throws off the whole "read in by paragraph"
> thing.
>
Can't you just replace the ^M as well as the \n?
s/\cM//;
Incidentally, the substitution operator and the match operator (s/// and //)
both use $_ by default so you don't need the "$_ =~ " bits.
Graham Wood
> Is there an easy way to get the string I want?
>
> Thnx
> Robert
------------------------------
Date: Mon, 16 Apr 2001 22:00:04 GMT
From: Tassilo.Parseval@post.rwth-aachen.de (Tassilo von Parseval)
Subject: Re: Reading one character through a socket
Message-Id: <3adb6a71.21530472@news.rwth-aachen.de>
Hi,
On 16 Apr 2001 19:31:04 GMT, Jonathan Stowe <gellyfish@gellyfish.com>
wrote:
>> This all works fine. But now there is one occasion on which I have to read
>> client input without waiting for a newline just like Term::ReadKey can do.
>
>perldoc -f read ?
No. :-)
As long as my telnet client is in line mode the server wont start
reading single bytes before a newline is ready on the clientside.
I think nobull pointed me to something that might work.
Regards,
Tassilo
------------------------------
Date: Mon, 16 Apr 2001 22:15:02 GMT
From: Tassilo.Parseval@post.rwth-aachen.de (Tassilo von Parseval)
Subject: Re: Reading one character through a socket
Message-Id: <3adb6bfa.21923506@news.rwth-aachen.de>
Hi,
On 16 Apr 2001 19:09:06 +0100, nobull@mail.com wrote:
>mjd@plover.com (Mark Jason Dominus) writes:
>
>> In article <9beps0$f2t$1@nets3.rz.RWTH-Aachen.DE>,
>> Tassilo v. Parseval <tassilo.parseval@post.rwth-aachen.de> wrote:
>> >Unfortunately when telnetting to the server one still needs to press Return.
>>
>> There is nothing you can do about that.
>
>Wrong, you can send the Telnet commands to tell the terminal to go
>into raw mode. For details see the RFCs that document Telnet. This,
>of course, has nothing to do with Perl.
That was what I kept thinking about the whole time because any
application run via telnet usually behaves as though it were attached
to an actual tty. And when fiddling around a little with the manpages
of telnet I learned about these three different modes. Raw would be
what I need so I'll dig a little in the appropriate RFC. As I already
have a running tcp/ip server it should be possible to send any command
whatsoever to the client.
Thanks a lot for this help.....I think I will first go for the above
option and see how far it'll get me. Using Net::Telnet might be more
convenient but it is not a module in a standard Perl distribution so
this would only come in second place.
At least it looks as though I do not have to write an own client. That
was what I have been trying in the first place but that was even
worse.
Greetings,
Tassilo
------------------------------
Date: Wed, 18 Apr 2001 01:44:50 +0300
From: "novastar" <root@novastar.dtdns.net>
Subject: Re: Recursive directory listing
Message-Id: <9bih11$bcb$1@usenet.otenet.gr>
for windows enviroment you can try this also :
&recursive_dir('f:\temp');
sub recursive_dir {my ($pwd,$i)=($_[0],$i++);
opendir ($i,$pwd) || die "Can't list $pwd\n";
while (my $node=readdir $i) {
next if $node=~/^\.*$/; # the 3 dots
$node="$pwd\\$node";
#-d $node==1 for dirs, -d $node!=1 for files, -e $node==1 for both
print "$node\n" if -e $node==1;
&recursive_dir($node) if -d $node==1 }
closedir $i}
"Claudio Inglesi" <cinglesi@puc.cl> wrote in message
news:bqOC6.1346$cy3.27956@maule...
> Does anyone know of a perl script that builds a directory listing such as
> etc/
> lib/
> pub/
> dos/
> incoming/
> lrwp/
> cgi-bin/
> others/
> etc/
> Thanks
>
>
>
>
------------------------------
Date: Tue, 17 Apr 2001 12:11:50 +0200
From: Christian Weyer <christian.weyer@eyesoft.de>
Subject: RegExp for parsing HTML table entries
Message-Id: <3ADC16E6.17398DBE@eyesoft.de>
Hi all,
I am looking for a neat and small solution to get a list/array of entries in an HTML table.
E.g.:
<HTML>
<TABLE ...>
<TR>
<TD>Text1</TD>
<TD>Text2</TD>
</TR>
...
<TR>
<TD>Text3</TD>
<TD>Text4</TD>
</TR>
</TABLE>
</HTML>
Now I want the 'Textn' values to be parsed ...
Any ideas?
Regards,
Christian
--
___________________________________________________
eYesoft We see your visions.
ŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻ
Christian Weyer http://www.eyesoft.de
christian.weyer@eyesoft.de Bernhard-Krieg-Str. 4
Tel.: +49-9393-993161 97845 Neustadt/Main
___________________________________________________
Building Smart Internet Architectures
ŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻ
------------------------------
Date: Tue, 17 Apr 2001 23:23:52 -0700
From: "whitetigercat" <whitetiger@pinc.com>
Subject: regular expression question
Message-Id: <tdqcqcs1iqq613@corp.supernews.com>
Hi all,
I've been playing around with regular expressions and can't seem to find an answer to this:
If I have a pattern, how can i delete everything in the string doesn't match that pattern?
For example, if $content is an HTML page that contains a FORM and $pattern = "<input ([^>]|\n)*>"
i.e. input statements in an HTML FORM, how can i delete everything in the page except
these INPUT tags so I can do further processing on them? I've tried numerous methods.
Any help appreciated.
--Shane
------------------------------
Date: Wed, 18 Apr 2001 12:04:44 +0100
From: "S Warhurst" <s.warhurst@rl.ac.uk>
Subject: Regular Expressions (again)
Message-Id: <9bjsd8$18m0@newton.cc.rl.ac.uk>
Hi
I have yet to get my head round regular expressions, but I need to perform a
task urgently in Perl, so please can you help me on this.
I have a string of data in the following format:
-----------------
person1@RHUL.AC.UK John Smith1 3AEAQABWEBWG////
person2@SALFORD.AC.UK John Smith2
3AEAQABWmBVI//// person3@EXETER.AC.UK John Smith3
3AEAQABWmBVI//// person4@BATHSPA.AC.UK John Smith4
3AFAQABWrBWt//// person5@ASTON.AC.UK John Smith5
-----------------
What I want to do is extract JUST the email addresses (this is not to do
with some sort of spam program!!). At the moment, I start at the beginning
of the string, find the first @, find the next space after the @, the space
before the @ & work out the email address from that... store it in an array
position... then find the next occurance of @ & repeat until I have all the
addresses. Now, this works, however, it takes along time as there are
thousands of addresses to pull out of various files.
With regular expressions, I *guess* I would need to extract all the email
addresses (and delimit them somehow), then split the string into an array.
Can you tell me the regular expression would do this?
Many thanks
Spencer Warhurst
-------------------
JISCmail Adminstrator
http://www.jiscmail.ac.uk
------------------------------
Date: 19 Apr 2001 12:37:01 +0100
From: nobull@mail.com
Subject: Re: Regular Expressions (again)
Message-Id: <u9ofttf7du.fsf@wcl-l.bham.ac.uk>
"S Warhurst" <s.warhurst@rl.ac.uk> writes:
> I have yet to get my head round regular expressions, but I need to perform a
> task urgently in Perl, so please can you help me on this.
>
> I have a string of data in the following format:
>
> -----------------
> person1@RHUL.AC.UK John Smith1 3AEAQABWEBWG////
> person2@SALFORD.AC.UK John Smith2
> 3AEAQABWmBVI//// person3@EXETER.AC.UK John Smith3
> 3AEAQABWmBVI//// person4@BATHSPA.AC.UK John Smith4
> 3AFAQABWrBWt//// person5@ASTON.AC.UK John Smith5
> -----------------
>
> What I want to do is extract JUST the email addresses (this is not to do
> with some sort of spam program!!). At the moment, I start at the beginning
> of the string, find the first @, find the next space after the @, the space
> before the @ & work out the email address from that... store it in an array
> position... then find the next occurance of @ & repeat until I have all the
> addresses.
In other words:
my @addresses = $string =~ /(\S+\@\S+)/sg;
Of course not all valid e-mail addresses match that pattern - see FAQ.
> With regular expressions, I *guess* I would need to extract all the email
> addresses (and delimit them somehow), then split the string into an
> array.
No you are fooling yourself into believing the problem is more complex
than it is.
--
\\ ( )
. _\\__[oo
.__/ \\ /\@
. l___\\
# ll l\\
###LL LL\\
------------------------------
Date: Thu, 19 Apr 2001 07:31:36 -0400
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Regular Expressions (again)
Message-Id: <slrn9dtj4o.2ik.tadmc@tadmc26.august.net>
S Warhurst <s.warhurst@rl.ac.uk> wrote:
>
>I have yet to get my head round regular expressions, but I need to perform a
>task urgently in Perl, so please can you help me on this.
^^^^^^^^
^^^^^^^^
Usenet is the wrong place then.
>I have a string of data in the following format:
>
>-----------------
>person1@RHUL.AC.UK John Smith1 3AEAQABWEBWG////
>person2@SALFORD.AC.UK John Smith2
>3AEAQABWmBVI//// person3@EXETER.AC.UK John Smith3
>3AEAQABWmBVI//// person4@BATHSPA.AC.UK John Smith4
>3AFAQABWrBWt//// person5@ASTON.AC.UK John Smith5
>-----------------
>
>What I want to do is extract JUST the email addresses
Assuming your string is in $_:
foreach (split) { print "$_\n" if /@/ }
print "$1\n" while /(\S+@\S+)/g; # another way
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Tue, 17 Apr 2001 23:10:16 GMT
From: echang@netstorm.net (E.Chang)
Subject: Re: Returning 2 arrays from a sub
Message-Id: <Xns9086C29E68A4Cechangnetstormnet@207.106.92.86>
Bryan Coon <bcoon@sequenom.com> wrote in <3ADCBC27.E728B44B@sequenom.com>:
>
>Ian Howlett wrote:
>
>>
>> use strict;
>>
>> sub getConfigInfo {
>> my $sectionName;
>> my @clientDirectories;
>> my @serverDirectories;
<code details snipped>
>>
>> return (\@clientDirectories, \@serverDirectories) ;
>>
>> } # end of getConfigInfo
>>
>> my @a;
>> my @b;
>>
>>> Attempt to put the array values into @a and @b
>> ($a, $b) = getConfigInfo() ;
>>
>
>Don't forget to dereference here.....
>i.e.
>(@$a, @$b) = getConfigInfo();
>
You need to dereference, but not there. A test run with that modification
would show there's no output for the array values. You need to dereference
when attempting to actually use the array contents. Here's an example
with a simplified subroutine. Notice that @a and @b are gone.
# Put the array reference into $a and $b
my ($a, $b) = getConfigInfo() ;
my $i;
print "\nclient:\n";
foreach $i (@$a) { #use the array for which $a is the reference
print "$i\n";
}
print "\nserver:\n";
foreach $i (@$b) { #use the array for which $b is the reference
print "$i\n";
}
sub getConfigInfo {
my @clientDirectories = (1, 3, 3);
my @serverDirectories = (4, 5, 6);
# Some simple example data so we can see results
return (\@clientDirectories, \@serverDirectories) ;
}
------------------------------
Date: Tue, 17 Apr 2001 14:56:55 -0700
From: Bryan Coon <bcoon@sequenom.com>
Subject: Re: Returning 2 arrays from a sub
Message-Id: <3ADCBC27.E728B44B@sequenom.com>
Ian Howlett wrote:
>
> use strict;
>
> sub getConfigInfo {
> my $sectionName;
> my @clientDirectories;
> my @serverDirectories;
> open (CONF, "test.conf") || die "Could not open test.conf";
> while (<CONF>) {
> chomp;
> # Detect if we are in the client or server part of the configuration file
> if (m/^# Client/) { $sectionName = "Client"; next; }
> if (m/^# Server/) { $sectionName = "Server"; next;}
> if (m/^#/) {next;} # Ignore comment lines beginning with #
> if (m/^$/) {;next;} # Ignore blank lines
>
> tr?\\?/?; # Replace any backslashes with slashes
>
> # Populate the relevant array
> if ($sectionName eq 'Client') { push @clientDirectories, $_; }
> if ($sectionName eq 'Server') { push @serverDirectories, $_; }
> }
>
> return (\@clientDirectories, \@serverDirectories) ;
>
> } # end of getConfigInfo
>
> my @a;
> my @b;
>
> # Attempt to put the array values into @a and @b
> ($a, $b) = getConfigInfo() ;
>
Don't forget to dereference here.....
i.e.
(@$a, @$b) = getConfigInfo();
perldoc perlsub -> Passing By Reference will help you a lot too....
Good luck!
Bryan
>
> # Attempt to print out the arrays to show that they have been retrieved
> correctly
> my $i;
> print "\nclient:\n";
> foreach $i (@a) {
> print "$i\n";
> }
>
> print "\nserver:\n";
> foreach $i (@b) {
> print "$i\n";
> }
------------------------------
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 716
**************************************