[17233] in Perl-Users-Digest

home help back first fref pref prev next nref lref last post

Perl-Users Digest, Issue: 4655 Volume: 9

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Oct 18 18:10:54 2000

Date: Wed, 18 Oct 2000 15:10:22 -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: <971907022-v9-i4655@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Wed, 18 Oct 2000     Volume: 9 Number: 4655

Today's topics:
    Re: Perl not functioning in practice as it should in th </michael>
    Re: Perl not functioning in practice as it should in th </michael>
    Re: Perl not functioning in practice as it should in th (John J. Trammell)
    Re: Perl not functioning in practice as it should in th (Gary E. Ansok)
    Re: Perl not functioning in practice as it should in th <anders@wall.alweb.dk>
    Re: Perl not functioning in practice as it should in th <bart.lateur@skynet.be>
    Re: Perl not functioning in practice as it should in th <newsposter@cthulhu.demon.nl>
    Re: Perl not functioning in practice as it should in th (Jerome O'Neil)
    Re: Perl not functioning in practice as it should in th </michael>
    Re: Perl not functioning in practice as it should in th <ren.maddox@tivoli.com>
    Re: Perl not functioning in practice as it should in th <jeff@vpservices.com>
    Re: Perl not functioning in practice as it should in th <mjcarman@home.com>
    Re: Perl not functioning in practice as it should in th <mjcarman@home.com>
    Re: Perl not functioning in practice as it should in th <krahnj@acm.org>
    Re: Perl not functioning in practice as it should in th <jeffp@crusoe.net>
    Re: Perl question - Backup and email a file? <peter.sundstrom@eds.com>
        Perl vs C on server side rosenb_m@my-deja.com
    Re: Perl vs C on server side <uri@sysarch.com>
        Problem with locale and \s (Sean McAfee)
    Re: Problem with locale and \s <bart.lateur@skynet.be>
    Re: problems with open2 use in cgi mrbigsecret@my-deja.com
    Re: Program design (Jerome O'Neil)
    Re: question <bart.lateur@skynet.be>
    Re: question <joe+usenet@sunstarsys.com>
        regex substitute nodo70@my-deja.com
    Re: regex substitute <tina@streetmail.com>
    Re: regex substitute <tina@streetmail.com>
        Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)

----------------------------------------------------------------------

Date: Wed, 18 Oct 2000 14:12:25 -0400
From: </michael>
Subject: Re: Perl not functioning in practice as it should in theory.  - test.pl (0/1)
Message-Id: <8cprus8h2g7s5pb4fqvaj47pjsruu11tvv@4ax.com>

On 18 Oct 2000 18:20:32 +0100, nobull@mail.com wrote:

></michael> writes:
>
>> Please look at this script.  It should find every sub directory
>> recursively but stops for some reason.
>
>Why are you re-inventing File::Find?

I'm not trying to re-invent File::Find.   I'm trying to batch process
contents of directories recursively.  This part was not in what I
supplied here because I thought it would just confuse things. 

>
>> Id anyone could figure this out I would greatly appreciate it.
>
>It is poor form to post code here that doesn't "use strict" because it
>wastes our time getting us to do something you could have made Perl do
>for you.  The same applies to enabling warnings and testing the return
>values from system calls.

I'm sorry I new to perl.  I've tested this extensively & can not
figure out the problem that's why I'm looking for help here. 

>
>Forgetting to my() your variables will cause trouble for you sooner or
>later.  In the case of recursive programs it is thankfully sooner
>rather than later.

Please enunciate or give an example. 

Do you mean adding or removing my()?


------------------------------

Date: Wed, 18 Oct 2000 14:17:40 -0400
From: </michael>
Subject: Re: Perl not functioning in practice as it should in theory.  - test.pl (0/1)
Message-Id: <p2qrusg9o8rcfnfeqpc6sc3lavp8s9ujft@4ax.com>

On Wed, 18 Oct 2000 17:33:01 GMT, jerome@activeindexing.com (Jerome
O'Neil) wrote:

></michael> elucidates:
>> Please look at this script.  It should find every sub directory
>> recursively but stops for some reason.  Id anyone could figure this
>> out I would greatly appreciate it.  
>
>There is already a very nice round wheel already carved for finding things
>recursively on your file system.  Check out the documentation for 
>File::Find, and be enlightened.
>
>Good Luck!

 I'm trying to batch process contents of directories recursively.
This part was not in what I supplied here because I thought it would
just confuse things.

 I would actually like to know what was wrong with what I wrote. 

Besides the File::Find does not accomplish what I need.  I have
already searched cpan for directory traversing modules and was
unsuccessful. 


------------------------------

Date: 18 Oct 2000 18:19:32 GMT
From: trammell@nitz.hep.umn.edu (John J. Trammell)
Subject: Re: Perl not functioning in practice as it should in theory.  - test.pl (0/1)
Message-Id: <slrn8ur02f.9pk.trammell@nitz.hep.umn.edu>

On Wed, 18 Oct 2000 13:05:28 -0400, /michael </michael> wrote:
>Please look at this script.  It should find every sub directory
>recursively but stops for some reason.  Id anyone could figure this
>out I would greatly appreciate it.  
[snip]

perldoc DirHandle, and good luck!

-- 
John J. Trammell
johntrammell@yahoo.com


------------------------------

Date: 18 Oct 2000 18:56:07 GMT
From: ansok@alumni.caltech.edu (Gary E. Ansok)
Subject: Re: Perl not functioning in practice as it should in theory.  - test.pl (0/1)
Message-Id: <8skro7$9du@gap.cco.caltech.edu>

In article <nqlrusc47vc1109qd4tea5qno18sk1nq6n@4ax.com>,  </michael> wrote:
>Please look at this script.  It should find every sub directory
>recursively but stops for some reason.  Id anyone could figure this
>out I would greatly appreciate it.  
>
>
>#!/usr/bin/perl
>
>@directory = ('/home/users/michael');
>
>sub openDir {
>
>   my ($ImageDir) = @_;
>
>   opendir(LS,$ImageDir);
>      @file = readdir(LS);
>   closedir(LS);
>
>   foreach $file (@file) {
>      if ((-d $file)&&(!($file =~ /\./))) {
>         push(@directory,"$ImageDir/$file");
>         print "   Adding: $ImageDir/$file\n";
>      }
>   }
>}
>
>while (@directory) {
>   print "Searching: $directory[0]\n";
>   openDir($directory[0]);
>   shift(@directory);
>}

Remember that readdir() only returns the bare file name, so $file
will only contain the bare filename -- probably you want
if ((-d "$ImageDir/$file")...

That said, here are some miscellaneous comments:

1)  -w and "use strict" are *highly* recommended.

2)  Checking the results of opendir() and printing an error message
    (including the dir name and $!) is highly recommended.

3)  Do you mean to skip any directory name that contains a "."?
    You may know that for your specific data set, none will, but
    in general directory names can contain "." (even start with ".").
    You may want to just skip "." and ".." explicitly.

