[30165] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 1408 Volume: 11

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Mar 31 09:09:44 2008

Date: Mon, 31 Mar 2008 06:09:07 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Mon, 31 Mar 2008     Volume: 11 Number: 1408

Today's topics:
    Re: empty variables - getting rid of "uninitialized val <joe@inwap.com>
    Re: empty variables - getting rid of "uninitialized val <Peter@PSDT.com>
        new CPAN modules on Mon Mar 31 2008 (Randal Schwartz)
    Re: NIC Configurations <ThomasKratz@REMOVEwebCAPS.de>
    Re: Parse x.500 DN  and change order  displayed <uri@stemsystems.com>
    Re: Parse x.500 DN  and change order  displayed <h.b.furuseth@usit.uio.no>
    Re: printf: zero pad after the decimal a given amount <someone@example.com>
    Re: printf: zero pad after the decimal a given amount <szrRE@szromanMO.comVE>
    Re: Sharing a DBI::Mysql database connection with your  <hjp-usenet2@hjp.at>
    Re: Sharing a DBI::Mysql database connection with your  <devnull4711@web.de>
    Re: Timer/Stopwatch <RedGrittyBrick@SpamWeary.foo>
    Re: Windows paths in glob <mitia2008.remove@gmail.com>
    Re: Windows paths in glob <mitia2008.remove@gmail.com>
    Re: Windows paths in glob <mitia2008.remove@gmail.com>
    Re: Windows paths in glob <szrRE@szromanMO.comVE>
    Re: Windows paths in glob <joe@inwap.com>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Mon, 31 Mar 2008 01:14:21 -0700
From: Joe Smith <joe@inwap.com>
Subject: Re: empty variables - getting rid of "uninitialized value" warnings?
Message-Id: <H_adnZFV2sHDAG3anZ2dnUVZ_judnZ2d@comcast.com>

Tomasz Chmielewski wrote:
> use strict;
> use warnings;
>...
>     if ( $execargs[0] ne '' ) { ..... }

Whenever you are using warnings, you should never attempt to use
an array element without first testing that it is there.

    if (@execargs and $execargs[0] ne '') { ... }

	-Joe


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

Date: Mon, 31 Mar 2008 12:17:42 GMT
From: Peter Scott <Peter@PSDT.com>
Subject: Re: empty variables - getting rid of "uninitialized value" warnings?
Message-Id: <pan.2008.03.31.12.17.42.361877@PSDT.com>

On Mon, 31 Mar 2008 01:14:21 -0700, Joe Smith wrote:
> Tomasz Chmielewski wrote:
>> use strict;
>> use warnings;
>>...
>>     if ( $execargs[0] ne '' ) { ..... }
> 
> Whenever you are using warnings, you should never attempt to use
> an array element without first testing that it is there.
> 
>     if (@execargs and $execargs[0] ne '') { ... }

Not quite good enough.  The element could exist but be undef.

  if (defined $execargs[0] && $execargs[0] ne '') { ... }

-- 
Peter Scott
http://www.perlmedic.com/
http://www.perldebugged.com/



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

Date: Mon, 31 Mar 2008 04:42:20 GMT
From: merlyn@stonehenge.com (Randal Schwartz)
Subject: new CPAN modules on Mon Mar 31 2008
Message-Id: <JyKvqK.1FKt@zorch.sf-bay.org>

The following modules have recently been added to or updated in the
Comprehensive Perl Archive Network (CPAN).  You can install them using the
instructions in the 'perlmodinstall' page included with your Perl
distribution.

