Loading ...
Sorry, an error occurred while loading the content.

Little Script doesn't end

Expand Messages
  • Christian Fuchs
    Hi everybody, I just wrote a little script for practising perl.It s a perl rewrite of the tac tool. It does what it should do, but it just doesn t end ;) I can
    Message 1 of 9 , Oct 31, 2011
    • 0 Attachment
      Hi everybody,

      I just wrote a little script for practising perl.It's a perl rewrite of the tac tool. It does what it should do, but it just doesn't end ;) I can only stop it via the kill signal. I hope someone could help me with this.

      Script:

      #!/usr/bin/perl -w

      while(@lines = <>)
      {
      @lines = reverse @lines;
      print @lines;
      }
    • Shawn H Corey
      ... You don t need the while loop. When you read a file handle into an array, the entire stream gets read. It reverses and print the contents. It then goes
      Message 2 of 9 , Oct 31, 2011
      • 0 Attachment
        On 11-10-31 09:42 AM, Christian Fuchs wrote:
        > I just wrote a little script for practising perl.It's a perl rewrite of
        > the tac tool. It does what it should do, but it just doesn't end ;) I
        > can only stop it via the kill signal. I hope someone could help me with
        > this.
        >
        > Script:
        >
        > #!/usr/bin/perl -w
        >
        > while(@lines = <>)
        > {
        > @lines = reverse @lines;
        > print @lines;
        > }

        You don't need the while loop. When you read a file handle into an
        array, the entire stream gets read. It reverses and print the contents.
        It then goes back and tries to read the next stream. Since there isn't
        one, it sleeps waiting for input.

        Try this instead:

        #!/usr/bin/perl

        use strict;
        use warnings;

        my @lines = <>;
        @lines = reverse @lines;
        print @lines;

        __END__

        --
        Just my 0.00000002 million dollars worth,
        Shawn

        Confusion is the first step of understanding.

        Programming is as much about organization and communication
        as it is about coding.

        The secret to great software: Fail early & often.

        Eliminate software piracy: use only FLOSS.

        "Make something worthwhile." -- Dear Hunter
      • Amish Husain
        try this:   use strict; use warnings; use strict; use warnings; my $lines = ; $lines = reverse $lines; print $lines; ________________________________ From:
        Message 3 of 9 , Oct 31, 2011
        • 0 Attachment
          try this:
           
          use strict;
          use warnings;
          use strict;
          use warnings;
          my $lines = <>;
          $lines = reverse $lines;
          print $lines;


          ________________________________
          From: Shawn H Corey <shawnhcorey@...>
          To: perl-beginner@yahoogroups.com
          Sent: Monday, October 31, 2011 12:27 PM
          Subject: Re: [PBML] Little Script doesn't end


           
          On 11-10-31 09:42 AM, Christian Fuchs wrote:
          > I just wrote a little script for practising perl.It's a perl rewrite of
          > the tac tool. It does what it should do, but it just doesn't end ;) I
          > can only stop it via the kill signal. I hope someone could help me with
          > this.
          >
          > Script:
          >
          > #!/usr/bin/perl -w
          >
          > while(@lines = <>)
          > {
          > @lines = reverse @lines;
          > print @lines;
          > }

          You don't need the while loop. When you read a file handle into an
          array, the entire stream gets read. It reverses and print the contents.
          It then goes back and tries to read the next stream. Since there isn't
          one, it sleeps waiting for input.

          Try this instead:

          #!/usr/bin/perl

          use strict;
          use warnings;

          my @lines = <>;
          @lines = reverse @lines;
          print @lines;

          __END__

          --
          Just my 0.00000002 million dollars worth,
          Shawn

          Confusion is the first step of understanding.

          Programming is as much about organization and communication
          as it is about coding.

          The secret to great software: Fail early & often.

          Eliminate software piracy: use only FLOSS.

          "Make something worthwhile." -- Dear Hunter



          [Non-text portions of this message have been removed]
        • Shawn H Corey
          ... Duplicate, not needed. ... Duplicate, not needed. ... This will read only one line, with a newline at the end. ... This will reverse the characters in the
          Message 4 of 9 , Oct 31, 2011
          • 0 Attachment
            On 11-10-31 01:11 PM, Amish Husain wrote:
            > try this:
            >
            > use strict;
            > use warnings;
            > use strict;

            Duplicate, not needed.

            > use warnings;

            Duplicate, not needed.

            > my $lines = <>;

            This will read only one line, with a newline at the end.

            > $lines = reverse $lines;

            This will reverse the characters in the line. The newline is now at the
            beginning.

            > print $lines;


            --
            Just my 0.00000002 million dollars worth,
            Shawn

            Confusion is the first step of understanding.

            Programming is as much about organization and communication
            as it is about coding.

            The secret to great software: Fail early & often.

            Eliminate software piracy: use only FLOSS.

            "Make something worthwhile." -- Dear Hunter
          • Amish Husain
            right, i just replaced the array with a scalar on ur script. but u made a good point with n ________________________________ From: Shawn H Corey
            Message 5 of 9 , Oct 31, 2011
            • 0 Attachment
              right, i just replaced the array with a scalar on ur script.
              but u made a good point with \n



              ________________________________
              From: Shawn H Corey <shawnhcorey@...>
              To: perl-beginner@yahoogroups.com
              Sent: Monday, October 31, 2011 1:30 PM
              Subject: Re: [PBML] Little Script doesn't end


               
              On 11-10-31 01:11 PM, Amish Husain wrote:
              > try this:
              >
              > use strict;
              > use warnings;
              > use strict;

              Duplicate, not needed.

              > use warnings;

              Duplicate, not needed.

              > my $lines = <>;

              This will read only one line, with a newline at the end.

              > $lines = reverse $lines;

              This will reverse the characters in the line. The newline is now at the
              beginning.

              > print $lines;

              --
              Just my 0.00000002 million dollars worth,
              Shawn

              Confusion is the first step of understanding.

              Programming is as much about organization and communication
              as it is about coding.

              The secret to great software: Fail early & often.

              Eliminate software piracy: use only FLOSS.

              "Make something worthwhile." -- Dear Hunter



              [Non-text portions of this message have been removed]
            • merlyn@stonehenge.com
              ... Amish right, i just replaced the array with a scalar on ur script. And broke it. If your help hurts more than it helps, please stop answering. It makes
              Message 6 of 9 , Oct 31, 2011
              • 0 Attachment
                >>>>> "Amish" == Amish Husain <amishhusain@...> writes:

                Amish> right, i just replaced the array with a scalar on ur script.

                And broke it.

                If your help hurts more than it helps, please stop answering. It makes
                more work for the rest of us.

                --
                Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
                <merlyn@...> <URL:http://www.stonehenge.com/merlyn/>
                Smalltalk/Perl/Unix consulting, Technical writing, Comedy, etc. etc.
                See http://methodsandmessages.posterous.com/ for Smalltalk discussion
              • Shawn H Corey
                ... Actually, it s not clear if the OP wanted to reverse the order of the lines in the file or reverse each line but keep the same order. Or perhaps both. We
                Message 7 of 9 , Oct 31, 2011
                • 0 Attachment
                  On 11-10-31 01:59 PM, merlyn@... wrote:
                  > >>>>> "Amish" == Amish Husain <amishhusain@...
                  > <mailto:amishhusain%40ymail.com>> writes:
                  >
                  > Amish> right, i just replaced the array with a scalar on ur script.
                  >
                  > And broke it.
                  >
                  > If your help hurts more than it helps, please stop answering. It makes
                  > more work for the rest of us.

                  Actually, it's not clear if the OP wanted to reverse the order of the
                  lines in the file or reverse each line but keep the same order. Or
                  perhaps both. We have have to wait for the OP to respond to see which is
                  correct.


                  --
                  Just my 0.00000002 million dollars worth,
                  Shawn

                  Confusion is the first step of understanding.

                  Programming is as much about organization and communication
                  as it is about coding.

                  The secret to great software: Fail early & often.

                  Eliminate software piracy: use only FLOSS.

                  "Make something worthwhile." -- Dear Hunter
                • Christian Fuchs
                  ... Sorry that i hadn t made it clear enough. My purpose is to get the words in the same order as they are, but reversing the lines in which they are printed
                  Message 8 of 9 , Oct 31, 2011
                  • 0 Attachment
                    On Mon, Oct 31, 2011 at 02:02:54PM -0400, Shawn H Corey wrote:
                    > On 11-10-31 01:59 PM, merlyn@... wrote:
                    > > >>>>> "Amish" == Amish Husain <amishhusain@...
                    > > <mailto:amishhusain%40ymail.com>> writes:
                    > >
                    > > Amish> right, i just replaced the array with a scalar on ur script.
                    > >
                    > > And broke it.
                    > >
                    > > If your help hurts more than it helps, please stop answering. It makes
                    > > more work for the rest of us.
                    >
                    > Actually, it's not clear if the OP wanted to reverse the order of the
                    > lines in the file or reverse each line but keep the same order. Or
                    > perhaps both. We have have to wait for the OP to respond to see which is
                    > correct.
                    >
                    >
                    > --
                    > Just my 0.00000002 million dollars worth,
                    > Shawn
                    >
                    > Confusion is the first step of understanding.
                    >
                    > Programming is as much about organization and communication
                    > as it is about coding.
                    >
                    > The secret to great software: Fail early & often.
                    >
                    > Eliminate software piracy: use only FLOSS.
                    >
                    > "Make something worthwhile." -- Dear Hunter


                    Sorry that i hadn't made it clear enough. My purpose is to get the words in the same order as they are, but reversing the lines in which they are printed (First line is last and so on).


                    Thanks for your help!
                  • timothy adigun
                    Hi Christian ... * *I believe Shawn script will do exactly what you are asking for, however, if you want a one liner without the array variable you could also
                    Message 9 of 9 , Nov 2, 2011
                    • 0 Attachment
                      Hi Christian
                      Christian Fuchs <agentphreak@...> wrote:

                      > **
                      >
                      > Sorry that i hadn't made it clear enough. My purpose is to get the words
                      > in the same order as they are, but reversing the lines in which they are
                      > printed (First line is last and so on). Thanks for your help!
                      >

                      * *I believe Shawn script will do exactly what you are asking for, however,
                      if you want a one liner without the array variable you could also use this:

                      #!/usr/bin/perl -w
                      use strict;

                      print reverse <>;






                      _,___

                      >


                      --
                      Tim


                      [Non-text portions of this message have been removed]
                    Your message has been successfully submitted and would be delivered to recipients shortly.