[25188] in Perl-Users-Digest
Perl-Users Digest, Issue: 7437 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Nov 22 18:05:47 2004
Date: Mon, 22 Nov 2004 15:05:08 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Mon, 22 Nov 2004 Volume: 10 Number: 7437
Today's topics:
Re: a length of variable question <jwillmore@fastmail.us>
Re: a length of variable question <mritty@gmail.com>
Re: a length of variable question <tadmc@augustmail.com>
Re: a length of variable question <tassilo.von.parseval@rwth-aachen.de>
Re: a length of variable question <tony_curtis32@yahoo.com>
Re: Bits of a number... why is this true? <tzz@lifelogs.com>
Can I run Perl on Palm Pilot? <tihana@verso.co.izbaciovo>
Re: Can I run Perl on Palm Pilot? <eon@hotmail.com>
Re: Can I run Perl on Palm Pilot? ioneabu@yahoo.com
Re: Command-line HTML Post-method (medline in lynx) <tadmc@augustmail.com>
Re: Command-line HTML Post-method (medline in lynx) <spam@nimblegen.com>
Re: cookies vs. hidden fields <toreau@gmail.com>
Re: Copying a folder (Jim)
FAQ 5.36: How do I select a random line from a file? <comdog@panix.com>
FAQ 6.21: What's wrong with using grep in a void contex <comdog@panix.com>
Re: finding the number of keys in hash <mritty@gmail.com>
Get list of files. (Binny V A)
Re: Get list of files. <1usa@llenroc.ude.invalid>
Re: Get list of files. <mritty@gmail.com>
Re: Get list of files. <gnari@simnet.is>
Re: Get list of files. <jurgenex@hotmail.com>
Re: Get list of files. <eon@hotmail.com>
Re: Get list of files. <mritty@gmail.com>
Re: how *.cgi file can get the parameters from client? (David Efflandt)
Re: how to use default_headers? (Tim Jowers)
Re: Ignore spaces in string match <thelma@alpha2.csd.uwm.edu>
Re: Ignore spaces in string match <bigj@kamelfreund.de>
Re: Managing PERL5LIB with multiple perl installation <FILTERjvsSPAM@india.ti.com>
Re: Managing PERL5LIB with multiple perl installation <FILTERjvsSPAM@india.ti.com>
Re: Perl on the Pocket PC - Easy! <mritty@gmail.com>
Re: Perl on the Pocket PC - Easy! ioneabu@yahoo.com
Re: Search.cgi followup <tadmc@augustmail.com>
Re: Searching backward <tadmc@augustmail.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Mon, 22 Nov 2004 11:03:32 -0500
From: James Willmore <jwillmore@fastmail.us>
Subject: Re: a length of variable question
Message-Id: <pan.2004.11.22.16.03.30.688168@fastmail.us>
On Sun, 21 Nov 2004 21:05:20 -0600, Tony Curtis wrote:
>>> On 21 Nov 2004 18:59:30 -0800,
>>> eight02645999@yahoo.com (justme) said:
>
>> hi in my script i will process from a database and assign a
>> value to a variable $var1 The value assigned to $var1 is a
>> number. eg 1, 2 or 3. But it is in "string" format. There
>> will be spaces in front as well as behind it.
>
> would just casting it into an int work?
>
> $m = ' 4 ';
> $n = int $m;
> print "$n\n";
>
> 4
It would ... if Perl were another language :-)
scalars (very simply those variables represented with a '$' in front of
the variable name) are type independent in Perl. Other languages (like
C++ and Java) *required* you to associate a variable with a type - Perl
doesn't.
`perldoc -q scalar` might help, as well as `perldoc perldata`
HTH
Jim
------------------------------
Date: Mon, 22 Nov 2004 16:37:37 GMT
From: "Paul Lalli" <mritty@gmail.com>
Subject: Re: a length of variable question
Message-Id: <lBood.8508$sX5.326@trndny05>
"James Willmore" <jwillmore@fastmail.us> wrote in message
news:pan.2004.11.22.16.03.30.688168@fastmail.us...
> On Sun, 21 Nov 2004 21:05:20 -0600, Tony Curtis wrote:
>
> >>> On 21 Nov 2004 18:59:30 -0800,
> >>> eight02645999@yahoo.com (justme) said:
> >
> >> hi in my script i will process from a database and assign a
> >> value to a variable $var1 The value assigned to $var1 is a
> >> number. eg 1, 2 or 3. But it is in "string" format. There
> >> will be spaces in front as well as behind it.
> >
> > would just casting it into an int work?
> >
> > $m = ' 4 ';
> > $n = int $m;
> > print "$n\n";
> >
> > 4
>
> It would ... if Perl were another language :-)
This language will do just fine.
> scalars (very simply those variables represented with a '$' in front
of
> the variable name) are type independent in Perl. Other languages
(like
> C++ and Java) *required* you to associate a variable with a type -
Perl
> doesn't.
All of which is wholly irrelevant to the discussion at hand.
Perl doesn't have strict 'types', that's true. But it does have
contexts. Specifically, it has both a string and an numeric context.
When a variable containing a string is used in a numeric context - such
as that provided by the int() function - perl scans the variable
character by character to determine what number the string represents.
Leading whitespace is ignored in this scan.
> `perldoc -q scalar` might help, as well as `perldoc perldata`
perldoc -f int might help you, as would simply running the example
program above.
Hope that clarifies,
Paul Lalli
------------------------------
Date: Mon, 22 Nov 2004 10:46:11 -0600
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: a length of variable question
Message-Id: <slrncq45uj.sd6.tadmc@magna.augustmail.com>
James Willmore <jwillmore@fastmail.us> wrote:
> On Sun, 21 Nov 2004 21:05:20 -0600, Tony Curtis wrote:
>>>> On 21 Nov 2004 18:59:30 -0800,
>>>> eight02645999@yahoo.com (justme) said:
>>
>>> There
>>> will be spaces in front as well as behind it.
>>
>> would just casting it into an int work?
>>
>> $m = ' 4 ';
>> $n = int $m;
>> print "$n\n";
>>
>> 4
>
> It would ...
It does!
> if Perl were another language :-)
Tony's code looked just like Perl to me. :-)
> scalars (very simply those variables represented with a '$' in front of
> the variable name) are type independent in Perl.
Right, but what was wanted by the OP was to remove leading and trailing
whitespace, and Tony's code does just that (but it is not "casting"
at all).
It works because of the rules Perl uses when converting a
string into a number:
1) ignore leading whitespace
2) ignore anything after the 1st char that cannot be part of a number.
Rule 1 removes the leading, Rule 2 removes the trailing.
Of course, the $n temporary variable is not needed:
$m = int $m;
or
$m = 0 + $m;
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Mon, 22 Nov 2004 18:03:31 +0100
From: "Tassilo v. Parseval" <tassilo.von.parseval@rwth-aachen.de>
Subject: Re: a length of variable question
Message-Id: <slrncq46v3.s0.tassilo.von.parseval@localhost.localdomain>
Also sprach Tad McClellan:
> It works because of the rules Perl uses when converting a
> string into a number:
>
> 1) ignore leading whitespace
>
> 2) ignore anything after the 1st char that cannot be part of a number.
>
> Rule 1 removes the leading, Rule 2 removes the trailing.
>
> Of course, the $n temporary variable is not needed:
>
> $m = int $m;
> or
> $m = 0 + $m;
And yet, I'd drop the first of the anove two alternatives. int() is
really used for dropping the decimal part of a floating point number.
It's not its primary purpose to convert a string to a number as it will
only convert it to an integer. This starts to matter when $m is
something like
$m = ' 1.5 ';
Tassilo
--
$_=q#",}])!JAPH!qq(tsuJ[{@"tnirp}3..0}_$;//::niam/s~=)]3[))_$-3(rellac(=_$({
pam{rekcahbus})(rekcah{lrePbus})(lreP{rehtonabus})!JAPH!qq(rehtona{tsuJbus#;
$_=reverse,s+(?<=sub).+q#q!'"qq.\t$&."'!#+sexisexiixesixeseg;y~\n~~dddd;eval
------------------------------
Date: Mon, 22 Nov 2004 11:03:58 -0600
From: Tony Curtis <tony_curtis32@yahoo.com>
Subject: Re: a length of variable question
Message-Id: <87ekilg6ip.fsf@limey.hpcc.uh.edu>
>> On Mon, 22 Nov 2004 10:46:11 -0600,
>> Tad McClellan <tadmc@augustmail.com> said:
> Right, but what was wanted by the OP was to remove leading
> and trailing whitespace, and Tony's code does just that (but
> it is not "casting" at all).
Yeah, years of C wrecks yer brain :-)
> Of course, the $n temporary variable is not needed:
> $m = int $m; or $m = 0 + $m;
I usually include more intermediate variables in examples than
I might ordinarily use in "real" code.
t
------------------------------
Date: Mon, 22 Nov 2004 11:59:15 -0500
From: Ted Zlatanov <tzz@lifelogs.com>
Subject: Re: Bits of a number... why is this true?
Message-Id: <4nact9bz18.fsf@lifelogs.com>
On Fri, 19 Nov 2004, sean.berry2@cox.net wrote:
> I have 35 items, each of which I assign a number... like
> 1, 2, 4, 8, 16, 32, .... ,17179869184
>
> 2**0 = 1
> 2**34 = 17179869184
>
> So there are 35 numbers. After all options are decided the
> numbers are added up and saved to a database.
>
> I now want to retrieve the number and see what bits are on.
You may want to consider an inversion list. It has many advantages
over bit vectors, especially if you expect few options to be turned on
in your bit vector. Check this article out:
http://www-106.ibm.com/developerworks/linux/library/l-cpinv.html
Good luck
Ted
------------------------------
Date: Mon, 22 Nov 2004 21:33:52 +0100
From: "Tihana" <tihana@verso.co.izbaciovo>
Subject: Can I run Perl on Palm Pilot?
Message-Id: <41a24d23@news.s5.net>
Can I run Perl on Palm Pilot?
------------------------------
Date: Mon, 22 Nov 2004 22:01:50 GMT
From: "Leon" <eon@hotmail.com>
Subject: Re: Can I run Perl on Palm Pilot?
Message-Id: <iltod.339$Sq.249@newsfe5-win.ntli.net>
"Tihana" <tihana@verso.co.izbaciovo> wrote in message
news:41a24d23@news.s5.net...
> Can I run Perl on Palm Pilot?
>
>
Was wondering this myself, this link might help...
http://www.cpan.org/authors/id/JWIEGLEY/
------------------------------
Date: 22 Nov 2004 14:24:17 -0800
From: ioneabu@yahoo.com
Subject: Re: Can I run Perl on Palm Pilot?
Message-Id: <1101162257.601420.274600@c13g2000cwb.googlegroups.com>
Tihana wrote:
> Can I run Perl on Palm Pilot?
I don't know what's available in Perl for Palm Pilot, last time I
programmed it using superwaba, a Java dialect. I remember that the
problem was that there is no traditional file system. Data is stored
in a set of 64k records, or something like that. I moved to win ce
because it has the usual hierarchical file system. Perl works great
there.
wana
------------------------------
Date: Mon, 22 Nov 2004 00:09:24 -0600
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: Command-line HTML Post-method (medline in lynx)
Message-Id: <slrncq30kk.qc3.tadmc@magna.augustmail.com>
[ newsgroups trimmed ]
vjp2.at@at.BioStrategist.dot.dot.com <vjp2.at@at.BioStrategist.dot.dot.com> wrote:
>
>
> I found the groups I posted to by searching groups.google.com for html
> and "post method".
How was your question related to the Perl programming language?
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Mon, 22 Nov 2004 08:38:33 -0600
From: Chuck Dillon <spam@nimblegen.com>
Subject: Re: Command-line HTML Post-method (medline in lynx)
Message-Id: <cnstkl$hes$1@grandcanyon.binc.net>
vjp2.at@at.BioStrategist.dot.dot.com wrote:
> I found the groups I posted to by searching groups.google.com for html
> and "post method". The replies obtained were positively unAmerican.
The quality of response reflects the quality of your post.
Have you studied the doc and examples that NCBI provides at
http://eutils.ncbi.nlm.nih.gov/entrez/query/static/eutils_help.html?
I suggest you consider using one of the "API" that NCBI offers for
Entrez rather than coding the query syntax yourself. Or you might want
to see if there bioperl (http://www.bioperl.org) folks have something
that you can use without reinventing the wheel.
-- ced
>
>
>
> - = -
> Vasos-Peter John Panagiotopoulos II, Columbia'81+, Bio$trategist
> BachMozart ReaganQuayle EvrytanoKastorian
> http://ourworld.compuserve.com/homepages/vjp2/vasos.htm
> ---{Nothing herein constitutes advice. Everything fully disclaimed.}---
> [Homeland Security means private firearms not lazy obstructive guards]
> [Health Reform means abolishing FDR's insurance tax exemption]
> [To stop SPAM, Charge net-postage] [Abolish 16th (Inc Tx) Amendment]
--
Chuck Dillon
Senior Software Engineer
NimbleGen Systems Inc.
------------------------------
Date: Mon, 22 Nov 2004 13:28:12 +0100
From: Tore Aursand <toreau@gmail.com>
Subject: Re: cookies vs. hidden fields
Message-Id: <pan.2004.11.22.12.28.12.309780@gmail.com>
On Mon, 22 Nov 2004 07:21:59 +0000, John Bokma wrote:
>> One other thing: There's no harm in practising some "security by
>> obscurity" in this case. :) Use a hidden file which points to a
>> temporary file where the _real_ values are stored, ie.:
>>
>> <input type="hidden" name="tmp" value="blahfoobar.tmp">
>>
>> Never (!) use a path in that name, of course.
> And you get all problems most CGI scripts can't get right, like file
> locking and temp file creation..
"Most CGI scripts" won't suffer from this; only one instance reads from,
and writes to, the same temporary file at the same time. In addition, the
programmer don't reinvent the wheel; he/she will use a CPAN module for
this task.
--
Tore Aursand <toreau@gmail.com>
"War is too serious a matter to entrust to military men." (Georges
Clemenceau)
------------------------------
Date: 22 Nov 2004 06:18:04 -0800
From: garvey_jim@yahoo.com (Jim)
Subject: Re: Copying a folder
Message-Id: <3327e074.0411220618.6ad53ccb@posting.google.com>
Thanks again for all the help.
I am trying wget in a cmd.exe shell, sorry.
I'm getting a permisson denied error when I try mirror.
------------------------------
Date: Mon, 22 Nov 2004 17:03:27 +0000 (UTC)
From: PerlFAQ Server <comdog@panix.com>
Subject: FAQ 5.36: How do I select a random line from a file?
Message-Id: <cnt64u$s1h$1@reader1.panix.com>
This message is one of several periodic postings to comp.lang.perl.misc
intended to make it easier for perl programmers to find answers to
common questions. The core of this message represents an excerpt
from the documentation provided with Perl.
--------------------------------------------------------------------
5.36: How do I select a random line from a file?
Here's an algorithm from the Camel Book:
srand;
rand($.) < 1 && ($line = $_) while <>;
This has a significant advantage in space over reading the whole file
in. You can find a proof of this method in *The Art of Computer
Programming*, Volume 2, Section 3.4.2, by Donald E. Knuth.
You can use the File::Random module which provides a function for that
algorithm:
use File::Random qw/random_line/;
my $line = random_line($filename);
Another way is to use the Tie::File module, which treats the entire file
as an array. Simply access a random array element.
--------------------------------------------------------------------
Documents such as this have been called "Answers to Frequently
Asked Questions" or FAQ for short. They represent an important
part of the Usenet tradition. They serve to reduce the volume of
redundant traffic on a news group by providing quality answers to
questions that keep coming up.
If you are some how irritated by seeing these postings you are free
to ignore them or add the sender to your killfile. If you find
errors or other problems with these postings please send corrections
or comments to the posting email address or to the maintainers as
directed in the perlfaq manual page.
Note that the FAQ text posted by this server may have been modified
from that distributed in the stable Perl release. It may have been
edited to reflect the additions, changes and corrections provided
by respondents, reviewers, and critics to previous postings of
these FAQ. Complete text of these FAQ are available on request.
The perlfaq manual page contains the following copyright notice.
AUTHOR AND COPYRIGHT
Copyright (c) 1997-2002 Tom Christiansen and Nathan
Torkington, and other contributors as noted. All rights
reserved.
This posting is provided in the hope that it will be useful but
does not represent a commitment or contract of any kind on the part
of the contributers, authors or their agents.
------------------------------
Date: Mon, 22 Nov 2004 23:03:01 +0000 (UTC)
From: PerlFAQ Server <comdog@panix.com>
Subject: FAQ 6.21: What's wrong with using grep in a void context?
Message-Id: <cntr75$77s$1@reader1.panix.com>
This message is one of several periodic postings to comp.lang.perl.misc
intended to make it easier for perl programmers to find answers to
common questions. The core of this message represents an excerpt
from the documentation provided with Perl.
--------------------------------------------------------------------
6.21: What's wrong with using grep in a void context?
The problem is that grep builds a return list, regardless of the
context. This means you're making Perl go to the trouble of building a
list that you then just throw away. If the list is large, you waste both
time and space. If your intent is to iterate over the list, then use a
for loop for this purpose.
In perls older than 5.8.1, map suffers from this problem as well. But
since 5.8.1, this has been fixed, and map is context aware - in void
context, no lists are constructed.
--------------------------------------------------------------------
Documents such as this have been called "Answers to Frequently
Asked Questions" or FAQ for short. They represent an important
part of the Usenet tradition. They serve to reduce the volume of
redundant traffic on a news group by providing quality answers to
questions that keep coming up.
If you are some how irritated by seeing these postings you are free
to ignore them or add the sender to your killfile. If you find
errors or other problems with these postings please send corrections
or comments to the posting email address or to the maintainers as
directed in the perlfaq manual page.
Note that the FAQ text posted by this server may have been modified
from that distributed in the stable Perl release. It may have been
edited to reflect the additions, changes and corrections provided
by respondents, reviewers, and critics to previous postings of
these FAQ. Complete text of these FAQ are available on request.
The perlfaq manual page contains the following copyright notice.
AUTHOR AND COPYRIGHT
Copyright (c) 1997-2002 Tom Christiansen and Nathan
Torkington, and other contributors as noted. All rights
reserved.
This posting is provided in the hope that it will be useful but
does not represent a commitment or contract of any kind on the part
of the contributers, authors or their agents.
------------------------------
Date: Mon, 22 Nov 2004 14:37:43 GMT
From: "Paul Lalli" <mritty@gmail.com>
Subject: Re: finding the number of keys in hash
Message-Id: <XQmod.5228$hJ6.1214@trndny01>
"Jürgen Exner" <jurgenex@hotmail.com> wrote in message
news:nEVnd.517$Rs2.132@trnddc03...
> Kjetil Skotheim wrote:
> > print "The number of keys is: ".(0+keys%$A)."\n";
> >
> > The secret is forcing scalar context upon keys%$A,
>
> True, but you got a little bit confused.
> - You add 0 if you want to ensure numerical treatment of your values
> - You use scalar() to enforce scalar context (big surprise there)
Slight clarification - scalar() is used when the expression would
produce a list context without it. In the above example, the .
operators force scalar context as they are.
print "The number of keys is: " . (keys %$A) . "\n";
Of course, nothing will be harmed by adding scalar() to this example,
but it is redundant.
------------------------------
Date: 22 Nov 2004 11:13:30 -0800
From: binnyva@hotmail.com (Binny V A)
Subject: Get list of files.
Message-Id: <68cd8f94.0411221113.3c0b0f9d@posting.google.com>
Hello Everyone,
I want to get a list of all HTML files in a folder. How do I do this?
I tried
$list = <*.htm>;
but it gave only one html file. The same result with glob("*.htm")
I am currently doing this with
$list = `dir *.htm`;
and then spliting it. But that is not portable.
Other questions - How do I get the names of folders?
How do I relusivly list all files in a folder and within folders in that folder?
Thanking You,
Binny V A
http://www.geocities.com/binnyva
Perl Special http://www.geocities.com/binnyva/code/perl
------------------------------
Date: 22 Nov 2004 19:26:29 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: Get list of files.
Message-Id: <Xns95A992E838895asu1cornelledu@132.236.56.8>
binnyva@hotmail.com (Binny V A) wrote in
news:68cd8f94.0411221113.3c0b0f9d@posting.google.com:
> Hello Everyone,
>
> I want to get a list of all HTML files in a folder. How do I do this?
>
> I tried
> $list = <*.htm>;
> but it gave only one html file. The same result with glob("*.htm")
>
> I am currently doing this with
> $list = `dir *.htm`;
> and then spliting it. But that is not portable.
>
> Other questions - How do I get the names of folders?
> How do I relusivly list all files in a folder and within folders in
> that folder?
perldoc -f opendir
perldoc -f readdir
perldoc -f closedir
or
use File::Find::Rule;
Sinan
------------------------------
Date: Mon, 22 Nov 2004 19:48:04 GMT
From: "Paul Lalli" <mritty@gmail.com>
Subject: Re: Get list of files.
Message-Id: <Unrod.28$zm4.18@trndny02>
"Binny V A" <binnyva@hotmail.com> wrote in message
news:68cd8f94.0411221113.3c0b0f9d@posting.google.com...
> I want to get a list of all HTML files in a folder. How do I do this?
>
> I tried
> $list = <*.htm>;
> but it gave only one html file. The same result with glob("*.htm")
You should always read the documentation for the function you're using:
perldoc -f glob
glob EXPR
glob In list context, returns a (possibly empty) list of
filename expansions on the value of EXPR such as the
standard Unix shell /bin/csh would do. In scalar
context, glob iterates through such filename
expansions, returning undef when the list is
exhausted.
You're using a scalar context, and not attempting to iterate. You need
to do one or the other to get the full list.
> Other questions - How do I get the names of folders?
Open a directory, read the directory one entry at a time, and test each
entry to determine whether or not it is a directory or a file:
perldoc -f opendir
perldoc -f readdir
perldoc -f -X
> How do I relusivly list all files in a folder and within folders in
that folder?
Assuming you mean "recursively", use the standard File::Find module, or
the available-on-CPAN File::Find::Rule module.
Paul Lalli
------------------------------
Date: Mon, 22 Nov 2004 19:49:38 -0000
From: "gnari" <gnari@simnet.is>
Subject: Re: Get list of files.
Message-Id: <cntfnl$c0g$1@news.simnet.is>
"Binny V A" <binnyva@hotmail.com> wrote in message
news:68cd8f94.0411221113.3c0b0f9d@posting.google.com...
> $list = <*.htm>;
> but it gave only one html file. The same result with glob("*.htm")
actually, <*.htm> does return a list of files, but you are assigning it to
a scalar, as if you had done : $x=('a','b','c');
try @list instead
gnari
------------------------------
Date: Mon, 22 Nov 2004 20:14:19 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: Get list of files.
Message-Id: <vMrod.6835$1B2.3754@trnddc02>
Binny V A wrote:
> I want to get a list of all HTML files in a folder. How do I do this?
>
> I tried
> $list = <*.htm>;
> but it gave only one html file. The same result with glob("*.htm")
1: You are asking for only one file. If you want a list of all files, then
ask for a list:
@list = <*.htm>;
2: Your verbal specification conflicts with your code. You said you want
HTML files, but in your code you are globbing htm files.
@list = <*.HTML>;
> Other questions - How do I get the names of folders?
See "perldoc -f -X" and check in particular the -d operator.
> How do I relusivly list all files in a folder and within folders in
> that folder?
I guess you meant 'recursively'? See "perldoc File::Find".
jue
------------------------------
Date: Mon, 22 Nov 2004 20:16:10 GMT
From: "Leon" <eon@hotmail.com>
Subject: Re: Get list of files.
Message-Id: <eOrod.255$Sq.180@newsfe5-win.ntli.net>
"Binny V A" <binnyva@hotmail.com> wrote in message
news:68cd8f94.0411221113.3c0b0f9d@posting.google.com...
> Hello Everyone,
>
> I want to get a list of all HTML files in a folder. How do I do this?
>
> I tried
> $list = <*.htm>;
> but it gave only one html file. The same result with glob("*.htm")
Try @list = glob("*.htm");
# Just to note that this is for *.htm files, it does not include *.html.
>
> I am currently doing this with
> $list = `dir *.htm`;
> and then spliting it. But that is not portable.
>
> Other questions - How do I get the names of folders?
Check opendir, readdir, closedir command.
> How do I relusivly list all files in a folder and within folders in that
folder?
Not sure on this one, sure someone will point you in the right direction:)
>
> Thanking You,
> Binny V A
> http://www.geocities.com/binnyva
> Perl Special http://www.geocities.com/binnyva/code/perl
------------------------------
Date: Mon, 22 Nov 2004 21:00:09 GMT
From: "Paul Lalli" <mritty@gmail.com>
Subject: Re: Get list of files.
Message-Id: <trsod.3952$356.3074@trndny04>
"gnari" <gnari@simnet.is> wrote in message
news:cntfnl$c0g$1@news.simnet.is...
> "Binny V A" <binnyva@hotmail.com> wrote in message
> news:68cd8f94.0411221113.3c0b0f9d@posting.google.com...
>
> > $list = <*.htm>;
> > but it gave only one html file. The same result with glob("*.htm")
>
> actually, <*.htm> does return a list of files, but you are assigning
it to
> a scalar, as if you had done : $x=('a','b','c');
Well, not quite the same since the OP's code will assign $list to the
*first* element otherwise returned by the glob, whereas this code will
assing $x to the last element of the 'list'....
Paul Lalli
------------------------------
Date: Mon, 22 Nov 2004 22:12:00 +0000 (UTC)
From: efflandt@xnet.com (David Efflandt)
Subject: Re: how *.cgi file can get the parameters from client?
Message-Id: <slrncq4p1f.jfm.efflandt@typhoon.xnet.com>
On Sat, 20 Nov 2004 19:08:57 +0800, Alont <end@dream.life> wrote:
> how I can get the parameter from client through in Perl script?
> I can't find it in CGI:: module,
"perldoc CGI" (or web search for CGI.pm) explains how it works and has an
example that generates a form and gets several types of parameters. It
also shows how to get a complete list of parameters.
If you gave a small example of form and script you are attempting, someone
might steer you in the right direction. But that would be best posted in
a cgi newsgroup.
------------------------------
Date: 22 Nov 2004 11:12:52 -0800
From: timjowers@yahoo.com (Tim Jowers)
Subject: Re: how to use default_headers?
Message-Id: <b1b4167f.0411221112.25e90e69@posting.google.com>
Bob Walton <see@sig.invalid> wrote in message news:<419ff052$1_3@127.0.0.1>...
> Tim Jowers wrote:
>
> > Advice? I get this error message:
> >
> > C:\houses\scraper>perl test2.pl
> > Can't locate object method "default_headers" via package
> > "LWP::UserAgent" at tes
> > t2.pl line 11.
>
> What makes you think "default_headers" is an object method? The docs
> say it is a hash key of an optional hash which may be provided as an
> argument to LWP::UserAgent->new() in order to modify its behavior. So
> an appropriate usage might be something like [untested]:
>
> my $ua=LWP::UserAgent->new({default_headers=>...});
>
> >
> > But downloaded the latest libwww-perl-5.801 and copied the files from
> > /bin and /lib into my Perl install. Why does not this work?
>
> Maybe you missed something the install does? Why didn't you just do a
> proper install?
>
> ...
> > TimJowers
Thanks for responding. It was apparently a port problem as it worked
fine in U**x but I was running under ActiveState ActivePerl in
Windows. Haven't done any Perl since 1994 so I've switched out most
anything I knew 'bout it. Of course I did a fresh install et cetera -
the "object method" is the error message received from perl, not my
concoction. Got another cut that sets the header elsewhere rather than
using default_headers and it worked like a charm.
Best luck, TimJowers
------------------------------
Date: 22 Nov 2004 14:29:26 GMT
From: Thelma Lubkin <thelma@alpha2.csd.uwm.edu>
Subject: Re: Ignore spaces in string match
Message-Id: <cnst46$7mj$1@uwm.edu>
Tad McClellan <tadmc@augustmail.com> wrote:
:> if($hh2 =~ /^$h1$/x) ...
: Do you intend for $h1 to contain regex metacharacters that *are* meta?
: If not, then what you have there is an equality test disguised as a
: pattern match and implemented in an "expensive" way.
It was the preceding sentence that really showed me
how hopeless and useless--and silly--my approach was.
I will do the tr and then the eq comparision.
Thanks to everyone who helped me with this.
--thelma
: if ( $hh2 eq $hh1 ) # more clear AND faster!
: --
: Tad McClellan SGML consulting
: tadmc@augustmail.com Perl programming
: Fort Worth, Texas
------------------------------
Date: Mon, 22 Nov 2004 18:52:35 +0100
From: Janek Schleicher <bigj@kamelfreund.de>
Subject: Re: Ignore spaces in string match
Message-Id: <pan.2004.11.22.17.52.18.429094@kamelfreund.de>
On Sat, 20 Nov 2004 14:50:39 +0000, Thelma Lubkin wrote:
> I am trying to compare two strings that must match except for their
> spacing.
>
> If I write:
>
> $h1 = 'here i am';
> $h2 = 'herei am';
>
> can I do a less clumsy comparison than
>
> ($hh2 = $h2) =~ s/\s//x;
> if($hh2 =~ /^$h1$/x) ...
You could also use the CPAN module String::Compare, e.g.:
use String::Compare;
my $h1 = 'here i am';
my $h2 = 'herei am';
if (String::Compare::chars_only($h1,$h2) eq 1) {
print "...";
}
Greetings,
Janek
------------------------------
Date: 22 Nov 2004 14:25:29 GMT
From: Jahagirdar Vijayvithal S <FILTERjvsSPAM@india.ti.com>
Subject: Re: Managing PERL5LIB with multiple perl installation
Message-Id: <cnsssp$rrt$1@home.itg.ti.com>
* Ben Morrow <usenet@morrow.me.uk>:
>
> Quoth $HOME:
>> The default global installation of perl here is 5.005_03
>>
>> I have installed v5.8.4 locally as a higher version was needed for some
>> of the modules i am using.
>>
>> Now I need to constantly switch the value of PERL5LIB enviornment
>> variable depending on wether I am using my local scripts or scripts
>> developed by others . Is there a way to automate this without changing
>> my perl scripts?
>
> Write a module which checks $] and sets @INC to the approriate thing[1],
> and put e.g. -MLocal::MyINC in PERL5OPT.
This seems to fail when I do something like
perl -d:ptkdb <script>
My guess would be that the above command tries to first load ptkdb
followed by MyINC.
>
> [1] use lib rather than explicitly setting @INC, as it deals with
> finding the right arch-specific directory as well.
>
> Ben
>
------------------------------
Date: 22 Nov 2004 14:27:42 GMT
From: Jahagirdar Vijayvithal S <FILTERjvsSPAM@india.ti.com>
Subject: Re: Managing PERL5LIB with multiple perl installation
Message-Id: <cnst0u$rrt$2@home.itg.ti.com>
* Big and Blue <No_4@dsl.pipex.com>:
<SNIP>
> Write an interlude (for *both* perls if necessary) which sets the
> relevant PERL5LIB for each before exec'ing the real perl executable (or
> write modules and prepend a -M.... arg before those passed on before
> exec'ing). Then use those interludes to free yourself from environmental
> pollution.
I am not sure what an interlude is. can you please elaborate on it?
Regards
Jahagirdar Vijayvithal S
>
>
>
------------------------------
Date: Mon, 22 Nov 2004 21:41:13 GMT
From: "Paul Lalli" <mritty@gmail.com>
Subject: Re: Perl on the Pocket PC - Easy!
Message-Id: <Z1tod.5516$hJ6.2788@trndny01>
<ioneabu@yahoo.com> wrote in message
news:1101103239.151520.159670@z14g2000cwz.googlegroups.com...
Just some very basic constructive criticism . . .
> #!/usr/bin/perl
would strict and warnings adversely affect your ability to get this
thing to a size proper for the Pocket PC? I know nothing about it, so
that's an honest question. If not, put them in.
> use File::Slurp;
> @a = read_dir('\\oldpts\\');
> foreach(@a)
No real reason for the intermediary variable there.
foreach (read_dir('\\oldpts\\')) {
> {
> @b = ();
> @b = read_file("\\oldpts\\$_");
Almost never any reason to initialize an array to (). Definately no
reason if you then immediately assign it to a different value.
(If this was meant to 'clear' @b before the next loop, simply properly
scope the variable:)
my @b = read_file("\\oldpts\\$_);
> if (not (grep /^total/, @b))
> {
> $c = 0;
> map
> {
> /^(\d+)\s/;
> $c += int $&;
1) $& is generally a Bad Thing. It slows down all regexps in the
program (though not as much as in previous versions)
2) You're using capturing parentheses without using the captured value.
3) You're using values determined from a regular expression without
determining whether that pattern match succeeded. Maybe you're really
really confident about the format of your files, but that's not a good
pattern to fall into:
$c += $1 if /^(\d+)\s/;
> } @b;
map() should almost never be used in a void context. Use map when you
want to obtain a list of modified values from an existing list. If
you're not using the modified values (or in this case, not even
modifying them), use a foreach loop instead:
for (@b) {
$c += $1 if /^(\d+)\s/;
}
> push @b, "total: $c";
> write_file("\\oldpts\\$_",@b);
> }
> }
>
> I know it is not entirely efficient, but it worked. I couldn't
believe
> how fast it ran. One second to compile and no time to process dozens
> of files. Now I just need the portable keyboard :-)
> wana (now using map and grep a little :-)
Knowing how to use them is a good step in the right direction. Knowing
*when* to use them is a better step. :-)
Paul Lalli
>
------------------------------
Date: 22 Nov 2004 14:32:56 -0800
From: ioneabu@yahoo.com
Subject: Re: Perl on the Pocket PC - Easy!
Message-Id: <1101162776.647885.294630@c13g2000cwb.googlegroups.com>
Thanks for tips! I admit I have been lazy and a little sloppy in my
Perl work on the pda. There should be no reason not to use strict and
warnings. Thanks for advice on map.
Typing on the little on-screen keyboard and looking at the tiny screen,
it is easy to get into bad habits. I think this will be a passing fad
for me. It has been a way to do some Perl practicing in my free time
away from my pc. I work at a boring non-programming job, so when I
take a break, I can do a few minutes of Perl on the pda. Probably a
good use for it is to write well formed perl on the desktop that will
be useful for file processing on the pda and then send it over.
wana
------------------------------
Date: Mon, 22 Nov 2004 08:33:39 -0600
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: Search.cgi followup
Message-Id: <slrncq3u63.rg5.tadmc@magna.augustmail.com>
Ken Saunders <bnbliss@comcast.net> wrote:
> the script
> is working
Don't fix it if it isn't broken.
> but won't return any search results.
Errr, I guess you assign a rather strange definition to the
word "working" then...
> Here is the code can
> someone tell me why I get no results page?
^^^^^^^^^^^^^^^^^^^
What, exactly, does that mean?
The browser "hangs" and you never get *anything* back?
You get a web page, but it doesn' report finding any "hits"?
Have you looked for messages in your server log?
(Have you already looked for Perl FAQs that mention the CGI?
perldoc -q CGI
)
> use strict;
Good, but you should also add:
use warnings; # ask for all the help you can get!
> find(\&search_file, $filePath);
> sub search_file {
>
> my $query = param('query');
>
> if( $_ !~ /html|txt$/o ) {
> return();
> }
I'd switch the order of those 2 operations. There is no point in
fetching a param only to return() without using it.
The m//o does not do anything for the pattern you are using, so
it should not be there. Don't throw options on the end willy-nilly.
Either understand what they do for you, or don't use them yet.
Your pattern will match 'foo.html.bar' you know.
I _was_ just going to ask you to search for "precedence" in perlre.pod,
but that doesn't find docs that explain why it will match. The
right place is harder to find than it should be, but you can find
it by searching for "minimize confusion".
Your pattern says:
match "html" anywhere or "txt" at the end of string
as if you had written /html|(txt$)/.
I expect those are meant to be filename extensions, so you should
also require the dot before the extension.
You can say "unless" instead of "if not", which seems preferable
here (to me at least).
Phew! That's a lot of comments for only 4 lines of code. :-)
So, you can replace those four lines with these two:
return unless /\.(html|txt)$/;
my $query = param('query');
If the query might contain regex metacharacters that you want to
match literally, then you'll want this instead:
my $query = quotemeta param('query');
> open(IN, "$_") or warn "Can't open $_: $!\n";
perldoc -q vars
What's wrong with always quoting "$vars"?
then:
open(IN, $_) or warn "Can't open $_: $!\n";
> while ( my $line = <IN> ) {
> chomp($line);
>
> # Remove HTML from the line
> $line =~ s/\<.*?\>//g;
perldoc -q HTML
How do I remove HTML from a string?
Which gives several examples of HTML that will mess things
up for the pattern you are using.
HTML tags may span across more than one line too.
Since these are your own files, you might be able to guarantee
that none of that "tricky stuff" will be present, but in general
you would need to do a Real Parse of the HTML to do it correctly.
Angle brackets are not meta in regular expressions, so there is
no need to backslash them.
> $uri =~ s/^$filePath//;
> $uri = "/$uri";
You can combine those 2 into a single substitution:
$uri =~ s/^$filePath/\//;
or, since you now have a slash character in your replacement string,
choose to use an alternate delimiter so that you won't need
any backslashing:
$uri =~ s#^$filePath#/#;
> if( $line =~ /$query/o ) {
We need 2 pieces of information to analyse why a pattern match
is not working correctly (the pattern and the string it is to
be matched against).
We have zero of those pieces of information, so we cannot help
explain why it is, or is not, matching...
> print "<A HREF=$uri>$_</A><BR>";
You really should put quotes around your attribute values.
Using an alternate form of double quoting helps to avoid
yet more backslashing:
print qq(<A HREF="$uri">$_</A><BR>);
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Sun, 21 Nov 2004 23:09:39 -0600
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: Searching backward
Message-Id: <slrncq2t4j.qac.tadmc@magna.augustmail.com>
Evan <stern_evan@yahoo.com> wrote:
> I have multiple patterns to search within each string defined in a
> separate file.
>
> Departure|Arrival
> MORNING|AFTERNOON
>
> Need to search for the occurence and position of pattern 1, if found,
> search for the occurence and position of pattern 2 and so on. The
> search for reasons needs to be done in a backward direction.
>
> Looked at rindex. It searches the string right to left but the problem
> using it is that the string cannot be a regexp.
So far you haven't said anything that *requires* a regex.
> So the only option remains is to use a regexp.
^^^^^^^^^^^^^^^
Then there is something you are not telling us.
> Could anyone suggest any ideas in the direction of approaching this
> problem.
Call rindex() 4 times instead of doing 2 pattern matches with 2 alternatives.
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
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.
NOTE: due to the current flood of worm email banging on ruby, the smtp
server on ruby has been shut off until further notice.
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 7437
***************************************