Re: Use of uninitialized value in concatenation (.) or string Error

Discussion in 'Perl' started by Sukhbir Dhillon, Apr 5, 2004.

  1. Hi! I'm trying to split the string from some file with | (pipe) seperated.
    heres one of the string lines from data file.

    Sukhbir Dhillon||data.txt|Thank you|student|
    I'm using following code to read and split
    open (READ_DB, "$dbfile");
    while (<READ_DB>)
    {
    $_ =~ tr/A-Z/a-z/;
    ($name, $value, $filename, $message, $position) = split(/\|/);
    close(READ_DB);

    and I found that $position is getting undef value and which gives lots of error mentioned in the subject.
    I'm pretty new in perl so please excuse my ignorance.
    Thank you
    Sukhbir
    Sukhbir Dhillon, Apr 5, 2004
    #1
    1. Advertising

  2. Sukhbir Dhillon

    Joe Smith Guest

    Sukhbir Dhillon wrote:

    > Sukhbir Dhillon||data.txt|Thank you|student|
    > I'm using following code to read and split
    > open (READ_DB, "$dbfile");
    > while (<READ_DB>)
    > {
    > $_ =~ tr/A-Z/a-z/;
    > ($name, $value, $filename, $message, $position) = split(/\|/);
    > close(READ_DB);
    >
    > and I found that $position is getting undef value


    Of course it is. Your program should expect that, and do something like
    $message = "" unless defined $message;
    $position = "" unless defined $position;

    -Joe
    Joe Smith, Apr 5, 2004
    #2
    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. G Kannan
    Replies:
    1
    Views:
    1,234
    Eric J. Roode
    Oct 11, 2003
  2. smartins68
    Replies:
    1
    Views:
    6,003
    Joe Smith
    Jun 9, 2004
  3. S
    Replies:
    3
    Views:
    327
    Gunnar Hjalmarsson
    Feb 3, 2004
  4. Jesse Cary
    Replies:
    2
    Views:
    220
    J├╝rgen Exner
    Oct 15, 2004
  5. Amaninder
    Replies:
    6
    Views:
    221
    J. Gleixner
    Jul 18, 2006
Loading...

Share This Page