[31749] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 3012 Volume: 11

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Jul 1 00:14:54 2010

Date: Wed, 30 Jun 2010 21:14:22 -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           Wed, 30 Jun 2010     Volume: 11 Number: 3012

Today's topics:
    Re: Parsing file names with spaces <uri@StemSystems.com>
    Re: Parsing file names with spaces <uri@StemSystems.com>
    Re: Parsing file names with spaces <jak@isp2dial.com>
    Re: Parsing file names with spaces <jak@isp2dial.com>
    Re: Parsing file names with spaces <ben@morrow.me.uk>
    Re: Parsing file names with spaces <jak@isp2dial.com>
    Re: Parsing file names with spaces <jurgenex@hotmail.com>
    Re: Parsing file names with spaces <jurgenex@hotmail.com>
    Re: Parsing file names with spaces <jak@isp2dial.com>
    Re: Parsing file names with spaces <jegan473@comcast.net>
    Re: Parsing file names with spaces <jak@isp2dial.com>
    Re: Parsing file names with spaces sln@netherlands.com
    Re: Parsing file names with spaces <tadmc@seesig.invalid>
    Re: Parsing file names with spaces <tadmc@seesig.invalid>
    Re: Parsing file names with spaces <uri@StemSystems.com>
    Re: Parsing file names with spaces <uri@StemSystems.com>
    Re: Parsing file names with spaces <uri@StemSystems.com>
    Re: Parsing file names with spaces <uri@StemSystems.com>
    Re: Parsing file names with spaces <ben@morrow.me.uk>
    Re: Parsing file names with spaces <jurgenex@hotmail.com>
    Re: Parsing file names with spaces <jurgenex@hotmail.com>
    Re: Parsing file names with spaces <tadmc@seesig.invalid>
    Re: Parsing file names with spaces <jak@isp2dial.com>
    Re: Parsing file names with spaces <tadmc@seesig.invalid>
    Re: Parsing file names with spaces <uri@StemSystems.com>
    Re: Parsing file names with spaces <derykus@gmail.com>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Wed, 30 Jun 2010 21:10:20 -0400
From: "Uri Guttman" <uri@StemSystems.com>
Subject: Re: Parsing file names with spaces
Message-Id: <8739w4f1mr.fsf@quad.sysarch.com>

