See below
> Greetings, > > I am trying to get name, phone and address in a lexical variable and > trying to print it, but, I am not getting the expected output. Any > help is greatly appreciated. > > [code] > use strict; > use warnings; > > while (<DATA>) { > my ($name, $phone, $address) = /^([a-zA-Z ]+):([\-\d]+):([\w, > ])$/; > print "Name : $name\n" if defined $name; > print "Phone : $phone\n" if defined $phone; > print "Address : $address\n" if defined $address; > } > > __DATA__ > Sachin Tendulkar:408-724?0140:23, Brooke Street, Sunnyvale,CA 94088 > Mahendra Singh Dhoni:408?456?1234:76, Charles Street, Washington, MA > 02131 > Rahul Dravid:408?253?3122:123, Queens Street, Canberra, Australia > Virendar Sehwag:293?259?5395:15 Hilton Avenue, Sydney, Australia > [/code] > > > Where am I going wrong?. > > best, > Shaji > ------------------------------------------------------------------------------- > Your talent is God's gift to you. What you do with it is your gift > back to God. > ------------------------------------------------------------------------------- Shaji, This worked for me: use strict; use warnings; while (<DATA>) { my ($name, $phone, $address) = split(':'); print "Name : $name\n" if defined $name; print "Phone : $phone\n" if defined $phone; print "Address : $address\n" if defined $address; } __DATA__ Sachin Tendulkar:408-7240140:23, Brooke Street, Sunnyvale,CA 94088 Mahendra Singh Dhoni:4084561234:76, Charles Street, Washington, MA 02131 Rahul Dravid:4082533122:123, Queens Street, Canberra, Australia Virendar Sehwag:2932595395:15 Hilton Avenue, Sydney, Australia Note that the "split" is using the default "$_". Nathan -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/