On Thu, 2 Apr 2015 08:34:37 -0700
SSC_perl <p...@surfshopcart.com> wrote:

> On Apr 2, 2015, at 7:43 AM, Anirban Adhikary wrote:
> > When I am trying to split the line based on whitespace
> > @elements = split(/\s+/,$line);
> 
>       It will be interesting if someone can come up with a solution
> to this, but I don't see one.  If your separator is whitespace, then
> the split has nothing to work with if some values are blank.  You'd
> need to add some kind of separator between your values, like a tab,
> or a comma, or something else unique that you can split it on.
> 
>       What kind of a file is this information in?  If it's in
> something like Excel, then, of course, you could just re-export it
> with another separator.  However, if it's in a simple text file, you
> may have to add them by hand.  I copied your data into a text file
> and it looks like you have an arbitrary number of spaces between your
> data (though that could just be the formatting from the email).  I
> thought that if the spacing was consistent, then you could count the
> number of spaces, but it doesn't look like that will work, either.
> 
>       Am I missing something?
> 

From what the OP posted, I think these are fixed-field records. The
best way to handle fixed-field records is using `substr` or `unpack`.

See:
perldoc -f substr  http://perldoc.perl.org/functions/substr.html
perldoc -f unpack  http://perldoc.perl.org/functions/unpack.html
perldoc -f pack    http://perldoc.perl.org/functions/pack.html



-- 
Don't stop where the ink does.
        Shawn

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to