>>>>> "JK" == John Kelly <jak@isp2dial.com> writes:

  JK> On Wed, 30 Jun 2010 23:53:13 GMT, James Egan <jegan473@comcast.net>
  JK> wrote:

  >> I want to take these three array elements and extract the file names which 
  >> include spaces:
  >> 
  >> -rwxrwxrwx   1 777   22000   2971201 Jan 24 18:17 file1.zip
  >> -rwxrwxrwx   1 777   22000   2969941 Jan 28 18:10 file2 onespace.zip
  >> -rwxrwxrwx   1 777   22000   2969941 Jan 29 13:28 file3 two spaces.zip


  JK> This works for me:

  >> #!/usr/bin/perl
  >> 
  >> open DATA, 'data';
  >> @files = <DATA>;
  >> foreach (@files) {
  >> 
  >> my $file;
  >> (undef, undef, undef, undef, undef, undef, undef, undef, $file) = split ' ', $_, 9;
  >> $file =~ / / and print "$file";

that is just poor code. do you want to count the undefs each time you do
something like that? and why is that last line checking for space? he
wants all the file names. it is just that some also have spaces in them.

uri

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


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

Date: Wed, 30 Jun 2010 21:12:49 -0400
From: "Uri Guttman" <uri@StemSystems.com>
Subject: Re: Parsing file names with spaces
Message-Id: <87y6dwdmy6.fsf@quad.sysarch.com>

>>>>> "BM" == Ben Morrow <ben@morrow.me.uk> writes:

  BM> ls -l output intentionally uses fixed-width columns, except for the
  BM> filename. So

normally that is true, but very large files can cause the name column to
be shifted over. some ls flavors or options will change the size to use
a suffix but you can't count on fixed width there. as i posted it is
best to assume fixed width until the size but that is always a number
with a possible size suffix so it is easy to match and the rest is the
file name.

  BM> You could also try File::Listing from the LWP distribution.

another good idea. parsing ls -l is annoying. why the OP is stuck with
that is a good question.

uri

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


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

Date: Thu, 01 Jul 2010 01:46:45 +0000
From: John Kelly <jak@isp2dial.com>
Subject: Re: Parsing file names with spaces
Message-Id: <5ksn26hrnsqv48u6f1mbdf5ia6hbok7qcu@4ax.com>

On Wed, 30 Jun 2010 21:08:27 -0400, "Uri Guttman" <uri@StemSystems.com>
wrote:

>  JK> Try to relax.  It's only Perl.  Or does Perl make you tense.

>no, just bad and/or useless perl makes me react. you seem to be a font
>of it. i will correct your posted code whenever i feel like it. note
>that others didn't even come close to your way off response to the same
>ambiguous OP. and you still never answered my question, what was your
>code trying to even show? reading and printing a file of line
>(regardless of their being file names) doesn't do anything close to what
>the OP wanted. so your analytical skills need to be honed as well. best
>you sit back and not respond to most posts here until you have seen what
>others have to say.

Criticism is one thing.  When it's mean and personal, it's trolling.

Why would I want to follow the advice of a troll.



-- 
Web mail, POP3, and SMTP
http://www.beewyz.com/freeaccounts.php
 


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

Date: Thu, 01 Jul 2010 01:55:27 +0000
From: John Kelly <jak@isp2dial.com>
Subject: Re: Parsing file names with spaces
Message-Id: <79tn26p6v7v4mdkvhi8c3od60ve5maj2ed@4ax.com>

On Wed, 30 Jun 2010 21:10:20 -0400, "Uri Guttman" <uri@StemSystems.com>
wrote:

>  >> my $file;
>  >> (undef, undef, undef, undef, undef, undef, undef, undef, $file) = split ' ', $_, 9;
>  >> $file =~ / / and print "$file";
>
>that is just poor code. do you want to count the undefs each time you do
>something like that? and why is that last line checking for space? he
>wants all the file names.

That's not what he said.  But trolls don't care what people say, do
they.



-- 
Web mail, POP3, and SMTP
http://www.beewyz.com/freeaccounts.php
 


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

Date: Thu, 1 Jul 2010 03:06:46 +0100
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: Parsing file names with spaces
Message-Id: <mq9tf7-9cs.ln1@osiris.mauzo.dyndns.org>


Quoth "Uri Guttman" <uri@StemSystems.com>:
> >>>>> "BM" == Ben Morrow <ben@morrow.me.uk> writes:
> 
>   BM> ls -l output intentionally uses fixed-width columns, except for the
>   BM> filename. So
> 
> normally that is true, but very large files can cause the name column to
> be shifted over. some ls flavors or options will change the size to use
> a suffix but you can't count on fixed width there. as i posted it is
> best to assume fixed width until the size but that is always a number
> with a possible size suffix so it is easy to match and the rest is the
> file name.

Meh. Yes, you're probably right. (Now I check ls(1), at least on my
system, it appears most of the fields are variable-width.) Since modern
systems (OS X, at least) allow user- and group names with spaces in,
splitting on space doesn't work either.

The correct answer, of course, is 'go back several steps and get the
data in a more reasonable format'.

Ben



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

Date: Thu, 01 Jul 2010 02:19:33 +0000
From: John Kelly <jak@isp2dial.com>
Subject: Re: Parsing file names with spaces
Message-Id: <lcun265k1mca4iln8i8s851em5rvesl0r7@4ax.com>

On Wed, 30 Jun 2010 21:08:27 -0400, "Uri Guttman" <uri@StemSystems.com>
wrote:

> best you sit back and not respond to most posts here until you have
> seen what others have to say

The second "N" in NNTP means "news."  If you don't have any news to
share, maybe answering questions is all you can do.  But don't expect
everyone else to be like you.  I sometimes have news to post.  Which
reminds me ...


-- 
Web mail, POP3, and SMTP
http://www.beewyz.com/freeaccounts.php
 


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