B-Utils-0.05_03
http://search.cpan.org/~smueller/B-Utils-0.05_03/
Helper functions for op tree manipulation 
----
BDB-1.44
http://search.cpan.org/~mlehmann/BDB-1.44/
Asynchronous Berkeley DB access 
----
BDB-1.45
http://search.cpan.org/~mlehmann/BDB-1.45/
Asynchronous Berkeley DB access 
----
Cache-Memcached-libmemcached-0.02002
http://search.cpan.org/~dmaki/Cache-Memcached-libmemcached-0.02002/
Perl Interface to libmemcached 
----
Catalyst-Plugin-Acme-LOLCAT-0.03
http://search.cpan.org/~ashley/Catalyst-Plugin-Acme-LOLCAT-0.03/
IM IN UR CATALYST APLACASHUN REWRITIN YUR OUTPUTS. 
----
Catalyst-Plugin-Log-Colorful-0.11
http://search.cpan.org/~tomyhero/Catalyst-Plugin-Log-Colorful-0.11/
Catalyst Plugin for Colorful Log 
----
Crypt-ECDSA-0.060
http://search.cpan.org/~billh/Crypt-ECDSA-0.060/
Elliptical Cryptography Digital Signature Algorithm 
----
DBIx-Coro-0.00_01
http://search.cpan.org/~berle/DBIx-Coro-0.00_01/
Coroutine compatible DBI 
----
DBIx-Coro-0.00_02
http://search.cpan.org/~berle/DBIx-Coro-0.00_02/
Coroutine compatible DBI 
----
DBIx-Coro-0.00_03
http://search.cpan.org/~berle/DBIx-Coro-0.00_03/
Coroutine compatible DBI 
----
DBIx-Coro-0.00_04
http://search.cpan.org/~berle/DBIx-Coro-0.00_04/
Coroutine compatible DBI 
----
Devel-Backtrace-0.09
http://search.cpan.org/~pepe/Devel-Backtrace-0.09/
Object-oriented backtrace 
----
Devel-PartialDump-0.02
http://search.cpan.org/~nuffin/Devel-PartialDump-0.02/
Partial dumping of data structures, optimized for argument printing. 
----
Devel-StackTrace-1.17
http://search.cpan.org/~drolsky/Devel-StackTrace-1.17/
Stack trace and stack trace frame objects 
----
Device-Velleman-K8055-Fuse-0.2
http://search.cpan.org/~ronan/Device-Velleman-K8055-Fuse-0.2/
Communication with the Velleman K8055 USB experiment board using Fuse and K8055fs 
----
Device-Velleman-K8055-Fuse-0.3
http://search.cpan.org/~ronan/Device-Velleman-K8055-Fuse-0.3/
Communication with the Velleman K8055 USB experiment board using Fuse and K8055fs 
----
Egg-Release-3.08
http://search.cpan.org/~lushe/Egg-Release-3.08/
Version of Egg WEB Application Framework. 
----
Exception-Class-1.24
http://search.cpan.org/~drolsky/Exception-Class-1.24/
A module that allows you to declare real exception classes in Perl 
----
ExtUtils-Depends-0.300
http://search.cpan.org/~tsch/ExtUtils-Depends-0.300/
Easily build XS extensions that depend on XS extensions 
----
File-Assets-0.055
http://search.cpan.org/~rkrimen/File-Assets-0.055/
Manage .css and .js assets in a web application 
----
Games-Sudoku-CPSearch-0.03
http://search.cpan.org/~martyloo/Games-Sudoku-CPSearch-0.03/
A fast technique to solve Sudoku problems. 
----
Games-Sudoku-CPSearch-0.04
http://search.cpan.org/~martyloo/Games-Sudoku-CPSearch-0.04/
A fast technique to solve Sudoku problems. 
----
Glib-1.182
http://search.cpan.org/~tsch/Glib-1.182/
Perl wrappers for the GLib utility and Object libraries 
----
Graph-Easy-0.62
http://search.cpan.org/~tels/Graph-Easy-0.62/
Convert or render graphs (as ASCII, HTML, SVG or via Graphviz) 
----
Graph-Easy-As_svg-0.22
http://search.cpan.org/~tels/Graph-Easy-As_svg-0.22/
Output a Graph::Easy as Scalable Vector Graphics (SVG) 
----
Gtk2-1.182
http://search.cpan.org/~tsch/Gtk2-1.182/
Perl interface to the 2.x series of the Gimp Toolkit library 
----
IO-AIO-2.6
http://search.cpan.org/~mlehmann/IO-AIO-2.6/
Asynchronous Input/Output 
----
Image-Info-1.28
http://search.cpan.org/~tels/Image-Info-1.28/
Extract meta information from image files (DEPRECATED) 
----
Lingua-Jspell-1.50
http://search.cpan.org/~ambs/Lingua-Jspell-1.50/
Perl interface to the Jspell morphological analyser. 
----
MIME-Charset-1.004
http://search.cpan.org/~nezumi/MIME-Charset-1.004/
Charset Informations for MIME 
----
MIME-EncWords-1.009
http://search.cpan.org/~nezumi/MIME-EncWords-1.009/
deal with RFC 2047 encoded words (improved) 
----
MPEG-MP3Play-0.16
http://search.cpan.org/~jred/MPEG-MP3Play-0.16/
Perl extension for playing back MPEG music 
----
Mac-iTunes-Library-XML-0.01
http://search.cpan.org/~dinomite/Mac-iTunes-Library-XML-0.01/
Perl extension for parsing an iTunes XML library 
----
Net-MAC-1.3
http://search.cpan.org/~oliver/Net-MAC-1.3/
Perl extension for representing and manipulating MAC addresses 
----
Openvatar-URL-0.0.2
http://search.cpan.org/~gugod/Openvatar-URL-0.0.2/
Make URLs for Openvatars from an OpenID 
----
POE-Component-IRC-Plugin-BaseWrap-0.002
http://search.cpan.org/~zoffix/POE-Component-IRC-Plugin-BaseWrap-0.002/
base class for IRC plugins which need triggers/ban/root control 
----
POE-Component-IRC-Plugin-BaseWrap-0.003
http://search.cpan.org/~zoffix/POE-Component-IRC-Plugin-BaseWrap-0.003/
base class for IRC plugins which need triggers/ban/root control 
----
POE-Component-IRC-Plugin-BaseWrap-0.004
http://search.cpan.org/~zoffix/POE-Component-IRC-Plugin-BaseWrap-0.004/
base class for IRC plugins which need triggers/ban/root control 
----
POE-Component-IRC-Plugin-CSS-PropertyInfo-0.001
http://search.cpan.org/~zoffix/POE-Component-IRC-Plugin-CSS-PropertyInfo-0.001/
lookup CSS property information from IRC 
----
POE-Component-ResourcePool-0.03
http://search.cpan.org/~nuffin/POE-Component-ResourcePool-0.03/
Asynchronous generic resource management for POE based apps. 
----
POE-Component-WWW-Pastebin-Many-Retrieve-0.001
http://search.cpan.org/~zoffix/POE-Component-WWW-Pastebin-Many-Retrieve-0.001/
non-blocking wrapper around WWW::Pastebin::Many::Retrieve 
----
PPIx-Shorthand-v1.0.0
http://search.cpan.org/~elliotjs/PPIx-Shorthand-v1.0.0/
Translation of short names to PPI::Element classes. 
----
Parse-Marpa-0.205_008
http://search.cpan.org/~jkegl/Parse-Marpa-0.205_008/
(Alpha) Earley's algorithm with LR(0) precomputation 
----
Parse-Marpa-0.206000
http://search.cpan.org/~jkegl/Parse-Marpa-0.206000/
(Alpha) Earley's algorithm with LR(0) precomputation 
----
RPC-Serialized-0.0604
http://search.cpan.org/~oliver/RPC-Serialized-0.0604/
Subroutine calls over the network using common serialization 
----
Rinchi-DOM-0.01
http://search.cpan.org/~bmames/Rinchi-DOM-0.01/
DOM Interface. 
----
SOAP-WSDL-2.00_33
http://search.cpan.org/~mkutter/SOAP-WSDL-2.00_33/
SOAP with WSDL support 
----
SVG-Parser-1.03
http://search.cpan.org/~peterw/SVG-Parser-1.03/
XML Parser for SVG documents 
----
Search-Xapian-1.0.6.0
http://search.cpan.org/~olly/Search-Xapian-1.0.6.0/
Perl XS frontend to the Xapian C++ search library. 
----
Sub-AliasedUnderscore-0.02
http://search.cpan.org/~jrockway/Sub-AliasedUnderscore-0.02/
transform a subroutine that operates on $_ into one that operates on $_[0] 
----
Task-WWW-Pastebin-0.001
http://search.cpan.org/~zoffix/Task-WWW-Pastebin-0.001/
a bundle of WWW::Pastebin::* modules 
----
Text-SenseClusters-1.00
http://search.cpan.org/~tpederse/Text-SenseClusters-1.00/
Cluster similar contexts using co-occurrence matrices and Latent Semantic Analysis 
----
Text-Twiddler-0.0.1
http://search.cpan.org/~dmuey/Text-Twiddler-0.0.1/
Twiddle text for any type of output 
----
Verby-0.04
http://search.cpan.org/~nuffin/Verby-0.04/
A framework for compositing and sequencing steps of execution. 
----
Verby-Action-Template-0.04
http://search.cpan.org/~nuffin/Verby-Action-Template-0.04/
Action to process Template Toolkit files 
----
WWW-Pastebin-Many-Retrieve-0.001
http://search.cpan.org/~zoffix/WWW-Pastebin-Many-Retrieve-0.001/
retrieve pastes from many different pastebin sites 
----
YAML-Tiny-1.27
http://search.cpan.org/~adamk/YAML-Tiny-1.27/
Read/Write YAML files with as little code as possible 
----
perl-ldap-0.35
http://search.cpan.org/~gbarr/perl-ldap-0.35/


