From: John Kelly on
On Wed, 30 Jun 2010 20:03:54 -0400, "Uri Guttman" <uri(a)StemSystems.com>
wrote:

>and what did that show? he is not reading or getting a file with just
>file names in them. they are full ls listings. of course you will get
>pissed off at my question but try to answer it!


Well he said:

>I'm not reading a directory with the ls command.

So it sounded like his data only included the file names. But in a
later post he says it does include the directory info. My post prompted
him to explain further, without treating him like a fool.

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


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

From: Ben Morrow on

Quoth James Egan <jegan473(a)comcast.net>:
> 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?

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

for (@myfiles) {
print substr($_, 50), "\n";
}

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

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

Why on Earth would you have expected that to work? Apart from anything
else, you aren't even using $f...

Ben

From: Uri Guttman on
>>>>> "JK" == John Kelly <jak(a)isp2dial.com> writes:

JK> On Wed, 30 Jun 2010 20:03:54 -0400, "Uri Guttman" <uri(a)StemSystems.com>
JK> wrote:

>> and what did that show? he is not reading or getting a file with just
>> file names in them. they are full ls listings. of course you will get
>> pissed off at my question but try to answer it!


JK> Well he said:

>> I'm not reading a directory with the ls command.

JK> So it sounded like his data only included the file names. But in a
JK> later post he says it does include the directory info. My post prompted
JK> him to explain further, without treating him like a fool.

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. that is generally good advice on usenet.

uri

--
Uri Guttman ------ uri(a)stemsystems.com -------- http://www.sysarch.com --
----- Perl Code Review , Architecture, Development, Training, Support ------
--------- Gourmet Hot Cocoa Mix ---- http://bestfriendscocoa.com ---------
From: Uri Guttman on
>>>>> "JK" == John Kelly <jak(a)isp2dial.com> writes:

JK> On Wed, 30 Jun 2010 23:53:13 GMT, James Egan <jegan473(a)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(a)stemsystems.com -------- http://www.sysarch.com --
----- Perl Code Review , Architecture, Development, Training, Support ------
--------- Gourmet Hot Cocoa Mix ---- http://bestfriendscocoa.com ---------
From: Uri Guttman on
>>>>> "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.

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(a)stemsystems.com -------- http://www.sysarch.com --
----- Perl Code Review , Architecture, Development, Training, Support ------
--------- Gourmet Hot Cocoa Mix ---- http://bestfriendscocoa.com ---------