UndergroundScene Forums  

Welcome to the UndergroundScene Forums forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content and access many other special features. Registration is fast, simple and absolutely free so please, join our community today!


Go Back   UndergroundScene Forums > SPECIAL AREAS > Information Technology
Register FAQ Site Areas Gig Guides Members Calendar Arcade Mark Forums Read

Reply
 
LinkBack Thread Tools Display Modes
Old 25th January 2006, 10:04 PM   #1 (permalink)
monk23785
Senior Member
 
monk23785's Avatar
 
Join Date: Feb 2003
Location: Dundee
Posts: 2,537
monk23785 is on a distinguished road
perl programming(quite similar to java)

I'm currently doing perl programming as part of my chemistry course and so far its been pretty similar to java so maybe someone can help me with this.

How can you return/print the number of an array, not the actual value thats in the array but the array numbers itself(eg 0, 1,2, 3, 4 etc)

Its just a little task we've been given but its bugging me that i can't do it
monk23785 is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 25th January 2006, 10:49 PM   #2 (permalink)
krashd
Senior Member
 
krashd's Avatar
 
Join Date: May 2003
Location: Kirktonia
Posts: 2,064
Band: Crosby, Stills, Nash, krashd and Young
krashd Is an irrepressible FUCKING MACHINEkrashd Is an irrepressible FUCKING MACHINEkrashd Is an irrepressible FUCKING MACHINEkrashd Is an irrepressible FUCKING MACHINEkrashd Is an irrepressible FUCKING MACHINEkrashd Is an irrepressible FUCKING MACHINEkrashd Is an irrepressible FUCKING MACHINEkrashd Is an irrepressible FUCKING MACHINEkrashd Is an irrepressible FUCKING MACHINEkrashd Is an irrepressible FUCKING MACHINEkrashd Is an irrepressible FUCKING MACHINE
not a clue, if you were in dundee you could go to the balcony and ask for Ken, he's a Perl whizzkid.

chemistry teaching perl? curious.
krashd is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 25th January 2006, 10:56 PM   #3 (permalink)
monk23785
Senior Member
 
monk23785's Avatar
 
Join Date: Feb 2003
Location: Dundee
Posts: 2,537
monk23785 is on a distinguished road
yea, i found it really weird aswell, it is quite similar to java, I did a java course last year thats why its bugging me that i can't remember how to do it
monk23785 is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 26th January 2006, 12:05 AM   #4 (permalink)
humndislocation
Hardcore is serious guys
 
humndislocation's Avatar
 
Join Date: Mar 2003
Location: Dundee
Posts: 5,996
Band: Blasphemous Necrorapist
humndislocation has a reputation beyond reputehumndislocation has a reputation beyond reputehumndislocation has a reputation beyond reputehumndislocation has a reputation beyond reputehumndislocation has a reputation beyond reputehumndislocation has a reputation beyond reputehumndislocation has a reputation beyond reputehumndislocation has a reputation beyond reputehumndislocation has a reputation beyond reputehumndislocation has a reputation beyond reputehumndislocation has a reputation beyond repute
I don't know perl, but what exactly is it that you want to do? Your question isn't really clear.

"The number of an array" doesn't really make sense.

Your explanation after that doesn't really clarify things either.

It sounds like you might be talking about an associative array, or "hash table", rather than an array, and you want to print a list of keys rather than values? I'm assuming that, because it doesn't really make sense to talk about a regular array that way. If you know the length of a normal array, then you know what all the indices are.

Bear in mind I don't know perl, there could be errors in this because I just looked at some examples on the net and tried to change them without really knowing the syntax all that well.

Code:
%capitals = ('china' => 'beijing', 'england' => 'london', 'france' => 'paris', 'norway' => 'oslo', 'italy' => 'rome');
 
# process hash elements
foreach $k (keys (%capitals))
{
        print $k, " ";
}
If you change the names of countries to numbers, then I think that's basically what you're asking for.

Last edited by humndislocation : 26th January 2006 at 12:10 AM.
humndislocation is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 26th January 2006, 12:28 AM   #5 (permalink)
pixelsink
Senior Member
 
pixelsink's Avatar
 
Join Date: Sep 2002
Location: www.carbonhideout.com
Posts: 4,722
Band: Carbon
pixelsink is a name known to allpixelsink is a name known to allpixelsink is a name known to allpixelsink is a name known to allpixelsink is a name known to allpixelsink is a name known to allpixelsink is a name known to allpixelsink is a name known to allpixelsink is a name known to allpixelsink is a name known to allpixelsink is a name known to all
aaaarrgghhhhh, what planet are you guys from!!!!

I'm just jealous, I wish my brain could do that kinda stuff.
pixelsink is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 26th January 2006, 01:13 AM   #6 (permalink)
monk23785
Senior Member
 
monk23785's Avatar
 