If you're an author of one of these modules, please submit a detailed
announcement to comp.lang.perl.announce, and we'll pass it along.

This message was generated by a Perl program described in my Linux
Magazine column, which can be found on-line (along with more than
200 other freely available past column articles) at
  http://www.stonehenge.com/merlyn/LinuxMag/col82.html

print "Just another Perl hacker," # the original

--
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!


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

Date: Mon, 31 Mar 2008 10:58:11 +0200
From: Thomas Kratz <ThomasKratz@REMOVEwebCAPS.de>
Subject: Re: NIC Configurations
Message-Id: <47f0a7a2$0$2601$bb690d87@news.main-rheiner.de>

Cosmic Cruizer wrote:

> Thanks Ron. It looks like Win32::IPConfig will do what I need.

If you are interested in the special NIC configuration (such as media 
speed etc.) you'll have to use WMI.

I can post a script if needed.

Thomas

-- 
$/=$,,$_=<DATA>,s,(.*),$1,see;__END__
s,^(.*\043),,mg,@_=map{[split'']}split;{#>J~.>_an~>>e~......>r~
$_=$_[$%][$"];y,<~>^,-++-,?{$/=--$|?'"':#..u.t.^.o.P.r.>ha~.e..
'%',s,(.),\$$/$1=1,,$;=$_}:/\w/?{y,_, ,,#..>s^~ht<._..._..c....
print}:y,.,,||last,,,,,,$_=$;;eval,redo}#.....>.e.r^.>l^..>k^.-


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

