I am getting output
4068801968
56320830995
Is there any way that i can get output like this-
start -40
End - 56
start -68
End- 320
start-801
End -830
start-968
End-995
I cann't able to figure out that how i can pick elements of array one
by one.can you please help me?
Thanks.
Usually that is part of "Introduction to programming for beginners" in the
section that deals with aggregate data structures.
You simple use an index, e.g. $sort_start[5] or $sort_start[$i].
jue
> print @sort_start,"\n";
> print @sort_end,"\n";
>
> I am getting output
> 4068801968
> 56320830995
>
> Is there any way that i can get output like this-
> start -40
> End - 56
>
> start -68
> End- 320
>
> start-801
> End -830
>
> start-968
> End-995
> I cann't able to figure out that how i can pick elements of array one
> by one.can you please help me?
Assuming, for the moment, that @start and @end have the same number of
elements, just iterate through the indices of one of them:
for my $i (0..$#sort_start){
print "start - $sort_start[$i]\n";
print "End - $sort_end[$i]\n";
}
Paul Lalli
Similar discusion happened in the following thread some days back:
HTH,
Mahesh.
For a generalized solution, try using each_array, from the
List::MoreUtils module:
#!/usr/bin/perl
use strict;
use warnings;
use List::MoreUtils qw/each_array/;
my @start = (15, 25, 35, 45);
my @end = (18, 28, 38, 48);
my $each = each_array(@start, @end);
while (my ($start, $end) = $each->()){
print "Start - $start\n";
print "End - $end\n";
}
Paul Lalli
> Hi All,
> I am getting some values from loop and i store all that value in array
> using push function.
> push @start,$start2;
> push @end,$end2;
How about:
push @values, {
start => $start2,
end => $end2
};
> the start values are
> 68 801 968 40
> and the End values are
> 320 830 995 56
> then I sort values of array-
> my @sort_start = sort { $a<=>$b } @start;
> my @sort_end = sort { $a<=>$b } @end;
> print @sort_start,"\n";
> print @sort_end,"\n";
If the intervals are non-overlapping you could do:
@values = sort { $a->{ start } <=> $b->{ start } } @values;
> I am getting output
> 4068801968
> 56320830995
>
> Is there any way that i can get output like this-
> start -40
> End - 56
print "Start - $_->{ start }\nEnd - $_->{ end }\n"
for @values;
--
John Small Perl scripts: http://johnbokma.com/perl/
Perl programmer available: http://castleamber.com/
I ploink googlegroups.com :-)
> yes I know that but i tried it but
If you post your broken code, then we can help you fix it.
--
Tad McClellan SGML consulting
ta...@augustmail.com Perl programming
Fort Worth, Texas
"start2" and end2 shouldn't exist in a vacuum, thier linked somewhere.
A modified Bokma code:
use strict;
use warnings;
## -- what you want to get --
# 40 68 801 968
# 56 320 830 995
## -- what you have --
my @se_array = (68,320, 801,830, 968,995, 40,56);
my %StartEnd_hash = ();
for (my $i = 0; $i < @se_array; $i+=2) {
my ($start2, $end2) = @se_array[$i..($i+1)];
$StartEnd_hash{$start2} = $end2;
}
for (sort {$a <=> $b} keys %StartEnd_hash) {
print "start/end = $_,$StartEnd_hash{$_}\n";
}
__END__
output:
start/end = 40,56
start/end = 68,320
start/end = 801,830
start/end = 968,995
Please note that you have to have apriori knowledge as
to the nature of the link between start and end.
You can write code till you blue in the face, but
unless its got a strategy for sucess, theres no use
writing it.
You mentioned obtaining start2, end2 somewhere
else. Then you portray them as seperate entities
to be correlated later as if you can't link the
two at the time of accuisition. If thats the
case, and as you mention, sometimes theres
multiple start or end values, that totally
invalidates any coding effort whatsoever.
All you have is two dissimilar arrays that have
no correllation.
Please Rita, get it together woman.
^^ s/cc/qu/
Regards
Jahagirdar Vijayvithal S
--
Is OS/2 only half an operating system?
Jahagirdar .V.S 91-80-25099129(O) 91-80-28540394(R)
IC Design Engineer RGES-WLAN,
Texas Instruments (India) Ltd.
Don't follow up my post, I never quoted any of this shit asshole!
Regards
Jahagirdar Vijayvithal S
--
Why doesn't DOS ever say "EXCELLENT command or filename!"