From: J�rgen Exner on 30 Jun 2010 22:27 "Uri Guttman" <uri(a)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
From: John Kelly on 30 Jun 2010 22:30 On Wed, 30 Jun 2010 19:24:07 -0700, J�rgen Exner <jurgenex(a)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
From: James Egan on 30 Jun 2010 23:01 On Wed, 30 Jun 2010 20:05:43 -0400, Uri Guttman wrote: >>>>>> "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 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
From: John Kelly on 30 Jun 2010 23:08 On Thu, 01 Jul 2010 03:01:37 GMT, James Egan <jegan473(a)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
From: sln on 30 Jun 2010 23:14
On Wed, 30 Jun 2010 22:58:50 GMT, James Egan <jegan473(a)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 |