1 Replies - 1692 Views - Last Post: 31 December 2008 - 04:12 PM

#1 no2pencil   User is offline

  • Professor Snuggly Pants
  • member icon

Reputation: 6747
  • View blog
  • Posts: 31,231
  • Joined: 10-May 07

Reverse a given string

Posted 26 July 2007 - 06:51 AM

Description: This script uses the split command to split a string into an array & then reverses the order of the array elements.
#!/usr/bin/perl
# Written by #2pencil 7/26/2007

print "n======= Enter word to reverse: ";

$word=;
chop($word);
@letters=split(undef,$word);

for($i=0;$i
						
						

Is This A Good Question/Topic? 0
  • +

Replies To: Reverse a given string

#2 KevinADC   User is offline

  • D.I.C Regular
  • member icon

Reputation: 27
  • View blog
  • Posts: 401
  • Joined: 23-January 07

Re: Reverse a given string

Posted 31 December 2008 - 04:12 PM

if you want to easily reverse a string use the reverse function in scalar context: print "\n======= Enter word to reverse: "; my $word=; chomp($word); print scalar reverse $word;
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1