473,385 Members | 1,814 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Finding an element in an unordered list

Dear friends
i would like to know how do get back the keys in hashes using a print statement
and also how do we get the number of elements in a list and their indexes
eg: if i have
Expand|Select|Wrap|Line Numbers
  1. print (("nothing",255, 123, 555)[2]); it prints 123
but now that i want to know which element in the list is 123?. is there a way out to do it
please reply
Oct 6 '07 #1
3 1897
pbmods
5,821 Expert 4TB
Heya, rathankar. Welcome to TSDN!

Please use CODE tags when posting source code:

[CODE=perl]
Perl code goes here.
[/CODE]

I'm going to go ahead and move this thread to the Perl forum, where our resident Experts will be better able to help you out.
Oct 6 '07 #2
numberwhun
3,509 Expert Mod 2GB
Dear friends
i would like to know how do get back the keys in hashes using a print statement
and also how do we get the number of elements in a list and their indexes
eg: if i have
Expand|Select|Wrap|Line Numbers
  1. print (("nothing",255, 123, 555)[2]); it prints 123
but now that i want to know which element in the list is 123?. is there a way out to do it
please reply
First, I completely back up pbmods with regards to the code tags. They are a best practice here on TSDN and should always be used to enclose any posted code.

As for your issue, you will want to read about the keys function that comes with Perl. That is how you access the keys in a hash.

And while you are there, you may want to read the rest of the wonderful documentation they have their, including the perlfunc page, which goes over the standard Perl functions.

Regards,

Jeff
Oct 6 '07 #3
KevinADC
4,059 Expert 2GB
Dear friends
i would like to know how do get back the keys in hashes using a print statement
Expand|Select|Wrap|Line Numbers
  1. print  keys %hash;
and also how do we get the number of elements in a list and their indexes
eg: if i have

Expand|Select|Wrap|Line Numbers
  1. print (("nothing",255, 123, 555)[2]); it prints 123
  2.  
Yes, index 2 is the third element (123) because perl arrays start at index 0 (zero).


The number of elements in an array:

Expand|Select|Wrap|Line Numbers
  1. my $n = @array;
  2. print $n;
but now that i want to know which element in the list is 123?. is there a way out to do it
please reply
You have to loop through the list/array and count where you are in the list/array to know the index number. There is no builtin function in perl5 to do that but there might be in perl6, which is still in development.

Also read the documents Jeff linked you to.
Oct 6 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: CJ | last post by:
I started with this schema: <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified"> <xs:element name="response"> <xs:complexType> <xs:sequence> <xs:element...
5
by: ibiza | last post by:
Hi all, I have a question which I have no ideal of the answer...I am currently working on a web application and at some time, I have a string representing a short text. This could be a simple...
2
by: ElkGroveR | last post by:
Hi there! I'm using PHP to create a simple, dynamic MySQL SELECT query. The user chooses a selection from a HTML Form SELECT element's many options and submits the form via a POST action. ...
3
by: User | last post by:
Hi, Is it possible to transform Ordered/Unordered list into navigation dropdown menus? Is this effect achieved by CSS? or via Javascript? PLease advise Thanks.
4
by: SM | last post by:
Hello, I have an unordered list similar to this one: <ul id=list> <li onclick="addParagraph(0)">Item 1</li> <li onclick="addParagraph(1)">Item 2</li> <li onclick="addParagraph(2)">Item...
2
by: torweb | last post by:
I'm using an image for an unordered list, which works fine. The problem is, the image is also appearing in my numbered "ordered list." Here is my code for the unordered list:...and thanks in...
15
by: rhino | last post by:
I've put together a prototype of two-tiered CSS tabs that works really well in IE6, IE7, and FF2. It also works very well in Opera 9.27 _except_ that the placement of the lower tier of tabs is...
7
by: Nick | last post by:
Hi there, I have a website that functions fine locally, but when published to the server it develops a bottleneck during loading some of the pages. Basically what happens is the page loads to...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.