Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > Bit Bucket?

Reply
Thread Tools

Bit Bucket?

 
 
$_@_.%
Guest
Posts: n/a
 
      01-09-2004
I have a string like this:
-rwx------ 1 user group 0 Jan 06 15:07 a file with spaces

and im placing that string in an array with this command:
my @dline = split(' ', $dirline);

now notice that there are three spaces between 'with spaces'
so when i re-stringify this array using this command:
my $filename = join(' ', @dline);

$filename now contains 'a file with spaces'
notice only one space between 'with spaces'

did split eat my extra spaces? i doubt it would have eaten other chars.
any suggestions or explanations? perhaps another way of doing this?

thanks, and i hope my post hasnt upset you very much, have a nice day
 
Reply With Quote
 
 
 
 
Josef Möllers
Guest
Posts: n/a
 
      01-09-2004
"$_"@_.% wrote:
>
> I have a string like this:
> -rwx------ 1 user group 0 Jan 06 15:07 a file with spaces
>
> and im placing that string in an array with this command:
> my @dline = split(' ', $dirline);
>
> now notice that there are three spaces between 'with spaces'
> so when i re-stringify this array using this command:
> my $filename = join(' ', @dline);
>
> $filename now contains 'a file with spaces'
> notice only one space between 'with spaces'
>
> did split eat my extra spaces? i doubt it would have eaten other chars.
> any suggestions or explanations? perhaps another way of doing this?
>
> thanks, and i hope my post hasnt upset you very much, have a nice day


split usually splits on a pattern. As a special case, a space (' ') will
split on the pattern /\s+/, to emulate awk's default behaviour.

see perldoc -f split and scroll almost to the end.

--
Josef Möllers (Pinguinpfleger bei FSC)
If failure had no penalty success would not be a prize
-- T. Pratchett
 
Reply With Quote
 
 
 
 
$_@_.%
Guest
Posts: n/a
 
      01-09-2004
> Josef M=F6llers (Pinguinpfleger bei FSC)
> If failure had no penalty success would not be a prize
> -- T. Pratchett


wrote:

> split usually splits on a pattern. As a special case, a space (' ') will
> split on the pattern /\s+/, to emulate awk's default behaviour.
>
> see perldoc -f split and scroll almost to the end.
>


Thank you very much that is very helpfull.

What i ended up doing was replacing the spaces with *'s which should work out
since a * is illegal in a filename (i think).

#example raw dir lines
#need to distinguish btwn dirs and files and reformat for display
#desired format is: file size or <DIR> date
#-rwx------ 1 user group 217752 Nov 05 1995 file.exe
#drwx------ 1 user group 0 Jan 07 11:57 dir3
#-rwx------ 1 user group 0 Jan 06 15:07 a file with spaces
#-rwx------ 1 user group 13 Jan 06 15:08 file.txt