Date: Mon, 31 Mar 2008 04:09:07 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: Parse x.500 DN  and change order  displayed
Message-Id: <x7lk3z7cwt.fsf@mail.sysarch.com>

>>>>> "S" == SecureIT  <gotsecure@gmail.com> writes:

  S> I am trying to change this
  S> "cn=Bob Smith+serialNumber=CR013120080827,o=ICM,c=US"

  S> to this:

  S> "serialNumber=CR013120080827+cn=Bob Smith,o=ICM,c=US"

  S> There are about 2000 entries like this and I need to have them all
  S> displayed with serialNumber first, and cn last then the rest of the
  S> DN, the names and serialNumbers are all unique to each entry.

are all the entries separated by +? how many are there (you show only 2)?

if it is always + then you can just split the lines, grab out the cn one
(use grep) and also filter out the rest. then order them as you
want. call join '+' to rebuild the line. it can also be done with a hash
but that is about the same amount of code. 

uri

-- 
Uri Guttman  ------  uri@stemsystems.com  --------  http://www.sysarch.com --
-----  Perl Code Review , Architecture, Development, Training, Support ------
--------- Free Perl Training --- http://perlhunter.com/college.html ---------
---------  Gourmet Hot Cocoa Mix  ----  http://bestfriendscocoa.com ---------


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

