[EMAIL PROTECTED] wrote:
> 
> ok, let's say you have a file where each line looks like this:
> 
> --a--       430 Fri Mar 19 18:32:47 1999 D:\Program Files\Common
> Files\Adobe\Web\AwePrefs.txt
> 
> and you want to get the filename (and every other field) out of it, the obvious
> thing to split on is whitespace (\s+) which give something like the following:
> 
> my ( $attribs, $size, $day, $mon, $date, $time, $year, $file ) = split(/\s+/,
> $line);
> 
> but of course that fails when files contain spaces, as in the above line.
> 
> Later on I'm trying to get JUST the filename out of the line and using:
> 
> ($file = (split( /\s+/, $line ))[7]) =~ s/\*//g;
> 
> that little sub at the end strips '*' off the ends of filenames, again this
> works great as long as there are no spaces in the filename/folders
> 
> Can anyone think up a slick way to extract the full filename from the above
> line, in all cases?  the file cannot be reformatted (ie. I cannot change the
> 'bad' spaces into '|' or something else)  My first thought was to split to an
> array, shift out the first 7 values, then shift the rest into the file variable
> concatenating tham as I went, but that seems un-perlish to me, anyone have a
> better way?

Assuming each line maintains a constant column width (that is, column 1
has the same width on each line, column 2 has the same width on each
line, etc; not necesarrily that the individual columns within a single
line have the same width), and the columns are space-padded, unpack
should work quite nicely.

Example: my ($attribs, $size, $datetime, $filename) =
unpack("A6A10A25A*", $line)


HTH,
Ian


-- 
99 little bugs in the code, 99 bugs in the code.
Fix one bug, compile again, 100 little bugs in the code.
100 little bugs in the code, 100 bugs in the code.
Fix one bug, compile again, 101 little bugs in the code...

---
You are currently subscribed to perl-win32-users as: [archive@jab.org]
To unsubscribe, forward this message to
         [EMAIL PROTECTED]
For non-automated Mailing List support, send email to  
         [EMAIL PROTECTED]

Reply via email to