[25943] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 8162 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Jun 10 14:05:21 2005

Date: Fri, 10 Jun 2005 11:05:06 -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           Fri, 10 Jun 2005     Volume: 10 Number: 8162

Today's topics:
    Re: chown recursively <tadmc@augustmail.com>
    Re: chown recursively <tim@vegeta.ath.cx>
        com port <jdieter@nospam.carlnet.org>
    Re: com port <josef.moellers@fujitsu-siemens.com>
    Re: Fibonacci string <noneedto@email.me>
    Re: Masking by columns for grep <nobull@mail.com>
    Re: newbie regexp question: how to extract just the fil axel@white-eagle.invalid.uk
    Re: newbie regexp question: how to extract just the fil <amheiserbush@yahoo.com.au>
    Re: newbie regexp question: how to extract just the fil <my.address@is.chris.at.lowth.dot.com>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Thu, 9 Jun 2005 23:35:53 -0500
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: chown recursively
Message-Id: <slrndai659.8cd.tadmc@magna.augustmail.com>

Tim O'Donovan <timodonovan@localhost.com> wrote:

> From now on 
> I'll be replacing 'shell outs' with the appropriate Perl, where applicable.

> open(FIND, "find $path -lname '/home/$username/*' |");


Pipe opens *are* "shelling out".


> to find all the symbolic links in the given path to files in a users 
> home directory is also not the most resourceful method?!
> 
> I have some rethinking to do...  :)


And some reading:

   perldoc File::Find

   perldoc -f -X


-- 
    Tad McClellan                          SGML consulting
    tadmc@augustmail.com                   Perl programming
    Fort Worth, Texas


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

Date: Fri, 10 Jun 2005 16:32:47 GMT
From: Tim Hammerquist <tim@vegeta.ath.cx>
Subject: Re: chown recursively
Message-Id: <slrndajg4c.mt.tim@vegeta.saiyix>

Jürgen Exner <jurgenex@hotmail.com> wrote:
> Where do you find chown on a Windows PC, on a Mac, or a any of the dozen and 
> dozen OSs that are supported by Perl?

kotoko:~>% uname -a
Darwin kotoko 8.1.0 Darwin Kernel Version 8.1.0: Tue May 10 18:16:08
PDT 2005; root:xnu-792.1.5.obj~4/RELEASE_PPC Power Macintosh powerpc
kotoko:~>% which chown
/usr/sbin/chown

Of course, that's only Mac OS X (>= 10).

The point still stands.  Native Perl functions should be used whenever
possible and appropriate to maintain portability.

For example, if you decide to shell out to an external chown(1) command,
it will work on Linux, *BSD, Solaris, and even Mac OS X, and several
others... but fail on Win32.  Whereas if you used Perl's chown(), the
unimplemented function will return true and your script can continue as
normal.

Tim Hammerquist
-- 
With a PC, I always felt limited by the software available.
On Unix, I am limited only by my knowledge. 
    -- Peter J. Schoenster 


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

Date: Fri, 10 Jun 2005 08:49:21 -0500
From: "Jeff Dieterle" <jdieter@nospam.carlnet.org>
Subject: com port
Message-Id: <11aj6j3gpbtiq01@corp.supernews.com>

How does Perl address the serial com port when running on Win98 ?  Can't 
find anything about it in the doc's 




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

Date: Fri, 10 Jun 2005 16:27:31 +0200
From: Josef Moellers <josef.moellers@fujitsu-siemens.com>
Subject: Re: com port
Message-Id: <d8c7o8$m03$1@nntp.fujitsu-siemens.com>

Jeff Dieterle wrote:
> How does Perl address the serial com port when running on Win98 ?  Can'=
t=20
> find anything about it in the doc's=20

I use Win32::SerialPort, available from your nearest CPAN mirror.
--=20
Josef M=F6llers (Pinguinpfleger bei FSC)
	If failure had no penalty success would not be a prize
						-- T.  Pratchett



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

Date: Fri, 10 Jun 2005 08:42:22 -0400
From: Tom Bates <noneedto@email.me>
Subject: Re: Fibonacci string
Message-Id: <ch2ja199t7go42n0prh3bqeqld0knfe87o@4ax.com>

I think I know perl pretty well, but I have to carefully study most of
these alternatives to see how they work! You guys are amazing!

Tom


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

Date: Fri, 10 Jun 2005 17:48:30 +0100
From: Brian McCauley <nobull@mail.com>
Subject: Re: Masking by columns for grep
Message-Id: <d8cg93$k7q$1@redhat2.bham.ac.uk>



