question on inverting text -> txet

A

arctan

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.
 
G

Gunnar Hjalmarsson

arctan said:
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';
 
S

Steve Grazzini

Gunnar Hjalmarsson said:
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.
 
G

Gunnar Hjalmarsson

Steve said:
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.
 
A

arctan

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.
 

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

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,042
Latest member
icassiem

Latest Threads

Top