in reply to I am now slice-aware

Whilst array (and hash) are, indeed, most cool, your current problem could have been solved by investigating the rarely used third parameter to split.

@entry = split(/:/, $_, 8); $newentry = join(":", @entry);

Update: And if you're wondering why I only split into 8 elements when the original code used 9 (0 .. 8), I counted the ':' characters in the original data and saw that there were only 8 elements :)

--
<http://www.dave.org.uk>

"Perl makes the fun jobs fun
and the boring jobs bearable" - me

Replies are listed 'Best First'.
Re^2: I am now slice-aware
by tadman (Prior) on Apr 17, 2001 at 19:15 UTC
    Or, as tye enlightened me earlier, you can always use -1 if you have no idea about the number of entries you want, as -1 prevents split from discarding trailing empty fields:      $newentry = join(":", split(/:/, $_, -1));

      Any negative number would do. From perldoc -f split:

      "If LIMIT is specified and positive, splits into no more than that many fields (though it may split into fewer). If LIMIT is unspecified or zero, trailing null fields are stripped (which potential users of pop() would do well to remember). If LIMIT is negative, it is treated as if an arbitrarily large LIMIT had been specified."

      --
      <http://www.dave.org.uk>

      "Perl makes the fun jobs fun
      and the boring jobs bearable" - me

Re: Re: I am now slice-aware
by jeroenes (Priest) on Apr 17, 2001 at 19:22 UTC
    Another possibility is, and I say this also to frankus below, to set the limit to -1. From perlfunc (5.6):
    into fewer). If LIMIT is unspecified or zero, trailing null fields are stripped (which potential users of `pop' would do well to remember). If LIMIT is negative, it is treated as if an arbitrarily large LIMIT had been specified.
    In other words, -1 would allow you to fetch any empty field, regardless of the number of fields, regardless of the placing of these fields (trailing are normally neglected, heading not).

    Oh yeah, for the supersplit fans among you, this behaviour can be achieved by adding the number to your argument list. Neat, isn't it?

    Hope this helps,

    Jeroen
    "We are not alone"(FZ)

Re: Re: I am now slice-aware
by birdbrane (Chaplain) on Apr 17, 2001 at 19:29 UTC
    davorg,

    Don't forget the there is an element at the end, that is not bound by a colon (ergo 9 elements).

    uucp:NP:6445::::::

    When you use only 8 elements, you miss the last ":". I know I also tried 8.

    bb

      Oh, I didn't forget. The example in your original post was foo:asDflkj123./d:6445::::: which has (counts) seven colons - hence eight fields :)

      --
      <http://www.dave.org.uk>

      "Perl makes the fun jobs fun
      and the boring jobs bearable" - me

        davorg,

        Thanks for pointing that out. I grabbed an entry from the one that I used 0..8. It must be the head cold talking.

        birdbrane