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 here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
How to transpose data elements in awk ahjiefreak Shell Programming and Scripting 2 05-13-2008 01:44 AM
Map - printing all elements - why? dhanamurthy High Level Programming 0 04-14-2008 10:19 AM
Reomve elements from a path name kgeasler Shell Programming and Scripting 3 03-26-2008 10:48 AM
Help in extracting only certain elements in file ahjiefreak Shell Programming and Scripting 1 12-07-2007 12:20 AM
seperate elements of a file nektarios4u Shell Programming and Scripting 1 11-02-2007 09:53 AM

Reply
 
Submit Tools LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 05-10-2008
Registered User
 

Join Date: May 2008
Posts: 1
Stumble this Post!
just want certail elements

I just want to be able to take every 6 value out of an arrays
can someone tell me what i'm doing wrong? the data looks like

1500680,Treverbyn,397,1,2136,4420 and i want the 2 element treverbyn out of every row

#hour0.pl
my $url = 'http://en19.tribalwars.net/map/tribe.txt';
use LWP::Simple;
my $content = get $url;
@array=split(/,/, $content);
$n=1;
print " @array[1,7..56]\n";
$n++;
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 05-10-2008
Moderator
 

Join Date: Sep 2002
Location: Hong Kong, China
Posts: 1,432
Stumble this Post!
Even though you are getting the entire file in a variable, the best is to treat it as if an ordinary file and read the file line-by-line and then split the fields as usual.

Code:
#!/usr/bin/perl -w

my $url = 'http://en19.tribalwars.net/map/tribe.txt';
use LWP::Simple;
my $content = get $url;
my @uid;
open(DAT, "<", \$content) or die $!;
while ($line = <DAT>) {
	push(@uid, [split(/,/, $line)]->[1]);
}
close DAT;

use Data::Dumper;
print Dumper(\@uid);
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 11:37 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008 The CEP Blog All Rights Reserved -Ad Management by RedTyger Visit The Global Fact Book

Content Relevant URLs by vBSEO 3.2.0