[19577] in Perl-Users-Digest
Perl-Users Digest, Issue: 1772 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Sep 19 09:05:27 2001
Date: Wed, 19 Sep 2001 06: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: <1000904707-v10-i1772@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Wed, 19 Sep 2001 Volume: 10 Number: 1772
Today's topics:
Re: call c from Perl <peb@bms.umist.ac.uk>
copy STDERR to file (Rory)
Re: copy STDERR to file <bart.lateur@skynet.be>
Re: example for rewinddir (Martien Verbruggen)
Re: example for rewinddir (Anno Siegel)
Re: example for rewinddir (Martien Verbruggen)
Re: example for rewinddir <bart.lateur@skynet.be>
Re: example for rewinddir (Anno Siegel)
Re: Global variables <tsee@gmx.net>
Re: Global variables (Damian James)
Re: HELP! Having Trouble concatenating or joining and (codeslayer)
Re: How to htmlize an email, for eg lynx? (Chris Fedde)
Need help with perl script... <jonas.vonlanthen@jef.ch>
Re: Need help with perl script... <Thomas@Baetzler.de>
Re: package initialization <bart.lateur@skynet.be>
Problem with DBI+DBD MySQL, using fetchall_arrayref and (Altair04)
select() timeout problem <philippe.perrin@sxb.bsf.alcatel.fr>
Re: split SuchKindOfWord into individual words (Anno Siegel)
Re: split SuchKindOfWord into individual words <bart.lateur@skynet.be>
What does this error mean? (Stan Brown)
Re: What does this error mean? <bkennedy99@Home.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Wed, 19 Sep 2001 11:32:18 +0100
From: Paul Boardman <peb@bms.umist.ac.uk>
Subject: Re: call c from Perl
Message-Id: <3BA87432.488BF1D9@bms.umist.ac.uk>
fly98us wrote:
> Is there any method to call c functions directly from Perl?
Yes. Have a look at perldoc perlxs (if perldoc is installed on your
machine) or look at the perlxs page on www.perldoc.org.
HTH
Paul
------------------------------
Date: 19 Sep 2001 03:47:12 -0700
From: rory@campbell-lange.net (Rory)
Subject: copy STDERR to file
Message-Id: <ba9de059.0109190247.7ff4b8da@posting.google.com>
I would like, for part of a script, to copy STDERR to a file, as I
have a script that takes ages to run, and I might miss some of the
messages written to the console.
I have tried the recipe in perlfunc, but after closing the STDERR
filehandle, I don't get messages reported to the console at all.
Thanks for any help
Rory
(I'd be grateful for a cc to my mail address)
------------------------------
Date: Wed, 19 Sep 2001 12:48:33 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: copy STDERR to file
Message-Id: <kv4hqtoa97opndib6251i1t0jj45qkj647@4ax.com>
Rory wrote:
>I would like, for part of a script, to copy STDERR to a file, as I
>have a script that takes ages to run, and I might miss some of the
>messages written to the console.
Is it OK to send all of it ONLY to a file? Then this will do:
open STDERR, ">stderr.log";
--
Bart.
------------------------------
Date: Wed, 19 Sep 2001 20:11:27 +1000
From: mgjv@tradingpost.com.au (Martien Verbruggen)
Subject: Re: example for rewinddir
Message-Id: <slrn9qgrqf.sv.mgjv@martien.heliotrope.home>
On 19 Sep 2001 02:13:36 -0700,
Joachim Ziegler <ziegler@algorilla.de> wrote:
> anno4000@lublin.zrz.tu-berlin.de (Anno Siegel) wrote in message news:<9o75b3$cjj$1@mamenchi.zrz.TU-Berlin.DE>...
>> According to Joachim Ziegler <ziegler@algorilla.de>:
>> > can someone give me a good example
>> > for a situation, in which "rewinddir" is useful?
>> >
>> > i don't see any!
>>
>> You can't think of a situation where it would be useful to read
>> a directory twice?
>>
>> Anno
>
> no, because
>
> 1) if i knew, i would not pollute this newsgroup with unnecessary
> questions
Good :)
> 2) you can save all file names in an array while reading a directory
File names might change. I can imagine an application that opens a
directory, loops over it, finding all the files, then sleeps a bit, then
does it again. Maybe it wants to look for the arrival of certain types
of files.
I can imagine an application that scans a directory, and on discovering
a certain file creates new files, or deletes other files based on
information in that certain file. If it wanted to scan the directory
again, it could just rewind.
If an application detected that halfway through a directory scan files
were missing (maybe deleted by another application), it could start
again.
If you write a proxy server with a large set of cache directories, and
you have an external program that cleans up this cache, you may very
well want to, and need to read these directories as fast as possible,
with the least amount of overhead. seekdir and rewinddir are probably
faster than re-opening the directory.
> 3) you can closedir() a directory, then opendir() it again and read
> again
Yes, you could just open the directory again. But you could also just
open a file again, instead of seeking to the beginning, or even seeking
to somewhere else. Or are you also questioning why seek exists? Opening
directories is most likely slightly heavier on the system than
rewinding. For most applications that isn't a problem, but for those
very few applications that do need to do heavy processing on
directories, multiple times, this may make some significant difference.
> 4) if you make changes to a directoy (removing/adding a file), you can
> remember this by changing the corresponding array
What if someone else makes those changes? What if you make those changes
in some other remote part of your application, which may very well be a
module with a totally closed interface?
> so, i don't see any examplary situation for a meaningful use of
> rewinddir (or, what's worse, seekdir() and telldir() ).
The fact that you can't conceive of such a situation does not mean that
there is no such situation. These functions have been part of BSD for a
long, long time. If they weren't useful in certain situations, they
probably wouldn't have persisted.
As I said, most applications, probably the vast majority, will never
need to call rewinddir or seekdir, but there may be situations where it
comes in handy.
> i'm not a system programmer, so maybe some can give me a hint.
Maybe the comp.unix.programmer group could give you some actual
practical examples.
I just did a find on the tree where I store and compile applications, to
find which packages have seekdir in them. Of course, this only finds the
ones that are unpacked, at the moment:
$ find . -name \*.c -o -name \*.h | xargs grep -l seekdir
the packages coming up:
ImageMagick
bash
mysql
and various versions of Perl.
rewinddir also appears in all of the above, as well as in ctags, and
leafnode.
I don't even have that much unpacked, right now. I did expect squid to
show up here as well, and maybe apache and/or mod_perl, but they didn't.
Martien
--
Martien Verbruggen |
Interactive Media Division | System Administration is a dirty job,
Commercial Dynamics Pty. Ltd. | but someone said I had to do it.
NSW, Australia |
------------------------------
Date: 19 Sep 2001 10:36:44 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: example for rewinddir
Message-Id: <9o9sfs$kf9$4@mamenchi.zrz.TU-Berlin.DE>
According to Martien Verbruggen <mgjv@tradingpost.com.au>:
[good examples of possible usefulness of rewinddir()]
> The fact that you can't conceive of such a situation does not mean that
> there is no such situation. These functions have been part of BSD for a
> long, long time. If they weren't useful in certain situations, they
> probably wouldn't have persisted.
Ahem. That a feature persists hardly proves its usefulness. The most
common reason for not canceling a dubious feature is that it once was
there, so someone may have used it. Talk about deprecated...
Anno
------------------------------
Date: Wed, 19 Sep 2001 20:59:03 +1000
From: mgjv@tradingpost.com.au (Martien Verbruggen)
Subject: Re: example for rewinddir
Message-Id: <slrn9qgujm.sv.mgjv@martien.heliotrope.home>
On 19 Sep 2001 10:36:44 GMT,
Anno Siegel <anno4000@lublin.zrz.tu-berlin.de> wrote:
> According to Martien Verbruggen <mgjv@tradingpost.com.au>:
>
> [good examples of possible usefulness of rewinddir()]
>
>> The fact that you can't conceive of such a situation does not mean that
>> there is no such situation. These functions have been part of BSD for a
>> long, long time. If they weren't useful in certain situations, they
>> probably wouldn't have persisted.
>
> Ahem. That a feature persists hardly proves its usefulness. The most
> common reason for not canceling a dubious feature is that it once was
> there, so someone may have used it. Talk about deprecated...
The last bit of my post actually showed a few current applications that
used these calls, which means that they are still in use, and that at
least some people still believe thay are useful :)
Martien
--
Martien Verbruggen |
Interactive Media Division | I'm just very selective about what I
Commercial Dynamics Pty. Ltd. | accept as reality - Calvin
NSW, Australia |
------------------------------
Date: Wed, 19 Sep 2001 12:33:49 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: example for rewinddir
Message-Id: <f04hqtgjmvd1fjqmqqj200irtol2rng9vr@4ax.com>
Anno Siegel wrote:
>Well, rewinddir() is certainly not indispensable, but neither are tell()
>and seek() for ordinary files.
tell() and especially seek() are far more indispensable than
rewinddir()! How else would you read and modify a file in one go?
Without seek(), you'd need to fall back on external lockfiles, because
you just can't keep a file locked when you have to reopen it.
--
Bart.
------------------------------
Date: 19 Sep 2001 12:49:09 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: example for rewinddir
Message-Id: <9oa485$1f0$1@mamenchi.zrz.TU-Berlin.DE>
According to Bart Lateur <bart.lateur@skynet.be>:
> Anno Siegel wrote:
>
> >Well, rewinddir() is certainly not indispensable, but neither are tell()
> >and seek() for ordinary files.
>
> tell() and especially seek() are far more indispensable than
> rewinddir()! How else would you read and modify a file in one go?
> Without seek(), you'd need to fall back on external lockfiles, because
> you just can't keep a file locked when you have to reopen it.
True. And it makes sense because directories do their own locking,
so the concurrency problem doesn't arise.
Anno
------------------------------
Date: Wed, 19 Sep 2001 14:54:39 +0200
From: "Steffen Müller" <tsee@gmx.net>
Subject: Re: Global variables
Message-Id: <9oa48v$o6q$01$1@news.t-online.com>
"Philippe PERRIN" <philippe.perrin@sxb.bsf.alcatel.fr> schrieb im
Newsbeitrag news:3BA852A1.A63B3858@sxb.bsf.alcatel.fr...
> Hi
>
> I have a script.pl file, where I use a global variable :
> use strict;
> my %hash;
>
> In this .pl file, I use some .pm files of my own. How can I make these
> .pm modules access the %hash variable, defined in the .pl script ?
The most obvious way might be to pass a hashref to the pm's subroutine(s).
Steffen
------------------------------
Date: 19 Sep 2001 13:00:51 GMT
From: damian@qimr.edu.au (Damian James)
Subject: Re: Global variables
Message-Id: <slrn9qh5jt.822.damian@puma.qimr.edu.au>
On Wed, 19 Sep 2001 10:09:05 +0200, Philippe PERRIN said:
>Hi
>
>I have a script.pl file, where I use a global variable :
>use strict;
>my %hash;
>
>In this .pl file, I use some .pm files of my own. How can I make these
>.pm modules access the %hash variable, defined in the .pl script ?
>
By declaring the hash with my(), you are making it lexical, and not
accessible from other file/package scopes. You need to either declare
it with an explicit package name:
%main::hash = ();
or, with recent perls, use our():
our %hash;
and in either case, then refer to it from other packages as:
$main::hash{'foo'} = 'bar';
That is, assuming you declare package namespaces in your modules :-).
Cheers,
Damian
--
@:=grep!(m!$/|#!..$|),split//,<DATA>;@;=0..$#:;while($:=@;){$;=rand
$:--,@;[$;,$:]=@;[$:,$;]while$:;push@|,shift@;if$;[0]==@|;select$,,
$,,$,,1/80;print qq x\bxx((@;+@|)*$|++),@:[@|,@;],!@;&&$/} __END__
Just another Perl Hacker,### http://home.pacific.net.au/~djames.hub
------------------------------
Date: 19 Sep 2001 05:49:04 -0700
From: weedmonster_99@yahoo.com (codeslayer)
Subject: Re: HELP! Having Trouble concatenating or joining and making or building a url with ActivePerl and the '.' operator.
Message-Id: <4b459565.0109190449.2cbf9ef2@posting.google.com>
Thanks to everyone who responded. I tried the code at home and it
worked this time!
I was trying to write a program that lets a user enter information
about a particular web page or graphic, (including a range of numbers)
for numerically sequential documents. The script will open all the
documents almost instantly. So if you put a start number and an end
number resulting in a range of 50, 50 browser windows will pop up (so
be careful!!!).
This is what I mean by sequentially numbered docs:
EX:
page_01, page_02, .. page_nn, etc...
OR
http://www.yahoo.com/prettypic_a6-300i.jpg,
http://www.yahoo.com/prettypic_a6-301i.jpg,
http://www.yahoo.com/prettypic_a6-302i.jpg,
etc ...
... And it works !
Here is a link to a post where my final code is:
http://groups.google.com/groups?q=codeslayer&hl=en&rnum=4&selm=4b459565.0109181000.19305984%40posting.google.com
If there is an easier way, please let me know.
Thanks again.
------------------------------
Date: Wed, 19 Sep 2001 10:43:00 GMT
From: cfedde@fedde.littleton.co.us (Chris Fedde)
Subject: Re: How to htmlize an email, for eg lynx?
Message-Id: <UE_p7.534$Owe.263000576@news.frii.net>
!/usr/bin/perl
#
# Please excuse the jeopardy style response
# This is not especially clever but it does the job
# BTW. I prefer w3m to lynx. You might too
#
print "<html><head></head><body><pre>\n";
while (<DATA>) {
s|(http://\S+)|<a href="$1">$1</a>|g;
print;
}
print "</pre></body></html>\n";
__END__
In article <9o9fph$m84$1@panix1.panix.com>,
David Combs <dkcombs@panix.com> wrote:
>I get emails (from a listserv) that has
>lots of interesting links.
>
>Being as I do *not* use M$, and instead use
>(as email-reader) mutt, I need some way to
>convert an email like this:
>
>
>Building Debate: Should Twin Towers Go Up Again?
>http://www.dallasnews.com/national/472263_nycarchitect_1.html
>
>We Cannot Allow Fear to Dictate Commercial Architecture
>http://www.jsonline.com/news/metro/sep01/goulcol17091601a.asp
>
>The End of Tall Buildings
>http://www.planetizen.com/oped/item.php?id=30
>
>Rebuild or Not: Architects Respond
>http://www.nytimes.com/2001/09/23/magazine/23REBUILD.html
>
>
>
>
>into an html doc that I can read via lynx and then
>easily link to the various sites.
>
>Now, there is a program, "urlview", that aids in this:
>you map a mutt key to run that program on the current
>email, and it runs lynx with the "page" being a simple
>list of the urls themselves -- but with none of that
>commentary *about* the link, eg the
>"The end of Tall buildings"
>above.
>
>Writing a perl program to convert this to html should
>be trivial -- any suggestions on how to do this in
>a clever way?
>
>Thanks!
>
>David
>
--
This space intentionally left blank
------------------------------
Date: Wed, 19 Sep 2001 01:29:13 +0200
From: Jonas Vonlanthen <jonas.vonlanthen@jef.ch>
Subject: Need help with perl script...
Message-Id: <3BA7D8C9.CDD58F82@jef.ch>
This is a multi-part message in MIME format.
--------------90B72368FB63A111FC27DDA3
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
Hi,
Could someone help me with the following perl script...
1. Is it possible to modify the script so that it doesn' search only the
"base" directory but also other directories?
2. Is it possible to search text instead of keywords?
3. How can we exclude some files from being scanned?
I would appreciate any help on this.
Thank you.
Jonas
--------------90B72368FB63A111FC27DDA3
Content-Type: application/x-perl;
name="search.pl"
Content-Transfer-Encoding: 8bit
Content-Disposition: inline;
filename="search.pl"
#!/usr/bin/perl
# Copyright (C) 1998 by Sierra Kempster. All rights reserved.
# Quick script to search a directory for what files contain certain keywords.
# Searches HTML files in one directory except index.htm
# Distribute freely, but keep this notice intact, and do not charge money
# for my work. Keep information free.
$dir = "/www/WP011B25/"; # Directory to search
$url = "http://WP011B25.sizch.net/"; # URL of directory
# Get the form information
read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
@pairs = split(/&/, $buffer);
foreach $pair (@pairs)
{
($name, $value) = split(/=/, $pair);
$value =~ tr/+/ /;
$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
$value =~ s/~!/ ~!/g;
$FORM{$name} = $value;
}
# Open the directory and get file list
opendir(DIR, "$dir");
local(@files) = grep /\S+\.[Hh][Tt][Mm]/, readdir(DIR);
closedir(DIR);
# List of key words
$FORM{keywords} = ~tr/[A-Z]/[a-z]/;
@keywords = split(/ /,$FORM{keywords});
# Check each file for the words
foreach $file (@files)
{
if($file ne "index.htm")
{
open(FILE, "$dir/$file");
$x = 0;
while(<FILE>)
{
chomp;
$_ =~ tr/[A-Z]/[a-z]/;
foreach $word (@keywords)
{
if($_ =~ /$word/)
{
$x = $x+1;
}
}
}
close(FILE);
# Add to the list if any matches are found
if($x > 0)
{
push @list, "$x:$file";
}
}
}
# Sort the list according to most matches
@sorted = sort { $b <=> $a } @list;
# Print the results
print"Content-type: text/html\n\n";
while(<HEAD>)
{
print"$_";
}
close(HEAD);
print"<p><Font face='Verdana,Arial,Lucida,Helvetica,sans-serif' color='#006600'><h3><b>Suchresultate</b></h3></font><Font face='Verdana,Arial,Lucida,Helvetica,sans-serif'></p>\n";
print"<p><br><center><table border=0 cellspacing=0 cellpadding=0 align=left>\n";
print"<tr><th align=left>Übereinstimmung</th><th align=right>Seite</th></tr>\n";
foreach $item (@sorted)
{
($match,$file) = split(/:/,$item,2);
print"<tr><td>$match</td><td align=right><a href=\"$url/$file\">$file</a></td></tr>\n";
}
print"</table></center></p>\n";
while(<FOOT>)
{
print"$_";
}
close(FOOT);
--------------90B72368FB63A111FC27DDA3--
------------------------------
Date: Wed, 19 Sep 2001 14:18:33 +0200
From: =?ISO-8859-1?Q?Thomas_B=E4tzler?= <Thomas@Baetzler.de>
Subject: Re: Need help with perl script...
Message-Id: <sm2hqtcl91fv071er1fpv47iajqugr7986@4ax.com>
On Wed, 19 Sep 2001, Jonas Vonlanthen <jonas.vonlanthen@jef.ch> wrote:
>1. Is it possible to modify the script so that it doesn' search only the
>"base" directory but also other directories?
Certainly.
>2. Is it possible to search text instead of keywords?
Certainly.
>3. How can we exclude some files from being scanned?
You would've to remove them from the @files array.
>I would appreciate any help on this.
Sorry, this is comp.lang.perl.misc, not alt.idiots.who.work.for.free.
I guess nobody would mind looking at _your code_ to suggest
improvements, but please don't expect us to do all the work for you
just because you're too cheap or too lazy to do it yourself.
OTTOH, some suggestions about the code you posted:
- add use strict; and -wT flags - this is safe thing to do with CGI
programs. It'll also flag down all the undeclared variables in the
code.
- consider using the CGI module for argument parsing instead of
doing it manually.
- consider using a proper search engine on the back end - something
like glimpse for example. Exhaustively searching all files for each
query is not very efficient.
HTH,
--
use strict;my($i,$t,@r)=(0,'5 -.@BHJPT4acd6e2hk2lmn2o4r2s3tuz',map{ord}
split//,unpack('u*','L#`T&)QD5#0`#!!`#%1D)#08`#P05!!(3``$$"``#"0L&``('.
'"`P<!`````0$`'));$t=~s/(\d)(.)/$2x$1/eg;map{$t.=substr$t,$i,1,''while
$_--;$i++}@r;print"$t\n";# Thomas@Baetzler.de - http://baetzler.de/perl
------------------------------
Date: Wed, 19 Sep 2001 12:38:28 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: package initialization
Message-Id: <o84hqt4fv79p6enf19ebe59dhqbfum9q2g@4ax.com>
Tad McClellan wrote:
>local() does not get you a "local variable", it gets you
>a "local value" (which, strangely enough, is NOT local,
>but global!).
Actually, it's more of a "temporary replacement for a (global) value".
"local" most definitely was a poor choice of words from Larry, when
designing this feature.
I know you knew that. But that's pedantry for you: one just has to get
it right.
--
Bart.
------------------------------
Date: 19 Sep 2001 03:44:51 -0700
From: altair_04@altavista.com (Altair04)
Subject: Problem with DBI+DBD MySQL, using fetchall_arrayref and dereferencing with random function
Message-Id: <54d5ca0a.0109190244.a2328b3@posting.google.com>
Hello, I have the following sentences that read all te rows in the
"countries" table and then select one of those rows, using the random
function. The print works OK, but if I assign the same expression to a
variable, it contains always a '1':
$query = 'SELECT country FROM countries';
$sth = $dbh->prepare($query);
$sth->execute;
$countries_ref = $sth->fetchall_arrayref();
#################################################################
# this print works OK (gives the name of a country, at random): #
#################################################################
print @{@{$countries_ref}[rand(@{$countries_ref})]};
#################################
# but this prints always a '1': #
#################################
$country = @{@{$countries_ref}[rand(@{$countries_ref})]};
print $country;
As you can see, I assign to $country the same expression that I am
printing in the first print.
I'd like to know why $country does not contain the name of a country
(this is what I get from the first print).
Note1: I have removed error checks for clarity. There are no errors...
as far as I can tell.
Note2: it seems $countries_ref is the reference to an array that
contains more array references. Those references, point to an array of
one element, containing the name of the country. Pretty complicated
for a newbie like me...
Thanks for your help and time.
------------------------------
Date: Wed, 19 Sep 2001 14:17:33 +0200
From: Philippe PERRIN <philippe.perrin@sxb.bsf.alcatel.fr>
Subject: select() timeout problem
Message-Id: <3BA88CDD.94299297@sxb.bsf.alcatel.fr>
Hi
I use the script below on a linux box. The "myFifo" file is a fifo,
created with mkfifo. While running, it is supposed to wait for data to
be readable in this fifo, then display them. This works fine.
The problem is, that it is also supposed to timeout after 5 seconds...
and this never happens ! The select() call only exits when I send bytes
in the fifo, and the value of $left is always 5. Why doesn't it timeout
??
Thanks
--
PhP
=========SCRIPT===========
use strict;
while(1) {
open(FIFO, "myFifo");
my($rin, $win, $ein) = ('', '', '');
vec($rin, fileno(FIFO), 1) = 1;
$ein = $rin | $win;
my($rout, $wout, $eout);
my ($nfound, $left) = select($rout = $rin, $wout = $win, $eout =
$ein, 5);
print "nfound = $nfound and left = $left\n";
if($nfound == 0) {
print "timeout !\n";
next;
}
while(<FIFO>) {
chomp;
print "I read [$_]\n";
exit if $_ eq 'exit';
}
close(FIFO);
}
------------------------------
Date: 19 Sep 2001 10:07:00 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: split SuchKindOfWord into individual words
Message-Id: <9o9qo4$kf9$3@mamenchi.zrz.TU-Berlin.DE>
According to Michael Budash <mbudash@sonic.net>:
> In article <sa88zfc6y8f.fsf@suntong.personal.users.sourceforge.net>, *
> Tong * <sun_tong@users.sourceforge.net> wrote:
>
> > Hi,
> >
> > I'm wondering if there are some neat ways to split SuchKindOfWord
> > into individual words, i.e., Such Kind Of Word.
> >
> > Any tip will be appreciated. Thanks
>
> based strictly on your example, here's one way:
>
> push @words, $1 while /([A-Z][^A-Z]+)/g;
^ ^ ^
Besides the obvious typo, you may want "*" instead of "+" (ACatAndADog).
Shorter and perhaps faster:
@words = /([A-Z][a-z]*)/g;
Anno
------------------------------
Date: Wed, 19 Sep 2001 12:41:52 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: split SuchKindOfWord into individual words
Message-Id: <7h4hqtkko6ntpmb1a1lqg4jjae8q3upb7m@4ax.com>
Chris Fedde wrote:
>I'm sure that the golf pros can do better than this but here is my attempt:
>
>perl -e 'print "$1 "while("SuchKindOfWord"=~/([A-Z][[a-z]+)/g);print"\n"'
That gives me an extra space at the end of the string. Ugh.
perl -e 'print join(" ", "SuchKindOfWord"=~/([A-Z][[a-z]+)/g)."\n"'
Yup, it's shorter.
--
Bart.
------------------------------
Date: 19 Sep 2001 08:42:02 -0400
From: stanb@panix.com (Stan Brown)
Subject: What does this error mean?
Message-Id: <9oa3qq$56o$1@panix3.panix.com>
'm still strugling with a Tk::filevent, Storabel::fd_retrieve problem. In
an effort to determine oif it's a bug in my perl installation (HP-UX 10.20,
perl v5.6.0 ), I decided to try it on one of my FreeBSD machine (FreeBSD
4.3-RC, perl 5.005_03). But when I run the script, I get the follwing
error:
Tk::Error: Can't use an undefined value as a symbol reference at ./stan.pl
line 175.
Here's line 175:
pipe my ($reader, $writer) or die "pipe: $!";
What is perl trying to tell me?
--
"They that would give up essential liberty for temporary safety deserve
neither liberty nor safety."
-- Benjamin Franklin
------------------------------
Date: Wed, 19 Sep 2001 12:59:28 GMT
From: "Ben Kennedy" <bkennedy99@Home.com>
Subject: Re: What does this error mean?
Message-Id: <QE0q7.28908$5A3.9603631@news1.rdc2.pa.home.com>
"Stan Brown" <stanb@panix.com> wrote in message
news:9oa3qq$56o$1@panix3.panix.com...
> Tk::Error: Can't use an undefined value as a symbol reference at ./stan.pl
> line 175.
>
> Here's line 175:
>
> pipe my ($reader, $writer) or die "pipe: $!";
>
> What is perl trying to tell me?
This is definitely a 5.6 vs 5.5 issue - you get the same error on 5.5 with
open(my $handle, "filename") or die "Cannot open: $!";
It looks like 5.5 treats the variable as a soft reference to a glob - so if
you set $out to HANDLE, you can then read/use HANDLE after the open
statement. In 5.6, if you pass it a variable that is undef it will be smart
and fill the variable with an anonymous glob reference that can be used as a
handle - all in all a better solution. Perhaps someone else knows where
this is officially documented? The perl docs seem a bit behind the times
--Ben Kennedy
------------------------------
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 1772
***************************************