Date: Wed, 30 Jun 2010 19:24:07 -0700
From: Jürgen Exner <jurgenex@hotmail.com>
Subject: Re: Parsing file names with spaces
Message-Id: <5dun26lvipodjl2dj02d0bjkfa5s9gcccd@4ax.com>

James Egan <jegan473@comcast.net> wrote:
>Assuming an array named @myfiles contained three elements like:
>
>-rwxrwxrwx   1 777   22000   2971201 Jan 24 18:17 file1.zip
>-rwxrwxrwx   1 777   22000   2969941 Jan 28 18:10 file2 onespace.zip
>-rwxrwxrwx   1 777   22000   2969941 Jan 29 13:28 file3 two spaces.zip
>
>
>I want to extract just the file which contain spaces to work with like:
>
>file1.zip
>file2 onespace.zip
>file3 two spaces.zip

Easy. split() the line into its 9 elements at any non-empty sequence of
spaces and then pick the last one:

    my $file = (split(/ +/, $_, 9))[8];

>How can I extract the file names which have spaces?

I would run a grep afterwards and filter for those names that contain
spaces.

>I've been trying unsuccessfully with the glob function:
>
>foreach my $f (@myfiles) {
>  print join "\n",glob("*")'
>}

You seem to be very confused about what glob() is doing.

jue


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

Date: Wed, 30 Jun 2010 19:27:14 -0700
From: Jürgen Exner <jurgenex@hotmail.com>
Subject: Re: Parsing file names with spaces
Message-Id: <j4vn26110qd9p89ai9tngmr4o43eia26pb@4ax.com>

"Uri Guttman" <uri@StemSystems.com> wrote:
>that is just poor code. do you want to count the undefs each time you do
>something like that? and why is that last line checking for space? he
>wants all the file names. 

That is not what the OP said. He explicitely said:
"I want to extract just the file which contain spaces" 

To me that excludes filenames without spaces.

jue


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

Date: Thu, 01 Jul 2010 02:30:40 +0000
From: John Kelly <jak@isp2dial.com>
Subject: Re: Parsing file names with spaces
Message-Id: <t9vn26tu15m5bern73u7jv7gfmvjspi6rn@4ax.com>

On Wed, 30 Jun 2010 19:24:07 -0700, Jürgen Exner <jurgenex@hotmail.com>
wrote:

>>I want to extract just the file which contain spaces to work with like:
>>
>>file1.zip
>>file2 onespace.zip
>>file3 two spaces.zip
>
>Easy. split() the line into its 9 elements at any non-empty sequence of
>spaces and then pick the last one:
>
>    my $file = (split(/ +/, $_, 9))[8];
>

That handles blanks, but this will handle all whitespace, such as tabs.

my $file = (split(' ', $_, 9))[8];



-- 
Web mail, POP3, and SMTP
http://www.beewyz.com/freeaccounts.php
 


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

Date: Thu, 01 Jul 2010 03:01:37 GMT
From: James Egan <jegan473@comcast.net>
Subject: Re: Parsing file names with spaces
Message-Id: <lyTWn.273035$iG7.44926@en-nntp-12.dc1.easynews.com>

On Wed, 30 Jun 2010 20:05:43 -0400, Uri Guttman wrote:

>>>>>> "JE" == James Egan <jegan473@comcast.net> writes:
> 
>   JE> I should have mentioned that the dates, sizes, names, of the JE>
>   files, might be different, so they won't always start at position JE>
>   50.
> 
> so use a regex! it isn't hard to write one to parse out the file from ls
> output. and you can always assume the earlier part ofls is fixed width.
> the date is always fixed width. only the size and file name can change
> in width. so skip to the size, then match a number and space and the
> rest is the file name so match that and grab it. easy regex.
> 
> uri


Assume the files vary greatly in size.  Then the file names may 
not start at position 50 like:

-rwxrwxrwx   1 777   22000   2971201 Jan 24 18:17 file1.zip
-rwxrwxrwx   1 777   22000   9941 Jan 28 18:10 file2 onespace.zip
-rwxrwxrwx   1 777   22000   3002969941 Jan 29 13:28 file3 two spaces.zip


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

