Bit Bucket?

Discussion in 'Perl Misc' started by $_@_.%, Jan 9, 2004.

  1. $_@_.%

    $_@_.% Guest

    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 :)
    $_@_.%, Jan 9, 2004
    #1
    1. Advertising

  2. "$_"@_.% 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
    Josef Möllers, Jan 9, 2004
    #2
    1. Advertising

  3. $_@_.%

    $_@_.% Guest

    > 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;
    $_@_.%, Jan 9, 2004
    #3
  4. $_@_.%

    Uri Guttman Guest

    >>>>> "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
    Uri Guttman, Jan 9, 2004
    #4
  5. $_@_.%

    $_@_.% Guest

    > >>>>> "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.
    $_@_.%, Jan 9, 2004
    #5
  6. $_@_.%

    Ben Morrow Guest

    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.
    Ben Morrow, Jan 9, 2004
    #6
  7. 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!
    Walter Roberson, Jan 9, 2004
    #7
  8. $_@_.%

    Tore Aursand Guest

    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
    Tore Aursand, Jan 10, 2004
    #8
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. kumar
    Replies:
    8
    Views:
    3,526
    Vikram
    Feb 17, 2004
  2. Replies:
    3
    Views:
    1,743
    Timothy Bendfelt
    Jan 19, 2007
  3. ^cypis^ vel. SQ9JTI

    bucket sort with values from txt file

    ^cypis^ vel. SQ9JTI, Jan 8, 2007, in forum: C++
    Replies:
    7
    Views:
    589
    ^cypis^ vel. SQ9JTI
    Jan 10, 2007
  4. Replies:
    9
    Views:
    968
    Juha Nieminen
    Aug 22, 2007
  5. Jeff.M
    Replies:
    6
    Views:
    172
    Lasse Reichstein Nielsen
    May 4, 2009
Loading...

Share This Page