Join Date: Feb 2003
Location: Dundee
Posts: 2,537
monk23785 is on a distinguished road
@titrants=(175,149,122,126,150,169);
$min = $arr[0];
$array = 0;
foreach $t (@titrants) {
if ($t < $min) {
$min = $t;

}
print "Minium is $min\n";


I got that so far, but to the print statement i need to add the arraynumber becuase im using the following set of data

Titrant Ohms
0 175
1 148
2 122
3 126
4 150
5 169

The question is write a program to find the minium point on the graph and which point it is
monk23785 is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 26th January 2006, 12:42 PM   #7 (permalink)
humndislocation
Hardcore is serious guys
 
humndislocation's Avatar
 
Join Date: Mar 2003
Location: Dundee
Posts: 5,996
Band: Blasphemous Necrorapist
humndislocation has a reputation beyond reputehumndislocation has a reputation beyond reputehumndislocation has a reputation beyond reputehumndislocation has a reputation beyond reputehumndislocation has a reputation beyond reputehumndislocation has a reputation beyond reputehumndislocation has a reputation beyond reputehumndislocation has a reputation beyond reputehumndislocation has a reputation beyond reputehumndislocation has a reputation beyond reputehumndislocation has a reputation beyond repute
Quote:
Originally Posted by pixels|ink
aaaarrgghhhhh, what planet are you guys from!!!!

I'm just jealous, I wish my brain could do that kinda stuff.
To be fair, I think the exact same thing when I see one of you arty types draw something really awesome, so it all balances out!
humndislocation is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 26th January 2006, 12:51 PM   #8 (permalink)
humndislocation
Hardcore is serious guys
 
humndislocation's Avatar
 
Join Date: Mar 2003
Location: Dundee
Posts: 5,996
Band: Blasphemous Necrorapist
humndislocation has a reputation beyond reputehumndislocation has a reputation beyond reputehumndislocation has a reputation beyond reputehumndislocation has a reputation beyond reputehumndislocation has a reputation beyond reputehumndislocation has a reputation beyond reputehumndislocation has a reputation beyond reputehumndislocation has a reputation beyond reputehumndislocation has a reputation beyond reputehumndislocation has a reputation beyond reputehumndislocation has a reputation beyond repute
Ahh right, I see what you want to do now. This isn't really so much of a perl question, as it is a generic programming question (unless there's a specific way to do this in perl).

You need two more variables. One of them holds the current index you are looking at, one of them holds the index of the current min value. You update the current index each time you go through the loop, and you update the current min index each time you change the min.

Sorry, that sounds a bit more complex than it really is. Here's what I'm talking about

Code:
@titrants=(175,149,122,126,150,169);
$min = $titrants[0];

$minIndex = 0;
$currentIndex = 0;

foreach $t (@titrants) 
{
  
  if ($t < $min) 
  {
	$min = $t;
        $minIndex = $currentIndex;
  }

  $currentIndex = $currentIndex + 1;

}
Then you just print $minIndex and $min at the end
humndislocation is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 26th January 2006, 01:18 PM   #9 (permalink)
monk23785
Senior Member
 
monk23785's Avatar
 
Join Date: Feb 2003
Location: Dundee
Posts: 2,537
monk23785 is on a distinguished road
looks easy once youve seen it, i ended up just adding in some 'if else' statements because that was th eonly thing i could think of, it did work but it was a bit long winded
monk23785 is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 27th January 2006, 12:46 PM   #10 (permalink)
Red_Baron
Senior Member
 
Red_Baron's Avatar
 
Join Date: Apr 2002
Location: Dundee/Alyth hybrid
Posts: 1,502
Band: 15 Minutes
Red_Baron has a spectacular aura aboutRed_Baron has a spectacular aura aboutRed_Baron has a spectacular aura aboutRed_Baron has a spectacular aura aboutRed_Baron has a spectacular aura aboutRed_Baron has a spectacular aura about
You could actually be really fly and only keep a record of the index of the lowest element the just print the that index and the value at that index

Code:
@titrants=(175,149,122,126,150,169);
$min = $titrants[0];

$minIndex = 0;
$currentIndex = 0;

foreach $t (@titrants) 
{
  
  if ($t < $min) 
  {
	$minIndex = $currentIndex;
  }

  $currentIndex = $currentIndex + 1;

}

print "Minium is $titrants[$minIndex ] at position $minIndex";
Not entirely sure of the syntax for perl but you should get the gist.
Red_Baron is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 27th January 2006, 12:57 PM   #11 (permalink)
humndislocation
Hardcore is serious guys
 
humndislocation's Avatar
 
Join Date: Mar 2003
Location: Dundee
Posts: 5,996
Band: Blasphemous Necrorapist
humndislocation has a reputation beyond reputehumndislocation has a reputation beyond reputehumndislocation has a reputation beyond reputehumndislocation has a reputation beyond reputehumndislocation has a reputation beyond reputehumndislocation has a reputation beyond reputehumndislocation has a reputation beyond reputehumndislocation has a reputation beyond reputehumndislocation has a reputation beyond reputehumndislocation has a reputation beyond reputehumndislocation has a reputation beyond repute
Yeah, that's actually a hell of a lot smarter than my solution.

I must say though, Perl has to be up there as one of the ugliest non-joke languages I have ever seen.

Give me Python or Lua any day.
humndislocation is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 27th January 2006, 01:05 PM   #12 (permalink)
Red_Baron
Senior Member
 
Red_Baron's Avatar
 
Join Date: Apr 2002
Location: Dundee/Alyth hybrid
Posts: 1,502
Band: 15 Minutes
Red_Baron has a spectacular aura aboutRed_Baron has a spectacular aura aboutRed_Baron has a spectacular aura aboutRed_Baron has a spectacular aura aboutRed_Baron has a spectacular aura aboutRed_Baron has a spectacular aura about
Quote:
Originally Posted by humndislocation
Yeah, that's actually a hell of a lot smarter than my solution.

I must say though, Perl has to be up there as one of the ugliest non-joke languages I have ever seen.

Give me Python or Lua any day.
I'd agree with you there Perl has dreadful syntax, Python is a much better. Once you get used to needing tabs before it will compile.Code acually becomes neater as a result.

My favourite at the moment (mostly beause I'm working with it most of the time) is PL/SQL, based on ADA if I remember correctly, it makes life very easy with type anchoring and extensions to SQL.
Red_Baron is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

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

vB 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. The time now is 08:01 PM.


Powered by vBulletin
UndergroundScene.co.uk is bad-ass and under copyright

Content Relevant URLs by vBSEO 3.0.0 RC8