compare two value in array - Perl


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting compare two value in array - Perl
# 1  
Old 09-26-2011
compare two value in array - Perl

Hi, I just wondering if I want to compare previous value to next value if it same count + 1 if not doesn't count how do we compare in Perl? Thank
# 2  
Old 09-26-2011
What have you tried so far? How are you accessing the array (directly? in a loop? what kind of loop?) What kind of "count" has to be increased?
# 3  
Old 09-26-2011
actually wat I tried to do is to make program that simulated LRL ( Least Recently Loaded ) like Paging Algorithms so the program count for page fault
Code:
#!/usr/bin/perl -w

print "Enter page Access";
chomp ($item = <STDIN>);
my @queue = split /\s+/, $item;
print "Enter a page frame";
$frame = <STDIN>;
if ( $frame >= 3 )
{
    
    
    for ($queue[0]..$frame)
    {
        $pageFault = 0;
        if (grep {$_ eq } @queue)
        {
            $pageFault = $pageFault + 0;
        }
        else
        {
            $pageFault = $pageFault + 1;
        }
    }
    print "$pageFault\n";

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Compare file to array, replace with corresponding second array

ok, so here is the issue, I have 2 arrays. I need to be able to create a loop that will find ${ARRAY1 in the text doc, and replace it with ${ARRAY2 then write the results. I already have that working. The problem is, I need it to do that same result across however many items are in the 2... (2 Replies)
Discussion started by: gentlefury
2 Replies

2. Shell Programming and Scripting

compare two array

Hi firnds, I am having two arrays eg. @a=qw(1 2 3 4) and @b=qw(1 3 6 9) Now, I want to compare two arrays on first index of both arrays and if they matched, it should output remaining indexes Pseudo-code if ($a == $b) { print "remaining indexes";} How can i do this using perl? (1 Reply)
Discussion started by: Renesh
1 Replies

3. Shell Programming and Scripting

HELP on Perl array / sorting - trying to convert Korn Shell Script to Perl

Hi all, Not sure if this should be in the programming forum, but I believe it will get more response under the Shell Programming and Scripting FORUM. Am trying to write a customized df script in Perl and need some help with regards to using arrays and file handlers. At the moment am... (3 Replies)
Discussion started by: newbie_01
3 Replies

4. Shell Programming and Scripting

PERL : Read an array and write to another array with intial string pattern checks

I have an array and two variables as below, I need to check if $datevar is present in $filename. If so, i need to replace $filename with the values in the array. I need the output inside an ARRAY How can this be done. Any help will be appreciated. Thanks in advance. (2 Replies)
Discussion started by: irudayaraj
2 Replies

5. Shell Programming and Scripting

Array in Perl - Detect several file to be in one array

Hi everyone I have one question about using array in perl. let say I have several log file in one folder.. example test1.log test2.log test3.log and the list goes on.. how to make an array for this file? It suppose to detect log file in the current directory and all the log file will... (3 Replies)
Discussion started by: sayachop
3 Replies

6. Shell Programming and Scripting

perl, put one array into many array when field is equal to sth

Hi Everyone, #!/usr/bin/perl use strict; use warnings; my @test=("a;b;qqq;c;d","a;b;ggg;c;d","a;b;qqq;c;d"); would like to split the @test array into two array: @test1=(("a;b;qqq;c;d","a;b;qqq;c;d"); and @test2=("a;b;ggg;c;d"); means search for 3rd filed. Thanks find the... (0 Replies)
Discussion started by: jimmy_y
0 Replies

7. Shell Programming and Scripting

PERL - copy fiel contents to array then compare against other file

Basically to illuminate i want to take a file with mutliple lines, C:\searching4theseletters.txt a b c Read this into an array @ARRAY and then use this to compare against another file C:\inputletters.txt b o a c n a (9 Replies)
Discussion started by: bradleykins
9 Replies

8. Shell Programming and Scripting

Compare Array results

Hi, In a kshell , i need to compare the results of two array . each Non-match value should copy to a new array. For example: ========== Array one contain the following values: A B C Array two contain the following values: C F A E After comparing this arrays , a new array should... (4 Replies)
Discussion started by: yoavbe
4 Replies

9. UNIX for Dummies Questions & Answers

Compare array values

# tail myprocesses.txt 178 processes at Tue Oct 21 14:33:01 IST 2008 16 MySQL processes at Tue Oct 21 14:33:01 IST 2008 175 processes at Tue Oct 21 14:36:01 IST 2008 60 MySQL processes at Tue Oct 21 14:36:01 IST 2008 192 processes at Tue Oct 21 14:39:01 IST 2008 64 MySQL processes at Tue Oct... (2 Replies)
Discussion started by: shantanuo
2 Replies

10. Shell Programming and Scripting

[Perl] Accessing array elements within a sed command in Perl script

I am trying to use a script to replace the header of each file, whose filename are stored within the array $test, using the sed command within a Perl script as follows: $count = 0; while ( $count < $#test ) { `sed -e 's/BIOGRF 321/BIOGRF 332/g' ${test} > 0`; `cat 0 >... (2 Replies)
Discussion started by: userix
2 Replies
Login or Register to Ask a Question