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

Re: [PBML] Perl Problem

Expand Messages
  • Sakura Kinomoto
    I read ur problem entirely,but i don t know what does this perl -00lne push @{ $h{ $1 } }, $_ if /of ([0-9]+) bytes/m;}{print for map @{ $h{ $_ } }, sort { $b
    Message 1 of 11 , Jul 14 12:48 AM
    • 0 Attachment
      I read ur problem entirely,but i don't know what does this perl -00lne 'push @{
      $h{ $1 } }, $_ if /of ([0-9]+) bytes/m;}{print for map @{ $h{ $_ } }, sort { $b
      <=> $a } keys %h;'filename mean,why don't u try to write it as a
      script~?translate ur command-line code into a true perl code,and it can let u
      know where goes wrong^.^





      ________________________________
      From: hiprateek007 <hiprateek007@...>
      To: perl-beginner@yahoogroups.com
      Sent: Tue, July 6, 2010 1:19:19 PM
      Subject: [PBML] Perl Problem

       
      Hi,
      I have a task of sorting a file paragraph wise on the basis of an integer in the
      first line of those paragraphs.

      Like:

      the integer is 10
      ....
      ....
      p1

      the integer is 20
      .....
      ...
      ....
      p2

      the output sd be :

      p2

      p1

      I managed to get this done by command:
      perl -00lne 'push @{ $h{ $1 } }, $_ if /of ([0-9]+) bytes/m;}{print for map @{
      $h{ $_ } }, sort { $b <=> $a } keys %h;'filename

      But now I also want to print the some of those integers. I guess we can use the
      $a and $b to do that but I dont know how exactly to do that since I am all new
      to perl.

      Thanks in advance

      Prateek Mathur







      [Non-text portions of this message have been removed]
    • Prateek Mathur
      Hi All,              Extending to the question I asked earlier I have one more task to do and I think perl can handle that easily. What I need to
      Message 2 of 11 , Jul 14 2:46 AM
      • 0 Attachment
        Hi All,
                     Extending to the question I asked earlier I have one more task to do and I think perl can handle that easily.

        What I need to do is filer a file with multiple paragraphs based on certain criteria.
        1) Like I need to delete all those paragraphs which contain certain keyword
                 e.g delete all those paragraphs which contain words foo , bar , etc...(any one is sufficient to delete)
        2) Which contain two keywords one follwed by the other.
             e.g all paragraphs that contain word foo followed by bar anywhere in the remaining text of the paragraph.
        3) Delete all single line paragraphs.

        Also I need to save all the contents which will be deleted in a separate file and all the filtered contents in another file.

        I was able to do this task of deleting using sed also but I am not sure how can I save the deleted content using sed.

        Please let me know in case something is not clear.

        Thanks in advance

        Prateek
             

        --- On Wed, 7/14/10, Sakura Kinomoto <sxsakura@...> wrote:

        From: Sakura Kinomoto <sxsakura@...>
        Subject: Re: [PBML] Perl Problem
        To: perl-beginner@yahoogroups.com
        Date: Wednesday, July 14, 2010, 1:18 PM
















         









        I read ur problem entirely,but i don't know what does this perl -00lne 'push @{

        $h{ $1 } }, $_ if /of ([0-9]+) bytes/m;}{print for map @{ $h{ $_ } }, sort { $b

        <=> $a } keys %h;'filename mean,why don't u try to write it as a

        script~?translate ur command-line code into a true perl code,and it can let u

        know where goes wrong^.^



        ________________________________

        From: hiprateek007 <hiprateek007@...>

        To: perl-beginner@yahoogroups.com

        Sent: Tue, July 6, 2010 1:19:19 PM

        Subject: [PBML] Perl Problem



         

        Hi,

        I have a task of sorting a file paragraph wise on the basis of an integer in the

        first line of those paragraphs.



        Like:



        the integer is 10

        ....

        ....

        p1



        the integer is 20

        .....

        ...

        ....

        p2



        the output sd be :



        p2



        p1



        I managed to get this done by command:

        perl -00lne 'push @{ $h{ $1 } }, $_ if /of ([0-9]+) bytes/m;}{print for map @{

        $h{ $_ } }, sort { $b <=> $a } keys %h;'filename



        But now I also want to print the some of those integers. I guess we can use the

        $a and $b to do that but I dont know how exactly to do that since I am all new

        to perl.



        Thanks in advance



        Prateek Mathur



        [Non-text portions of this message have been removed]






























        [Non-text portions of this message have been removed]
      • Jenda Krynicky
        To: perl-beginner@yahoogroups.com From: Sakura Kinomoto Date sent: Wed, 14 Jul 2010 00:48:42 -0700 (PDT)
        Message 3 of 11 , Jul 19 1:21 PM
        • 0 Attachment
          To: perl-beginner@yahoogroups.com
          From: Sakura Kinomoto <sxsakura@...>
          Date sent: Wed, 14 Jul 2010 00:48:42 -0700 (PDT)
          Subject: Re: [PBML] Perl Problem
          Send reply to: perl-beginner@yahoogroups.com

          > I read ur problem entirely,but i don't know what does this perl -00lne 'push @{
          > $h{ $1 } }, $_ if /of ([0-9]+) bytes/m;}{print for map @{ $h{ $_ } }, sort { $b
          > <=> $a } keys %h;'filename mean,why don't u try to write it as a
          > script~?translate ur command-line code into a true perl code,and it can let u
          > know where goes wrong^.^

          I read your message entirely and right after I quit vomiting I sat
          down to write a response. FOR GAWDS SAKE FORGET THAT STUPID KEWL
          SPELLING.

          There is no "ur" or "u" in English!

          Jenda
          P.S.: You do not have to respond to every single message sent to the
          list, if you do not understand the question, why do you think your
          reply will be of any use?
          ===== Jenda@... === http://Jenda.Krynicky.cz =====
          When it comes to wine, women and song, wizards are allowed
          to get drunk and croon as much as they like.
          -- Terry Pratchett in Sourcery
        • Rob Richardson
          Ladies, gentlemen and others (of whom I hope we don t have too many), Please keep discussions civil. It is possible to suggest to others that their posts
          Message 4 of 11 , Jul 19 2:52 PM
          • 0 Attachment
            Ladies, gentlemen and others (of whom I hope we don't have too many),

            Please keep discussions civil. It is possible to suggest to others
            that their posts might be more easily understood if they are written
            in correct English without insulting them.

            Rob Richardson
            Moderator, perl-beginner@yahoogroups.com
          • Kenneth Wolcott
            Hi; Here s my request: Please do not use phonetic shorthand English that is popular during cell phone texting if you want me to read and (hopefully) respond to
            Message 5 of 11 , Jul 19 2:59 PM
            • 0 Attachment
              Hi;

              Here's my request:

              Please do not use phonetic shorthand English that is popular during cell
              phone texting if you want me to read and (hopefully) respond to your
              posting.

              Thanks,
              Ken Wolcott

              On Mon, Jul 19, 2010 at 14:52, Rob Richardson <CedricCicada@...>wrote:

              >
              >
              > Ladies, gentlemen and others (of whom I hope we don't have too many),
              >
              > Please keep discussions civil. It is possible to suggest to others
              > that their posts might be more easily understood if they are written
              > in correct English without insulting them.
              >
              > Rob Richardson
              > Moderator, perl-beginner@yahoogroups.com <perl-beginner%40yahoogroups.com>
              >
              >


              [Non-text portions of this message have been removed]
            • merlyn@stonehenge.com
              ... Kenneth Please do not use phonetic shorthand English that is popular during cell Kenneth phone texting if you want me to read and (hopefully) respond
              Message 6 of 11 , Jul 19 3:20 PM
              • 0 Attachment
                >>>>> "Kenneth" == Kenneth Wolcott <kennethwolcott@...> writes:

                Kenneth> Please do not use phonetic shorthand English that is popular during cell
                Kenneth> phone texting if you want me to read and (hopefully) respond to your
                Kenneth> posting.

                Seconded.

                As I say on IRC,

                "if you're paying for IRC by the character, sucks to be u". :)

                --
                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.vox.com/ for Smalltalk and Seaside discussion
              • andy_bach@wiwb.uscourts.gov
                Another usage note Perl Problem isn t much of a subject line - er, what *else* would you be writing to the list with? ;- perl -00lne push @{ $h{ $1 } },
                Message 7 of 11 , Jul 20 10:03 AM
                • 0 Attachment
                  Another usage note "Perl Problem" isn't much of a subject line - er, what
                  *else* would you be writing to the list with? ;->


                  perl -00lne '
                  push @{ $h{ $1 } }, $_ if /of ([0-9]+) bytes/m;
                  }
                  {
                  print for map @{ $h{ $_ } }, sort { $b <=> $a } keys %h;' /tmp/h.dat

                  -00 is used to set perl to 'slurp' in paragraph mode (see perldoc perlrun
                  -0 (that's zero) option). -l is to add newlines to print stmts. -n is is
                  in auto-while loop and -e is to mark the script. Those unmatched curlies
                  are a trick to get an loop and END block - because -n takes your code and
                  wraps it in while loop
                  while (<>) {
                  <-e code>
                  }

                  adding a close then open curly, in the middle of your code make it:
                  while (<>) {
                  <-e code up to close curly>
                  }
                  {
                  <-e code after curlies>

                  push @{ $h{ $1 } }, $_ if /of ([0-9]+) bytes/m;

                  finds the digits before the word "bytes", uses it as a hash key for %h,
                  which is then treated as an anonymous array and the whole line saved
                  therein <ahem> (that sentence is as convoluted as this code - sorry ;-).
                  The "m" flag isn't needed (?) as there's no "." in the RE, I believe. I
                  don't recall the data set but they may have meant/needed to use "\s+" for
                  the whitespace (if the data were wrapping on lines, say).

                  print for map @{ $h{ $_ } }, sort { $b <=> $a } keys %h;' /tmp/h.dat

                  after the data's been processed, we fetch back that # of bytes key, sort
                  them reverse numerically ("$b" before "$a") and print each line of the
                  anonymous array for that key.

                  #!/usr/bin/perl -00l
                  use strict;
                  use warnings;
                  my %data_lines;
                  while (<>) {
                  next unless /of (\d+) bytes/;
                  push @{ $data_lines{$1} }, $_;
                  # warn("adding $1 - $_");
                  }
                  foreach my $key ( sort { $b <=> $a } keys %data_lines ) {
                  print "Bytes: $key";
                  foreach my $line ( @{ $data_lines{$key} } ) {
                  # whatever you want, line by line now
                  print "\tdata: $line";
                  } # foreach line
                  } # foreach key


                  a

                  ----------------------
                  Andy Bach
                  Systems Mangler
                  Internet: andy_bach@...
                  Voice: (608) 261-5738;
                  Cell: (608) 658-1890

                  "Every time I see an adult on a bicycle, I no longer despair for the
                  future of
                  the human race."
                  H. G. Wells, 1904

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