4)  Are you sure File::Find isn't suitable for your needs?  A simple
    call like

  find sub { push @directory, $File::Find::name if -d && !/\./; }, $topdir;

    will do almost exactly what you have above (ordering being the
    main difference).  It also has several options regarding handling
    of symbolic links (which can put loops in the dirtree).

You didn't give any details regarding what your requirements are,
so what you're doing with regard to my comments 3 and 4 may well work
fine for you (on your data as it is now).  I'm giving suggestions
that I think would be helpful to most people who start writing code
similar to what you've presented.

-- Gary Ansok


------------------------------

Date: Wed, 18 Oct 2000 20:55:46 +0200
From: Anders Lund <anders@wall.alweb.dk>
Subject: Re: Perl not functioning in practice as it should in theory.  - test.pl (0/1)
Message-Id: <BnmH5.6537$Uy5.203480@news000.worldonline.dk>

no name wrote:
 
>  I'm trying to batch process contents of directories recursively.
> This part was not in what I supplied here because I thought it would
> just confuse things.
> 
>  I would actually like to know what was wrong with what I wrote.
> 
> Besides the File::Find does not accomplish what I need.  I have
> already searched cpan for directory traversing modules and was
> unsuccessful.

Here's a clip from perldoc File::Find:

    File::Find(User Contributed Perl Documentati.0::File::Find(3)
 
 
NAME
       find - traverse a file tree
 
       finddepth - traverse a directory structure depth-first
 
SYNOPSIS
           use File::Find;
           find(\&wanted, '/foo', '/bar');
           sub wanted { ... }
 
           use File::Find;
           finddepth(\&wanted, '/foo', '/bar');
           sub wanted { ... }
 
           use File::Find;
           find({ wanted => \&process, follow => 1 }, '.');
 
 
DESCRIPTION
       The first argument to find() is either a hash reference
       describing the operations to be performed for each file,
       or a code reference.
 
       Here are the possible keys for the hash:
 
       `wanted'
          The value should be a code reference.  This code
          reference is called the wanted() function below.                  
     
 ....

As you see, File::Find provedes the method find(), which looks in a list of 
locations and calls the wanted() subroutine with each file found therein as 
the single argument. Which seems to be what you want to do.

-anders

-- 
[ the word wall - and the trailing dot - in my email address
is my _fire_wall - protecting me from the criminals abusing usenet]


------------------------------

Date: Wed, 18 Oct 2000 19:31:37 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: Perl not functioning in practice as it should in theory.  - test.pl (0/1)
Message-Id: <2kurusklclfhp18hg00ujtmh774aek8ehg@4ax.com>

</michael> wrote:

>Please look at this script.  It should find every sub directory
>recursively but stops for some reason.  Id anyone could figure this
>out I would greatly appreciate it.  

The reason why it doesn't work, is because readdir() returns only bare
filenames, and -d and friends require a full file path, if the file
isn't in your current directory.

-- 
	Bart.


------------------------------

Date: 18 Oct 2000 18:43:11 GMT
From: Erik van Roode <newsposter@cthulhu.demon.nl>
Subject: Re: Perl not functioning in practice as it should in theory.  - test.pl (0/1)
Message-Id: <8skqvv$49m$1@internal-news.uu.net>

/michael wrote:
> Please look at this script.  It should find every sub directory
> recursively but stops for some reason.  Id anyone could figure this
> out I would greatly appreciate it.  


> @directory = ('/home/users/michael');

>       if ((-d $file)&&(!($file =~ /\./))) {

 -d looks for the file to be tested in the current working directory.
Check the _full_ path instead.

Erik



------------------------------

Date: Wed, 18 Oct 2000 19:35:44 GMT
From: jerome@activeindexing.com (Jerome O'Neil)
Subject: Re: Perl not functioning in practice as it should in theory.  - test.pl (0/1)
Message-Id: <kYmH5.177$wM1.102362@news.uswest.net>

</michael> elucidates:

>>There is already a very nice round wheel already carved for finding things
>>recursively on your file system.  Check out the documentation for 
>>File::Find, and be enlightened.
>>
>>Good Luck!
> 
>  I'm trying to batch process contents of directories recursively.
> This part was not in what I supplied here because I thought it would
> just confuse things.

Thats a fine goal.

>  I would actually like to know what was wrong with what I wrote. 

It's unlikely that anyone can tell you, as File::Find already
does what you want to do.

> Besides the File::Find does not accomplish what I need.  

Certainly it does.

Observe:

#!/usr/local/bin/perl -w
use strict;
use File::Find;

sub batch{
    my $directory = shift;
    print qq{Doing something interesting with $directory\n};
}

find( sub { batch($File::Find::name) if -d} , '.');

Larry Rosler will be along shortly, and turn this into a 
one liner.  :)

> I have already searched cpan for directory traversing modules and was
> unsuccessful.

Thats because File::Find ships with the core distribution.  Not only is
it a nice wheel, it's standard equipment. 

-- 
"Civilization rests on two things: the discovery that fermentation 
produces alcohol, and the voluntary ability to inhibit defecation.  
And I put it to you, where would this splendid civilization be without 
both?" --Robertson Davies "The Rebel Angels" 


------------------------------

Date: Wed, 18 Oct 2000 15:49:18 -0400
From: </michael>
Subject: Re: Perl not functioning in practice as it should in theory.  - test.pl (0/1)
Message-Id: <m6vrus4if6rcjdbubrnp373156ll58lmgd@4ax.com>

On 18 Oct 2000 18:56:07 GMT, ansok@alumni.caltech.edu (Gary E. Ansok)
wrote:

>In article <nqlrusc47vc1109qd4tea5qno18sk1nq6n@4ax.com>,  </michael> wrote:
>>Please look at this script.  It should find every sub directory
>>recursively but stops for some reason.  Id anyone could figure this
>>out I would greatly appreciate it.  
>>
>>
>>#!/usr/bin/perl
>>
>>@directory = ('/home/users/michael');
>>
>>sub openDir {
>>
>>   my ($ImageDir) = @_;
>>
>>   opendir(LS,$ImageDir);
>>      @file = readdir(LS);
>>   closedir(LS);
>>
>>   foreach $file (@file) {
>>      if ((-d $file)&&(!($file =~ /\./))) {
>>         push(@directory,"$ImageDir/$file");
>>         print "   Adding: $ImageDir/$file\n";
>>      }
>>   }
>>}
>>
>>while (@directory) {
>>   print "Searching: $directory[0]\n";
>>   openDir($directory[0]);
>>   shift(@directory);
>>}
>
>Remember that readdir() only returns the bare file name, so $file
>will only contain the bare filename -- probably you want
>if ((-d "$ImageDir/$file")...
>
>That said, here are some miscellaneous comments:
>
>1)  -w and "use strict" are *highly* recommended.
>
>2)  Checking the results of opendir() and printing an error message
>    (including the dir name and $!) is highly recommended.
>
>3)  Do you mean to skip any directory name that contains a "."?
>    You may know that for your specific data set, none will, but
>    in general directory names can contain "." (even start with ".").
>    You may want to just skip "." and ".." explicitly.
>
>4)  Are you sure File::Find isn't suitable for your needs?  A simple
>    call like
>
>  find sub { push @directory, $File::Find::name if -d && !/\./; }, $topdir;
>
>    will do almost exactly what you have above (ordering being the
>    main difference).  It also has several options regarding handling
>    of symbolic links (which can put loops in the dirtree).
>
>You didn't give any details regarding what your requirements are,
>so what you're doing with regard to my comments 3 and 4 may well work
>fine for you (on your data as it is now).  I'm giving suggestions
>that I think would be helpful to most people who start writing code
>similar to what you've presented.
>
>-- Gary Ansok

Thank you.  I appreciate the help a lot.  I've got a digital camera &
I download the images to the webserver.  I use imagemagik to create
thumbnails & a php script do display the images.   Cool huh

This made it all possible. 

michael


------------------------------

Date: 18 Oct 2000 13:54:20 -0500
From: Ren Maddox <ren.maddox@tivoli.com>
Subject: Re: Perl not functioning in practice as it should in theory.  - test.pl (0/1)
Message-Id: <m3d7gykmjn.fsf@dhcp11-177.support.tivoli.com>

</michael> writes:

> Please look at this script.  It should find every sub directory
> recursively but stops for some reason.  Id anyone could figure this
> out I would greatly appreciate it.  
> 
> 
> #!/usr/bin/perl
> 
> @directory = ('/home/users/michael');
> 
> sub openDir {
> 
>    my ($ImageDir) = @_;
> 
>    opendir(LS,$ImageDir);
>       @file = readdir(LS);

Bear in mind that readdir returns only the filenames, not their full
path.  This could bite you later...

>    closedir(LS);
> 
>    foreach $file (@file) {
>       if ((-d $file)&&(!($file =~ /\./))) {

 ...and so it did.  That '-d $file' test isn't going to work.  You want
'-d "$imageDir/$file"' instead.  See "perldoc -f readdir" -- it has an
explicit warning about this exact problem.

>          push(@directory,"$ImageDir/$file");
>          print "   Adding: $ImageDir/$file\n";
>       }
>    }
> }
> 
> while (@directory) {
>    print "Searching: $directory[0]\n";
>    openDir($directory[0]);
>    shift(@directory);

Minor issue, and certainly not your problem, but if you're going to
shift anyway, you might as well use the results in the call to
openDir:

     openDir(shift @directory);

> }

I believe the problem with readdir and -d is what you are tripping
over, but I've read some of the other responses and would like to
point out a couple of things.

First, you really should "use strict" and use lexical variables.
However, one poster assumed you were using recursion, which would have
really been a problem, but you aren't.  Still, it is a good habit to
get into as soon as possible ("use strict", that is).

Second, this really does seem like a task that could be accomplished
with File::Find.  Often, when people first look at File::Find they do
not realize how powerful it really is.  I suggest you take a second
look, and start from the position that it probably *will* do what you
want (rather than just assuming that it will not).  I don't guarantee
that it will work for you, but even after reading your response about
File::Find, it still sounds like it will do what you want.

-- 
Ren Maddox
ren@tivoli.com


------------------------------

Date: Wed, 18 Oct 2000 12:40:32 -0700
From: Jeff Zucker <jeff@vpservices.com>
Subject: Re: Perl not functioning in practice as it should in theory.  - test.pl  (0/1)
Message-Id: <39EDFCB0.DCABBC04@vpservices.com>


Well this is totally unhelpful to your problem but your subject line
gives me an excuse to post one of my favorite quotes, anyone know its
source?

  In theory practice and theory are the same, but in practice they
aren't.

-- 
Jef


------------------------------

Date: Wed, 18 Oct 2000 13:39:20 -0500
From: Michael Carman <mjcarman@home.com>
Subject: Re: Perl not functioning in practice as it should in theory.  - test.pl  (0/1)
Message-Id: <39EDEE58.780DA47A@home.com>

/michael wrote:
> 
> Please look at this script.  It should find every sub directory
> recursively but stops for some reason.  Id anyone could figure this
> out I would greatly appreciate it.

[snip]

You actually have several problems:
1) No -w, no 'use strict' These would give you all sorts of useful
   diagnostic messages when you make common programming errors.
2) Recursive functions generally call themselves. Your method
   destroys your directory listing even as you're building it.
   Seems a bit odd to me...
3) You aren't checking whether or not opendir() was successful.
4) You're testing "-d $file" in the current directory, not in 
   the directory you just read.
5) You skip any directory entry with a dot in the name. '.' and '..'
   are not the only ones that have dots in them. 'foo.bar' is
   a perfectly reasonable name for a directory.
6) The File::Find module can do all this for you.

HTH
-mjc


------------------------------

Date: Wed, 18 Oct 2000 14:19:04 -0500
From: Michael Carman <mjcarman@home.com>
Subject: Re: Perl not functioning in practice as it should in theory.  - test.pl  (0/1)
Message-Id: <39EDF7A8.C1424D54@home.com>

/michael wrote:
> 
> Besides the File::Find does not accomplish what I need.

What makes you so sure?

#!/usr/local/bin/perl -w
use strict;
use File::Find;

find(\&wanted, '/home/users/michael');

sub wanted {
    if (-d) {
        print "Processing $File::Find::dir/$_\n";
        # Do something
    }
}

-mjc


------------------------------

Date: Wed, 18 Oct 2000 13:35:45 -0700
From: "John W. Krahn" <krahnj@acm.org>
Subject: Re: Perl not functioning in practice as it should in theory.  - test.pl  (0/1)
Message-Id: <39EE09A1.274A6593@acm.org>

Jeff Zucker wrote:
> 
> Well this is totally unhelpful to your problem but your subject line
> gives me an excuse to post one of my favorite quotes, anyone know its
> source?
> 
>   In theory practice and theory are the same, but in practice they
> aren't.


From Bruce Schneier's new book Secrets & Lies:
"Yogi Berra once said, "In theory there is no difference between theory
and practice. In practice there is.""

HTH

John


------------------------------

Date: Wed, 18 Oct 2000 15:27:33 -0400
From: Jeff Pinyan <jeffp@crusoe.net>
Subject: Re: Perl not functioning in practice as it should in theory.  - test.pl (0/1)
Message-Id: <Pine.GSO.4.21.0010181526390.25707-100000@crusoe.crusoe.net>

On Oct 18, /michael said:

>   foreach $file (@file) {
>      if ((-d $file)&&(!($file =~ /\./))) {
>         push(@directory,"$ImageDir/$file");
>         print "   Adding: $ImageDir/$file\n";
>      }
>   }

Have you asked yourself why you have to push "$ImageDir/$file" to the
array, and yet you are only doing file tests on $file?  Could it be
because readdir() just returns the NAMES of the directory entries, and the
PATHS to them?  (Yes, it could.)

-- 
Jeff "japhy" Pinyan     japhy@pobox.com     http://www.pobox.com/~japhy/
PerlMonth - An Online Perl Magazine            http://www.perlmonth.com/
The Perl Archive - Articles, Forums, etc.    http://www.perlarchive.com/
CPAN - #1 Perl Resource  (my id:  PINYAN)        http://search.cpan.org/





------------------------------

Date: Thu, 19 Oct 2000 10:03:38 +1300
From: "Peter Sundstrom" <peter.sundstrom@eds.com>
Subject: Re: Perl question - Backup and email a file?
Message-Id: <8sl3e1$680$1@hermes.nz.eds.com>


John MacLeod <john@macleodweb.com> wrote in message
news:8skeld02akh@enews4.newsguy.com...
> I can't figure out how to do this using a Perl script. Could someone
please
> help me out?
>
> I need to...
>
> 1. Backup a txt file (formresults.txt).
> 2. Email the formresults.txt file to an external email address
> (client@hisdomain.com)
>
> The file is located at...
> /usr/www/users/myaccount/client/formresults.txt
>
> Once I have the script figured out I want to set up a cron job to backup
the
> file and email once a day.

You've already posted the same question to this newsgroup today.  Once is
enough.




------------------------------

Date: Wed, 18 Oct 2000 20:32:49 GMT
From: rosenb_m@my-deja.com
Subject: Perl vs C on server side
Message-Id: <8sl1dh$ffb$1@nnrp1.deja.com>

Diferent languages for diferent tasks, that's
true. The most important advantages of perl are
the high level programming (less coding time) and
string manipulation. One of it's disadvantages is
speed.

I don't have statics comparing speed between tasks
written in C and perl, but, it's often said that:
"the little speed gain that C provides it's too
expensive compared to the easy-coding that perl
provides".

So the question. I've been looking a lot, but if
anyway it's a stupid question, sorry.

¿Why every server, for whatever it's used, is
programmed in C? Say ircd, apache, ftpd, telnetd,
etc, etc.

Thanks!


Sent via Deja.com http://www.deja.com/
Before you buy.


------------------------------

Date: Wed, 18 Oct 2000 21:08:40 GMT
From: Uri Guttman <uri@sysarch.com>
Subject: Re: Perl vs C on server side
Message-Id: <x766mpsvqf.fsf@home.sysarch.com>

>>>>> "rm" == rosenb m <rosenb_m@my-deja.com> writes:

  rm> I don't have statics comparing speed between tasks
  rm> written in C and perl, but, it's often said that:
  rm> "the little speed gain that C provides it's too
  rm> expensive compared to the easy-coding that perl
  rm> provides".

  rm> programmed in C? Say ircd, apache, ftpd, telnetd,
  rm> etc, etc.

because that is one area where speed makes a difference. the faster and
more efficient a server is, the more clients and requests it can handle.
and that speed also lowers the cost of the needed hardware.

but there are plenty of smaller servers written in perl for which speed
is not a major issue but simplicity or ease of coding are. those can be
done in perl and i would never think about doing them in c.

BTW this is from someone who has code many client/server systems in both
c and perl. each has its strengths and weaknesses.

uri

-- 
Uri Guttman  ---------  uri@sysarch.com  ----------  http://www.sysarch.com
SYStems ARCHitecture, Software Engineering, Perl, Internet, UNIX Consulting
The Perl Books Page  -----------  http://www.sysarch.com/cgi-bin/perl_books
The Best Search Engine on the Net  ----------  http://www.northernlight.com


------------------------------

Date: Wed, 18 Oct 2000 18:40:38 GMT
From: mcafee@waits.facilities.med.umich.edu (Sean McAfee)
Subject: Problem with locale and \s
Message-Id: <G8mH5.7508$O5.157616@news.itd.umich.edu>

In article <th3dhuowta.fsf@lautaret.grenoble.xrce.xerox.com>,
Julien Quint  <julien.quint@xrce.xerox.com> wrote:
>I encountered a problem with the locale pragma. I needed to sort text in
>French in alphabetical order, so I used the locale pragma and sorting works
>just fine. However, I have a small function that pretty-prints my text which
>suffers from locale. I discovered that the character of code 0xa0, i.e. non-
>breaking space, was matched by \s which broke my formatting function.

>For instance: in French, a colon must be preceded by a non-breaking space.
>"Par exemple : en franc,ais..." (I typed a regular space so that my post
>remains in the ASCII domain). We use a non-breaking space so that we don't
>end up with something like

>	       ... Par exemple
>	: en francais ...

>but since perl considers the non-breaking space character to be a normal
>space character, this is what I end up with anyway. Grrr...

What you want is a character class that matches any whitespace *except* a
non-breaking space character, namely: [^\S\xa0].  For example:

$text = "Par exemple\xa0: en franc,ais...";
@words = split /[^\S\xa0]+/, $text;

>I quickly solved the problem by having my 'use locale;' line *after* having
>declared the formatting function (and *before* the code that needs it) but
>this is not satisfying.

Another option is to turn off locale-sensitive regexen with "no locale"
just for the code that needs it:

# start of program
use locale;
# ...
{ no locale; @words = split /\s+/, @words; }

I think the character-class solution above is cleaner, though.

-- 
Sean McAfee                                                mcafee@umich.edu
print eval eval eval eval eval eval eval eval eval eval eval eval eval eval
q!q@q#q$q%q^q&q*q-q=q+q|q~q:q? Just Another Perl Hacker ?:~|+=-*&^%$#@!


------------------------------

Date: Wed, 18 Oct 2000 19:34:23 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: Problem with locale and \s
Message-Id: <6qurus8lpdbrer7c9dl7blddr5fq1il59h@4ax.com>

Julien Quint wrote:

>However, I have a small function that pretty-prints my text which
>suffers from locale. I discovered that the character of code 0xa0, i.e. non-
>breaking space, was matched by \s which broke my formatting function.

Then don't use \s. Instead, use [\r\n\t ], for example.

-- 
	Bart.


------------------------------

Date: Wed, 18 Oct 2000 17:57:16 GMT
From: mrbigsecret@my-deja.com
Subject: Re: problems with open2 use in cgi
Message-Id: <8sko9n$77k$1@nnrp1.deja.com>

In article <8sitvs$kbgi9$2@ID-24002.news.cis.dfn.de>,
  news@tinita.de wrote:
> it works if you add $|=1; at the beginning of your
> script. but i don't know why. the doc says that
> open2 sets autoflush on the write handle, but i
> don't know why that makes the script print
> out the lines twice.
> anyone else?

Dang perl buffering. I'd still be curious why this is happening, but
I'm glad that it works.

Thanks!



Sent via Deja.com http://www.deja.com/
Before you buy.


------------------------------

Date: Wed, 18 Oct 2000 18:11:54 GMT
From: jerome@activeindexing.com (Jerome O'Neil)
Subject: Re: Program design
Message-Id: <KJlH5.113$wM1.65338@news.uswest.net>

Anders Lund <anders@wall.alweb.dk> elucidates:

>> Is there any way to force perl to force the user to use correct oop
>> "rules"? So perl behaves more like java and throws an error when you
>> access another classes private data, etc?
> 
> You should spend some money on books, visit http://perl.oreilly.com or 
> http://www.amazon.com and look around for some

Also, I would highly reccomend McConnel's "Code Complete", and K&P's 
"The Practice of Programming" specificaly.

-- 
"Civilization rests on two things: the discovery that fermentation 
produces alcohol, and the voluntary ability to inhibit defecation.  
And I put it to you, where would this splendid civilization be without 
both?" --Robertson Davies "The Rebel Angels" 


------------------------------

Date: Wed, 18 Oct 2000 18:10:13 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: question
Message-Id: <rsprus00lc4fa8p21br11k1o6p7mban6q4@4ax.com>

Bart Lateur wrote:

> I'll try to retype the English name from memory:
>
>	$INPU_LINENUMBER
>
>Did I get it right? No.

Oops. Even if this was valid English, it'd still be wrong. Which was my
point.  :-)

-- 
	Bart.


------------------------------

Date: 18 Oct 2000 16:21:46 -0400
From: Joe Schaefer <joe+usenet@sunstarsys.com>
Subject: Re: question
Message-Id: <m3u2a9q4rp.fsf@mumonkan.sunstarsys.com>

Bart Lateur <bart.lateur@skynet.be> writes:

> Bart Lateur wrote:
> 
> > I'll try to retype the English name from memory:
> >
> >	$INPU_LINENUMBER
> >
> >Did I get it right? No.
> 
> Oops. Even if this was valid English, it'd still be wrong. Which was my
> point.  :-)
> 
> -- 
> 	Bart.

I think perl offers a "shortcut" for people 
like you :)

-- 
Joe Schaefer


------------------------------

Date: Wed, 18 Oct 2000 18:58:35 GMT
From: nodo70@my-deja.com
Subject: regex substitute
Message-Id: <8skrsl$ahn$1@nnrp1.deja.com>

Can anyone help me with this perl script?  I appreciate your help.
#!/usr/local/bin/perl

$line = "Last modified: October 23, 1999 </p><image>";
$month = "October";
$day   = "18";
$year  = "2000";

$line =~ s/(Last modified:)\s+(\S+)\s+(\S+)\s+(\S+)((\s+<\/\S+) | (<\/
\S+))/$1 $month $day $year $5/g;
print "$line\n";

It works fine with $line up there but once I change $line to:
$line = "Last modified: October 23, 1999</p><image>";

then it won't work.  Please help.  Thanks.


Sent via Deja.com http://www.deja.com/
Before you buy.


------------------------------

Date: 18 Oct 2000 20:44:39 GMT
From: Tina Mueller <tina@streetmail.com>
Subject: Re: regex substitute
Message-Id: <8sl23n$kn9mq$2@ID-24002.news.cis.dfn.de>

hi,
In comp.lang.perl.misc nodo70@my-deja.com wrote:
> Can anyone help me with this perl script?  I appreciate your help.
> #!/usr/local/bin/perl

> $line = "Last modified: October 23, 1999 </p><image>";
> $month = "October";
> $day   = "18";
> $year  = "2000";

> $line =~ s/(Last modified:)\s+(\S+)\s+(\S+)\s+(\S+)((\s+<\/\S+) | (<\/
> \S+))/$1 $month $day $year $5/g;
> print "$line\n";

> It works fine with $line up there but once I change $line to:
> $line = "Last modified: October 23, 1999</p><image>";

hm, i wonder who set up this regex. obviously
not you. if you leave out that space, you have to
tell the regex to match 0 or more spaces (with a star *).
a "+" matches one or more spaces.
> $line =~ s/(Last modified:)\s+(\S+)\s+(\S+)\s+(\S+)((\s+<\/\S+) | (<\/
                                                        ^^^       ^^^


-- 
http://tinita.de    \  enter__| |__the___ _ _ ___
tina's moviedatabase \     / _` / _ \/ _ \ '_(_-< of
search & add comments \    \__,_\___/\___/_| /__/ perception
please don't email unless offtopic or followup is set. thanx


------------------------------

Date: 18 Oct 2000 20:45:24 GMT
From: Tina Mueller <tina@streetmail.com>
Subject: Re: regex substitute
Message-Id: <8sl254$kn9mq$3@ID-24002.news.cis.dfn.de>

hi,
In comp.lang.perl.misc nodo70@my-deja.com wrote:
> Can anyone help me with this perl script?  I appreciate your help.

oh and I forgot:
read
perldoc perlre

tina

-- 
http://tinita.de    \  enter__| |__the___ _ _ ___
tina's moviedatabase \     / _` / _ \/ _ \ '_(_-< of
search & add comments \    \__,_\___/\___/_| /__/ perception
please don't email unless offtopic or followup is set. thanx


------------------------------

Date: 16 Sep 99 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 16 Sep 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.  

| NOTE: The mail to news gateway, and thus the ability to submit articles
| through this service to the newsgroup, has been removed. I do not have
| time to individually vet each article to make sure that someone isn't
| abusing the service, and I no longer have any desire to waste my time
| dealing with the campus admins when some fool complains to them about an
| article that has come through the gateway instead of complaining
| to the source.

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 V9 Issue 4655
**************************************


home help back first fref pref prev next nref lref last post