The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
split and making an array inside another array dcfargo Shell Programming and Scripting 2 08-06-2008 11:07 AM
[KSH] Split string into array piooooter Shell Programming and Scripting 3 09-01-2007 01:22 PM
How to get array to not split at spaces? jjinno Shell Programming and Scripting 1 07-20-2007 01:06 AM
split to array in perl jaganadh Shell Programming and Scripting 3 07-06-2007 06:29 AM
How To Sort Array of Hashes ?? coolguyshail Shell Programming and Scripting 3 05-09-2005 10:31 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 08-29-2008
novera novera is offline
Registered User
  
 

Join Date: Aug 2008
Posts: 1
Array split function & hashes

Hi,

If this is the array that is being returned to me:
Quote:
2245685|2344|Peter|2008-08-01|email@mydomain.com\n2327375|3321|Eddie|2008-08-03|email@mydomain.com\n2351984|4123|Mike|2008-08-04|email@mydomain.com\n
How would I get the values for each of the 3 records?

This works for 1 Record:
Code:
foreach $item (@results)
{
($id, $id2, $name, $date, $email) = split(/\|/, $item, 5);
print "$name<br>";
}
  #2 (permalink)  
Old 08-29-2008
shamrock shamrock is offline Forum Advisor  
Registered User
  
 

Join Date: Oct 2007
Location: USA
Posts: 753
What platform are you on? On Unix the newline (\n) character wouldn't show up because they are line terminators. That is because text following \n would be on a new line.
  #3 (permalink)  
Old 09-01-2008
summer_cherry summer_cherry is offline Forum Advisor  
Registered User
  
 

Join Date: Jun 2007
Location: Beijing China
Posts: 1,088
Code:
open(FH,"<filename");
while(<FH>){
	@arr=split(/\\n/,$_);
        for($i=0;$i<$#arr;$i++){
		($id, $id2, $name, $date, $email)=split(/\|/,$arr[$i]);
		printf("Name:%s,ID1:%s,ID2:%s,Email:%s\n",$name,$id,$id2,$email);
	}
}
close(FH);
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 10:59 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0