Date: Mon, 31 Mar 2008 14:26:29 +0200
From: Hallvard B Furuseth <h.b.furuseth@usit.uio.no>
Subject: Re: Parse x.500 DN  and change order  displayed
Message-Id: <hbf.20080331qmls@bombur.uio.no>

SecureIT writes:
> I am trying to change this
> "cn=Bob Smith+serialNumber=CR013120080827,o=ICM,c=US"
> to this:
> "serialNumber=CR013120080827+cn=Bob Smith,o=ICM,c=US"

Without escape sequences like "\," and "\+" in the DNs (if that's
allowed anyway, I don't remember the details of X.500 Dn syntax), this
moves serialNumber first in each RDN:

s/(^|,)([^,]*)\+(serialNumber=[^+,]*)(?=[+,])/$1$3+$2/gi;
die "didn't catch all 'foo+serialNumber's" if /\+serialNumber=/i;

-- 
Hallvard


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

Date: Mon, 31 Mar 2008 05:24:00 GMT
From: "John W. Krahn" <someone@example.com>
Subject: Re: printf: zero pad after the decimal a given amount
Message-Id: <Qz_Hj.7167$pb5.579@edtnps89>

jidanni@jidanni.org wrote:
> Why is there no way to tell printf to zero pad like the right column:
> 0.1    :0.100
> 0.05   :0.050
> 0.03   :0.030
> 0.025  :0.025
> 0.02   :0.020
> 0.015  :0.015
> 0.0125 :0.0125
> 0.01   :0.010
> 0.009  :0.009
> 0.00625:0.00625
> 0.005  :0.005
> The challenge: Change only the "WHAT?" below to produce the right
> column above. Thanks.
> use constant S => 100000;
> for ( 10000, 5000, 3000, 2500, 2000, 1500, 1250, 1000, 900, 625, 500 ) {
>     printf "%-7g:WHAT?\n", $_ / S, $_ / S;
> }

$ perl -le'
use constant S => 100000;
my $x;
format =
@<<<<<< : @.#####
$x,       $x
 .
for ( 10000, 5000, 3000, 2500, 2000, 1500, 1250, 1000, 900, 625, 500 ) {
     $x = $_ / S;
     write;
}
'
0.1     : 0.10000
0.05    : 0.05000
0.03    : 0.03000
0.025   : 0.02500
0.02    : 0.02000
0.015   : 0.01500
0.0125  : 0.01250
0.01    : 0.01000
0.009   : 0.00900
0.00625 : 0.00625
0.005   : 0.00500



John
-- 
Perl isn't a toolbox, but a small machine shop where you
can special-order certain sorts of tools at low cost and
in short order.                            -- Larry Wall


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

Date: Mon, 31 Mar 2008 01:23:39 -0700
From: "szr" <szrRE@szromanMO.comVE>
Subject: Re: printf: zero pad after the decimal a given amount
Message-Id: <fsq72c02fod@news2.newsguy.com>

jidanni@jidanni.org wrote:
> Why is there no way to tell printf to zero pad like the right column:
> 0.1    :0.100
> 0.05   :0.050
> 0.03   :0.030
> 0.025  :0.025
> 0.02   :0.020
> 0.015  :0.015
> 0.0125 :0.0125
> 0.01   :0.010
> 0.009  :0.009
> 0.00625:0.00625
> 0.005  :0.005
> The challenge: Change only the "WHAT?" below to produce the right
> column above. Thanks.
> use constant S => 100000;
> for ( 10000, 5000, 3000, 2500, 2000, 1500, 1250, 1000, 900, 625, 500
>    ) { printf "%-7g:WHAT?\n", $_ / S, $_ / S;
> }

use constant S => 100000;
for ( 10000, 5000, 3000, 2500, 2000, 1500, 1250, 1000, 900, 625, 500 ) {
   printf "%-7g:%01d.%3.3s%s\n", $_ / S, int $_ / S,
      sprintf("%05d", $_),
      map { $_ ? $_ : '' } ($_ % 100) =~ m!^(\d+?)0*$!;
}

__OUTPUT__
0.1    :0.100
0.05   :0.050
0.03   :0.030
0.025  :0.025
0.02   :0.020
0.015  :0.015
0.0125 :0.0125
0.01   :0.010
0.009  :0.009
0.00625:0.00625
0.005  :0.005

:-)

