[27750] in Perl-Users-Digest

home help back first fref pref prev next nref lref last post

Perl-Users Digest, Issue: 9136 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sun Apr 9 14:05:36 2006

Date: Sun, 9 Apr 2006 11:05:06 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Sun, 9 Apr 2006     Volume: 10 Number: 9136

Today's topics:
    Re: A problem with precedence <rvtol+news@isolution.nl>
    Re: Extract range of lines from a text file <rvtol+news@isolution.nl>
    Re: Extract range of lines from a text file <softouch@softouch.on.ca>
    Re: FAQ 3.22 How can I compile Perl into Java? <matthew.garrish@sympatico.ca>
    Re: Tie::File question <joe@inwap.com>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

----------------------------------------------------------------------

Date: Sun, 9 Apr 2006 17:27:56 +0200
From: "Dr.Ruud" <rvtol+news@isolution.nl>
Subject: Re: A problem with precedence
Message-Id: <e1bgkl.1fo.1@news.isolution.nl>

Mark Hobley schreef:

> Why do I get the answer 6 to (4 + 2) * 3?

666 ;)

See perldoc -f print.

-- 
Affijn, Ruud

"Gewoon is een tijger."


------------------------------

Date: Sun, 9 Apr 2006 17:52:21 +0200
From: "Dr.Ruud" <rvtol+news@isolution.nl>
Subject: Re: Extract range of lines from a text file
Message-Id: <e1bhq7.nk.1@news.isolution.nl>

Amer Neely schreef:

> I'm walking through a mailbox file, and want to pull out specific
> lines from each message. The body of each message is in a similar
> format, having been generated by a script.
> 
> I'm doing OK except for one particular block of lines, the customer
> address data. There is a blank line before and after this block.
> Example: 
> 
> Transaction Time: 18:45:55
> 
> Amer Neely
> POB 1481 Station Main
> North Bay ON
> P1B 8K7
> CANADA
> 
> 123-456-7890


Or use a simplified state machine. 

  my $state = -1;
  my $line  = -1;

  while (<>) {
    chomp;  # s/^\s+//; s/\s+$//;

    if (-1 == $state) {
      if (/^Transaction Time:/) {
        ++$state;
      }
    }
    elsif (0 == $state) {
      if (/^$/)  {
        ++$state;
        $line = 0;
      }
      else {
        die "$state: <$_>?";
      }
    }
    elsif (1 == $state) {  # in address
      if (^$) {
        # skip
      }
      elsif (/^\d{3}-\d{3}-\d{4}$/) {
        $state = -1;
        $line  = -1;
      }
      else {
         ++$line;
         print "$line: $_\n";
      }
    }
    else {
      die "$state: <$_>?";
    }
  }

(untested)

-- 
Affijn, Ruud

"Gewoon is een tijger."


------------------------------

Date: Sun, 09 Apr 2006 12:38:18 -0400
From: Amer Neely <softouch@softouch.on.ca>
Subject: Re: Extract range of lines from a text file
Message-Id: <0La_f.64578$fd.49075@read2.cgocable.net>

Dr.Ruud wrote:
> Amer Neely schreef:
> 
>> I'm walking through a mailbox file, and want to pull out specific
>> lines from each message. The body of each message is in a similar
>> format, having been generated by a script.
>>
>> I'm doing OK except for one particular block of lines, the customer
>> address data. There is a blank line before and after this block.
>> Example: 
>>
>> Transaction Time: 18:45:55
>>
>> Amer Neely
>> POB 1481 Station Main
>> North Bay ON
>> P1B 8K7
>> CANADA
>>
>> 123-456-7890
> 
> 
> Or use a simplified state machine. 
> 
>   my $state = -1;
>   my $line  = -1;
> 
>   while (<>) {
>     chomp;  # s/^\s+//; s/\s+$//;
> 
>     if (-1 == $state) {
>       if (/^Transaction Time:/) {
>         ++$state;
>       }
>     }
>     elsif (0 == $state) {
>       if (/^$/)  {
>         ++$state;
>         $line = 0;
>       }
>       else {
>         die "$state: <$_>?";
>       }
>     }
>     elsif (1 == $state) {  # in address
>       if (^$) {
>         # skip
>       }
>       elsif (/^\d{3}-\d{3}-\d{4}$/) {
>         $state = -1;
>         $line  = -1;
>       }
>       else {
>          ++$line;
>          print "$line: $_\n";
>       }
>     }
>     else {
>       die "$state: <$_>?";
>     }
>   }
> 
> (untested)
> 

