Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do u sort a text file containing speech marks!

Status
Not open for further replies.

tanveer91

Programmer
Nov 13, 2001
31
GB
Hi all,

(Perl) I know how to split and print a text file using commas(,) as seperators.

My question is how can i split and then print a text file which contains speech marks?? e.g.

John Smith, 17, 30 Lee St, "Hobbies include football, basketball, tennis, etc"

YOUR HELP IS GREATLY APPRECIATED
 
OK.

$_= 'John Smith, 17, 30 Lee St, "Hobbies include football, basketball, tennis, etc"'
/"/; # find the first quote
$before = $`; # contains everything before first "
$rest = $& . $'; # everything after that

($nm, $age, $addr) = split(/,/);
$comment = $rest;
Mike
michael.j.lacey@ntlworld.com
Email welcome if you're in a hurry or something -- but post in tek-tips as well please, and I will post my reply here as well.
 
Thanks Mike,

Your code worked fine with a string, but how can i utilise it using an array??

for example, if i have the following text to split:-

John Smith, 17, 30 Lee St, "Hobbies include football, basketball, tennis, etc"
James Marsh, 21, 14 Elder Rd, "Hobbies include computers,
football,cricket, etc"
Tony Hobbs, 19, 54 Denmark Rd, "Hobbies include swimming, football, chess"

Cheers
 
I presume that each line above is an element in your array, so:

foreach $_ (@array){
# my code above
} Mike
michael.j.lacey@ntlworld.com
Email welcome if you're in a hurry or something -- but post in tek-tips as well please, and I will post my reply here as well.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top