Jim Gibson wrote:
> In article <42a7cd2b_2@news1.prserv.net>, Shannon Jacobs
> <shanen@cashette.com> wrote:
> 
> 
>>Shannon Jacobs wrote:
>><snip> 
>>
>>>@foo = grep(/.{50}$theString.{6},@foo);
>>
>>Should be:
>>
>>@foo = grep(/.{50}$theString.{6}/,@foo);
>>
> 
> 
> If you really want to ignore the first 50 columns and ignore the last
> 6, you should anchor your pattern:
> 
>    @foo = grep(/^.{50}$theString.{6}$/,@foo);

Actually sinde the OP stated fixed length records you can ignore the 
last 6 by, er, simply ignoring them.

     @foo = grep(/^.{50}\Q$theString/,@foo);

(Note: \Q inserted as per other branch of this thread as $theString is a 
target string not a target regex).



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

Date: Fri, 10 Jun 2005 10:33:57 GMT
From: axel@white-eagle.invalid.uk
Subject: Re: newbie regexp question: how to extract just the filename from a canonical file/pathname
Message-Id: <p0eqe.22787$bl3.9466@fe1.news.blueyonder.co.uk>

James Calivar <amheiserbush@yahoo.com.au> wrote:
> I've been trying to figure out how to use the regular expressions in Perl to 
> strip the leading path name information from a "canonical" path/filename and 
> just leave me with the filename.  For example, if I have C:/Program 
> Files/Microsoft Office Tools/excel.exe, I would like to extract just 
> "excel.exe".
 
> I've tried stuff like /\/(.)+(.){3}/ but that matches the *first* forward 
> slash, not the last one.

Yes. Because that is what you are specifying in your RE. 

Essentially you are wanting to capture everything after the last '/'.
So, something like this:

    my $instr = "C:/Program Files/Microsoft Office Tools/excel.exe";
    $instr =~ m#([^/]*)$#;	
    print $1;

yields

   excel.exe

(and an empty string is the file/pathname ends in '/').

However this will not work with a path/filename that has a drive letter but
no directory separators (e.e. 'C:foo.bar').

Axel



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

Date: Fri, 10 Jun 2005 08:39:04 -0400
From: "James Calivar" <amheiserbush@yahoo.com.au>
Subject: Re: newbie regexp question: how to extract just the filename from a canonical file/pathname
Message-Id: <d8c1l8$hl3$1@home.itg.ti.com>

<axel@white-eagle.invalid.uk> wrote in message
news:p0eqe.22787$bl3.9466@fe1.news.blueyonder.co.uk...
> James Calivar <amheiserbush@yahoo.com.au> wrote:
> > I've been trying to figure out how to use the regular expressions in
Perl to
> > strip the leading path name information from a "canonical" path/filename
and
> > just leave me with the filename.  For example, if I have C:/Program
> > Files/Microsoft Office Tools/excel.exe, I would like to extract just
> > "excel.exe".
>
> > I've tried stuff like /\/(.)+(.){3}/ but that matches the *first*
forward
> > slash, not the last one.
>
> Yes. Because that is what you are specifying in your RE.
>
> Essentially you are wanting to capture everything after the last '/'.
> So, something like this:
>
>     my $instr = "C:/Program Files/Microsoft Office Tools/excel.exe";
>     $instr =~ m#([^/]*)$#;
>     print $1;
>
> yields
>
>    excel.exe
>
> (and an empty string is the file/pathname ends in '/').
>
> However this will not work with a path/filename that has a drive letter
but
> no directory separators (e.e. 'C:foo.bar').
>

Ah, gotcha!  My interpretation of the regular expression you gave is (hope
this is right): "Anything that is not a forward slash, repeated zero or more
times, rooted to the end-of-line".

Thanks

James
> Axel
>




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

Date: Fri, 10 Jun 2005 17:07:22 GMT
From: Wolfman's Brother <my.address@is.chris.at.lowth.dot.com>
Subject: Re: newbie regexp question: how to extract just the filename from a canonical file/pathname
Message-Id: <eNjqe.5391$q46.1586@newsfe1-win.ntli.net>

axel@white-eagle.invalid.uk wrote:

> James Calivar <amheiserbush@yahoo.com.au> wrote:
> 
>     my $instr = "C:/Program Files/Microsoft Office Tools/excel.exe";
>     $instr =~ m#([^/]*)$#;	
>     print $1;
> 
> yields
> 
>    excel.exe
> 
> (and an empty string is the file/pathname ends in '/').
> 
> However this will not work with a path/filename that has a drive letter but
> no directory separators (e.e. 'C:foo.bar').

To handle the ":", just add ":" to the pattern.

$instr =~ m#([^/:]*)$#;

But *this* doesnt handle the case of backslashes instead of forward 
(windows allows both), so try..

$instr =~ m#([^/:\\]*)$#;

Chris

--
http://www.lowth.com/rope - Scripting linux's iptables/netfilter.


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

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 8162
***************************************


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