'ls' question, splitting and files with spaces in their name...

Madison Kelly linux-5ZoueyuiTZhBDgjK7y7TUQ at public.gmane.org
Sat May 22 14:30:16 UTC 2004


Rick Delaney wrote:
> On Sat, May 22, 2004 at 09:48:20AM -0400, 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//;
> 
> 
>     chomp;
> 
> 
>>		# The first $perm will be "total"
>>		($perm, $num, $owner, $group, $size, $month, $day, 
>>		$time_year, $file)=split/\s+/;
> 
> 
> Limit the number of fields to split into:
> 
>     split " ", $_, 9;
> 
> perldoc -f split
> 

Ahh!!!!

   I hadn't realised that you could limit the number of splits. That 
should do perfectly!

   By the way, Jim also recommended 'chomp' over substitue. May I ask 
(both of your) reasoning on this? Being a new perl programmer I am very 
open to tips and suggestions. Thanks!!

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