'ls' question, splitting and files with spaces in their name...
Madison Kelly
linux-5ZoueyuiTZhBDgjK7y7TUQ at public.gmane.org
Sat May 22 14:52:15 UTC 2004
With Rick and Jim's input I have my problem solved! The new code snipet is:
=- snip
open (LS, "ls -lAQ --full-time '$mnt_dir' 2>&1 |");
print "<pre>\n";
while (<LS>)
{
s/\n//;
# The first $perm will be "total"
($perm, $num, $owner, $group, $size, $date, $time, $time_zone,
$file)=split/\s+/, $_, 9;
=- snip
Thanks again!!
Madison
PS - If there is a fair argument for switching to 'chomp' I still will.
PPS - I changed the 'ls' call to fix the the time stamp, too.
Madison Kelly wrote:
> Hi all,
>
> I need to read in the results of an 'ls' call to a bunch of variables
> (in Perl) and I am doing so like this:
>
> =- Snip
> open (LS, "ls -lA '$mnt_dir' 2>&1 |");
> while (<LS>)
> {
> s/\n//;
> # The first $perm will be "total"
> ($perm, $num, $owner, $group, $size, $month, $day, $time_year,
> $file)=split/\s+/;
> =- Snip
>
> My problem is that I am just straight splitting on spaces and some
> files and directory names have spaces in them. I read the 'ls' man page
> and the closest thing I could find was a switch to add an escape
> character before the space but that would only be marginally helpful.
>
> What I need is some way to show the file or directory name with some
> other character instead of a space so that the first split will leave
> the file or directory name intact wherein after I could substitute the
> space back.
>
> Anyone have any ideas that might help?
>
> The only thing I can think of is to add a whole bunch of $file1,
> $file2, $file3, ... $file# and then splice them back together but that
> would be cumbersome and also create a limit on the number of spaces that
> could be in a file name (and risk missing those above that).
>
> Thanks yet again all!!
>
> Madison
--
The Toronto Linux Users Group. Meetings: http://tlug.ss.org
TLUG requests: Linux topics, No HTML, wrap text below 80 columns
How to UNSUBSCRIBE: http://tlug.ss.org/subscribe.shtml
More information about the Legacy
mailing list