Date: Thu, 01 Jul 2010 03:08:05 +0000
From: John Kelly <jak@isp2dial.com>
Subject: Re: Parsing file names with spaces
Message-Id: <vf1o269a3rf4tutuh8ll25bsphoobdpr02@4ax.com>

On Thu, 01 Jul 2010 03:01:37 GMT, James Egan <jegan473@comcast.net>
wrote:

>Assume the files vary greatly in size.  Then the file names may 
>not start at position 50 like:

>-rwxrwxrwx   1 777   22000   2971201 Jan 24 18:17 file1.zip
>-rwxrwxrwx   1 777   22000   9941 Jan 28 18:10 file2 onespace.zip
>-rwxrwxrwx   1 777   22000   3002969941 Jan 29 13:28 file3 two spaces.zip

True but the number of fields is always the same, up to the file name.
What Jürgen and I posted, is enough to get you going.


-- 
Web mail, POP3, and SMTP
http://www.beewyz.com/freeaccounts.php
 


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

Date: Wed, 30 Jun 2010 20:14:07 -0700
From: sln@netherlands.com
Subject: Re: Parsing file names with spaces
Message-Id: <0r1o26d1qdrbhk70e40vnnicqlj5j87eag@4ax.com>

On Wed, 30 Jun 2010 22:58:50 GMT, James Egan <jegan473@comcast.net> wrote:

>Assuming an array named @myfiles contained three elements like:
>
>-rwxrwxrwx   1 777   22000   2971201 Jan 24 18:17 file1.zip
>-rwxrwxrwx   1 777   22000   2969941 Jan 28 18:10 file2 onespace.zip
>-rwxrwxrwx   1 777   22000   2969941 Jan 29 13:28 file3 two spaces.zip
>
>
>I want to extract just the file which contain spaces to work with like:
>
>file1.zip
>file2 onespace.zip
>file3 two spaces.zip
>
>
>How can I extract the file names which have spaces?
>

Replacing 'space' with \s is left as an exercise.
-sln

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

use strict;
use warnings;

##
  my @fnames = (join '',<DATA>) =~ / \d*:\d* +([^ \n].* .*[^ \n])/g;
  print "@fnames";

# Or ..
# while (<DATA>) {
#    /\ \d*:\d*\ + ( [^\ \n] .* \  .* [^\ \n] ) /x and print "$1\n";
#    # or
#    # /\s\d*:\d*\s+(.++)/ and $1 =~ tr/ // and print $1,"\n";
# }

# Or ..
# while (<DATA>) {
#    /(?<=\d{2}:\d{2})\ +([^ \n].* .*[^ \n])/ and print $1,"\n";
# }


__DATA__

I want to take these three array elements and extract the file names which 
include spaces:

-rwxrwxrwx   1 777   22000   2971201 Jan 24 18:17 file1.zip
-rwxrwxrwx   1 777   22000   2969941 Jan 28 18:10 file2 onespace.zip
-rwxrwxrwx   1 777   22000   2969941 Jan 29 13:28 file3 two spaces.zip



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

Date: Wed, 30 Jun 2010 22:17:33 -0500
From: Tad McClellan <tadmc@seesig.invalid>
Subject: Re: Parsing file names with spaces
Message-Id: <slrni2o1uc.9as.tadmc@tadbox.sbcglobal.net>

James Egan <jegan473@comcast.net> wrote:


[ snip where a nice soul has tried to solve the OP's poorly specified problem ]


> I should have mentioned that the dates, sizes, names, of the files, might be
> different, so they won't always start at position 50.


No, you should not have mentioned that.

You should have provided test data that reflects your real data.


-- 
Tad McClellan
email: perl -le "print scalar reverse qq/moc.liamg\100cm.j.dat/"
The above message is a Usenet post.
I don't recall having given anyone permission to use it on a Web site.


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

Date: Wed, 30 Jun 2010 22:21:38 -0500
From: Tad McClellan <tadmc@seesig.invalid>
Subject: Re: Parsing file names with spaces
Message-Id: <slrni2o260.9as.tadmc@tadbox.sbcglobal.net>

James Egan <jegan473@comcast.net> wrote:
>
> I want to take these three array elements and extract the file names which 
> include spaces:
>
> -rwxrwxrwx   1 777   22000   2971201 Jan 24 18:17 file1.zip
> -rwxrwxrwx   1 777   22000   2969941 Jan 28 18:10 file2 onespace.zip
> -rwxrwxrwx   1 777   22000   2969941 Jan 29 13:28 file3 two spaces.zip


That is not three array elements.

my @ra = (
    "-rwxrwxrwx   1 777   22000   2971201 Jan 24 18:17 file1.zip\n",
    "-rwxrwxrwx   1 777   22000   2969941 Jan 28 18:10 file2 onespace.zip",
    "-rwxrwxrwx   1 777   22000   2969941 Jan 29 13:28 file3 two spaces.zip",
);


_That_ is three array elements.

You should speak Perl rather than English, when possible.

Have you seen the Posting Guidelines that are posted here frequently?


-- 
Tad McClellan
email: perl -le "print scalar reverse qq/moc.liamg\100cm.j.dat/"
The above message is a Usenet post.
I don't recall having given anyone permission to use it on a Web site.


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

Date: Wed, 30 Jun 2010 23:23:39 -0400
From: "Uri Guttman" <uri@StemSystems.com>
Subject: Re: Parsing file names with spaces
Message-Id: <8739w3evgk.fsf@quad.sysarch.com>

>>>>> "JE" == James Egan <jegan473@comcast.net> writes:

  JE> Assume the files vary greatly in size.  Then the file names may 
  JE> not start at position 50 like:

  JE> -rwxrwxrwx   1 777   22000   2971201 Jan 24 18:17 file1.zip
  JE> -rwxrwxrwx   1 777   22000   9941 Jan 28 18:10 file2 onespace.zip
  JE> -rwxrwxrwx   1 777   22000   3002969941 Jan 29 13:28 file3 two spaces.zip

so what have you tried? you can always skip the first fixed fields. or
you can match them with a regex. even something as trivial as a set of
\S+ parts with \s+ separators will do. the number of fields is fixed
too. so try a regex with that hint and see what you can do. if you still
have troubles, post what code you have tried. this is really an easy
problem which is why i am not giving you a direct answer.

uri

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


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

Date: Wed, 30 Jun 2010 23:25:23 -0400
From: "Uri Guttman" <uri@StemSystems.com>
Subject: Re: Parsing file names with spaces
Message-Id: <87y6dvdgt8.fsf@quad.sysarch.com>

>>>>> "JK" == John Kelly <jak@isp2dial.com> writes:

  JK> On Wed, 30 Jun 2010 21:08:27 -0400, "Uri Guttman" <uri@StemSystems.com>
  JK> wrote:

  JK> Try to relax.  It's only Perl.  Or does Perl make you tense.

  >> no, just bad and/or useless perl makes me react. you seem to be a font
  >> of it. i will correct your posted code whenever i feel like it. note
  >> that others didn't even come close to your way off response to the same
  >> ambiguous OP. and you still never answered my question, what was your
  >> code trying to even show? reading and printing a file of line
  >> (regardless of their being file names) doesn't do anything close to what
  >> the OP wanted. so your analytical skills need to be honed as well. best
  >> you sit back and not respond to most posts here until you have seen what
  >> others have to say.

  JK> Criticism is one thing.  When it's mean and personal, it's trolling.

  JK> Why would I want to follow the advice of a troll.

well, cause i am not a troll. but your perl code suggestions are weak at
best. i paTROL this group and correct/improve bad code. you are just a
recent target. nothing new. it isn't personal. i don't like to see poor
perl posted and will always comment on it. you can take it personally,
but that is your issue not mine. i care about the code.

uri

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


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

Date: Wed, 30 Jun 2010 23:26:59 -0400
From: "Uri Guttman" <uri@StemSystems.com>
Subject: Re: Parsing file names with spaces
Message-Id: <87tyojdgqk.fsf@quad.sysarch.com>

>>>>> "JK" == John Kelly <jak@isp2dial.com> writes:

  JK> On Wed, 30 Jun 2010 21:08:27 -0400, "Uri Guttman" <uri@StemSystems.com>
  JK> wrote:

  >> best you sit back and not respond to most posts here until you have
  >> seen what others have to say

  JK> The second "N" in NNTP means "news."  If you don't have any news to
  JK> share, maybe answering questions is all you can do.  But don't expect
  JK> everyone else to be like you.  I sometimes have news to post.  Which
  JK> reminds me ...

you don't get this group at all. it discusses perl. all posts here are
open to comments about the perl in them. the exclusively news aspect of
usenet or nntp is long gone. your bringing that up is just silly. silly!
silly! silly!

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


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

Date: Wed, 30 Jun 2010 23:28:58 -0400
From: "Uri Guttman" <uri@StemSystems.com>
Subject: Re: Parsing file names with spaces
Message-Id: <87pqz7dgn9.fsf@quad.sysarch.com>

>>>>> "BM" == Ben Morrow <ben@morrow.me.uk> writes:

  BM> Quoth "Uri Guttman" <uri@StemSystems.com>:
  >> >>>>> "BM" == Ben Morrow <ben@morrow.me.uk> writes:
  >> 
  BM> ls -l output intentionally uses fixed-width columns, except for the
  BM> filename. So
  >> 
  >> normally that is true, but very large files can cause the name column to
  >> be shifted over. some ls flavors or options will change the size to use
  >> a suffix but you can't count on fixed width there. as i posted it is
  >> best to assume fixed width until the size but that is always a number
  >> with a possible size suffix so it is easy to match and the rest is the
  >> file name.

  BM> Meh. Yes, you're probably right. (Now I check ls(1), at least on my
  BM> system, it appears most of the fields are variable-width.) Since modern
  BM> systems (OS X, at least) allow user- and group names with spaces in,
  BM> splitting on space doesn't work either.