-- 
szr 




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

Date: Mon, 31 Mar 2008 10:57:56 +0200
From: "Peter J. Holzer" <hjp-usenet2@hjp.at>
Subject: Re: Sharing a DBI::Mysql database connection with your children
Message-Id: <slrnfv19sk.6d6.hjp-usenet2@hrunkner.hjp.at>

On 2008-03-31 03:45, Andrew DeFaria <Andrew@DeFaria.com> wrote:
> I have a process I was thinking of making into a multithreaded daemon 
                                                   ^^^^^^^^^^^^^
> that deals with a MySQL database. The thought is that the daemon would 
> open the database once, then listen for clients. As clients connected 
> the daemon would fork off a copy of itself and handle the requests. This 
                   ^^^^
Do you want to use threads or fork?

> would make the process faster because I wouldn't need to open the 
> database every time a new client wanted service.

This cannot be done. Not only will the database server get a mixture of
requests from different database clients on the same connection (this
could be solved), but it also has to send back all replies via the same
connection: Which client will receive the response? There is no way to
determine that.

(There is at least one RDBMS where the client automatically opens a new
connection when it detects a pid change - presumably the new connection
will be pre-authenticated and faster to establish).

Your best bet is probably to use a pre-forked approach like some web
servers. Run a number of your your daemons in parallel, all listening on
the same port. A client connecting to that port will get any of them.
If all are busy, the client has to wait, or a controlling process can
start more worker processes.

	hp



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

Date: Mon, 31 Mar 2008 14:23:43 +0200
From: Frank Seitz <devnull4711@web.de>
Subject: Re: Sharing a DBI::Mysql database connection with your children
Message-Id: <65c3ehF2faasvU2@mid.individual.net>

Andrew DeFaria wrote:

> However, I've found that once I fork the database handle (obtained 
> through DBI) is no longer valid. Reading around a little bit I noticed 
> people saying to reopen or reconnect to the database in the child. Well 
> that's the very time consuming thing I was trying to avoid!

In my experience a connect to MySQL isn't time consuming.

Frank
-- 
Dipl.-Inform. Frank Seitz; http://www.fseitz.de/
Anwendungen für Ihr Internet und Intranet
Tel: 04103/180301; Fax: -02; Industriestr. 31, 22880 Wedel


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

Date: Mon, 31 Mar 2008 09:21:49 +0100
From: RedGrittyBrick <RedGrittyBrick@SpamWeary.foo>
Subject: Re: Timer/Stopwatch
Message-Id: <47f09f1f$0$10646$fa0fcedb@news.zen.co.uk>

Lamer wrote:
> How would I even begin to make a stopwatch with perl, cgi, and js?

I'd begin the same way I begin any project. Do some planning, break big 
problems down into many smaller problems until I have something I know 
how to do.

Maybe I'd start by thinking about what it would look like to the user. 
Will there be buttons labelled start and stop? Will there be a display 
of seconds elapsed? I'd ask myself whether the server should keep track 
of the seconds elapsed for each user or whether it might be better to do 
that part in Javascript.

