Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Perl (http://www.velocityreviews.com/forums/f17-perl.html)
-   -   question on inverting text -> txet (http://www.velocityreviews.com/forums/t24494-question-on-inverting-text-txet.html)

arctan 10-14-2003 05:50 PM

question on inverting text -> txet
 
Hello Group

I was wondering in anyone knew of or could generate a script that
takes an input file which consists of one long line of charachters,
and would output the file inverted (backwards)

i.e. input file looks like: opkiltyo
output file looks like: oytlikpo


Thanks alot in advance for any help offered.

Gunnar Hjalmarsson 10-14-2003 11:28 PM

Re: question on inverting text -> txet
 
arctan wrote:
> I was wondering in anyone knew of or could generate a script that
> takes an input file which consists of one long line of charachters,
> and would output the file inverted (backwards)
>
> i.e. input file looks like: opkiltyo
> output file looks like: oytlikpo


A hint:

print scalar reverse split //, 'opkiltyo';

--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl


Steve Grazzini 10-15-2003 04:30 AM

Re: question on inverting text -> txet
 
Gunnar Hjalmarsson <noreply@gunnar.cc> wrote:
> arctan wrote:
> > i.e. input file looks like: opkiltyo
> > output file looks like: oytlikpo

>
> A hint:
>
> print scalar reverse split //, 'opkiltyo';


Kind of a confusing hint... :-)

# in scalar context: reverses a string
print scalar reverse 'opkiltyo';

# in list context: reverses a list
print reverse split //, 'opkiltyo';

Not that your code doesn't work -- just that it works for an odd
reason. After you split() the characters, reverse() concatentated
them back together and treated them like a scalar.

--
Steve

Gunnar Hjalmarsson 10-15-2003 05:14 AM

Re: question on inverting text -> txet
 
Steve Grazzini wrote:
> Gunnar Hjalmarsson <noreply@gunnar.cc> wrote:
>>arctan wrote:
>>
>>>i.e. input file looks like: opkiltyo
>>> output file looks like: oytlikpo

>>
>>A hint:
>>
>> print scalar reverse split //, 'opkiltyo';

>
> Kind of a confusing hint... :-)
>
> # in scalar context: reverses a string
> print scalar reverse 'opkiltyo';
>
> # in list context: reverses a list
> print reverse split //, 'opkiltyo';
>
> Not that your code doesn't work -- just that it works for an odd
> reason. After you split() the characters, reverse() concatentated
> them back together and treated them like a scalar.


Hmm.. I think I misread the docs. Thanks for pointing it out.

--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl


Roy Johnson 10-15-2003 02:01 PM

Re: question on inverting text -> txet
 
perl -lpe '$_ = reverse'

Roy Johnson 10-15-2003 02:02 PM

Re: question on inverting text -> txet
 
Oh, and this newsgroup doesn't exist. Please use comp.lang.perl.misc instead.

arctan 10-16-2003 09:09 PM

Re: question on inverting text -> txet
 
rjohnson@shell.com (Roy Johnson) wrote in message news:<3ee08638.0310150602.162c82ab@posting.google. com>...
> Oh, and this newsgroup doesn't exist. Please use comp.lang.perl.misc instead.


Thanks alot to the members of this nonexistant group :) That was a
big help. Ill post furthur questions to the suggested perl group.


All times are GMT. The time now is 06:47 AM.

Powered by vBulletin®. Copyright ©2000 - 2013, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57