yow, that is annoying then. do they use tabs for separators or just more
spaces? if so, you can't really parse ls -l there. a group name could be
a number (or multiple numbers!) which is confused with the size, etc. blecch.

  BM> The correct answer, of course, is 'go back several steps and get the
  BM> data in a more reasonable format'.

yep. which i have suggested. oh well.

uri

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


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

Date: Thu, 1 Jul 2010 04:31:16 +0100
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: Parsing file names with spaces
Message-Id: <4petf7-7fv.ln1@osiris.mauzo.dyndns.org>


Quoth John Kelly <jak@isp2dial.com>:
> On Wed, 30 Jun 2010 19:24:07 -0700, Jürgen Exner <jurgenex@hotmail.com>
> wrote:
> 
> >>I want to extract just the file which contain spaces to work with like:
> >>
> >>file1.zip
> >>file2 onespace.zip
> >>file3 two spaces.zip
> >
> >Easy. split() the line into its 9 elements at any non-empty sequence of
> >spaces and then pick the last one:
> >
> >    my $file = (split(/ +/, $_, 9))[8];
> >
> 
> That handles blanks, but this will handle all whitespace, such as tabs.
> 
> my $file = (split(' ', $_, 9))[8];

 ...which do not appear in the output of ls(1), except possibly as part
of a filename.

It's also worth noting that none of the solutions offered (except
perhaps File::Listing) handle symlinks.

Ben



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

Date: Wed, 30 Jun 2010 20:34:38 -0700
From: Jürgen Exner <jurgenex@hotmail.com>
Subject: Re: Parsing file names with spaces
Message-Id: <843o26dcreb8pis5eentevbuqu0v2l811s@4ax.com>

James Egan <jegan473@comcast.net> wrote:
>On Wed, 30 Jun 2010 20:05:43 -0400, Uri Guttman wrote:
>>>>>>> "JE" == James Egan <jegan473@comcast.net> writes:
>>   JE> I should have mentioned that the dates, sizes, names, of the JE>
>>   files, might be different, so they won't always start at position JE>
>>   50.
>> 
>> so use a regex! it isn't hard to write one to parse out the file from ls
>> output. 
>
>Assume the files vary greatly in size.  Then the file names may 
>not start at position 50 like:

Which is completely irrelevant for the vast majority of regular
expressions.

jue


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

