[22919] in Perl-Users-Digest
Perl-Users Digest, Issue: 5139 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Jun 26 11:05:41 2003
Date: Thu, 26 Jun 2003 08:05:09 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Thu, 26 Jun 2003 Volume: 10 Number: 5139
Today's topics:
Also available: perl mailing lists, other perl newsgrou <davebaker@benefitslink.com>
Re: Altering values by reference <dlovecraft@remove.this.to.email.me.breathe.com>
Re: Altering values by reference <thens@nospam.com>
Re: array question <Graham.T.Wood@oracle.com>
Re: array question <nobull@mail.com>
Re: array question <Graham.T.Wood@oracle.com>
Re: array question <flavell@mail.cern.ch>
Execute shell script from a perl script <kderaedt@hotmail.com>
Re: Forking child process with WWW::Automate <Graham.T.Wood@oracle.com>
Re: how to convert all invalid UTF-8 sequences to numer (Shambo)
Re: Looking for inspiration: cascading CGI <kbpease@hotmail.com>
Re: Looking for inspiration: cascading CGI <kbpease@hotmail.com>
mod_perl 2 test failure at filter/in_bbs_msg (server si (-)
Re: Offer tips, comments on this code (generates html t <bigj@kamelfreund.de>
Re: Offer tips, comments on this code (generates html t <bigj@kamelfreund.de>
Re: Offer tips, comments on this code (generates html t <uri@stemsystems.com>
Re: perlio problem? redhat 9, perl 5.8.0 <flavell@mail.cern.ch>
Re: regexp help <nobull@mail.com>
Re: regexp help <bigj@kamelfreund.de>
Re: regexp: resetting search position to start of strin <nobull@mail.com>
Rotating Snips of HTML <jsc1971@hotmail.com>
SOAP Server <nntp.wfitzgerald@crtman.com>
Using Perl with ESRI ArcGIS? Or VB foolishness? (dnrg)
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Thu, 26 Jun 2003 13:57:19 GMT
From: "Dave Baker" <davebaker@benefitslink.com>
Subject: Also available: perl mailing lists, other perl newsgroups
Message-Id: <3ZCKa.23854$Fy6.8392@sccrnsc03>
Just a reminder -- you can find a wonderful list of specialized perl
mailing lists at http://lists.perl.org/ - each listing includes
instructions for how to subscribe as well as a link to each list's
online archive.
And a listing of other perl-related newsgroups is at
http://nntp.x.perl.org/group/ - the page even includes links to RSS
feeds of the newsgroups.
-----------------------------------
Dave Baker
------------------------------
Date: Thu, 26 Jun 2003 15:28:22 +0000
From: Dela Lovecraft <dlovecraft@remove.this.to.email.me.breathe.com>
Subject: Re: Altering values by reference
Message-Id: <ImDKa.170$s34.106061@newsfep2-gui.server.ntli.net>
To al that answered.
Thanks very much. I knew it was possible somehow, but I couldn't quite get
my head round it. I don't do a vast amount of coding, so was a bit lost.
Thanks again,
Dela
------------------------------
Date: Thu, 26 Jun 2003 20:20:09 +0530
From: Thens <thens@nospam.com>
Subject: Re: Altering values by reference
Message-Id: <20030626202009.2c134b6d.thens@nospam.com>
On Thu, 26 Jun 2003 12:42:19 +0200
Malte Ubl <ubl@schaffhausen.de> wrote:
>Dela Lovecraft wrote:
>Parameters in Perl are always passed by reference (That is, the
>references reside inside the magical array @_). "Pass by value" only
>happens when you take things out of @_ (e.g. by calling shift without
>arguments). If you access @_ directly you get the desired behavior.
Now i have another question are both these same
sub doSomething{
my ($arg1, $arg2) = @_;
..
}
sub doSomething{
my $arg1 = shift;
my $arg2 = shift;
..
}
Since you (and perldoc perlsub) say that the @_ contains aliases to scalar parameters and when you shift it they become values. Iam slightly confused. Im my first assignment am I assigning the references then ? I have code like these that has been working properly.
Thanks in advance
Regards,
Thens
------------------------------
Date: Thu, 26 Jun 2003 14:01:46 +0100
From: Graham Wood <Graham.T.Wood@oracle.com>
Subject: Re: array question
Message-Id: <3EFAEEBA.2644A40E@oracle.com>
This is a multi-part message in MIME format.
--------------1D9BE0FBC3D0EE49186AA665
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 7bit
> while(<READFILTEREDLIST>) {
>
> @filterArray=<READFILTEREDLIST>;
>
> }
> close READFILTEREDLIST;
Here's where I think your problem lies.
while(<READFILTEREDLIST>){ }
steps through each line of the file returning the contents in $_ each time
@filterArray=<READFILTEREDLIST>;
reads the rest of the file contents into @filterArray.
If you do both of these at the same time you will end up with nothing in
@filterArray because this is happening
1. While loop reads a line
2. @filterArray gets all the rest of the lines
3. While loop reads a line
4. @filterArray gets the rest of the lines
This will repeat until the while loop reads the last line and then
<READFILTEREDLIST> will return nothing to @filterArray then your script will
proceed with the lines after the while loop.
You either need to use a while loop or @array=<FILEHANDLE> not both at the same
time.
while(<READFILTEREDLIST>){
push(@filterArray,$_);
}
OR
@filterArray=<READFILTEREDLIST>;
Hope this helps
Graham
--------------1D9BE0FBC3D0EE49186AA665
Content-Type: text/x-vcard; charset=UTF-8;
name="Graham.T.Wood.vcf"
Content-Transfer-Encoding: 7bit
Content-Description: Card for Graham Wood
Content-Disposition: attachment;
filename="Graham.T.Wood.vcf"
begin:vcard
n:;Graham
x-mozilla-html:FALSE
adr:;;;;;;
version:2.1
email;internet:Graham.Wood@oracle.com
fn:Graham Wood
end:vcard
--------------1D9BE0FBC3D0EE49186AA665--
------------------------------
Date: 26 Jun 2003 14:04:03 +0100
From: Brian McCauley <nobull@mail.com>
Subject: Re: array question
Message-Id: <u9k7b9gfcs.fsf@wcl-l.bham.ac.uk>
magelord@t-online.de (Math55) writes:
> Subject: array question
Please put the subject of your post in the Subject of your post. If
in doubt try this simple test. Imagine you could have been bothered
to have done a search before you posted. Next imagine you found a
thread with your subject line. Would you have been able to recognise
it as the same subject?
If your subject truely refects your level of understanding of your
problem (which appears to be a question about reading files) then you
have not thought about your problem anywhere near enough thought to
dream of asking anyone else for help.
Math55, your poor subject lines have been pointed out to you before by
a number of people. Do you realise how rude you are being by still
not making any effort?
> my @filterArray;
> while(<READFILTEREDLIST>) {
>
> @filterArray=<READFILTEREDLIST>;
>
> }
Where did you learn that construct?
The above is an obfucated way of writing...
scalar <READFILTEREDLIST>; # Discard first line
my @filterArray=<READFILTEREDLIST>; # Read remainder of file into array
> the file FILTEREDLIST contains something like:
>
> 132k /var/backups/dpkg.status.1.gz
> 132k /var/backups/dpkg.status.2.gz
> 124k /var/backups/dpkg.status.3.gz
> 8.0k /var/log/auth.log.1.gz
> 12k /var/log/auth.log.2.gz
> 4.0k /var/log/auth.log.3.gz
> 12k /var/log/daemon.log.1.gz
> 12k /var/log/daemon.log.2.gz
> 8.0k /var/log/daemon.log.3.gz
> 8.0k /var/log/debug.1.gz
> 12k /var/log/debug.2.gz
> 4.0k /var/log/debug.3.gz
> 8.0k /var/log/kern.log.1.gz
> 4.0k /var/log/kern.log.2.gz
> 8.0k /var/log/kern.log.3.gz
> 8.0k /var/log/messages.1.gz
> 8.0k /var/log/messages.2.gz
> 8.0k /var/log/messages.3.gz
> 4.0k /var/log/setuid.changes.1.gz
>
> but when i want to read that into the array, something does wrong. the
> array is always empty, do you see the mistake?
Are you sure the file actually contains more than one line (as
determined by the EOL sequence for your OS)?
--
\\ ( )
. _\\__[oo
.__/ \\ /\@
. l___\\
# ll l\\
###LL LL\\
------------------------------
Date: Thu, 26 Jun 2003 14:11:24 +0100
From: Graham Wood <Graham.T.Wood@oracle.com>
Subject: Re: array question
Message-Id: <3EFAF0FC.EEDF8543@oracle.com>
This is a multi-part message in MIME format.
--------------AAEC378E9E86142F390742DA
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 7bit
This is balderdash. Ignore me.
Graham
Graham Wood wrote:
> > while(<READFILTEREDLIST>) {
> >
> > @filterArray=<READFILTEREDLIST>;
> >
> > }
> > close READFILTEREDLIST;
>
> Here's where I think your problem lies.
>
> while(<READFILTEREDLIST>){ }
> steps through each line of the file returning the contents in $_ each time
>
> @filterArray=<READFILTEREDLIST>;
> reads the rest of the file contents into @filterArray.
>
> If you do both of these at the same time you will end up with nothing in
> @filterArray because this is happening
>
> 1. While loop reads a line
> 2. @filterArray gets all the rest of the lines
> 3. While loop reads a line
> 4. @filterArray gets the rest of the lines
>
> This will repeat until the while loop reads the last line and then
> <READFILTEREDLIST> will return nothing to @filterArray then your script will
> proceed with the lines after the while loop.
>
> You either need to use a while loop or @array=<FILEHANDLE> not both at the same
> time.
>
> while(<READFILTEREDLIST>){
> push(@filterArray,$_);
> }
>
> OR
>
> @filterArray=<READFILTEREDLIST>;
>
> Hope this helps
>
> Graham
--------------AAEC378E9E86142F390742DA
Content-Type: text/x-vcard; charset=UTF-8;
name="Graham.T.Wood.vcf"
Content-Transfer-Encoding: 7bit
Content-Description: Card for Graham Wood
Content-Disposition: attachment;
filename="Graham.T.Wood.vcf"
begin:vcard
n:;Graham
x-mozilla-html:FALSE
adr:;;;;;;
version:2.1
email;internet:Graham.Wood@oracle.com
fn:Graham Wood
end:vcard
--------------AAEC378E9E86142F390742DA--
------------------------------
Date: Thu, 26 Jun 2003 15:24:43 +0200
From: "Alan J. Flavell" <flavell@mail.cern.ch>
Subject: Re: array question
Message-Id: <Pine.LNX.4.53.0306261520210.6298@lxplus090.cern.ch>
On Thu, Jun 26, by accident I became aware that Graham Wood
had caused the following to appear:
Parts/Attachments:
1 Shown 48 lines Text (charset: UTF-8)
2 OK 8 lines Text (charset: UTF-8), "Card for Graham Wood"
----------------------------------------
[ The following text is in the "UTF-8" character set. ]
and had then inscribed on the eternal scroll:
> This is balderdash. Ignore me.
That's OK. Usenet postings with attachments normally get ignored by
my newsreader. I had temporarily lifted the normal filters for a
different reason, otherwise I'd never have seen those non-conformant
postings.
all the best
------------------------------
Date: Thu, 26 Jun 2003 15:54:22 +0200
From: "kderaedt" <kderaedt@hotmail.com>
Subject: Execute shell script from a perl script
Message-Id: <3efafb0e$0$1064$ba620e4c@reader1.news.skynet.be>
Hi,
How can I executed a Unix shell script from a Perl script.
The shell script is a dump of a oracle table to a file. The perl script is
for the reformat of this output file.
Thanks
Karel
------------------------------
Date: Thu, 26 Jun 2003 14:32:09 +0100
From: Graham Wood <Graham.T.Wood@oracle.com>
Subject: Re: Forking child process with WWW::Automate
Message-Id: <3EFAF5D9.CCC1F5D1@oracle.com>
This is a multi-part message in MIME format.
--------------738018F210CEFFDBF707540F
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 7bit
I solved my problem with LWP::UserAgent and HTTP::Cookies. When I set up a
cookie_jar the login information became persistent.
See perldoc lwpcook for details of how to do it if you're suffering from the
same problem.
Graham
--------------738018F210CEFFDBF707540F
Content-Type: text/x-vcard; charset=UTF-8;
name="Graham.T.Wood.vcf"
Content-Transfer-Encoding: 7bit
Content-Description: Card for Graham Wood
Content-Disposition: attachment;
filename="Graham.T.Wood.vcf"
begin:vcard
n:;Graham
x-mozilla-html:FALSE
adr:;;;;;;
version:2.1
email;internet:Graham.Wood@oracle.com
fn:Graham Wood
end:vcard
--------------738018F210CEFFDBF707540F--
------------------------------
Date: 26 Jun 2003 07:15:41 -0700
From: shambo_p@yahoo.com (Shambo)
Subject: Re: how to convert all invalid UTF-8 sequences to numeric equivalent?
Message-Id: <72190192.0306260615.7c681a4a@posting.google.com>
> Your mental model is way adrift, I'm afraid. This talk of "non utf-8
> valid sequences" strikes me as a bit like counting what you've been
> told is a stack of pound notes and then being surprised that the stack
> doesn't contain US dollars.
You're sort of correct. I am believing what I'm being told. After
checking the converted XML against the Xerces parser, it reports
errors as "invalid utf-8 sequence". When I look at the character it's
referring to, it's something along the lines of £.
> You have the choice of either delivering utf-8 as XML likes it as
> default, or telling XML that it's getting iso-8859-1. Nothing to do
> with Perl there, though.
It has everything to do with Perl since I'm using Perl to convert the
text files to XML. I'd like to take care of all my needs in this one
script instead of having to run all the files thru several steps.
I will take your advice and figure out how to tell Perl to write the
proper encoiding on output.
thanks,
S
------------------------------
Date: Thu, 26 Jun 2003 13:38:18 GMT
From: "Kevin B. Pease" <kbpease@hotmail.com>
Subject: Re: Looking for inspiration: cascading CGI
Message-Id: <VGCKa.25000$Ab2.48663@sccrnsc01>
Hi Garry,
I think I have a script that will do exactly what you want, based on
(and I hope, improved...) a program in Lincoln Stein's "CGI.pm" book. The
most notable change from his version is that I wrote in support for
cascading style sheets (which cut about 50-60% of my html-generating code
right out, because I no longer have to worry about using tables and such to
lay out my page).
It sounds like it does what you're looking for (you'd have to modify it
to present your own data, of course), but it works, and I've been pretty
happy with it -- it's certainly not suited for large-scale use, and I make
absolutely no claims about it's security, but since you indicated somewhere
in this thread that it's for intranet-use only, by half a dozen users, this
would probably do the trick. That's how mine is being used currently, and
it's been running for about 3 months now with no problems.
I tried emailing you directly, but my mail bounced... if you'd like to
see a copy of it, you can email me at my work account, which is
kevin dot pease at fmr dot com
and I'll be happy to send a copy of it to you that way. I'd be happy to
send along a copy to anybody else who's interested, I just don't want to
post the entire thing to this newsgroup, as it's rather large -- ~850 lines
/ 37K. It has very little requirement other than that -- it uses CGI,
CGI::Carp, Mail::Sendmail, and that's about it. Works fine for me served
off Win2k & WinXP running Apache 2.0.46, viewed in IE6.0 SP1 or Mozilla
1.3.1 & 1.4 RC1 (my CSS doesn't work quite right in Mozilla, so it looks a
little weird, but it works fine -- I'm not a CSS wizard by any means, the
one I have was stolen from Blue Robot's Style Reservoir
(http://www.bluerobot.com)).
--
Kevin B. Pease
kbpease@hotmail.com
------------------------------
Date: Thu, 26 Jun 2003 13:38:18 GMT
From: "Kevin B. Pease" <kbpease@hotmail.com>
Subject: Re: Looking for inspiration: cascading CGI
Message-Id: <6GCKa.24998$Ab2.48001@sccrnsc01>
Hi Garry,
I think I have a script that will do exactly what you want, based on
(and I hope, improved...) a program in Lincoln Stein's "CGI.pm" book. The
most notable change from his version is that I wrote in support for
cascading style sheets (which cut about 50-60% of my html-generating code
right out, because I no longer have to worry about using tables and such to
lay out my page).
It sounds like it does what you're looking for (you'd have to modify it
to present your own data, of course), but it works, and I've been pretty
happy with it -- it's certainly not suited for large-scale use, and I make
absolutely no claims about it's security, but since you indicated somewhere
in this thread that it's for intranet-use only, by half a dozen users, this
would probably do the trick. That's how mine is being used currently, and
it's been running for about 3 months now with no problems.
I tried emailing you directly, but my mail bounced... if you'd like to
see a copy of it, you can email me at my work account, which is
kevin dot pease at fmr dot com
and I'll be happy to send a copy of it to you that way. I'd be happy to
send along a copy to anybody else who's interested, I just don't want to
post the entire thing to this newsgroup, as it's rather large -- ~850 lines
/ 37K. It has very little requirement other than that -- it uses CGI,
CGI::Carp, Mail::Sendmail, and that's about it. Works fine for me served
off Win2k & WinXP running Apache 2.0.46, viewed in IE6.0 SP1 or Mozilla
1.3.1 & 1.4 RC1 (my CSS doesn't work quite right in Mozilla, so it looks a
little weird, but it works fine -- I'm not a CSS wizard by any means, the
one I have was stolen from Blue Robot's Style Reservoir
(http://www.bluerobot.com)).
--
Kevin B. Pease
kbpease@hotmail.com
------------------------------
Date: 26 Jun 2003 07:21:51 -0700
From: cbdeja@my-deja.com (-)
Subject: mod_perl 2 test failure at filter/in_bbs_msg (server side failed)
Message-Id: <611952a3.0306260621.26ed1b50@posting.google.com>
I'm running "make test" for the latest version of mod_perl 2.0 and it
fails at:
filter/in_bbs_body.............ok
filter/in_bbs_msg..............server side has failed (response code:
404),
see t/logs/error_log for more details
filter/in_bbs_msg..............dubious
Test returned status 29 (wstat 7424, 0x1d00)
filter/in_init_basic...........ok
But there is no "bbs" in the error log. This is a pretty
straightforward build of Apache 2 and mod_perl 2, apart from adding
mod_rewrite to the apache build. Here are the configure/make command
lines I used:
For Apache:
CC=cc OPTIM=-O CFLAGS="-xarch=v9 -D_LARGEFILE_SOURCE
-D_FILE_OFFSET_BITS=64" ./configure --with-mpm=prefork
--enable-rewrite --prefix /home/colin/lib/Solaris2.9/apache
make
make install
For mod_perl:
CC=cc OPTIM=-O CFLAGS="-xarch=v9 -D_LARGEFILE_SOURCE
-D_FILE_OFFSET_BITS=64" /home/colin/bin/Solaris2.9/perl Makefile.PL
MP_INST_APACHE2=1 MP_COMPAT_1X=1
MP_AP_PREFIX=/home/colin/lib/Solaris2.9/apache
make
make test
Any suggestions what might be wrong here?
In case it helps I have pasted a copy of the error_log file below.
Thanks
Colin
t/logs/error_log:
-----------------
END in modperl_extra.pl, pid=22339
[Thu Jun 26 14:03:48 2003] [notice] Apache/2.0.46 (Unix)
mod_perl/1.99_09 Perl/v5.8.0 configured -- resuming normal operations
[Thu Jun 26 14:03:48 2003] [info] Server built: Jun 26 2003 11:57:19
[Thu Jun 26 14:03:48 2003] [debug] prefork.c(1039): AcceptMutex:
pthread (default: pthread)
[Thu Jun 26 14:03:49 2003] [error] server reached MaxClients setting,
consider raising the MaxClients setting
[Thu Jun 26 14:04:15 2003] [info] [client 127.0.0.1] TestAPI::aplog
test in progress
[Thu Jun 26 14:04:15 2003] [debug]
/home/colin/mod_perl-1.99_09/t/response/TestAPI/aplog.pm(43):
log_serror test ok
[Thu Jun 26 14:04:15 2003] [debug]
/home/colin/mod_perl-1.99_09/t/response/TestAPI/aplog.pm(46):
(20007)No time was provided and one was required.: log_serror test 2
ok
[Thu Jun 26 14:04:15 2003] [debug]
/home/colin/mod_perl-1.99_09/t/response/TestAPI/aplog.pm(49): [client
127.0.0.1] (20007)No time was provided and one was required.:
log_rerror test ok
[Thu Jun 26 14:04:15 2003] [error] $r->log_error test ok
[Thu Jun 26 14:04:15 2003] [error] $s->log_error test ok
[Thu Jun 26 14:04:15 2003] [debug]
/home/colin/mod_perl-1.99_09/t/response/TestAPI/aplog.pm(63):
TestAPI::aplog test done
[Thu Jun 26 14:04:15 2003] [warn] ApacheApache->warn test ok
[Thu Jun 26 14:04:15 2003] [warn] $s->warn test ok
[Thu Jun 26 14:05:01 2003] [error] Apache::log_error test ok
*** The following error entry is expected and it is harmless ***
[Thu Jun 26 14:05:45 2003] [error] [client 127.0.0.1] Undefined
subroutine &TestError::runtime::no_such_func called at
/home/colin/mod_perl-1.99_09/t/respo
nse/TestError/runtime.pm line 19.
*** The following error entry is expected and it is harmless ***
[Thu Jun 26 14:05:47 2003] [error] failed to resolve handler
`TestError::syntax'
[Thu Jun 26 14:05:47 2003] [error] [client 127.0.0.1] syntax error at
/home/colin/mod_perl-1.99_09/t/response/TestError/syntax.pm line 22,
near "\;"
Compilation failed in require at (eval 115) line 3.
[echo_filter] get_brigade: Error 0
[Thu Jun 26 14:05:54 2003] [error] [client 127.0.0.1] File does not
exist: /home/colin/mod_perl-1.99_09/t/htdocs/input_filter.html
*** The following error entry is expected and it is harmless ***
[Thu Jun 26 14:06:43 2003] [error] [client 127.0.0.1] File does not
exist: /home/colin/mod_perl-1.99_09/t/htdocs/nope
*** The following error entry is expected and it is harmless ***
[Thu Jun 26 14:07:15 2003] [error] [client 127.0.0.1] need AuthName:
/TestModperl__setauth
[Thu Jun 26 14:07:32 2003] [info] Child process pid=22341 is exiting
[Thu Jun 26 14:07:32 2003] [info] removed PID file
/home/colin/mod_perl-1.99_09/t/logs/httpd.pid (pid=22340)
[Thu Jun 26 14:07:32 2003] [notice] caught SIGTERM, shutting down
END in modperl_extra.pl, pid=22340
------------------------------
Date: Thu, 26 Jun 2003 13:09:18 +0200
From: "Janek Schleicher" <bigj@kamelfreund.de>
Subject: Re: Offer tips, comments on this code (generates html to index image files)
Message-Id: <pan.2003.06.26.09.31.28.739886@kamelfreund.de>
David Oswald wrote at Wed, 25 Jun 2003 23:35:55 -0700:
In my first posting,
I forgot something important:
> sub getdir() { #Opens the current directory and gets all image
^^
> sub openhtmlfile() { #Opens (@_) as file HTML for output.
^^
> sub printheader() { #Prints the html header to the outfile.
^^
> sub printlinks() { #Prints an img src and href tag for each image in
^^
> sub printfooter() { #Prints an html footer; the "closing" stuff.
^^
> sub closehtmlfile() { #Closes the html outfile.
^^
You don't need in Perl the brackets to indicate that a sub declaration
follows.
In fact, it's very dangerous to use them unless you really want,
as Perl understands them as prototype declarations.
Prototyping gives a chance to change the way how Perl will parse the
calling of the subroutines (so you can probably leave out some more
brackets or referenciations), but that's a difficult job (for explaining
and doing) and the best recommandation I can give is not to use it.
If you want to know the details, read
perldoc perlsub
Greetings,
Janek
------------------------------
Date: Thu, 26 Jun 2003 13:09:20 +0200
From: "Janek Schleicher" <bigj@kamelfreund.de>
Subject: Re: Offer tips, comments on this code (generates html to index image files)
Message-Id: <pan.2003.06.26.09.24.46.808931@kamelfreund.de>
David Oswald wrote at Thu, 26 Jun 2003 02:41:20 -0700:
>> > while (defined ( $file = readdir(CURRENTDIR))) {
>>
>> Where does $file come from?
>
> I should have declared $file as "my $file;" within the subroutine getdir().
> But without declaring it, its creation is implicit, though to your earlier
> point, use strict; would balk at that notion, forcing me to declare it as I
> should.
Exactly. I only wanted to warn at that point, as I have seen (and done)
lot of mistakes, where I changed something on a different part of the
script and got confused that it failed now.
The main problem is not the missing declaration as declaration, but
without a 'my', the variable is _global_, and in larger scripts it's usual
to have somewhere else also another variable called 'file', thus there
could be very nasty side effects.
> As far as how it gets loaded, readdir(CURRENTDIR) is loading it. As I'm
> looking at it now, I'm wondering if I could leave out all references to
> $file and thus imply $_? In other words, "while defined
> readdir(CURRENTDIR)" .... would that load $_ with a value if I didn't
> explicitly state $file= ? And then I could do away with the =~ operator in
> my reg exp, and I would just push @entries,$_ ...just a thought.
That would do it.
You also could leave out something like
$_ =~ /.../
and
push @entries,$_
as the short versions
/.../
and
push @entries;
would also work
>> > if ($file =~ /.*\.((jpe?g)|(tiff?)|(bmp)|(gif))$/i) {
>> ^^
>>
>> That's not necessary.
>> A test whether a file has a specific ending is easier with:
>>
>> if ($file =~ /\.(jpe?g|tiff?|bmp|gif)$/i) {
>>
>> Note, that the many extra brackets you wrote,
>> aren't necessary at all.
>>
> I should have looked up order of precidence again. But I was concerned
> that, for example, the | (alternate) operator would grab "g" and "t" instead
> of "jpe?g" and "bmp"... and so on. I wasn't sure how greedy | is. Why
> isn't .* necessary if I'm trying to match the entire filename? I guess I
> understand that; the entire filename gets loaded into $file even if I'm only
> matching a portion of it.
The variable a regexp is patterned again is never changed!
You're right that with /.*.../ a successful match (contained in the
variable $& - read perldoc perlvar about) matches than the whole variable,
while a /.../ match only the ending in your case.
But that distinction doesn't play any role in your case, as you are not
interested in the matched stuff, only whether it matches the ending or not.
>> > push (@entries,$file);
>
> Is there a better way of doing this? I read somewhere that it's best to
> avoid subscript access, so push seemed like a good alternative. But is
> there a construct that avoids any call at all? ...something like @entries=
> (@entries,$file); ??
Sorry, I forgot to write the real Perlish way:
my @entries = grep /\.(jpe?g|tiff?|bmp|gif)$/i, readdir(CURRENTDIR);
instead of the whole loop.
>> You still play a lot with global variables,
>> but the code is good structured and easy to understand.
>> (If it's really your first Perl project, I'm impressed).
>
> I think I had four globals. Did I miss something, or what could I have done
> to further reduce that while maintaining re-configurability?
>
Five globals including $file :-))
Your globals had been all file handles like HTML or CURRENTDIR.
If you want to avoid them, you'll have to work with references to them.
Read e.g.
perldoc -q filehandle
about them.
I didn't explained it more detailed as it doesn't play a big role in
little scripts where I usually also work with global file handles.
Another way to avoid them would be to make a more strict clarification of
the jobs the subs would have to do.
Instead of e.g.
sub printheader {
...
print HTML ...;
}
you can always instead write a
sub header {
...
return $header;
}
and call it from the main program instead as printheader();
as
print HTML header();
Greetings,
Janek
------------------------------
Date: Thu, 26 Jun 2003 14:40:36 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: Offer tips, comments on this code (generates html to index image files)
Message-Id: <x7wuf8j40r.fsf@mail.sysarch.com>
repost with line wrapping disabled.
use a deeper indent. 1 char indent is ridiculous. 4 is a good choice
don't comment on the source lines. comment before them. that is hard to
read (especially with the wrap problem
more after you clean those things up
uri
--
Uri Guttman ------ uri@stemsystems.com -------- http://www.stemsystems.com
--Perl Consulting, Stem Development, Systems Architecture, Design and Coding-
Search or Offer Perl Jobs ---------------------------- http://jobs.perl.org
------------------------------
Date: Thu, 26 Jun 2003 15:07:11 +0200
From: "Alan J. Flavell" <flavell@mail.cern.ch>
Subject: Re: perlio problem? redhat 9, perl 5.8.0
Message-Id: <Pine.LNX.4.53.0306261459170.6298@lxplus090.cern.ch>
On Tue, Jun 24, gordon inscribed on the eternal scroll:
(well, no-one seems to have offered an answer, so I suppose I might
try...)
> The weird thing is that with a 5.8.0 compiled from source with default
> settings, both matches work, which is what we'd expect.
I don't see any logical reason why it would not work, so I'd rate it
prima facie as a bug in the particular implementation that was
giving the problem.
Sorry, I'm not in a position to reproduce your error, so I'm neither
confirming nor denying your report - just saying that on the basis of
what you reported, it does seem like a bug.
> Here's a tiny script to show the problem:
[works for me, on several different platforms, but I didn't have the
specific one you mentioned]
(I think you'd need to report the release details of the RPM,
the output of perl -V and so forth, to make it a proper bug report.)
As you rightly say: with all of the characters involved being
us-ascii, there shouldn't be any difference. Could it be that for
some bizarre reason one of them got "upgraded" to unicode, and the
other didn't, and they were then reported as not matching? But I
might be talking rowlocks - it needs someone who understands the
internals.
------------------------------
Date: 26 Jun 2003 14:08:31 +0100
From: Brian McCauley <nobull@mail.com>
Subject: Re: regexp help
Message-Id: <u9fzlxgf5c.fsf@wcl-l.bham.ac.uk>
"sjaak" <sjaak538(spam)@domein.nl> writes:
> Can anybody set me a little on the wright direction how to replace
> route.htm"></a> to generate
> route.htm">route</a>
>
> so
> .htm"></a>
> .html"></a>
>
> must replaced to
>
> .htm">route</a>
> .html">route</a>
>
> I don't know where to begin this with regexp.
The search and replace operator is s/PATTERN/REPLACEMENT/egimosx
It is doecumented in perlop.
But don't use it. Use HTML::Filter.
> To avoid futher questions in this does anyone knows a good howto with many
> examples.
The standard Perl reference manuals as supplied with Perl.
--
\\ ( )
. _\\__[oo
.__/ \\ /\@
. l___\\
# ll l\\
###LL LL\\
------------------------------
Date: Thu, 26 Jun 2003 13:09:16 +0200
From: "Janek Schleicher" <bigj@kamelfreund.de>
Subject: Re: regexp help
Message-Id: <pan.2003.06.26.09.06.05.570873@kamelfreund.de>
sjaak wrote at Thu, 26 Jun 2003 12:35:08 +0200:
> Can anybody set me a little on the wright direction how to replace
> route.htm"></a> to generate
> route.htm">route</a>
>
> so
> .htm"></a>
> .html"></a>
>
> must replaced to
>
> .htm">route</a>
> .html">route</a>
Simple way:
s/(\.html?">)(</a>)/$1route$2/g;
If you do a lot of such stuff,
a HTML parser would be more useful.
> I don't know where to begin this with regexp.
Have you read
perldoc perlre
?
> To avoid futher questions in this does anyone knows a good howto with many
> examples.
You might also read the execellent
"Mastering Regular Expressions" book of J. Friedl
(read perldoc -q book for all details)
> Like this problem is a combination of regexp's and I don't understand them
> all so it's heard to do.
What combination?
> I just need them ones a year that's why i don't stay in touch with regexp.
IHMO, regular expressions must only be understood one times deeply. The
exact syntax is easy if the principle is understood. In fact, the exact
syntax differs very programs (vim, sed, grep, egrep, java, Perl).
Also, I believe using Perl would also indicate using regexps more often
than once a year.
Greetings,
Janek
------------------------------
Date: 26 Jun 2003 14:09:46 +0100
From: Brian McCauley <nobull@mail.com>
Subject: Re: regexp: resetting search position to start of string
Message-Id: <u9brwlgf39.fsf@wcl-l.bham.ac.uk>
Paul Burton <newsonly@pmburtonNOT-THIS.claraORTHIS.co.uk> writes:
> 1 while ($string =~ s/complicated/replacement/);
>
> which has the desired effect. Is there any neater way of achieving
> this without the "boring" while loop?
No.
--
\\ ( )
. _\\__[oo
.__/ \\ /\@
. l___\\
# ll l\\
###LL LL\\
------------------------------
Date: Thu, 26 Jun 2003 10:39:54 -0400
From: "Buffalo Static" <jsc1971@hotmail.com>
Subject: Rotating Snips of HTML
Message-Id: <bdf0jq$gp9$1@mohawk.hwcn.org>
Hi
Does anyone know of a CGI that can rotate snippets of HTML coded text from
the same source page (or I guess generated in the code itself)....ie.
display text 1 from page.html, change to text 2 from page.html and so on?
Thanks
Jeff
------------------------------
Date: Thu, 26 Jun 2003 09:09:55 -0400
From: Warrick FitzGerald <nntp.wfitzgerald@crtman.com>
Subject: SOAP Server
Message-Id: <bder93$ine$1@eri0.s8.isp.nyc.eggn.net>
Hi Guys,
I know this should be simple enough to write, but if someone has an
example it would save me the time.
I am looking for a simple soap server that can recive a stard SOAP
message, along with some binary MIME attachments and write then to disk.
The objecive is to be able to compare the saved files on disk against
what the source sent.
Thanks
Warrick
------------------------------
Date: 26 Jun 2003 06:10:40 -0700
From: dananrg@yahoo.com (dnrg)
Subject: Using Perl with ESRI ArcGIS? Or VB foolishness?
Message-Id: <c1888d06.0306260510.33a00904@posting.google.com>
I'm getting into GIS, using ESRI's ArcGIS product in particular. I'd
use the GPL'ed GRASS instead, but few employers seem to have ever
heard of it; ESRI, for better or worse, seems to have a monopoly on
GIS and they're in bed with Microsoft).
Anyway, VB seems to be the standard language used to customize and
extend ArcGIS; a step up from its Avenue programming language (at
least VB can be used to code other things), but I'm not all that happy
about having to learn VB to be successful as a GIS person.
Anyone here use Perl with ESRI products? Is it possible? Effective?
Productive?Pleasant? Or is it just the wrong tool for the job?
Unfortunately, I don't know C++ or Java (two other options,
apparently, for extending and customizing ArcGIS apps), but perhaps
now is the time to learn one or the other.
For those who eschew VB as a programming language for us with ArcGIS,
which is better / easier to learn / more useful / whatever adjective
that suits you as a GIS professional in your work, should I go with
C++ or Java or something else?
Thank you muchly.
- Dana
------------------------------
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 5139
***************************************