Re: Hash Sorting Problem



On 02/25/2008 04:32:42 AM, Anirban Adhikary wrote:
-> Dear List
->
-> I need to delete each element after every execution of the foreach
-> loop and
-> I need to update & sorted the @arr1 after every execution of the
-> foreach
-> loop. I have tried a lot but not able to do this ............Pls
-> help...........

You cannot mean what you just said, which is a big reason for it not to work. If you use the elements of an array and then expect redefining the array will continually mean something in a loop this makes no sense.

I did not carefully peruse your code but i think what you REALLY want is some form of nested loop:

$somecount = 0;
$somereason = 10;
until ($somecount > 10) {
foreach $e (@array) {
delete $file{$el};
}
$somereason++;
NOW REDEFINE @array;
}

Also you should understand "push" "shift" "unshift" "pop" because either i miss the point (very possible) or your relating of arrays and hashes does.
.



Relevant Pages

  • Re: a question about for and foreach
    ... foreach (@array) { ... why @array are changed after this foreach loop!!! ... The "foreach" loop iterates over a normal list value and sets the ... If any element of LIST is an lvalue, you can modify it by modifying ...
    (perl.beginners)
  • Re: Re: Re: RE: Perl Question: Optimization
    ... @ids array changes, the statement gets re-prepared, so unless you have the ... # THIS INPUT DATA FILE CONTAINS ABOUT 40000 ROWS ... >prepared statement inside the loop of 40000. ...
    (perl.dbi.users)
  • Re: foreach statement output
    ... by using a 'for' statement instead of the foreach loop: ... and I will use the array to generate a string. ... know about foreach loop workings. ...
    (comp.infosystems.www.authoring.cgi)
  • Re: foreach statement output
    ... know about foreach loop workings. ... I've got an incoming array of unknown ... The Perl Cookbook ... My big confusion over this foreach issue is I failed to realize that the ...
    (comp.infosystems.www.authoring.cgi)
  • Re: Strange behaviour
    ... Personally, I would use the foreach version, as it is easier to read. ... bool AllNegative{ ... besides the difference between for and foreach the first example will always test each element of the array while the second example only tests until it finds the first non-negative. ... This is independant of for/foreach since also a for loop can be exited with return ...
    (microsoft.public.dotnet.languages.csharp)