From: James Egan on
On Wed, 30 Jun 2010 23:49:55 +0000, John Kelly wrote:

> On Wed, 30 Jun 2010 23:18:18 GMT, James Egan <jegan473(a)comcast.net>
> wrote:
>
>>I'm not reading a directory with the ls command. I don't want to
>>complicate matters with where the long listing of file names comes from.
>> Suffice it to say it's a long listing, and the file names have spaces,
>>and I need to extract the file names.
>
> CODE:
>
> #!/usr/bin/perl
>
> open DATA, 'data';
> @files = <DATA>;
> foreach (@files) {
> print;
> }
>
>
> contents of 'data' FILE:
>
> file1.zip
> file2 onespace.zip
> file3 two spaces.zip
>
>
> OUTPUT:
>
> file1.zip
> file2 onespace.zip
> file3 two spaces.zip
>
>
> The spaces don't matter, the newline characters in the 'data' file are
> delimiters. Can you exlpain what you want to do, and why spaces are a
> problem?



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
From: James Egan on
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 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
>
> echo "-rwxrwxrwx 1 777 22000 2969941 Jan 29 13:28 file3 two
> spaces.zip" |perl -wnle '
>
> print 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.

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

JK> CODE:

JK> #!/usr/bin/perl

JK> open DATA, 'data';

always check open for success or failure

JK> @files = <DATA>;
JK> foreach (@files) {
JK> print;
JK> }

and how is that is different than?

print <DATA> ;

also don't use DATA for a file handle, it is defaulted to the __DATA__
section of the main file. also use lexical file handles. and to add one
more, that can be all done with:

use File::Slurp ;
print read_file( 'data' ) ;

JK> contents of 'data' FILE:

JK> file1.zip
JK> file2 onespace.zip
JK> file3 two spaces.zip

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!

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
>>>>> "JE" == James Egan <jegan473(a)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

--
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: John Kelly on
On Wed, 30 Jun 2010 23:53:13 GMT, James Egan <jegan473(a)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


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";
>
>}


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