Advertisement

03.26.2008 at 01:24PM PDT, ID: 23271989
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

Loading a variable into a 4-dimensional array?
Tags: Perl
here's a variable I have that looks like this:

1 2 5 20
2 4 7 30
3 4 5 20
4 6 4 20

so the variable looks like this: 1\t2\t5\20\n2\t4\t7\30\n3\t4\t5\20\n4\t6\t4\20

How would I lode the var into a 4-dimensional array so it looks like:
@array[1,1] = 1
@array[1,2] = 2
@array[1,3] = 5
@array[1,4] = 20
@array[2,1] = 2
and so on?

Thanks,
MS
Start your free trial to view this solution
Question Stats
Zone: Programming
Question Asked By: mschwade
Solution Provided By: Adam314
Participating Experts: 2
Solution Grade: A
Views: 0
Translate:
Loading Advertisement...
03.26.2008 at 01:37PM PDT, ID: 21215941

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
03.26.2008 at 01:43PM PDT, ID: 21215994

Rank: Genius

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
03.26.2008 at 01:46PM PDT, ID: 21216028

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
03.26.2008 at 01:55PM PDT, ID: 21216107

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
03.26.2008 at 02:26PM PDT, ID: 21216377

Rank: Genius

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
03.27.2008 at 11:14AM PDT, ID: 21224284

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
03.27.2008 at 11:56AM PDT, ID: 21224653

Rank: Genius

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
03.27.2008 at 12:01PM PDT, ID: 21224692

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
03.27.2008 at 12:03PM PDT, ID: 21224708

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
 
Loading Advertisement...
Microsoft
  • Internet Protocols
  • Applications
  • Development
  • OS
  • Hardware
  • Windows Security
Apple
  • Operating Systems
  • Hardware
  • Programming
  • Networking
  • Software
Internet
  • Search Engines
  • File Sharing
  • WebTrends / Stats
  • Spy / Ad Blockers
  • Web Browsers
  • New Net Users
  • Web Development
  • Chat / IM
  • Anti Spam
  • Web Servers
  • Anti-Virus
  • Email Clients
Gamers
  • Tips
  • Online / MMORPG
  • Puzzle
  • Emulators
  • Action / Adventure
  • Role Playing
  • Consoles
  • Game Programming
  • Strategy
  • Sports
  • Misc
  • Computer Games
Digital Living
  • Hardware
  • New Net Users
  • New Users
  • Software
  • Digital Music
  • Gaming World
  • Home Security
  • Apple
  • Networking Hardware
Virus & Spyware
  • Vulnerabilities
  • IDS
  • Encryption
  • Anti-Virus
  • Operating Systems Security
  • Software Firewalls
  • WebApplications
  • Cell Phones
  • Operating Systems
  • Internet
  • Hardware Firewalls
Hardware
  • Handhelds / PDAs
  • Displays / Monitors
  • Components
  • Networking Hardware
  • Peripherals
  • Laptops/Notebooks
  • Storage
  • Servers
  • Desktops
  • New Users
  • Misc
  • Apple
Software
  • System Utilities
  • Industry Specific
  • Network Management
  • Photos / Graphics
  • Page Layout
  • VMWare
  • Misc
  • Web Development
  • OS
  • CYGWIN
  • Voice Recognition
  • Message Queue
  • Quality Assurance
  • Security
  • Firewalls
  • MultiMedia Applications
  • Development
  • Database
  • Office / Productivity
  • Business Management
  • OS/2 Apps
  • Server Software
  • Internet / Email
ITPro
  • OS
  • Storage
  • Encryption
  • Operating Systems Security
  • Apple Hardware
  • Laptops & Notebooks
  • Servers
  • Networking Hardware
  • Peripherals
  • Devices
  • Displays / Monitors
  • WebTrends / Stats
  • Search Engines
  • Firewalls
  • WebApplications
  • IDS
  • Vulnerabilities
  • Email Clients
  • File Sharing
  • Spy / Ad Blockers
  • Web Browsers
  • Web Servers
  • Networking
  • Anti-Virus
  • Chat / IM
  • Anti Spam
Developer
  • Web Servers
  • Web Browsers
  • Game Programming
  • Dev Tools
  • Industry Specific
  • Office / Productivity
  • Database
  • CYGWIN
  • Web Development
  • Search Engines
  • File Sharing
  • WebTrends / Stats
  • Programming
  • Content Management
  • Application Servers
  • Protocols
Storage
  • Removable Backup Media
  • Storage Technology
  • Servers
  • Grid
  • Remote Access
  • Backup / Restore
  • Misc
  • Hard Drives
OS
  • Miscellaneous
  • Security
  • Development
  • Linux
  • VMWare
  • MainFrame OS
  • Unix
  • Apple
  • OS / 2
  • AS / 400
  • BeOS
  • Microsoft
  • VMS / OpenVMS
Database
  • Oracle
  • Miscellaneous
  • MySQL
  • Software
  • Sybase
  • Contact Management
  • PostgreSQL
  • Data Manipulation
  • Clarion
  • InterSystems Cache
  • Siebel
  • MUMPS
  • OLAP
  • SQLBase
  • SAS
  • GIS & GPS
  • 4GL
  • Berkeley DB
  • DB2
  • Informix
  • Interbase / Firebird
  • FoxPro
  • Reporting
  • LDAP
  • Filemaker Pro
  • MS SQL Server
  • dBase
  • MS Access