Date: Wed, 30 Jun 2010 20:38:57 -0700
From: Jürgen Exner <jurgenex@hotmail.com>
Subject: Re: Parsing file names with spaces
Message-Id: <ab3o261naadruum95gda13ia2bdkt6d1t1@4ax.com>

Ben Morrow <ben@morrow.me.uk> wrote:
>It's also worth noting that none of the solutions offered (except
>perhaps File::Listing) handle symlinks.

Which on the other hand weren't part of his problem statement....

A poorly specified problem necessarily leads to arbitrary guesses and
widely diverging 'solutions'.

jue


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

Date: Wed, 30 Jun 2010 22:44:10 -0500
From: Tad McClellan <tadmc@seesig.invalid>
Subject: Re: Parsing file names with spaces
Message-Id: <slrni2o3g8.9as.tadmc@tadbox.sbcglobal.net>

James Egan <jegan473@comcast.net> wrote:
> On Wed, 30 Jun 2010 20:05:43 -0400, Uri Guttman wrote:
>
>>>>>>> "JE" == James Egan <jegan473@comcast.net> writes:
>> 
>>   JE> I should have mentioned that the dates, sizes, names, of the JE>
>>   files, might be different, so they won't always start at position JE>
>>   50.
>> 
>> so use a regex! it isn't hard to write one to parse out the file from ls
      ^^^^^^^^^^^
      ^^^^^^^^^^^
>> output.

> Assume the files vary greatly in size.  Then the file names may 
> not start at position 50 like:
>
> -rwxrwxrwx   1 777   22000   2971201 Jan 24 18:17 file1.zip
> -rwxrwxrwx   1 777   22000   9941 Jan 28 18:10 file2 onespace.zip
> -rwxrwxrwx   1 777   22000   3002969941 Jan 29 13:28 file3 two spaces.zip


How's about *you* assume that, and then attempt to use a regex?

We are here to help you with your Perl problem.

We are not here to write your Perl program for you. 

It is expected that you will try and do that once we have pointed
you in the right direction.


Oh hell, have a fish.

----------------
#!/usr/bin/perl
use warnings;
use strict;

my @ra = (
    "-rwxrwxrwx   1 777   22000   2971201 Jan 24 18:17 file1.zip",
    "-rwxrwxrwx   1 777   22000   9941 Jan 28 18:10 file2 onespace.zip",
    "-rwxrwxrwx   1 777   22000   3002969941 Jan 29 13:28 file3 two
spaces.zip",
);

my @spacy;
foreach my $ls (@ra) {
    $ls =~ s/^(\S+\s+){8}//;
    push @spacy, $ls if $ls =~ / /;
}
print "$_\n" for @spacy;

