Write a script to reverse a string without using Perl's
built in function
Answers were Sorted based on User's Feedback
Answer / kiruthikau
my $i;
my $str="hello";
my @str=split('',$str);
for($i=$#str;$i>=0;$i--)
{
print $str[$i];
}
Is This Answer Correct ? | 47 Yes | 15 No |
Answer / vipul dalwala
#!/usr/bin/perl
my $str = "hello";
$revstr = "";
while($str =~ /(.)/g)
{
$revstr = $1.$revstr;
}
print $revstr."\n";
Is This Answer Correct ? | 12 Yes | 2 No |
Answer / kiran pawar
my $string = "kiran";
my @name = split//,$string;
while(@name){
print pop @name;
}
Is This Answer Correct ? | 9 Yes | 1 No |
Answer / arukumar g m
my $string="hello";
my $str;
my $i = length($string);
while($i>0) {
my $nthstr = substr($string, $i-1, 1);
$str.=$nthstr;
$i = $i-1;
}
print $str;
Is This Answer Correct ? | 3 Yes | 0 No |
Answer / uma from sswdept - hov service
$strin = "uma";
print "\n \$strin <$strin>";
$len = length($strin);
@arr = split(//,$strin);
print "\n \$len $len \@arr <@arr>";
for($i=$len-1;$i>=0;$i--)
{
print $arr[$i];
$retVal .= join(//,$arr[$i]);
print "\n retVal <$retVal> ";
}
Is This Answer Correct ? | 3 Yes | 2 No |
Answer / venkatesh
#!/usr/bin/perl
$a = "Venky";
@c;
@b = split("", $a);
foreach $char (@b){
unshift(@c, $char);
}
$value = join("", @c);
print "$value\n";
Is This Answer Correct ? | 1 Yes | 0 No |
Answer / pallavi w
#!/usr/bin/perl -w
2
3 use strict;
4 my $string = "STRING";
5 my $rev_string = join "", reverse (split ("", $string));
6
7 print "The String is ". $string ."\n";
8 print "The reverse string is ". $rev_string ."\n";
Is This Answer Correct ? | 4 Yes | 8 No |
What is perl dbi?
while (my ($key, $value) = each(%ENV)) { print "$key - $value\n"; } What does the above sample code produce? What function do you use for reading a list of files within a directory? my %hash = ( 'hi' => {'hello' => 'all'}, 'bye' => {'later' => 'gone'} ); print $hash{'hi'}; What is printed when the above code is executed? sub new { my $pkg = shift; my $test = {'name' => shift;}; ???? return $test; } Which one of the following replaces "????" in the above code in order to cause the function new to return an object of type "Test"? while (<STDIN>) { ???? print "$_\n"; } Which one of the following statements causes the above code to strip all whitespace from the end of all lines of input and to print the resulting lines to standard output while (my ($key,$value) = each(%hash)) { print "$key - $value\n"; delete $hash{$key}; } open(FILE,"<file.dat"); my $data = ''; { local $/ = undef; $data = <FILE>; } close(FILE); my $foo = 21; $foo <<= 5; $foo >>= 4; print $foo; @arr = (1,2,3); {local $" = "\n"; print "@arr\n"; } my $line = "Hello World"; substr($line,5,2) = "abc"; print $line; Why is sprintf rarely used in perl in comparison to similar (or the same) functions in other languages? my $subRef = sub {print shift;}; How is the subroutine above called with one parameter? How can the values of an associative array be placed in sorted order in a new array? What function is often necessary for building data structures to be passed to low-level routines such as ioctl and fcntl? sub foo { if (shift(@_) > 0) { shift; } } print foo(10,5); print foo(-10,5); What does the above sample for (my $i = 1; $i <= 3; $i++) { print 1..$i; print "\n"; } my $data = 5**3 * 12,2+2; print $data; sub foo { my $value = shift; if ($value) { print 1; shift; } else { return shift(@_) + 3; } } print foo(10,20); What is printed as the result of executing the above code? $var = 20; sub s1 { print "$var "; } sub s2 { local $var = 10; s1;} sub s3 { my $var = 30; s1;} s3; s2; s1; On systems that record file ownership, how may the owner of a file be identified? Which one of the following sets $y to be a copy of $x with every occurrence of foo changed to bar? Which one of the following is an array literal that represents a 4-element array containing the numbers 1, 4, 2, and 6? sub foo {2*shift || 'x';} printf ("%s %s %s", foo(5),foo(0),foo(-5)); What does the above sample code print? Suppose $x contains a number. Which one of the following statements sets $y to be a string containing the octal value of $x?
what are prefix dereferencer and list them out?
What does read () command do?
What is the difference between die and exit in perl?
How to connect with sqlserver from perl and how to display database table info?
Is there any way to add two arrays together?
Which web site will help the student to download the Java mini Project ?
How will you create a file in perl?
Difference between the variables in which chomp function work ?
Can any1 tell me 2 write the script using perl script 2 looking at a log file 2 see wheather the test has passed or not.
What can be done for efficient parameter passing in perl? Explain.