Security
  • Misc
  • Web Browsers
  • Software Firewalls
  • Operating Systems Security
  • File Sharing
  • Spy / Ad Blockers
  • Vulnerabilities
  • WebApplications
  • IDS
  • Anti-Virus
  • Encryption
  • Anti Spam
  • Email Clients
  • VPN
  • Chat / IM
Programming
  • Editors IDEs
  • Installation
  • Handhelds / PDAs
  • Multimedia Programming
  • System / Kernel
  • Algorithms
  • Game
  • Signal Processing
  • Project Management
  • Open Source
  • Database
  • Misc
  • Languages
  • Processor Platforms
  • Theory
Web Development
  • Scripting
  • Blogs
  • Web Servers
  • Software
  • Search Engines
  • Web Graphics
  • Images
  • Internet Marketing
  • Images and Photos
  • Components
  • Document Imaging
  • Web Languages/Standards
  • Illustration
  • WebApplications
  • Fonts
  • WebTrends / Stats
  • Authoring
  • Digital Camera Software
  • Miscellaneous
Networking
  • Protocols
  • Apple Networking
  • Network Management
  • Message Queue
  • Application Servers
  • Content Management
  • File Servers
  • Email Servers
  • Misc
  • Java Editors & IDEs
  • Wireless
  • Networking Hardware
  • Backup / Restore
  • System Utilities
  • ISPs & Hosting
  • Web Servers
  • Storage Technology
  • Removable Backup Media
  • Servers
  • Broadband
  • Grid
  • OS / 2
  • Novell Netware
  • Unix Networking
  • Windows Networking
  • Security
  • Telecommunications
  • Operating Systems
  • Linux Networking
Other
  • Community Advisor
  • Lounge
  • Community Support
  • New Net Users
  • Philosophy / Religion
  • Math / Science
  • Miscellaneous
  • URLs
  • Expert Lounge
  • Politics
  • Puzzles / Riddles
Community Support
  • Suggestions
  • New to EE
  • New Topics
  • Community Advisor
  • CleanUp
  • Announcements
  • General
  • Feedback
  • Input
  • EE Bugs
 
03.26.2008 at 01:37PM PDT, ID: 21215941
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
#!perl
 
use Data::Dumper;
 
my $v = "1\t2\t5\t20\n2\t4\t7\t30\n3\t4\t5\t20\n4\t6\t4\t20";
 
my @a;
 
for (my $x = 0; $x <4; $x++) {
	my @temp = split(/\n/, $v);
	@a[$x] = split(/\n/,$temp[$x]);
 
}
 
print Dumper \@a;
Open in New Window
 
03.26.2008 at 01:43PM PDT, ID: 21215994

Rank: Genius

The way you are indexing the @array isn't right for perl, you would use $array[1][1].  Also, array indexes normally begin at 0, not 1.  

If you really want the array to begin at 1 instead of 0, you coudl set $[=1, but this is highly discouraged.

Or you could fill the zero'th element with undef (or something else), so the first value from your data is at index 1.

Here is some code that will work though.  I've added statements to allow your data to start at 1, but have them commented out.
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
my @array;
#push @array, [];    #fill zero'th element with empty
while(<DATA>) {
	chomp;
	push @array, [split /\t/];     #Normal
	#push @array, [undef, split /\t/];     #Start at 1
}
 
 
 
__DATA__
1	2	5	20
2	4	7	30
3	4	5	20
4	6	4	20
Open in New Window
 
03.26.2008 at 01:46PM PDT, ID: 21216028
Wouldn't it be:

@a[$x] = split(/\t/,$temp[$x]);
instead of:
@a[$x] = split(/\n/,$temp[$x]);

??
Thanks,
MS
 
03.26.2008 at 01:55PM PDT, ID: 21216107
Depends on what you want to split on.  \t splits on the Tab.  \n splits on the NewLine.  In my example I am splitting on the new line and loading that entire line into the Array.

 
03.26.2008 at 02:26PM PDT, ID: 21216377

Rank: Genius

That code from dobbz does not create a 2-dimensional array like you asked for.  It creates an array, and loads a string (the entire line) into it.  If you change it to /\t/ instead of /\n/, you will end up with just the first value of each line in your final array.  Still not a 2-dimensional array.
Also, that is hard coded to have 4 rows of data.  If this isn't always the case, that won't work.

If you have you data in a single variable, you can change the code I gave before to this to work with that:
1:
2:
3:
4:
5:
6:
7:
my $str = "1\t2\t5\t20\n2\t4\t7\t30\n3\t4\t5\t20\n4\t6\t4\t20";
 
my @array;
foreach (split(/\n/, $str)) {
	push @array, [split /\t/];
}
 
Open in New Window
Accepted Solution
 
03.27.2008 at 11:14AM PDT, ID: 21224284
Adam, how would I print these then? I tried this, but it didn;t work:
foreach (@array) {
print $_;
}

Thanks,
MS
 
03.27.2008 at 11:56AM PDT, ID: 21224653

Rank: Genius

1:
2:
3:
foreach (@array) {
    print join(", ", @$_) . "\n";
}
Open in New Window
 
03.27.2008 at 12:01PM PDT, ID: 21224692
one other question before i close this,

can I reference it this way:

print @array[1][1]; to get the value stored in 1,1?

Thanks!
 
03.27.2008 at 12:03PM PDT, ID: 21224708
I figured it out... print $array[1][1];

thanks!
 
 
20080236-EE-VQP-29 / EE_QW_2_20070628