Very interesting. It's a little more complex than I need (see the reply 
by Xicheng Jia dated today 11:57). That works for me.

I did adopt your code (with a few minor fixes) to my situation, but got 
an error when I ran it on my test input file:
Sun Apr  9 12:29:32 2006
0: <xxxxxxxxxxxx
xxxxxxxxxxxxxxx
SAULT STE MARIE Ontario
P6A 3P4
CANADA>? at parse_mail7.pl line 39, <IN> chunk 2.

Thank you for this very different approach. I will keep it in mind for 
other situations.
-- 
Amer Neely
Home of Spam Catcher
W: www.softouch.on.ca
E: trudge@softouch.on.ca
Perl | MySQL | CGI programming for all data entry forms.
"We make web sites work!"


------------------------------

Date: Sun, 9 Apr 2006 13:35:04 -0400
From: "Matt Garrish" <matthew.garrish@sympatico.ca>
Subject: Re: FAQ 3.22 How can I compile Perl into Java?
Message-Id: <9Bb_f.196$fo1.32414@news20.bellglobal.com>


"PerlFAQ Server" <brian@stonehenge.com> wrote in message 
news:69dng3-nkc.ln1@blue.stonehenge.com...
> This is an excerpt from the latest version perlfaq3.pod, which
> comes with the standard Perl distribution. These postings aim to
> reduce the number of repeated questions as well as allow the community
> to review and update the answers. The latest version of the complete
> perlfaq is at http://faq.perl.org .
>
> --------------------------------------------------------------------
>
> 3.22: How can I compile Perl into Java?
>
>    You can also integrate Java and Perl with the Perl Resource Kit from
>    O'Reilly Media. See http://www.oreilly.com/catalog/prkunix/ .
>

A case of bad grammar, or is part of this FAQ missing?

Matt 




------------------------------

Date: Sun, 09 Apr 2006 08:14:43 -0700
From: Joe Smith <joe@inwap.com>
Subject: Re: Tie::File question
Message-Id: <S_qdnf1hx597uaTZnZ2dnUVZ_vydnZ2d@comcast.com>

robic0 wrote:
> Read through the docs on this module.

Yes, but did you read the source code of Tie/File.pm ?

> My question is about contraction and expansion of the file.
> It is stated that the entire file is not read into memory
> and I can understand that. Its also stated that changes made
> to the record array happen instantaneous to the file.
> To adjust the file is it using a file realloc primitive or 
> am I missing something? I understand mild buffereing is done.
> Is it a file realloc acting on the fat or am I missing something.

The module works on file systems that do not use a FAT, so
your assumption is completely off base.

> If so it must be an api, its not adjusting fat, like from a driver...

Not even close.  Modification is done at the file level, not at
the device driver level.  Do you not know how truncate() works?

# Truncate the file at the current position
sub _chop_file {
   my $self = shift;
   truncate $self->{fh}, tell($self->{fh});
}


------------------------------

Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 6 Apr 01)
Message-Id: <null>


Administrivia:

#The Perl-Users Digest is a retransmission of the USENET newsgroup
#comp.lang.perl.misc.  For subscription or unsubscription requests, send
#the single line:
#
#	subscribe perl-users
#or:
#	unsubscribe perl-users
#
#to almanac@ruby.oce.orst.edu.  

NOTE: due to the current flood of worm email banging on ruby, the smtp
server on ruby has been shut off until further notice. 

To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.

#To request back copies (available for a week or so), send your request
#to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
#where x is the volume number and y is the issue number.

#For other requests pertaining to the digest, send mail to
#perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
#sending perl questions to the -request address, I don't have time to
#answer them even if I did know the answer.


------------------------------
End of Perl-Users Digest V10 Issue 9136
***************************************


home help back first fref pref prev next nref lref last post