From: James Egan on 30 Jun 2010 18:58 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? I've been trying unsuccessfully with the glob function: foreach my $f (@myfiles) { print join "\n",glob("*")' } -Thanks
From: Uri Guttman on 30 Jun 2010 19:09 >>>>> "JE" == James Egan <jegan473(a)comcast.net> writes: JE> Assuming an array named @myfiles contained three elements like: JE> -rwxrwxrwx 1 777 22000 2971201 Jan 24 18:17 file1.zip JE> -rwxrwxrwx 1 777 22000 2969941 Jan 28 18:10 file2 onespace.zip JE> -rwxrwxrwx 1 777 22000 2969941 Jan 29 13:28 file3 two spaces.zip are you saying your array has those lines from ls? JE> I want to extract just the file which contain spaces to work with like: JE> file1.zip JE> file2 onespace.zip JE> file3 two spaces.zip JE> How can I extract the file names which have spaces? JE> I've been trying unsuccessfully with the glob function: JE> foreach my $f (@myfiles) { JE> print join "\n",glob("*")' JE> } but you said you already have an array with those lines in it. why would a glob work when globs work on directories, not arrays or lines? you need a regex to grab the file part of the lines. but why did you even have them in ls format? just read the dir directly with glob or opendir/readdir and get them that way. in fact readdir will be better as it doesn't have to care about spaces in the file names.. 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: James Egan on 30 Jun 2010 19:18 > but you said you already have an array with those lines in it. why would > a glob work when globs work on directories, not arrays or lines? > 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. -Thanks
From: Dr.Ruud on 30 Jun 2010 19:41 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 -- Ruud
From: John Kelly on 30 Jun 2010 19:49
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? -- Web mail, POP3, and SMTP http://www.beewyz.com/freeaccounts.php |