-- 
RGB


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

Date: Mon, 31 Mar 2008 05:54:54 GMT
From: Dmitry <mitia2008.remove@gmail.com>
Subject: Re: Windows paths in glob
Message-Id: <Xns9A7264DC2409Fmitia2008gmailcom@140.99.99.130>

"John W. Krahn" <someone@example.com> wrote in
news:cGRHj.9264$9X3.7583@edtnps82: 

> Dmitry wrote:
>> OK, so there's a well-known difficulty with handling Windows-style
>> paths in glob: it doesn't like backslashes, nor does it like spaces. 
>> One solution to that is to use Unix-style paths: 
>> 
>> glob('C:\Documents and Settings\*'); # Doesn't work
>> glob('C:/Documents\ and\ Settings/*'); # Works
>> 
>> Problem is, the rest of Perl's built-in file-handling functionality
>> behaves the other way around.  For instance, with -d:
>> 
>> -d 'C:\Documents and Settings'; # Works
>> -d 'C:/Documents\ and\ Settings'; # Doesn't work
>> 
>> Question: is there any way to use the same path string with glob and
>> with the rest of Perl, without having to convert them back and forth?
> 
> perldoc File::DosGlob
> perldoc File::Spec
> perldoc File::Basename

I tried DosGlob, but when I passed it 'C:\Documents and Settings\*' it bugged out with an 
error somewhere in the module...


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

Date: Mon, 31 Mar 2008 05:58:49 GMT
From: Dmitry <mitia2008.remove@gmail.com>
Subject: Re: Windows paths in glob
Message-Id: <Xns9A726585B56E7mitia2008gmailcom@140.99.99.130>

Martijn Lievaart <m@rtij.nl.invlalid> wrote in news:pan.2008.03.30.19.27.16@rtij.nl.invlalid:

