From: vicky on
J?rgen Exner <jurgenex(a)hotmail.com> 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:

How about split on the : and then substr from 3 chars in?
From: J�rgen Exner on
Justin C <justin.0911(a)purestblue.com> wrote:
>On 2010-07-01, Uri Guttman <uri(a)StemSystems.com> wrote:
>>>>>>> "BM" == Ben Morrow <ben(a)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.
>
>An observation (that may be erroneous) of the output of ls: The second
>to last field is always the time, which contains a colon. How about
>matching /:\d{2}\s+.*\s+.+\b/ ?
[...]
> if (/:\d{2}\s+(.*\s+.+)\b/) {
> print $1, "\n";

Not a good idea because colons and digits are legal characters in
filenames and therefore it will chop up filenames like e.g.
foo45:10 bar baz.tmp

jue
From: J�rgen Exner on
<vicky(a)dinky.vm.bytemark.co.uk> wrote:
>J?rgen Exner <jurgenex(a)hotmail.com> 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:
>
>How about split on the : and then substr from 3 chars in?

You would need to be able to distinguish between the : as part of the
time stamp and a : as part of a file name.

As others have mentioned already: this format is very poorly suited to
be parsed. The best solution is to ask for the file list in a usable
form.

jue
From: John Kelly on
On Thu, 01 Jul 2010 07:41:51 -0700, J�rgen Exner <jurgenex(a)hotmail.com>
wrote:

><vicky(a)dinky.vm.bytemark.co.uk> wrote:

>>How about split on the : and then substr from 3 chars in?
>
>You would need to be able to distinguish between the : as part of the
>time stamp and a : as part of a file name.
>
>As others have mentioned already: this format is very poorly suited to
>be parsed. The best solution is to ask for the file list in a usable
>form.
>
>jue

Similar to my idea of split with 8 undefs, but more concisely, your
suggestion of:

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

works fine. The field count, prior to the file name, will not likely
change for the OP. Not every solution needs to be universally portable,
most people just need something that works in their local environment.

Of course I realize that does little to assuage the social thirst of the
dominant clique here.



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

From: Sherm Pendley on
John Kelly <jak(a)isp2dial.com> writes:

> Of course I realize that does little to assuage the social thirst of the
> dominant clique here.

Boo hoo. Whine much?

sherm--

--
Sherm Pendley <www.shermpendley.com>
<www.camelbones.org>
Cocoa Developer