-
foreach $key (keys (%hash)){
-
print "$hash{$key}:";
-
}
-
The last element will also be followed by a ":" which is not what I want. Is there a way to tell when foreach loops to its last round, so that I can skip printing the last ":"? Thanks!
5 9175
First, please use code tags, they are required.
Second, can you provide a sample of the data so we can see what you are talking about?
Regards,
Jeff
already answered on tek-tips - print join(':', map{$hash{$_}} keys %hash);
for example assume i have an array i.e, -
my @a = (1,2,3,4,5,6);
-
-
for(my $i = 0;$i<$#a;$i++) {
-
print $a[$i];
-
}
-
Above for loop we r excluding last element to print;
That's because you have i<$#a - use i<=$#a instead.
Better yet, use a foreach loop: - for my $element (@a) {
-
print $element;
-
}
for example assume i have an array i.e, -
my @a = (1,2,3,4,5,6);
-
-
for(my $i = 0;$i<$#a;$i++) {
-
print $a[$i];
-
}
-
Above for loop we r excluding last element to print;
Next time post a new thread.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Mike P |
last post by:
In a foreach loop, how do you break out of the iteration but not the
loop? Break and continue both seem to exit the loop, I need something
that for example on an if statement will cease execution...
|
by: TrintCSD |
last post by:
How can I reset the collections within a foreach to be read as a change from
within the foreach loop then restart the foreach after collections has been
changed?
foreach(string invoice in...
|
by: Robert Bravery |
last post by:
HI all,
If I have a foreach loop, is there a way to tell what number of itteration I
am on during each loop
Thanks
Robert
|
by: cody |
last post by:
Currently it is only legal to use types which has a method named
GetEnumerator to be used in a foreach loop.
This makes it impossible to use the same Enumerator after and before a
foreach loop,...
|
by: Florian Lindner |
last post by:
Hello,
can I determine somehow if the iteration on a list of values is the last
iteration?
Example:
for i in :
if last_iteration:
print i*i
else:
|
by: fig000 |
last post by:
HI,
I'm new to generics. I've written a simple class to which I'm
passing a generic list. I'm able to pass the list and even pass the
type of the list so I can use it to traverse it. It's a...
|
by: Perl Beginner |
last post by:
I hope i can articulate this question properly. i have been trying to figure this out for over a week.
I am comparing the contents of two files, but the comparison is done inside of a foreach...
|
by: tshad |
last post by:
Is there a way to know if you are looking at the last record record of
foreach loop other then setting up a loop counter that you manually
increment?
foreach (Racecar racecar in...
|
by: fjm |
last post by:
Hello everyone and happy Sunday. :)
I have a problem that I *think* I may know the solution to but have no idea how to write the code for it. I am working on a templating system wher I have...
|
by: greyseal96 |
last post by:
Hi,
I am a pretty new programmer, so I apologize in andvance if this is a dumb question...
In a book that I'm reading to learn C#, it says that when using a foreach() loop, a read-only copy of...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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$) {
}
...
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
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
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
| |