> On Sun, 30 Mar 2008 19:09:18 +0000, Dmitry wrote:
> 
>> OK, so there's a well-known difficulty with handling Windows-style paths
>> in glob: it doesn't like backslashes, nor does it like spaces.  One
>> solution to that is to use Unix-style paths:
>> 
>> glob('C:\Documents and Settings\*'); # Doesn't work glob('C:/Documents\
>> and\ Settings/*'); # Works
>> 
>> Problem is, the rest of Perl's built-in file-handling functionality
>> behaves the other way around. For instance, with -d:
>> 
>> -d 'C:\Documents and Settings'; # Works -d 'C:/Documents\ and\
>> Settings'; # Doesn't work
>> 
>> Question: is there any way to use the same path string with glob and
>> with the rest of Perl, without having to convert them back and forth?
> 
> I don't have Windows to test here, but I recall that using either a 
> forward slash '/' or a backward slash -- properly escaped -- '\\' works 
> either way in both situations.
> 
> In the examples you gave, the versions with backslashes cannot work, the 
> backslashes are not escaped.
> 
> M4

Spaces are a more serious problem than slashes.  But anyway, the examples work, 
because I used single quotes.  BTW, current core glob seems to ignore backslashes 
altogether, unless they escape something other than a backslash.


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

Date: Mon, 31 Mar 2008 06:09:33 GMT
From: Dmitry <mitia2008.remove@gmail.com>
Subject: Re: Windows paths in glob
Message-Id: <Xns9A726757D689Emitia2008gmailcom@140.99.99.130>

Gunnar Hjalmarsson <noreply@gunnar.cc> wrote in
news:65aa8vF2euim1U1@mid.individual.net: 

> Dmitry wrote:
>> OK, so there's a well-known difficulty with handling Windows-style
>> paths in glob: it doesn't like backslashes, nor does it like spaces. 
>> One solution to that is to use Unix-style paths: 
>> 
>> glob('C:\Documents and Settings\*'); # Doesn't work
>> glob('C:/Documents\ and\ Settings/*'); # Works
>> 
>> Problem is, the rest of Perl's built-in file-handling functionality
>> behaves the other way around.  For instance, with -d:
>> 
>> -d 'C:\Documents and Settings'; # Works
>> -d 'C:/Documents\ and\ Settings'; # Doesn't work
>> 
>> Question: is there any way to use the same path string with glob and
>> with the rest of Perl, without having to convert them back and forth?
> 
> A long time ago I decided to use opendir() and readdir() instead of 
> glob(). It may not be as 'elegant', but it works flawlessly without 
> escaping spaces.
> 

OK, thanks. I guess if I wanted to process wildcards in the file name, I would pass them 
through grep?


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

Date: Mon, 31 Mar 2008 00:16:27 -0700
From: "szr" <szrRE@szromanMO.comVE>
Subject: Re: Windows paths in glob
Message-Id: <fsq34c02ajb@news2.newsguy.com>

Dmitry wrote:
> OK, so there's a well-known difficulty with handling Windows-style
> paths in glob: it doesn't like backslashes, nor does it like spaces.
> One solution to that is to use Unix-style paths:
>
> glob('C:\Documents and Settings\*'); # Doesn't work
> glob('C:/Documents\ and\ Settings/*'); # Works
>
> Problem is, the rest of Perl's built-in file-handling functionality
> behaves the other way around. For instance, with -d:
>
> -d 'C:\Documents and Settings'; # Works
> -d 'C:/Documents\ and\ Settings'; # Doesn't work
>
> Question: is there any way to use the same path string with glob and
> with the rest of Perl, without having to convert them back and forth?

I find, just as in geenral under Win32, putting double quotes around the 
path gets around problems like this:

C:\>perl -e "my @d = glob('"""C:/Documents and Settings"""/*'); print 
qq{\n}, join(qq{\n}, @d), qq{\n};"

C:/Documents and Settings/Administrator
C:/Documents and Settings/All Users
[...]

*** Note that """, when used in a double quoted string, under the 
cmd.exe shell yields a literal ", so the glob statement is effectively:

   glob('"C:/Documents and Settings"/*');

*** This is only because the command was run from the command line; in 
an actual script you would of course use a normal double quote around 
the path (just like in the linux examples below.)


And this works for tests like -d as well:

C:\>perl -e "print int (-d """C:/Documents and Settings""")"
1
C:\>perl -e "print int (-d """C:/123Documents and Settings""")"
0


And this form works under linux as well:

$ perl -e 'my @d = glob(q{"/mnt/samba/win_hd/Documents and 
Settings"/*}); print qq{\n}, join(qq{\n}, @d), qq{\n};'

/mnt/samba/win_hd/Documents and Settings/Administrator
/mnt/samba/win_hd/Documents and Settings/All Users

$ perl -e 'print int (-d "/mnt/samba/win_hd/Documents and Settings")'
1
$ perl -e 'print int (-d "/mnt/samba/win_hd/123Documents and Settings")'
0

This was tested under ActivePerl 5.6.1 and 5.8.7, and under linux using 
5.10.0, 5.8.8, and 5.6.1.


So if you want to do it in a way that works on most platforms (at the 
very least windows and *nix),

1) Use a forward slash, not a back slash, as a path delimiter.
   I.E., C:/path to/somewhere/file.ext, and

2) Surround the path with quotes.
   I.E., "C:/path to/somewhere/a long filename.ext", or
         "C:/path to/somewhere"/file.ext, or
         "C:/Documents and Settings/"

and you should be fine.

Hope this helps.

-- 
szr 




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

Date: Mon, 31 Mar 2008 00:52:56 -0700
From: Joe Smith <joe@inwap.com>
Subject: Re: Windows paths in glob
Message-Id: <n7idnTBmQLXFBW3anZ2dnUVZ_tHinZ2d@comcast.com>

Dmitry wrote:

> OK, thanks. I guess if I wanted to process wildcards in the file name, I would pass them 
> through grep?

Yes, after converting wildcard characters into regex characters, of course.


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

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 V11 Issue 1408
***************************************


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