Comparing arrays using pop and shift.

S

sree

Hey, can someone tell me the next step:

I wanna compare if one of this string is the reverse of the next,
using the functions- shift and pop. I could manage to print the
strings using 'while' loop.

$str1=<>;
chomp $str1;
@str1= split("", $str1);

while(@str1) {
@pop= pop(@str1);
}

print "\n";

$str2=<>;
chomp $str2;
@str2= split("", $str2);

while(@str2){
@shift= shift(@str2);
}

Now, how to compare these two arrays, to check if one of the array is
the reverse of the other.
 
S

sln

Hey, can someone tell me the next step:

I wanna compare if one of this string is the reverse of the next,
using the functions- shift and pop. I could manage to print the
strings using 'while' loop.

$str1=<>;
chomp $str1;
@str1= split("", $str1);

while(@str1) {
@pop= pop(@str1);
}

print "\n";

$str2=<>;
chomp $str2;
@str2= split("", $str2);

while(@str2){
@shift= shift(@str2);
}

Now, how to compare these two arrays, to check if one of the array is
the reverse of the other.

Try this:

$reverse='$print';
$print='tnirp$';
if((reverse$reverse)eq$print) {
print "$reverse equals reverse $print\n";
}

-sln
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,989
Messages
2,570,207
Members
46,783
Latest member
RickeyDort

Latest Threads

Top