# same thing, but done all at once    
@spacy = map {s/^(\S+\s+){8}//; / / ? $_ : ()} @ra;
print "$_\n" for @spacy;
----------------


-- 
Tad McClellan
email: perl -le "print scalar reverse qq/moc.liamg\100cm.j.dat/"
The above message is a Usenet post.
I don't recall having given anyone permission to use it on a Web site.


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

Date: Thu, 01 Jul 2010 03:46:17 +0000
From: John Kelly <jak@isp2dial.com>
Subject: Re: Parsing file names with spaces
Message-Id: <7e3o26t9f803l575h9fcbclgiv4hma96ie@4ax.com>

On Wed, 30 Jun 2010 23:26:59 -0400, "Uri Guttman" <uri@StemSystems.com>
wrote:

>you don't get this group at all. it discusses perl. all posts here are
>open to comments about the perl in them. the exclusively news aspect of
>usenet or nntp is long gone. your bringing that up is just silly. silly!
>silly! silly!

Like a troll, you don't hear what I say.  You hear what you want to
hear.  I didn't say usenet is *exclusively* news.  

You regard this ng as your personal territory, and hate it when someone
won't follow your self projection bias.


-- 
Web mail, POP3, and SMTP
http://www.beewyz.com/freeaccounts.php
 


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

Date: Wed, 30 Jun 2010 23:03:46 -0500
From: Tad McClellan <tadmc@seesig.invalid>
Subject: Re: Parsing file names with spaces
Message-Id: <slrni2o4l1.9jd.tadmc@tadbox.sbcglobal.net>

John Kelly <jak@isp2dial.com> wrote:
> On Wed, 30 Jun 2010 23:26:59 -0400, "Uri Guttman" <uri@StemSystems.com>
> wrote:
>
>>you don't get this group at all.


> Like a troll, 


Do you have much experience on Usenet?

If so, and if you truly believe that Uri is a troll, 
then please attempt to exert some self control and don't feed it!


-- 
Tad McClellan
email: perl -le "print scalar reverse qq/moc.liamg\100cm.j.dat/"
The above message is a Usenet post.
I don't recall having given anyone permission to use it on a Web site.


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

Date: Thu, 01 Jul 2010 00:05:23 -0400
From: "Uri Guttman" <uri@StemSystems.com>
Subject: Re: Parsing file names with spaces
Message-Id: <874ogjdeyk.fsf@quad.sysarch.com>

>>>>> "JK" == John Kelly <jak@isp2dial.com> writes:

  JK> On Wed, 30 Jun 2010 23:26:59 -0400, "Uri Guttman" <uri@StemSystems.com>
  JK> wrote:

  >> you don't get this group at all. it discusses perl. all posts here are
  >> open to comments about the perl in them. the exclusively news aspect of
  >> usenet or nntp is long gone. your bringing that up is just silly. silly!
  >> silly! silly!

  JK> Like a troll, you don't hear what I say.  You hear what you want to
  JK> hear.  I didn't say usenet is *exclusively* news.  

  JK> You regard this ng as your personal territory, and hate it when someone
  JK> won't follow your self projection bias.

nah, i just don't like bad perl code and comment on it when i see
it. you are projecting dislike of your code onto dislike of you. keep it
up and they will become the same. in the mean time your code needs work
and you shouldn't be offering help to others until it gets better. you
will still do that and will still comment on your code.

uri 

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


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

Date: Wed, 30 Jun 2010 21:08:39 -0700 (PDT)
From: "C.DeRykus" <derykus@gmail.com>
Subject: Re: Parsing file names with spaces
Message-Id: <5b071d60-9c43-4feb-b7e0-e9bde6756f0b@i9g2000prn.googlegroups.com>

On Jun 30, 4:56=A0pm, James Egan <jegan...@comcast.net> wrote:
> On Thu, 01 Jul 2010 01:41:33 +0200, Dr.Ruud wrote:
> > James Egan wrote:
>
> >> Assuming an array named @myfiles contained three elements like:
>
> >> -rwxrwxrwx =A0 1 777 =A0 22000 =A0 2971201 Jan 24 18:17 file1.zip -rwx=
rwxrwx
> >> =A01 777 =A0 22000 =A0 2969941 Jan 28 18:10 file2 onespace.zip -rwxrwx=
rwx =A0 1
> >> 777 =A0 22000 =A0 2969941 Jan 29 13:28 file3 two spaces.zip
>
> >> I want to extract just the file which contain spaces to work with like=
:
>
> >> file1.zip
> >> file2 onespace.zip
> >> file3 two spaces.zip
>
> > echo "-rwxrwxrwx =A0 1 777 =A0 22000 =A0 2969941 Jan 29 13:28 file3 two
> > spaces.zip" |perl -wnle '
>
> > =A0 =A0print substr($_, 50);
> > '
> > file3 two spaces.zip
>
> I should have mentioned that the dates, sizes, names, of the files, might=
 be
> different, so they won't always start at position 50.
>

A split'n-splice perhaps:

   my @f =3D split ' ', $dirline;
   splice(  @f, 0, 8 );
   print qq{@f} if  @f > 1;

This'll squeeze down multiple spaces though.
To avoid that:

   chomp $dirline;
   my @f =3D split  /(\s+)/x, $dirline;
   splice(  @f, 0, 16 );
   print join '',@f,"\n" if @f > 1;

--
Charles DeRykus


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

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:

To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.

Back issues are available via anonymous ftp from
ftp://cil-www.oce.orst.edu/pub/perl/old-digests. 

#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 3012
***************************************


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