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

  • Thread starter Sukhbir Dhillon
  • Start date
S

Sukhbir Dhillon

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|[email protected]|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
 
J

Joe Smith

Sukhbir said:
Sukhbir Dhillon|[email protected]|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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,731
Messages
2,569,432
Members
44,834
Latest member
BuyCannaLabsCBD

Latest Threads

Top