[12936] in Perl-Users-Digest
Perl-Users Digest, Issue: 346 Volume: 9
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Aug 3 06:07:29 1999
Date: Tue, 3 Aug 1999 03:05:10 -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 Tue, 3 Aug 1999 Volume: 9 Number: 346
Today's topics:
Re: $/ for cross platform text files? (Bart Lateur)
Re: [was]Re: reg expression (Abigail)
Re: [was]Re: reg expression (I.J. Garlick)
Escaping HTML tags <karah@ida.liu.se>
Re: File Permissions (Mike Grandin)
Re: Goodbye clp.misc, Tad is checking out (was: why are (Bart Lateur)
Re: How do i append the beginning of a HTML file? (Larry Rosler)
Re: How do I pass arguments from one CGI script to anot (I.J. Garlick)
Re: How to access only last field of a split ? (Andreas Fehr)
Re: How to access only last field of a split ? (brian d foy)
Re: How to block a file nochax@my-deja.com
Re: How to block a file (Andreas Fehr)
Re: how to remove cr/lf ??? (Bart Lateur)
looking for XML comments <chris@inta.net.uk>
Re: Newbie Q: Removing files from a folder <eedalf@eed.ericsson.se>
Re: Newbie Q: Removing files from a folder <andrewf@beausys.freeserve.co.uk>
Re: Perl Begineer Question... (Bart Lateur)
Re: Perl or CGI (Abigail)
Re: Perl or CGI (Abigail)
perl problem with associative array superba77@my-deja.com
Re: perl problem with associative array <eedalf@eed.ericsson.se>
Re: Problem reading forms with perl (I.J. Garlick)
reg.expressions: replace a substring ??? <hubert.ming@iggi.lu.ch>
Re: reg.expressions: replace a substring ??? <eedalf@eed.ericsson.se>
Re: Use of uninitialized value .... (Asher)
Re: Why no Perl books at Fry's? <eedalf@eed.ericsson.se>
Re: Working Telnet Script Needed <ssanbeg@home.com>
Re: Working Telnet Script Needed <carvdawg@patriot.net>
Digest Administrivia (Last modified: 1 Jul 99) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Tue, 03 Aug 1999 08:54:46 GMT
From: bart.lateur@skynet.be (Bart Lateur)
Subject: Re: $/ for cross platform text files?
Message-Id: <37a7a634.7336222@news.skynet.be>
Abigail wrote:
>%% I think that one reason for keeping it this way, is that performance for
>%% reading lines would drop considerably, say to around 50% of what it is
>%% now, even for the common case where $/ is just plain text. That would
>%% put it in the same range as what you get now, but ALWAYS.
>
>What makes you think it will take such a huge performance hit?
Don't shoot the messenger! This subject has been brought up on the
MacPerl mailing list quite a few times in the past already. After all,
it's far more likely for a Mac to have to process Unix files, than vice
versa. I was always in favor of changing $/ to a regex. But Matthias,
the prime person behind the Mac port, reported always having hit a brick
wall whenever he brought this up with Perl-Porters.
>awk has
>always done it, and it's very trivial to determine that a regex only
>contains a fixed string. Not to mention the fact nothing different than
>now needs to be done if $/ isn't set in the program.
Now you're expecting optimizations. Perl has already been disapointing
in that regard quite a few times. For example, it won't optimize
/a*a*a*b/ into /a*b/.
It would also need a bit rethinking of Perl's basic readline algorithm.
The basis for most problems is the subdivision of the file contents into
chunks when reading the file.
Take the example somebody brought up just a little while ago:
qr/\xB3{1,4}/. Suppose the current buffer ends with "/\xB3\xB3". That is
a match. But if the data following that happens to start with "\xB3",
that should be part of the match too!
Just as an example, I've implemented some Perl code that demonstrates
the principle. It's not too efficient, since it uses the no-no variables
qw($& $` $') (I couldn't get it to work using pos()). And I've used a
very small buffer size (16 bytes), just to make sure that crossing
buffer boundaries, actually happens.
I assumed that if you get a match that is followed by something else,
then you have a valid and complete match.
But that doesn't work for all cases, either. If the regex is
qr/abcde|bc/ and the current chunk happens to end in "abcd", you get a
match for "bc", which is followed by "d". But if the following chunk
starts with "e", we ought to have matched the bigger chunk "abcde",
because it starts more upfront!
#! perl -w
require 5.005;
tie *FILE, "RegexRS", $0, qr/\n+/ or die "Cannot open file: $!";
while(<FILE>) {
print "!!! ",$_;
}
package RegexRS;
use FileHandle;
sub TIEHANDLE {
my($class,$file,$regex) = @_;
my $fh = new FileHandle;
$fh->open($file) or return; # false
bless { FH => $fh, buffer => "", RS => qr/$regex/ }, $class;
}
sub READLINE {
my $self = shift;
{
if($self->{buffer} =~ $self->{RS} and length($')) {
$pos = length($`) + length($&);
return substr($self->{buffer}, 0, $pos, "");
}
read $self->{FH}, $self->{buffer}, 16, length $self->{buffer}
and redo;
my $line = $self->{buffer};
return unless length $line; # EOF
$self->{buffer} = "";
return $line;
}
}
__END__
This shows that plain Perl regexes (probably) aren't up to the task. One
problem is the inefficiency of restarting the search at the front of the
buffer, whenever a new chunk is appended. It should keep track of where
the last attempt for a pattern match started, and restart the next
attempt from there.
The second problem is that failure of a match because the end of the
buffer is reached, should be fatal. That would solve the qr/abcde|bc/
problem.
And third, a more reliable way than pos() (why does it need //g
anyway?), and a more effecient way than using qw($` $& $'), of getting
an index for match length and match start should be available.
In fact, the mere existence of those special variables wouldn't be
necessary, if we only had matchlength() and matchstart(), because we can
always get the data by combining these with substr().
p.s. chomp() would need to be rewritten as s|$/$||, but more efficient.
Bart.
------------------------------
Date: 3 Aug 1999 02:22:23 -0500
From: abigail@delanet.com (Abigail)
Subject: Re: [was]Re: reg expression
Message-Id: <slrn7qd64c.rb1.abigail@alexandra.delanet.com>
llornkcor@my-deja.com (llornkcor@my-deja.com) wrote on MMCLXIII September
MCMXCIII in <URL:news:7o618q$tpa$1@nnrp1.deja.com>:
{} and I wonder how many people have come here, seeking knowlege about
{} perl, and asked a simple question, and have gotten back some rude
{} non-answer from the 'regulars'?
Way too many. Got any solutions for exterminating those pesky people
that ask questions that trigger rude responses?
{} I suppose you all teach someone to ride
{} a bike by saying 'read the FAQ'?
We don't teach Perl here. If you pay me, I'll teach. I will help people
who are willing to help themselves. I don't care for lusers, gimme gimme
people, script kiddies, lazy people, people who can't even figure out the
appropriate group to ask their question in, and people who are just plain
stupid. If you don't like that, RTFM of your newsreader and killfile me.
{} Now, Tom, and any other 'regular' who
{} provide snide answers here, I have seen your script work, and I admire
{} it. But nowhere else on any newsgroup, have I seen such ridicule for
{} newbies, and their questions.
Perhaps you should go out more often. The world is a big place. BTW,
people are being ridiculed for their lack of showing a clue, not for
being newbies.
{} All I am asking anyone here, is if you
{} read a post that is, to you, a stupid question, and you don't have an
{} answer..('read the FAQ'- is a non-answer) DON'T reply...
That's not how it works.
But we knew you don't understand how Usenet works. Despite being told
many times, you keep your jeopardy style of writing articles; including
quoting the article completely, including the .sig. That doesn't make
you look smart - not at all.
Abigail
--
perl -wle\$_=\<\<EOT\;y/\\n/\ /\;print\; -eJust -eanother -ePerl -eHacker -eEOT
-----------== 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: Tue, 3 Aug 1999 09:35:23 GMT
From: ijg@connect.org.uk (I.J. Garlick)
To: llornkcor@my-deja.com
Subject: Re: [was]Re: reg expression
Message-Id: <FFvun0.1Jr@csc.liv.ac.uk>
[Posted and mailed]
I usually don't like doing this but you need it.
In article <7o618q$tpa$1@nnrp1.deja.com>,
llornkcor@my-deja.com writes:
> and I wonder how many people have come here, seeking knowlege about
> perl, and asked a simple question, and have gotten back some rude
> non-answer from the 'regulars'? I suppose you all teach someone to ride
> a bike by saying 'read the FAQ'? Now, Tom, and any other 'regular' who
> provide snide answers here, I have seen your script work, and I admire
> it. But nowhere else on any newsgroup, have I seen such ridicule for
> newbies, and their questions. All I am asking anyone here, is if you
> read a post that is, to you, a stupid question, and you don't have an
> answer..('read the FAQ'- is a non-answer) DON'T reply...
Since you can't have read my first response and more importantly James'
further enlightenment I will summarise them here again.
The reason why Abigail, Tad, Tom, Larry, Uri and many others who have
been here for years jump in with varying degrees of "rudeness" is
simply for self preservation and the good of Perl. If they do what you
propose a FAQ doesn't get answered correctly so some well meaning
not-so-newbie comes along and says "oh good one I can answer". They
then proceed to answer, badly.
In the case of this thread you would probably have gotten the
/<img[^>>+/gi answer. This has been pointed out to be bad code, and
because the above mentioned care about Perl they would then feel honour
bound to correct the mistake. By then however the mistake is in black
and white and the original poster may never read the correct way of
doing things.
And as I R A Darth Aggie pointed out more importantly
And in deja.com until the end of time...hmmm...
It's quite simple really. I have lurked here for a little over a year now
and TBH the newbies are getting to me. So poor Tom must be near certifiable
by now. Is it any wonder he responds the way he does?
I know for a fact that Tom can stand up for himself, he will no doubt
lambast you some more. IMHO Tom deserves canonization for his patience
alone, it is truly phenomenal.
--
Ian J. Garlick
ijg@csc.liv.ac.uk
Science is facts; just as houses are made of stones, so is science made
of facts; but a pile of stones is not a house and a collection of facts
is not necessarily science.
-- Henri Poincaire
------------------------------
Date: Tue, 03 Aug 1999 11:52:21 +0200
From: Karl Ahlin <karah@ida.liu.se>
Subject: Escaping HTML tags
Message-Id: <37A6BBD5.7070E004@ida.liu.se>
Hi!
Is there a way to escape HTML tags? I want the browser to display the
actual HTML tags, not interpret them and display their output. In other
words, I want <IMG SRC="blabla.gif"> to be translated to <IMG
SRC="blabla.gif">. Of course I can do this on my own, I was
just wondering if there is a subroutine or package already available
somewhere?
/Karl
------------------------------
Date: 3 Aug 1999 07:20:02 GMT
From: tcsh@holly.colostate.edu (Mike Grandin)
Subject: Re: File Permissions
Message-Id: <slrn7qd6a8.lb8.tcsh@localhost.localdomain>
abc@abc.net (NiteFever):
> I'm writing a perl script that will check all of the directorys under
> the /home directory to see if it has the following permissions:
>
> drwx--x--x
0711
>
> And if it's not, to change it, the problem is, that I don't know what
> is the octal form of this, like
--
Mike Grandin
------------------------------
Date: Tue, 03 Aug 1999 08:54:50 GMT
From: bart.lateur@skynet.be (Bart Lateur)
Subject: Re: Goodbye clp.misc, Tad is checking out (was: why are you so harsh to this guy ?)
Message-Id: <37a6a4cf.6979154@news.skynet.be>
Tad McClellan wrote:
> I have wasted an inordinate amount of time here. I thought I was
> helping people, but clearly I have not been.
>
> I quit.
>
> I am leaving comp.lang.perl.misc.
Too bad. You were one of the nicer people here. Whether you've been
helpful or not, it's a pity to see you go.
> I have learned a lot about Perl in the 5 years and 9,000 posts
> worth of participating in this newsgroup.
Yup. Helping isn't the main reason to hang out here. It's supposed to be
one of the nicer aspects, though.
> Now I'll have lots more time to play with my daughter.
>
> I'm going to go do that right now...
Ah, but don't say you've neglected your daughter for this newsgroup! If
so, you've been spending too much of your time here! It ain't worth it.
So long.
Bart.
------------------------------
Date: Tue, 3 Aug 1999 00:07:04 -0700
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: How do i append the beginning of a HTML file?
Message-Id: <MPG.121034e79a8344f989da2@nntp.hpl.hp.com>
In article <7o5vpq$so6$1@nnrp1.deja.com> on Tue, 03 Aug 1999 05:47:40
GMT, urb123@my-deja.com <urb123@my-deja.com> says...
> In article <7o2lfn$3v1$1@apple.news.easynet.net>,
> "matt saunders" <nfs@ukonline.co.uk> wrote:
> > I've not been using perl for long at all and
> i've been desperately seeking
> > the source code for a CGI to append the
> beginning of a file. I was
> > wondering if any of you (obviously knowledgable)
> people could reply with the
> > source code. I'd be eternally grateful.
...
> open(TEMP,"+<$FileName");
> @Array = <TEMP>;
> seek (TEMP,0,0);
> truncate (TEMP,0);
> print TEMP "line three";
> print TEMP @Array;
> close (TEMP);
Besides the failure to check system calls, that approach risks losing
all the data. Suppose, for example, the unthinkable happened just after
the file is truncated and before all the data are written?
A far safer approach is to use a temporary file, as described in
perlfaq5: "How do I change one line in a file/delete a line in a
file/insert a line in the middle of a file/append to the beginning of a
file?"
Doesn't that sound amazingly like the question that was asked? Why
wouldn't the answer provided there be preferable to an off-the-cuff
approach?
--
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: Tue, 3 Aug 1999 08:18:47 GMT
From: ijg@connect.org.uk (I.J. Garlick)
Subject: Re: How do I pass arguments from one CGI script to another?
Message-Id: <FFvr3B.Mwu@csc.liv.ac.uk>
In article <7o4aak$19a$1@news.gte.com>,
"Justin Development" <mark.thomas@gsc.gte.com> writes:
> I have an HTML file (my.html) that passes a username and password to a CGI
> script (let's call it my1.cgi), the my1.cgi script then passes name,
> address, phone number to another CGI script (my2.cgi) which prints it out
> to a file.
Why? More later.
>
> How do I pass the username and password from my.html to my2.cgi so I can
> print it to a file? my1.cgi knows about the username and password but
> my2.cgi doesn't. I know it has something to do with the scope of the
> namespace but I don't know how?
My news reader shows 2 responses to this, which do give answers, probably
with varying amounts of milage, I don't know.
However, IMHO you are going down a dead end. I have wanted to do this a
couple of time (until I learnt), and now when ever I start thinking like
this I immediately put the brakes on and back up. Go for a rest. Basically
chill out and then come back.
In my experience it is never a good idea to do this. It is nearly always
better to put the two separate scripts into a library as subroutines and
call them one after the other passing what ever parameters you need to.
Hay you may even get to oprtimize a little as they may have routines that
can be combined with a little tweaking. Also you will only have one call
to CGI.pm (you are using CGI.pm aren't you?), not that it should matter as
a module should only load once. However in a couple of the solutions
proposed perl would have to be reloaded as a new process, decidely not good.
Well that's how I would do it but TIMTOWTDI, so choose your own poison.
OH yes. There is an added benefit, if you ever need to do this again it's
done, you just
use Whatever;
and call the relevant subroutine. (I think this is known as laziness, see
camel, it's in there somewhere I remember reading it but can't track it
down)
--
Ian J. Garlick
ijg@csc.liv.ac.uk
Science is facts; just as houses are made of stones, so is science made
of facts; but a pile of stones is not a house and a collection of facts
is not necessarily science.
-- Henri Poincaire
------------------------------
Date: Tue, 03 Aug 1999 09:05:49 GMT
From: backwards.saerdna@srm.hc (Andreas Fehr)
Subject: Re: How to access only last field of a split ?
Message-Id: <37a6aede.12933617@news.uniplus.ch>
>> >Try:
>> >$line = "word.10.word.20.30.40.50";
>> >$scalar = ( reverse split '.',$line)[0]; # last element of split line
>> >
>> Sorry, does not work for me, I got:
>> Use of uninitialized value at C:\TEMP\bla11.plx line 17.
>>
>> Did you try it?
>
>So Abigail was right all along! The syntax error *is* on line 17! ;-)
>
>She must have used the Psychic::Hotline module...
>
Hmm, no, I have no copyright information on that line. Just happen
that I have lot of comments above (I check some stuff comment it
out and check new things). The problem with the code above was about
the '.' instead of e.g. '\.' or "\\." or... split does nothing usefull
there.
I'm not sure whether Abigail would use any hotline module to
communicat with me, unless she wants to go crazy on my mistakes
and/or my English.
Andreas
------------------------------
Date: Tue, 03 Aug 1999 02:20:44 -0400
From: brian@pm.org (brian d foy)
Subject: Re: How to access only last field of a split ?
Message-Id: <brian-0308990220460001@1cust126.tnt1.durham.nc.da.uu.net>
In article <7o5vv6$sqa$1@nnrp1.deja.com>, urb123@my-deja.com wrote:
>In article <01bedc97$7a0d0a80$f34f39cb@stingray>,
> "John Hennessy" <john@hendigital.com.au> wrote:
>> Hi, I am wanting to access only the last field of a split line.
>> Is there a quick way of doing this keeping in mind I won't know
>> how many fields will be returned in the line.
>>
>> Example line...
>>
>$Temp = "word.10.word.20.30.40.50";
>(@Array) = split(/\./,$Temp);
>$Last = $Array[$#Array];
you can also skip the intermediate array:
$last = ( split )[-1]
since a negative subscript counts from the end of the list.
--
brian d foy
CGI Meta FAQ <URL:http://www.smithrenaud.com/public/CGI_MetaFAQ.html>
Perl Monger Hats! <URL:http://www.pm.org/clothing.shtml>
------------------------------
Date: Tue, 03 Aug 1999 08:52:59 GMT
From: nochax@my-deja.com
Subject: Re: How to block a file
Message-Id: <7o6al9$4dt$1@nnrp1.deja.com>
Uri Guttman <uri@sysarch.com> wrote:
> >>>>> "A" == Abigail <abigail@delanet.com>
writes:
>
> A> NoCHaX (nochax@bigfoot.com) wrote on
MMCXLVI September MCMXCIII in
> A> <URL:news:378FE37A.D1C6C508@bigfoot.com>:
> A> == I need to block a file in Perl. How to
do this?
>
> A> Define "block a file".
>
> assuming lines are converted to fixed sized
records:
>
> system( "dd obs=80 if=$in_file
of=$outfile" ) ;
>
> :-)
>
> uri
>
Sorry, I wanted to say "lock", not "block".
I put a script saving data to a text file in a
web site, but after some days the data was
corrupted... I know the problem is that the
database file must be locked, but the Perl
documentation hasn't helped me too much...
The method I'm using to save the data is:
open (FILE, 'filename');
foreach (@dataarray) {
print FILE $_;
}
close (FILE);
Anyone can tell me the process to evitate the
database to get corrupted?
Thanx,
NoCHaX
Sent via Deja.com http://www.deja.com/
Share what you know. Learn what you don't.
------------------------------
Date: Tue, 03 Aug 1999 09:08:23 GMT
From: backwards.saerdna@srm.hc (Andreas Fehr)
Subject: Re: How to block a file
Message-Id: <37a6b143.13546268@news.uniplus.ch>
>
>Sorry, I wanted to say "lock", not "block".
>
For file locking, try
perldoc -q lock
Andreas
------------------------------
Date: Tue, 03 Aug 1999 07:16:42 GMT
From: bart.lateur@skynet.be (Bart Lateur)
Subject: Re: how to remove cr/lf ???
Message-Id: <37a69708.3452146@news.skynet.be>
elephant wrote:
>>(This assumes your machine treats \n as CR-LF. This is the case if you're
>>on a PC.)
>
>a PC ? .. so you mean if I run Linux or NT on my PC then my line endings
>are still the same as DOS ? .. oh man - what a ripoff - I'm taking this
>thing back
You're easily disturbed, if a change in definition of line endings
bothers you that much.
Bart.
------------------------------
Date: Tue, 3 Aug 1999 10:52:55 +0100
From: "Chris Denman" <chris@inta.net.uk>
Subject: looking for XML comments
Message-Id: <7o6e43$22dj$1@news2.vas-net.net>
I have delevoped a perl script that stores information for dynamic websites.
This information can be accessed by the site owner with a user-friendly
browser based interface.
The site information is stored in separate files and easily accessible via a
logical directory structure. I also index as much data as possible for very
fast search proceedures.
At the moment XML seems to be the buzz word, and my employers wants me to
look seriously into this new 'industry standard for storing information'.
As I understand it, isn't XML just another way of storing information? What
benifits should I expect if I change the way I store data? Should I bother
at all, and only supply clients with XML generated documents from their
existing data as and when they need it?
The way I see it, storing information in XML seems to create all sorts of
problems for searching and data extraction.
Comments would be greatly appreciated.
Cheers,
Chris Denman
------------------------------
Date: Tue, 03 Aug 1999 11:13:36 +0200
From: Alex Farber <eedalf@eed.ericsson.se>
To: Andrew Fry <andrewf@beausys.freeserve.co.uk>
Subject: Re: Newbie Q: Removing files from a folder
Message-Id: <37A6B2C0.93E2801E@eed.ericsson.se>
Hi Andrew,
Andrew Fry wrote:
> sub ClearFolder
> {
> my $foldername = $_[0];
> my $extension = $_[1];
> my $myext = '*'; # extension to be used, default value
> my @filelist = ();
> my $numfound = 0;
> my $numdeleted = 0;
>
> # check if folder exists...
> if ($verbose)
> {
> print "ClearFolder: Checking $foldername...\n";
> }
> if (-d $foldername)
> {
> # get list of files in folder...
> if (defined ($extension))
> {
> $myext = $extension;
> }
> #@filelist = glob("$foldername/*.$myext");
> #@filelist = <$foldername/*.$myext>;
> if (opendir(DIR,$foldername))
> {
> @filelist = grep { /\.$myext$/ } readdir(DIR);
> closedir(DIR);
> $numfound = $#filelist;
maybe better $numfound = @filelist; here.
> if ($numfound > 0)
> {
> print @filelist;
> }
> # delete files...
> # $i = unlink(@filelist);
My guess is that you should do unlink (map "$foldername/$_", @filelist);
> print "Folder: $foldername, file [*.$myext], found $numfound,
> deleted $numdeleted.\n";
> }
> }
> }
Regards
Alex
--
Ich studiere Elektrotechnik (Technische Informatik) an der RWTH Aachen
und bin ein guter Perl-Programmierer (arbeite seit 4 Jahren als Intranet-
Entwickler). Kann auch C, Java, SQL, JavaScript und HTML, CGI und TCP/IP.
Ich suche eine gut bezahlte Diplomstelle in Koeln, Aachen oder Umgebung.
------------------------------
Date: Tue, 3 Aug 1999 10:59:36 +0100
From: Andrew Fry <andrewf@beausys.freeserve.co.uk>
Subject: Re: Newbie Q: Removing files from a folder
Message-Id: <aNkpmFAI2rp3Ewer@beausys.freeserve.co.uk>
In article <37A6B2C0.93E2801E@eed.ericsson.se>, Alex Farber
<eedalf@eed.ericsson.se> writes
>Hi Andrew,
>
>Andrew Fry wrote:
>> sub ClearFolder
>> {
>> my $foldername = $_[0];
>> my $extension = $_[1];
>> my $myext = '*'; # extension to be used, default value
>> my @filelist = ();
>> my $numfound = 0;
>> my $numdeleted = 0;
>>
>> # check if folder exists...
>> if ($verbose)
>> {
>> print "ClearFolder: Checking $foldername...\n";
>> }
>> if (-d $foldername)
>> {
>> # get list of files in folder...
>> if (defined ($extension))
>> {
>> $myext = $extension;
>> }
>> #@filelist = glob("$foldername/*.$myext");
>> #@filelist = <$foldername/*.$myext>;
>> if (opendir(DIR,$foldername))
>> {
>> @filelist = grep { /\.$myext$/ } readdir(DIR);
Basically, the problem is that what gets put into
@filelist seems OK in some instances, but not OK in
others. For instance, I've got a whole load of files
in C:\Windows\Temporary Internet Files
...but they dont show up in @filelist!
BTW, I got the 'grep' line from the Perl Cookbook.
>> closedir(DIR);
>> $numfound = $#filelist;
>
>maybe better $numfound = @filelist; here.
>
>> if ($numfound > 0)
>> {
>> print @filelist;
>> }
>> # delete files...
>> # $i = unlink(@filelist);
>
>My guess is that you should do unlink (map "$foldername/$_", @filelist);
>
>> print "Folder: $foldername, file [*.$myext], found $numfound,
>> deleted $numdeleted.\n";
>> }
>> }
>> }
>
>Regards
>Alex
---
Andrew Fry
"Time flies like an arrow. Fruit flies like a banana". (Groucho Marx).
------------------------------
Date: Tue, 03 Aug 1999 07:40:46 GMT
From: bart.lateur@skynet.be (Bart Lateur)
Subject: Re: Perl Begineer Question...
Message-Id: <37a8998f.4099437@news.skynet.be>
Jimmy wrote:
> I am new to Perl. I want to implement the following requirements in
>using Perl.
>
> If the length of variable A (after trim) is equal to zero, then put
>$no_of_space space characters into variable B.
Ah. Homework?
> So :
>
> if length(trim($A)) == 0 then {
> put null string to variable B, the length of null string is
>equal to $no_of_space value
> }
You're mixing Perl with Basic and Applescript.
Let me change the requirements: If $A is all spaces, assign that
particular value to $B. Typical for 1 is to use regexes, like
( $A =~ /^ *$/ ). You can build that kind of string using ( " " x 20 ).
Alternatively, try ( pack("A20", '') ), pack 'A' pads with spaces).
Bart.
------------------------------
Date: 3 Aug 1999 02:12:18 -0500
From: abigail@delanet.com (Abigail)
Subject: Re: Perl or CGI
Message-Id: <slrn7qd5hd.rb1.abigail@alexandra.delanet.com>
CGI (PerlCoder@Unix.com) wrote on MMCLXIII September MCMXCIII in
<URL:news:37ac83fe.189776116@news.giganews.com>:
<> On 2 Aug 1999 22:32:48 -0500, abigail@delanet.com (Abigail) wrote:
<>
<> >|| If I want to write a program that tak
<> >|| form input on my website and write that to some other file, on the server
<> >|| (UNIX), what do I use best?
<> >
<> >Python.
<>
<> That's a very flippant answer from you, which is typical. It seems
<> like you have nothing better to do than write smart alec responses to
<> newbies. One time I checked and literally 20 percent of the messages
<> on this newsgroup were from you.
I am aiming for 33.3%. Perhaps I should get a better newsreader, with
a send button that I get hit multiple times. Or I could write a Rexx
script that posts for me.
<> Maybe in some ways, Python is better than Perl. But Perl is what
<> people are using and Perl is what's on a lot of web servers, not
<> Python. I haven't seen Python mentioned in any job ads. Also,
<> processing a form is a pretty simple task. I don't think you'd
<> particularly need Python for it.
Nor does one need Perl for that! A shell script will do just fine.
Or Eiffel! Yeah, Eiffel will do.
<> Your answer was like recommending someone learn Esperanto instead of
<> English.
Python is easier to learn than Perl. Python will get the task done.
Esperanto is probably easier to learn than English as well. And if that
someone needs to communicate with someone that doesn't care whether that
someone speaks Esperanto or English, Esperanto would be the way to go.
The web server certainly doesn't care whether the program is written in
Perl or Python.
Abigail
--
package Just_another_Perl_Hacker; sub print {($_=$_[0])=~ s/_/ /g;
print } sub __PACKAGE__ { &
print ( __PACKAGE__)} &
__PACKAGE__
( )
-----------== 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: 3 Aug 1999 02:13:34 -0500
From: abigail@delanet.com (Abigail)
Subject: Re: Perl or CGI
Message-Id: <slrn7qd5ap.rb1.abigail@alexandra.delanet.com>
CGI (PerlCoder@Unix.com) wrote on MMCLXIII September MCMXCIII in
<URL:news:37ac83fe.189776116@news.giganews.com>:
<> On 2 Aug 1999 22:32:48 -0500, abigail@delanet.com (Abigail) wrote:
<>
<> >|| If I want to write a program that tak
<> >|| form input on my website and write that to some other file, on the server
<> >|| (UNIX), what do I use best?
<> >
<> >Python.
<>
<> That's a very flippant answer from you, which is typical. It seems
<> like you have nothing better to do than write smart alec responses to
<> newbies. One time I checked and literally 20 percent of the messages
<> on this newsgroup were from you.
I am aiming for 33.3%. Perhaps I should get a better newsreader, with
a send button that I get hit multiple times. Or I could write a Rexx
script that posts for me.
<> Maybe in some ways, Python is better than Perl. But Perl is what
<> people are using and Perl is what's on a lot of web servers, not
<> Python. I haven't seen Python mentioned in any job ads. Also,
<> processing a form is a pretty simple task. I don't think you'd
<> particularly need Python for it.
Nor does one need Perl for that! A shell script will do just fine.
Or Eiffel! Yeah, Eiffel will do.
<> Your answer was like recommending someone learn Esperanto instead of
<> English.
Python is easier to learn than Perl. Python will get the task done.
Esperanto is probably easier to learn than English as well. And if that
someone needs to communicate with someone that doesn't care whether that
someone speaks Esperanto or English, Esperanto would be the way to go.
The web server certainly doesn't care whether the program is written in
Perl or Python.
Abigail
--
package Just_another_Perl_Hacker; sub print {($_=$_[0])=~ s/_/ /g;
print } sub __PACKAGE__ { &
print ( __PACKAGE__)} &
__PACKAGE__
( )
-----------== 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: Tue, 03 Aug 1999 08:02:44 GMT
From: superba77@my-deja.com
Subject: perl problem with associative array
Message-Id: <7o67n1$2im$1@nnrp1.deja.com>
Hi people!
Though I am a newbie in perl I hope someone will help me anyway ;-)
- I've created an associative array:
%thumbswidth =
("up1",64,"up88",68,"up87",80,"up85",52,"up79",72,"up75",72,"up63",128,"
up52",56,"up4",76,"up34",64,"up21",104,"up17",52,"up14",48,"up13",128,"u
p10",72);
- Then in a loop I wanted to call this array:
$actimgw = $thumbswidth{'$elementname'};
or I also tried:
$actimgw = $thumbswidth{$elementname};
$elementname is equal to an index-name in the array above (eg. up1)
Each time the loop is passed through $elementname will have a different
value (eg. up4) because each time $actimgw will be parsed in a img-tag
(to indicate the respective width of the thumbnail)
print "<img src=\"$thumb.jpg\" width=$actimgw height=$actimgh>"
Perl gave me this output:
<img src="anythinghere.jpg" width= height=>
My question now:
Is it possible to give a scalar of an associative array a variable as
index-name like in: $actimgw = $thumbswidth{$elementname};
or must it always be a specific index-name like eg. $actimgw =
$thumbswidth{'up1'}; ?
How can I solve this problem? Any hints very very welcome!!
Thanks to all perl experts!!
Chris
---------
akris@gmx.net (write in English or German.thanks)
Sent via Deja.com http://www.deja.com/
Share what you know. Learn what you don't.
------------------------------
Date: Tue, 03 Aug 1999 10:22:36 +0200
From: Alex Farber <eedalf@eed.ericsson.se>
To: superba77@my-deja.com
Subject: Re: perl problem with associative array
Message-Id: <37A6A6CC.869D2A03@eed.ericsson.se>
Hi Chris,
superba77@my-deja.com wrote:
> %thumbswidth =
> ("up1",64,"up88",68,"up87",80,"up85",52,"up79",72,"up75",72,"up63",128,"
> up52",56,"up4",76,"up34",64,"up21",104,"up17",52,"up14",48,"up13",128,"u
> p10",72);
> - Then in a loop I wanted to call this array:
> $actimgw = $thumbswidth{'$elementname'};
'$elementname' is probably not want you want, since
the variable $elementname will not be interpolated.
> or I also tried:
> $actimgw = $thumbswidth{$elementname};
That should work
> $elementname is equal to an index-name in the array above (eg. up1)
> Each time the loop is passed through $elementname will have a different
> value (eg. up4) because each time $actimgw will be parsed in a img-tag
> (to indicate the respective width of the thumbnail)
>
> print "<img src=\"$thumb.jpg\" width=$actimgw height=$actimgh>"
>
> Perl gave me this output:
> <img src="anythinghere.jpg" width= height=>
Sometimes adding -w helps (#!/bin/perl -w) to track down the problem...
I also wonder where will you get heights. Maybe following is better:
%thumbswidth = ('up1' => [64, 73], 'up88' => [68, 100]);
And then (see also "perldoc perldsc"):
print "<img src=\"$thumb.jpg\" width=" . $thumbswidth{$elementname} -> [0] .
' height=' . $thumbswidth{$elementname} -> [1] . '>';
By the way there's a good article on determening image sizes with the
Image::Size module at http://www.stonehenge.com/merlyn/WebTechniques/col36.html
Regards
Alex
--
Ich studiere Elektrotechnik (Technische Informatik) an der RWTH Aachen
und bin ein guter Perl-Programmierer (arbeite seit 4 Jahren als Intranet-
Entwickler). Kann auch C, Java, SQL, JavaScript und HTML, CGI und TCP/IP.
Ich suche eine gut bezahlte Diplomstelle in Koeln, Aachen oder Umgebung.
------------------------------
Date: Tue, 3 Aug 1999 08:58:34 GMT
From: ijg@connect.org.uk (I.J. Garlick)
Subject: Re: Problem reading forms with perl
Message-Id: <FFvsxM.px@csc.liv.ac.uk>
In article <7o53ga$9fv$1@nnrp1.deja.com>,
makarand_kulkarni@my-deja.com writes:
Firstly. Please post your replies after the quoted text. Thanks.
>> The problem is that when a user enters "<" in the text area, the
>> following text does not make it to the file. So if the user
>> types "a<b>c", the file winds up with "ac" written to it.
>>
[re-arranged post]
>
> -
> When you use forms the user is expected to type
> plain text. Plain text by definition does
> not include '<' or '>' or '&'.
Last time I checked text/plain was a 7-bit encoding and correct me if I am
wrong but '>', '<', and '&' are all 7-bit ascii characters. So why are
they illegal?
> These have
> special meaning in HTML
True.
> and are interpreted
> as HTML tags and are lost.
By what? Last time I tried this I got everything that was entered in the
text field, warts and all. I suspect the fact that the original poster is
not using CGI.pm may have something to do with this. Your browser will
encode what's in the field and send it safely. It's upto you to decode it,
or CGI.pm to be specific. Read the CGI.pm docs to see how to deal with
special HTML characters when outputting to the browser.
--
Ian J. Garlick
ijg@csc.liv.ac.uk
Science is facts; just as houses are made of stones, so is science made
of facts; but a pile of stones is not a house and a collection of facts
is not necessarily science.
-- Henri Poincaire
------------------------------
Date: Tue, 3 Aug 1999 09:59:41 +0200
From: "Ming Hubert" <hubert.ming@iggi.lu.ch>
Subject: reg.expressions: replace a substring ???
Message-Id: <7o67nu$bi5$1@pollux.ip-plus.net>
hello perl-gurus
i have a outputstring (outstr1) on which i'd like to replace multiple
substrings
which all begin with the same characters, for example: "repl_me".
the replacement should only be done till the next delimiter. the outstring
has
the delimiter ";".
exampel: outstr1:
H1234;Tom John;repl_me tillnxt delim;Berlin;5000;repl_me again tillnxt
delim;Germany;repl_me again;
H1235;Kim Wild;Hamburg;repl_me tillnxt delim;8000;Germany;repl_me again
tillnxt delim;repl_me again;
how can i substitute all the substrings which start with "repl_me" to the
next
semicolom with "xxx" ??
exampel: outstr1:
H1234;Tom John;xxx;Berlin;5000;xxx;Germany;xxx;
H1235;Kim Wild;Hamburg;xxx;8000;Germany;xxx;xxx;
thanx alot for your help
hubert
------------------------------
Date: Tue, 03 Aug 1999 11:07:02 +0200
From: Alex Farber <eedalf@eed.ericsson.se>
Subject: Re: reg.expressions: replace a substring ???
Message-Id: <37A6B136.85025A83@eed.ericsson.se>
Hi Hubert,
Ming Hubert wrote:
> i have a outputstring (outstr1) on which i'd like to replace multiple
> substrings which all begin with the same characters, for example: "repl_me".
> the replacement should only be done till the next delimiter. the outstring
> has the delimiter ";".
if the delimiter is just one character (like ";")
s/repl_me.+?;/xxx;/g;
if the delimiter is a string (like "delim")
s/repl_me(?:(?!delim).)+delim/xxxdelim/g;
Enter "perldoc perlre" and search on non-greedy and look-ahead
Regards
Alex
------------------------------
Date: Tue, 03 Aug 1999 08:06:39 GMT
From: asher@localhost.localdomain (Asher)
Subject: Re: Use of uninitialized value ....
Message-Id: <slrn7qd7ik.vd.asher@localhost.localdomain>
On Mon, 02 Aug 1999 18:47:03 -0700, Laura Bello <lrb@aimnet.com> wrote:
[program generates warning]
>[Mon Aug 2 15:35:50 1999] memolist.cgi: Use of uninitialized value at
>./memolist.cgi line 146.
>
>I would get it twice, once each for two files I know don't have a date in
>the actual document.
[snip]
>#--------------------------------------------------------------------
># DATE_HTML - extract date from html files
>#--------------------------------------------------------------------
>sub date_html {
> my (@f) = @_;
> my ($date, $tmp);
> ($tmp) = grep { /<TD.*>.*, \d{4}/i } @f;
> if ( defined $tmp ) {
> ($tmp) = ($tmp =~ m#<TD.*>\s*(.*?, \d{4})#i); # Extract just the date
> ($date = $tmp) =~ s/<[^>]*>//gs; # Kill any other tags
> } else {
> $date = &mod_date("$memdir/$memo");
Where are $memdir and $memo defined?
------------------------------
Date: Tue, 03 Aug 1999 11:17:16 +0200
From: Alex Farber <eedalf@eed.ericsson.se>
Subject: Re: Why no Perl books at Fry's?
Message-Id: <37A6B39C.AFA24EA@eed.ericsson.se>
Abigail wrote:
> section is usually stuffed with popular and overrated things as HTML,
> O'Reilly's zoo, how to use Netscape, and Windows for dummies. Try to
Hey, I like O'Reilly's zoo!
> find a real important book, like "The Art of Computer Programming" or
> something from the grey wall. Often, they won't even have it. Hyped,
What's a grey wall?
Regards
Alex
--
Ich studiere Elektrotechnik (Technische Informatik) an der RWTH Aachen
und bin ein guter Perl-Programmierer (arbeite seit 4 Jahren als Intranet-
Entwickler). Kann auch C, Java, SQL, JavaScript und HTML, CGI und TCP/IP.
Ich suche eine gut bezahlte Diplomstelle in Koeln, Aachen oder Umgebung.
------------------------------
Date: Tue, 03 Aug 1999 07:12:09 GMT
From: "Scott Sanbeg" <ssanbeg@home.com>
Subject: Re: Working Telnet Script Needed
Message-Id: <dDwp3.25472$dP4.5362@news.rdc1.wa.home.com>
HC and Bill J. -- thanks for the script fragments... Appreciate it.
David, I had been using the search engines to try to find working code.
They returned a lot about CGI, HTTP and/or Java, but not much on telnet. I
guess being on the net for the past 10 years or so leads one to try that
approach first -- even though newsgroups were, at least originally, designed
to exchange information amongst group members rather than a forum for just
holy wars and the like. Anyway, as my signature suggested in the original,
I'm a UNIX guy. Now, in addition, I am trying to use the perl package from
Active State. Net::Ping doesn't seem to work very well. So, after fumbling
around for some hours using perl on this NT platform (a different SW
architecture than perl on UNIX), I decided to post what I did while asking
for pointers from the group. No harm done - no instructions needed.
Scott
David Cassell <cassell@mail.cor.epa.gov> wrote in message
news:37A62AE0.180B6469@mail.cor.epa.gov...
> Scott Sanbeg wrote:
> > -- snip --
>
> If you're looking for a script, rather than writing one yourself,
> then you may be in the wrong place. You will probably have much
> better luck searching the web using one of the major search
> engines like Lycos or Alta Vista. Just be sure to include all
> the keywords you want, so you don't get too many useless hits.
>
> HAND,
> David
------------------------------
Date: Tue, 03 Aug 1999 05:46:14 -0400
From: HC <carvdawg@patriot.net>
Subject: Re: Working Telnet Script Needed
Message-Id: <37A6BA66.DA220ABE@patriot.net>
Oh, ow! Must I suffer these slings and arrows?!?
Gee, I'm really sorry about using a MS product...but I got on the newsgroups
when I was trying to install Linux, asked a question, and was told to "search
the Internet". Funny thing was, I'd RTFM'd, read the FAQ, read the Linux
Documentation Site, and couldn't find the answer to my specific problem.
Now, in my endeavor to run Linux, I have developed my own plan...since no one
on the newsgroups could recommend anything different...searching the Internet
has yet to produce anything viable. I figured I would do consulting work in
order
to earn enough money to purchase a simple computer to run the beloved Linux.
Since most clients have some sort of MS os running, I had to go where the
money
is...and one day, one day soon, I'll be able to wrap my fingers around a Linux
boot
disk and begin the installation procedure. Until then, I will continue to
search the
Internet for the elusive answer to my question, just out of reach, always just
over
the digital horizon....
elephant wrote:
> HC writes ..
> >Wow, Dave! You don't have anything to contribute, so you hammer the guy!
>
> you have a strange definition of the term "hammer the guy" .. from where
> I sit David's response was polite and informative .. in fact - much more
> useful that your "any day now" response
>
> also .. you may want to consider leaving in the attributions .. makes
> your article THAT much easier to read .. and god knows what's happened to
> your line wrapping
>
> --
> jason - remove all hyphens for email reply -
------------------------------
Date: 1 Jul 99 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 1 Jul 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.
To submit articles to comp.lang.perl.misc (and this Digest), send your
article to perl-users@ruby.oce.orst.edu.
To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.
To request back copies (available for a week or so), send your request
to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
where x is the volume number and y is the issue number.
The Meta-FAQ, an article containing information about the FAQ, is
available by requesting "send perl-users meta-faq". The real FAQ, as it
appeared last in the newsgroup, can be retrieved with the request "send
perl-users FAQ". Due to their sizes, neither the Meta-FAQ nor the FAQ
are included in the digest.
The "mini-FAQ", which is an updated version of the Meta-FAQ, is
available by requesting "send perl-users mini-faq". It appears twice
weekly in the group, but is not distributed in the digest.
For other requests pertaining to the digest, send mail to
perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
sending perl questions to the -request address, I don't have time to
answer them even if I did know the answer.
------------------------------
End of Perl-Users Digest V9 Issue 346
*************************************