question on inverting text -> txet

Discussion in 'Perl' started by arctan, Oct 14, 2003.

  1. arctan

    arctan Guest

    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.
    arctan, Oct 14, 2003
    #1
    1. Advertising

  2. 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
    Gunnar Hjalmarsson, Oct 15, 2003
    #2
    1. Advertising

  3. Gunnar Hjalmarsson <> 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
    Steve Grazzini, Oct 15, 2003
    #3
  4. Steve Grazzini wrote:
    > Gunnar Hjalmarsson <> 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
    Gunnar Hjalmarsson, Oct 15, 2003
    #4
  5. arctan

    Roy Johnson Guest

    perl -lpe '$_ = reverse'
    Roy Johnson, Oct 15, 2003
    #5
  6. arctan

    Roy Johnson Guest

    Oh, and this newsgroup doesn't exist. Please use comp.lang.perl.misc instead.
    Roy Johnson, Oct 15, 2003
    #6
  7. arctan

    arctan Guest

    (Roy Johnson) wrote in message news:<>...
    > 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.
    arctan, Oct 16, 2003
    #7
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. MWells
    Replies:
    1
    Views:
    635
    spalding
    Jan 28, 2005
  2. spalding
    Replies:
    1
    Views:
    397
    Peter Blum
    Jan 28, 2005
  3. Niels Dybdahl

    inverting custom cursor

    Niels Dybdahl, Nov 21, 2005, in forum: Java
    Replies:
    0
    Views:
    388
    Niels Dybdahl
    Nov 21, 2005
  4. Irmen de Jong

    'inverting' a dict

    Irmen de Jong, Dec 30, 2003, in forum: Python
    Replies:
    15
    Views:
    625
    Nick Vargish
    Jan 8, 2004
  5. Gary Wessle

    inverting a string

    Gary Wessle, Aug 17, 2006, in forum: C++
    Replies:
    2
    Views:
    451
    Jerry Coffin
    Aug 18, 2006
Loading...

Share This Page