[19720] in Perl-Users-Digest
Perl-Users Digest, Issue: 1915 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Oct 11 21:05:31 2001
Date: Thu, 11 Oct 2001 18:05:08 -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: <1002848707-v10-i1915@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Thu, 11 Oct 2001 Volume: 10 Number: 1915
Today's topics:
Re: A more complete background <mjcarman@home.com>
Access a hash key by hash value ? <bootsy52@gmx.net>
Re: Access a hash key by hash value ? (Garry Williams)
Re: counting substrings in strings (F. Xavier Noria)
Re: DOS Filename > 8.3 <LindaTuner@hotmail.com>
Re: Filename case... (Martien Verbruggen)
Hashe keys and references? (Dimitri)
Re: Hashe keys and references? (Malcolm Dew-Jones)
Re: Keeping an escape code in a line <iltzu@sci.invalid>
Module help <jessica.bull@broadwing.com>
Re: please check my script (Kimo R.)
Re: sort of array containing strings doesn't work (Martien Verbruggen)
Strange behaviour or I/O error (Idiot Operator)? <aneely@softouch.on.ca>
Re: Uploading <aneely@softouch.on.ca>
Re: Uploading <pilsl_@goldfisch.at>
Re: zipping files? (Martien Verbruggen)
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Thu, 11 Oct 2001 17:01:17 -0500
From: Michael Carman <mjcarman@home.com>
Subject: Re: A more complete background
Message-Id: <3BC616AD.D6D56756@home.com>
RoJo wrote:
>
> I'm sorry I haven't been giving you incomplete information. [...]
> let me take a minute to give you the whole picture.
[snip]
Okay, that's a little more than I needed to know. :)
> I didn't know until recently that Perl could be run
> on a workstation !
Perl can be run damn near anywhere.
> I did not jump at the idea of installing a web server to run on
> my PC because I want these apps to work on any PC.
Ah, but if your program is written in Perl, then it will run anywhere
that Perl does[1]. The web server is just the thing that lets a browser
request your script and then passes the output back to it.
> Since the web server is just for development purposes, then
> I'm ready to go in that direction. Do you have any to recommend?
I'd check out Apache first, but a quick web search should turn up other
alternatives. There's even one built into Windows (which I don't like
because you can't shut it down).
> Honestly, I'm still concerned about developing on a local web
> server, and then porting it to Mindspring's.
Don't be. The server configuration may be different, but it's really
quite easy to write portable Perl. I would expect very few (if any)
problems.
> I'm beginning to wonder if Mindspring has a compete, successful
> installation of Perl on that server.
Probably. You seem to be tackling a number of areas at once (Perl, CGI,
Unix, etc.) It's easy to get overwhelmed in all that and start imagining
problems that aren't really there.
[1] Assuming that you haven't made OS calls or used any of the
(relatively few) platform-dependant features.
-mjc
------------------------------
Date: Fri, 12 Oct 2001 00:26:39 +0200
From: "Carsten Menke" <bootsy52@gmx.net>
Subject: Access a hash key by hash value ?
Message-Id: <pan.2001.10.12.00.26.38.464.3119@gmx.net>
Hi all,
I got the following problem:
################ BEGIN CODE #######################
open (FILE, ">>$path"."Summary\.log")
or die "Could not open LogFile for writing\n$!\n";
foreach (sort (values(%result)))
{
print FILE $_,"\n";
}
close(FILE);
############## END CODE #########################
Now I have the problem that I have to print the key of the hash at the
same time But the content has to be
sorted by the values of the hash, and I could not revert the hash to
to a temporary hash, because
1. The hash has a size of around 3MB, and I don't want to waste all the
memory
2. Some values of the hash are the same.
So how can I print out now the key of the hash accordingly to the value
of the hash in the foreach loop?
Anybody got an idea?
Carsten
------------------------------
Date: Thu, 11 Oct 2001 23:28:58 GMT
From: garry@ifr.zvolve.net (Garry Williams)
Subject: Re: Access a hash key by hash value ?
Message-Id: <slrn9scapp.gmc.garry@zfw.zvolve.net>
On Fri, 12 Oct 2001 00:26:39 +0200, Carsten Menke <bootsy52@gmx.net>
wrote:
> I got the following problem:
>
> ################ BEGIN CODE #######################
> open (FILE, ">>$path"."Summary\.log")
> or die "Could not open LogFile for writing\n$!\n";
> foreach (sort (values(%result)))
> {
> print FILE $_,"\n";
> }
> close(FILE);
> ############## END CODE #########################
>
> Now I have the problem that I have to print the key of the hash at the
> same time But the content has to be
> sorted by the values of the hash,
This is a FAQ.
See the perlfaq4 manual page, "How do I sort a hash (optionally by
value instead of key)?". I found that by entering the following
command:
perldoc -q "sort.*hash"
--
Garry Williams
------------------------------
Date: 11 Oct 2001 22:50:16 GMT
From: fxn@retemail.es (F. Xavier Noria)
Subject: Re: counting substrings in strings
Message-Id: <9q57n8$2bvr31@news2s.iddeo2.es>
On 11 Oct 2001 14:16:06 -0700, shaz <ssa1701@yahoo.co.uk> wrote:
: I want to count the number of times that a substring appears within a
: longer string.
You have sent this question several times and changing the things you
want the code to do over and over: once you said you wanted to know
whether a string was substring of some keys of a hash, then you wanted
to know moreover which of the keys contained the substring, later you
said that in fact you wanted to count how many times that held, and
later three hashes came to scene....
PLEASE, think what is exactly the problem you need to solve and try
then to explain it as concisely as you can, for otherwise we all are
wasting time.
: This is being used in the following code: -
:
: foreach $substring (keys %substrings)
: {
: $check = grep { index($_, $substring) != -1 } keys %longstrings;
:
: if ($check != 0)
: {
: print "$substring found in longer strings";
: }
: }
:
: The problem with the code is:-
:
: If $substring = "the" it should find "the end" and "end the" etc
: BUT at the moment it also finds "there is" and "then" amongst others.
: This is not correct.
Then you are not just looking for substrings, you are looking for
substrings that satisfy certain additional conditions. Please, try to
specify the problem a little bit harder. For instance, are all the
keys in %substrings whole words?
And, definitively, you need to read some Perl documentation.
-- fxn
------------------------------
Date: Thu, 11 Oct 2001 23:48:47 GMT
From: "Linda Turner" <LindaTuner@hotmail.com>
Subject: Re: DOS Filename > 8.3
Message-Id: <zdqx7.4380$YC3.1490429@typhoon.southeast.rr.com>
Yes, the c:\\ is missing the colon. But it's correct in the code.
The code is not recognizing strings in certain modules, and those
modules have the long file names. I hope this makes my question
clearer.
Thanks for your help.
"Bart Lateur" <bart.lateur@skynet.be> wrote in message
news:ol8bstkt95jlserrdpn79ahvabn69nid8b@4ax.com...
> Linda Turner wrote:
>
> >With a lot of help from this newsgroup, I have written a script to
> >sweep through a directory and updates some modules in place.
However,
> >it won't recognize Win NT files with names greater than the
> >traditional 8.3 format. Can someone tell me how I can get them to
> >recognize them?
>
> I don't understand. I use long file names on Win98 all the time,
without
> having to take spacial care if it.
>
> Are you sure you describe the problem properly? Because this start
> directory doen't look right:
>
> my $start_dir = 'C\\SCRIPTS';
>
> It contains no colon.
>
> If your problem is that you attempt to "drop" a directory on the
script
> (perhaps as a batch file), and all you see is the 8.3 compatible
file
> path, then you'll be glad to know that convertors between short and
long
> filepaths are built into Win32 perl: look up the docs for the Win32
> module, and in paricular, the function GetLongPathName:
>
> use Win32;
> my $start_dir = Win32::GetLongPathName(shift);
>
> --
> Bart.
------------------------------
Date: Fri, 12 Oct 2001 00:34:49 GMT
From: mgjv@tradingpost.com.au (Martien Verbruggen)
Subject: Re: Filename case...
Message-Id: <slrn9scel9.l88.mgjv@verbruggen.comdyn.com.au>
On Thu, 11 Oct 2001 16:30:11 GMT,
Steve Allan <stevea@wrq.com> wrote:
[Snip of previous quotes]
> A co-worker and I were coincidentally working on this same problem
> this week. I had initially used
>
> if ( /[A-Z]/ ) {
> rename $_, lc $_ or warn "Failed to rename $_: $!";
> }
>
> but thought it would be more efficient to use a string equality test
> instead of a regex:
>
> my $lcfile = lc $_;
> unless ( $_ eq $lcfile ) {
> rename $_, $lcfile or warn "Failed to rename $_: $!";
> }
>
> Do you think there's any significant difference between the two?
Yes, and no. It is unlikely that either of these two will run any
faster, simply because the rename is going to take much longer than
the comparisons. However, there are semantic differences between the
two versions. The regex may miss out on capitalisation in certain
locales. I believe Finnish has some letters that could fall outside of
the A-Z range. A more equivalent, and locale-safe version would be
if ( /[[:upper:]]/ ) { }
The perlre documentation has more information about the POSIX
character classes.
Martien
PS. According to perlre, [A-Z] is always a character class of 26
letters. Is this really true? Even if the collation of the characters
is someting like: A a B b C c D ..? perllocale is silent on this.
--
Martien Verbruggen |
Interactive Media Division | Unix is user friendly. It's just
Commercial Dynamics Pty. Ltd. | selective about its friends.
NSW, Australia |
------------------------------
Date: 11 Oct 2001 16:04:35 -0700
From: mauroid@csi.forth.gr (Dimitri)
Subject: Hashe keys and references?
Message-Id: <a3ebf7b8.0110111504.60a69967@posting.google.com>
Can the key of a hash table element be a reference? Would the
following work?
$key = [1, 2, 3]; ## reference to anonymous array (1, 2, 3)
$val = "bla";
$hash{$key} = $val;
It doesn't seem to work for me. It seems like the $key is stringified,
i.e. the above command behaves as if I had done this :
$hash{"$key"} = $val;
Which of course messes everything up (can't use $key any more to
dereference the original array).
Thanks for any help,
Dimitri
------------------------------
Date: 11 Oct 2001 16:43:03 -0800
From: yf110@vtn1.victoria.tc.ca (Malcolm Dew-Jones)
Subject: Re: Hashe keys and references?
Message-Id: <3bc62e87@news.victoria.tc.ca>
Dimitri (mauroid@csi.forth.gr) wrote:
: Can the key of a hash table element be a reference?
No, not as of 5.005 for sure, and I'm pretty sure not in any 5.6x either.
This is discussed in the pods, and probably the FAQ. A hash key is always
a string.
If you really need to do this, then perhaps you could do it indirectly.
$ref = [1, 2, 3]; ## reference to anonymous array (1, 2, 3)
$key = ''.$ref
$val = "bla";
$refs{$key} = $ref;
$hash{$key} = $val;
now given $key, you can get the ref from $refs{$key}
e.g.
# call function foo([ary]) for each saved ref
foreach $key (keys %hash)
{
foo( $refs{$key} );
}
(but I wonder if this is what you really want)
------------------------------
Date: 12 Oct 2001 00:11:22 GMT
From: Ilmari Karonen <iltzu@sci.invalid>
Subject: Re: Keeping an escape code in a line
Message-Id: <1002844864.9053@itz.pp.sci.fi>
In article <9e243fc1.0110110706.37f875b5@posting.google.com>, Greg Thorne wrote:
>Ilmari Karonen <iltzu@sci.invalid> wrote in message news:<1002751760.8699@itz.pp.sci.fi>...
>>
>> s/(\\*[\$\@\"])/length($1)%2 ? "\\$1" : $1/eg;
>> $_ = eval qq("$_");
>
>I had to stare at this a while, but I finally got it. The left-hand
>side is equivalent to:
>(\+[$@"])
Well, not exactly. /\+/ matches a literal plus sign. /\\*/ matches
zero or more backslashes. And if you don't backslash "$@", perl will
replace it with the value of the special variable $@.
Basically, what I'm doing is making sure that any dollar sign, at sign
or double quote has an _odd_ number of backslashes before it.
>After messing around with this statement some, I came up with:
>s/\\([nrt])/eval qq("\\$1")/eg;
This works just fine, though -- even if you were confused about the
backslashes above, you're using them correctly here.
--
Ilmari Karonen -- http://www.sci.fi/~iltzu/
"Get real! This is a discussion group, not a helpdesk. You post something,
we discuss its implications. If the discussion happens to answer a question
you've asked, that's incidental." -- nobull in comp.lang.perl.misc
------------------------------
Date: Thu, 11 Oct 2001 22:21:32 GMT
From: "Jessica Bull" <jessica.bull@broadwing.com>
Subject: Module help
Message-Id: <MXox7.702681$NK1.63994261@bin3.nnrp.aus1.giganews.com>
I am working with Spreadsheet::ParseExcel::Simple. I am using it to tell me
how many rows have data in them so I can write to the next row. I am
running into a problem with the module though. When I run my code (below) I
get this error: uninitialized value at line 106 (line 106 also below.) can
someone take a look? I am on the verge of Perl Brain Fry. :) Thanks!!
My Code:
use Spreadsheet::ParseExcel::Simple;
my $excelfile = "c:\\test.xls";
my ($sheet, @data);
my $xls = Spreadsheet::ParseExcel::Simple->read("$excelfile");
foreach $sheet ($xls->sheets){
while ($sheet->has_data) {
@data = $sheet->next_row;
}
}
print "@data\n";
The script is dying when it calls "has_data". Uninitialized value in
numeric le (<=)
Code:
sub has_data {$_[0]->{row} <= $_[0]->{sheet}->{MaxRow} }
------------------------------
Date: 11 Oct 2001 15:05:38 -0700
From: kimor79@hotmail.com (Kimo R.)
Subject: Re: please check my script
Message-Id: <e5a5752b.0110111405.75b44175@posting.google.com>
Thanks, I got the script working. I added crypt() and I added a
function to make sure the username doesn't contain illegal characters.
I haven't added system() yet. I have another question though (this is
probably the wrong group)...
I added an if statement to check HTTP_REFERER to make sure the script
is being called from the right form. I read somewhere that browsers
don't always send HTTP_REFERER. Am I correct in using it, or is there
another way to make sure the script is only used from the right form?
Kimo R.
------------------------------
Date: Fri, 12 Oct 2001 00:18:20 GMT
From: mgjv@tradingpost.com.au (Martien Verbruggen)
Subject: Re: sort of array containing strings doesn't work
Message-Id: <slrn9scdmd.l88.mgjv@verbruggen.comdyn.com.au>
On Wed, 10 Oct 2001 23:46:30 GMT,
Daniel Berger <djberg96@hotmail.com> wrote:
>
> "Abigail" <abigail@foad.org> wrote in message
> news:slrn9s91vd.soe.abigail@alexandra.xs4all.nl...
>> Ralph Jocham (rjocham72@netscape.net) wrote on MMCMLXI September MCMXCIII
>> in <URL:news:ee8febb5.0110091426.1b3fa8f5@posting.google.com>:
>> @@ Then I sort the array with : sort @uniq;
>> @@ But the result is not sorted. Is there a size limite. The array
> contains
>> @@ about 2000 lines??
>>
>> The only size limit is your system. You can't sort a huge array if
>> you don't have the RAM for it. But if Perl runs out of memory, it'll
>> tell you.
>
> On the other hand, Abigail, I've seen cases where values simply dropped off
> the stack in very large arrays (actually, I think it was a hash in my case)
> without any warning from Perl or the OS. It took about 10 times through the
> debugger before I would believe my own eyes, but in the end I had to accept
> what was happening. Fortunately, I was able to work around it.
Then that was a bug, and a rather serious one at that. Did you report
it? There should be no case, ever, where Perl just ignores the fact
that it can't allocate memory, and continues running with incorrect,
incomplete or corrupt data.
> This is rare, though I'm not the only one in my office that it's happened
> to, so I'm pretty sure I'm not going crazy. Well, maybe I am, but it would
> be for other reasons. :)
Do you, or your collegues, have a code and data sample that exhibits
this behaviour? If this is occurring, then the p5p should be made
aware of it, so they can fix it.
Martien
--
Martien Verbruggen |
Interactive Media Division | The four horsemen of the apocalypse
Commercial Dynamics Pty. Ltd. | are called Abort, Retry, Ignore and
NSW, Australia | Fail.
------------------------------
Date: Thu, 11 Oct 2001 18:10:47 -0700
From: Amer Neely <aneely@softouch.on.ca>
Subject: Strange behaviour or I/O error (Idiot Operator)?
Message-Id: <3BC64317.CA6CC047@softouch.on.ca>
Forgive me if this has already been covered - I've gone through the
relevant google postings and not found anything like this.
I have a log file consisting of data in the form:
2000-07-12|12:19:43|209.240.200.81|Mozilla/3.0 WebTV/1.2 (compatible;
MSIE 2.0)
2000-07-12|12:19:56|209.240.200.81|Mozilla/3.0 WebTV/1.2 (compatible;
MSIE 2.0)
2000-07-12|12:31:25|216.254.150.180|Mozilla/4.0 (compatible; MSIE 5.0;
Windows NT; DigExt)
2000-07-12|12:35:59|216.209.106.187|Mozilla/4.51 [en] (Win95; U)
2000-07-12|12:37:52|216.209.106.187|Mozilla/4.51 [en] (Win95; U)
That is: date|time|IP|agent
It consists of almost 6000 lines which I've thrown into a __DATA__ block
at the end of my script. I then throw this into @IN.
Walking through the array (@IN) and simply printing it out introduces
blank lines in the output at a few locations - always the same
locations.
Checked and fixed the input data for multiple newlines and bad data -
still produced blank lines.
chomped @IN: output on one line as expected.
chomped each line: output on one line as expected.
chomped each line then added \n back to each line upon printing: blank
lines show up again in the same locations.
Introducing 'sort' didn't change the behaviour - blank lines in the
*same* locations as unsorted output.
This really has me stumped. I can't go further (splitting out and
sorting by IP) until this issue with the blank lines is resolved. If
anyone has a light to shine on this I would certainly appreciate it.
Thanks in advance.
--
Amer Neely aneely@softouch.on.ca
Softouch Information Services: www.softouch.on.ca/
Perl / CGI programming for shopping carts, data entry forms.
"We make web sites work!"
------------------------------
Date: Thu, 11 Oct 2001 18:41:26 -0700
From: Amer Neely <aneely@softouch.on.ca>
Subject: Re: Uploading
Message-Id: <3BC64A46.1B31186C@softouch.on.ca>
peter pilsl wrote:
>
> M.A. Oxby wrote:
>
> > I want to add an extention to a web mailling script, but wish to allow for
> > once attachment. Can anyone point me in the right direction maybe of
> > another module to do this? I'm using <input type=file name="att">
> > (obviously!). Any Offers?
> > Thanks,
> >
>
> you may want to use the special file-upload-field which is documented in
> any html-reference.
> I recommend using the CGI-module (downloadable at www.cpan.org) and looking
> for 'upload' in the documentation.
>
> hope this helps,
> peter
>
> --
> peter pilsl
> pilsl_@goldfisch.at
> http://www.goldfisch.at
I would also suggest getting if possible the "Official Guide to
Programming with CGI.pm" by Lincoln Stein. It contains good examples of
code for uploading files. However, he does state that in some situations
it fails, so be aware if this happens and you start pulling your hair
out as I did :)
--
Amer Neely aneely@softouch.on.ca
Softouch Information Services: www.softouch.on.ca/
Perl / CGI programming for shopping carts, data entry forms.
"We make web sites work!"
------------------------------
Date: Fri, 12 Oct 2001 01:45:37 +0200
From: peter pilsl <pilsl_@goldfisch.at>
Subject: Re: Uploading
Message-Id: <3bc62f21$1@e-post.inode.at>
Amer Neely wrote:
>
> I would also suggest getting if possible the "Official Guide to
> Programming with CGI.pm" by Lincoln Stein. It contains good examples of
> code for uploading files. However, he does state that in some situations
> it fails, so be aware if this happens and you start pulling your hair
> out as I did :)
File-upload-fields are part of my daily bread (so you can imagine what
low-qualitiy-food I eat every day ;), but I never had any problems with em.
The code I use (mainly from cgi.pm) is fairly simple and robust.
What problems are you talking about ?
peter
--
peter pilsl
pilsl_@goldfisch.at
http://www.goldfisch.at
------------------------------
Date: Fri, 12 Oct 2001 00:44:47 GMT
From: mgjv@tradingpost.com.au (Martien Verbruggen)
Subject: Re: zipping files?
Message-Id: <slrn9scf7v.l88.mgjv@verbruggen.comdyn.com.au>
On Thu, 11 Oct 2001 16:23:55 +0200,
Jean-Philippe Fauvelle <JPFauvelle@Colt-Telecom.fr> wrote:
> Le Thu, 11 Oct 2001 14:12:08 GMT, Bart Lateur <bart.lateur@skynet.be> écrit:
>
>>Nope. Compress::Zlib makes .gz files. He asked for (Windows style)
>>.zip files, so Archive::Zip is the better answer.
>
> As far as i know, winzip supports (reading) the unix zip format
> (possibly tar'ed). Because i dont't know the module Archive::Zip, i
> can't affirm which solution is better.
Let's return to the original question:
>I am on a Win NT system. I have a directory with various files. I
>would like to pull files with a certain extention and put them into a
^^^^^ ^^^^ ^
>new zip file with a specific name. Does anyone know if and how this
^^^^^^^^
>could be done?
I have underlined some of the operative words in that question. There
is talk about putting multiple files into a single zip file. Since
Compress::Zlib does not create archives, it will not allow you to do
this. It only operates on single files (or data streams or memory
blobs).
> There's More Than One Way To Do It
Yes, there is. One could use Archive::Tar and Compress::Zlib. But it
is probably much simpler to just use Archive::Zip, especially since
that is much closer to what was actually asked for.
Martien
--
Martien Verbruggen |
Interactive Media Division | Think of the average person. Half of
Commercial Dynamics Pty. Ltd. | the people out there are dumber.
NSW, Australia |
------------------------------
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 1915
***************************************