$dirline =~ s/\s/*/g;
 
Reply With Quote
 
Uri Guttman
Guest
Posts: n/a
 
      01-09-2004
>>>>> "J" == <_@_.%> writes:

J> Thank you very much that is very helpfull.

J> What i ended up doing was replacing the spaces with *'s which should work out
J> since a * is illegal in a filename (i think).

no it isn't.

on unix flavors, the only char not allowed in a filename is /

instead of split, use a regex so you get the fields you want. and there
is at least one module on cpan that parses out ls -l listings.

uri

--
Uri Guttman ------ -------- http://www.stemsystems.com
--Perl Consulting, Stem Development, Systems Architecture, Design and Coding-
Search or Offer Perl Jobs ---------------------------- http://jobs.perl.org
 
Reply With Quote
 
$_@_.%
Guest
Posts: n/a
 
      01-09-2004
> >>>>> "J" == <_@_.%> writes:
>
> J> Thank you very much that is very helpfull.
>
> J> What i ended up doing was replacing the spaces with *'s which should work out
> J> since a * is illegal in a filename (i think).
>
> no it isn't.
>
> on unix flavors, the only char not allowed in a filename is /
>
> instead of split, use a regex so you get the fields you want. and there
> is at least one module on cpan that parses out ls -l listings.
>
> uri
>
> --
> Uri Guttman ------ -------- http://www.stemsystems.com
> --Perl Consulting, Stem Development, Systems Architecture, Design and Coding-
> Search or Offer Perl Jobs ---------------------------- http://jobs.perl.org
>

Thanks! yea this is soo difficult, some ftp site use an arbitrary number of spaces
in the time format.
 
Reply With Quote
 
Ben Morrow
Guest
Posts: n/a
 
      01-09-2004

Uri Guttman <> wrote:
> >>>>> "J" == <_@_.%> writes:

> J> What i ended up doing was replacing the spaces with *'s which
> J> should work out since a * is illegal in a filename (i think).
>
> no it isn't.
>
> on unix flavors, the only char not allowed in a filename is /


Just for correctness: and "\000", ASCII NUL.

Ben

--
Although few may originate a policy, we are all able to judge it.
- Pericles of Athens, c.430 B.C.

 
Reply With Quote
 
Walter Roberson
Guest
Posts: n/a
 
      01-09-2004
In article <btn3hn$31u$>,
Ben Morrow <> wrote:

:Uri Guttman <> wrote:
:> on unix flavors, the only char not allowed in a filename is /

:Just for correctness: and "\000", ASCII NUL.

To be even more pedantic: a pathname that starts with exactly two
slashes may be interpreted in an implimentation-defined manner.
In theory, that implimentation-defined manner could treat later slashes
as filename components (or as anything else it wanted). [IEEE 1003.1
section 2.2.2.57] Just not as POSIX standard filenames, which -are-
defined to not contain slash or null [2.2.2.32].

To avoid confusion here: POSIX.1 is distinguishing between "pathnames"
and "filenames", and to POSIX.1, a "filename" is the part in-between
slashes, so it is perfectly correct to say that POSIX.1 "filenames"
cannot contain / or null -- but POSIX.1 leaves an loophole for
local non-POSIX structures in which slash might be just another
character.
--
The Knights Of The Lambda Calculus aren't dead --this is their normal form!
 
Reply With Quote
 
Tore Aursand
Guest
Posts: n/a
 
      01-10-2004
On Fri, 09 Jan 2004 15:03:32 +0000, $_ wrote:
> I have a string like this:
> -rwx------ 1 user group 0 Jan 06 15:07 a file with spaces
>
> and im placing that string in an array with this command:
> my @dline = split(' ', $dirline);
>
> now notice that there are three spaces between 'with spaces'
> so when i re-stringify this array using this command:
> my $filename = join(' ', @dline);
>
> $filename now contains 'a file with spaces'
> notice only one space between 'with spaces'


split() normally takes a pattern as first argument; If you use ' ' as
argument, Perl will read this as '\s+', ie. matching one or more spaces.

You should use '/\s/' as pattern, ie.:

my @dline = split(/\s/, $dirline);


--
Tore Aursand <>
"Out of missiles. Out of bullets. Down to harsh language." -- Unknown
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
What is the point of having 16 bit colour if a computer monitor can only display 8 bit colour? How do you edit 16 bit colour when you can only see 8 bit? Scotius Digital Photography 6 07-13-2010 03:33 AM
Reversing Bit Order.. i.e. MSB becomes bit 0, LSB becomes bit 15 benn686@hotmail.com C++ 9 08-22-2007 12:13 AM
"LoadLibrary" of a 32 bit so with 64 bit java on a 64 bit machine markryde@gmail.com Java 3 01-19-2007 10:30 PM
64 bit - Windows Liberty 64bit, Windows Limited Edition 64 Bit, Microsoft SQL Server 2000 Developer Edition 64 Bit, IBM DB2 64 bit - new ! vvcd Computer Support 0 09-17-2004 08:15 PM
64 bit - Windows Liberty 64bit, Windows Limited Edition 64 Bit,Microsoft SQL Server 2000 Developer Edition 64 Bit, IBM DB2 64 bit - new! Ionizer Computer Support 1 01-01-2004 07:27 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57