Gossamer Forum
Home : General : Perl Programming :

Split error

Quote Reply
Split error
I read a data from data and i need to split the line. Let's said i got this for
$line = "name|male|23";
@data = split('|',$line);
print $line;
print $data[2];

When I print $line the whole line was printed but when pritn $data[2] was executed only the second character was print but not 'male.

Any idea?
Quote Reply
Re: Split error In reply to
Split doesn't work the same way join does, it usually expects a regular expression. This is how your code should look:

$line = "name|male|23";
@data = split /\|/, $line;
print $line;
print $data[2];

This is a common mistake, I always get my splits and joins kinda confused, and I have been doing this for awhile.


------------------
Fred Hirsch
Web Consultant & Programmer
Quote Reply
Re: Split error In reply to
ok it worked thanx