[24670] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 6834 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Aug 4 14:05:56 2004

Date: Wed, 4 Aug 2004 11:05:11 -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           Wed, 4 Aug 2004     Volume: 10 Number: 6834

Today's topics:
    Re: @platforms = (sort keys %prj_platforms) || (DEFAULT <Paul.Gaborit@invalid.invalid>
    Re: @platforms = (sort keys %prj_platforms) || (DEFAULT <mritty@gmail.com>
        any resources to assist with why perl is better? <davZZZYYYXXXout@dial.pipex.com>
    Re: any resources to assist with why perl is better? <nobull@mail.com>
    Re: any resources to assist with why perl is better? <uri.guttman@fmr.com>
    Re: Confused by sorting array elements <jgibson@mail.arc.nasa.gov>
    Re: Confused by sorting array elements <nobull@mail.com>
    Re: creating shell scripts using #!/usr/local/env perl <tzz@lifelogs.com>
    Re: creating shell scripts using #!/usr/local/env perl (Randal L. Schwartz)
        CRLF problem with DOS files <noemail@#$&&!.net>
    Re: CRLF problem with DOS files <nobull@mail.com>
    Re: delimited data into nested array (krakle)
        eO( Almost FREE MONEY !! eO( <meyer_j@allthis.net>
    Re: getting line between 2 patterns (mike)
    Re: getting line between 2 patterns <jgibson@mail.arc.nasa.gov>
    Re: join on space instead of comma <nobull@mail.com>
    Re: join on space instead of comma <jgibson@mail.arc.nasa.gov>
    Re: join on space instead of comma (Anno Siegel)
    Re: Kqueue interface module implementation (U. A. R. Ruirarchzatrea)
        name of perl jobs newsgroup? (Chris Richmond - MD6-FDC ~)
    Re: recursive functions <matrix_calling@yahoo.dot.com>
    Re: recursive functions (Anno Siegel)
    Re: recursive functions (Anno Siegel)
    Re: recursive functions (Anno Siegel)
    Re: recursive functions <me@example.com>
    Re: recursive functions <me@example.com>
    Re: recursive functions <richard@zync.co.uk>
    Re: recursive functions <spamtrap@dot-app.org>
    Re: RegEx issue <nobull@mail.com>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Wed, 04 Aug 2004 17:17:36 +0200
From: Paul GABORIT <Paul.Gaborit@invalid.invalid>
Subject: Re: @platforms = (sort keys %prj_platforms) || (DEFAULT);
Message-Id: <r7u0vjaq5r.fsf@michelange.enstimac.fr>


À (at) 4 Aug 2004 08:04:33 -0700,
Alexander.Farber@t-online.de (A. Farber) écrivait (wrote):
[...]
> Could someone please explain, why does the code below warns 
> "Useless use of sort in scalar context at ./test_case.pl"?
>
> #!/usr/bin/perl -w
> use constant DEFAULT => qw(ARMI ARM4 THUMB WINS WINSCW);
> @platforms = (sort keys %prj_platforms) || (DEFAULT);


Use :

   (@platforms = sort keys %prj_platforms) || (@platforms = DEFAULT);

or :

   @platforms = sort keys %platforms or @platforms = DEFAULT;

-- 
Paul Gaborit - <http://www.enstimac.fr/~gaborit/>
Perl en français - <http://www.enstimac.fr/Perl/>


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

Date: Wed, 4 Aug 2004 11:41:28 -0400
From: Paul Lalli <mritty@gmail.com>
Subject: Re: @platforms = (sort keys %prj_platforms) || (DEFAULT);
Message-Id: <20040804113212.V14831@barbara.cs.rpi.edu>

On Wed, 4 Aug 2004, A. Farber wrote:

> Hi,
>
> I must confess, that I don't fully understand the
> difference between an array and a list

perldoc -q 'list and an array'

Basically, a list is a constant sequence of scalar values.  An array is a
Perl datatype which contains a list.  The array may be altered.  A list
cannot.   It is roughly analogous to a string 'Hello' and a variable $foo
which contains 'Hello'.  You can say $foo .= ' World'.  But you cannot
say 'Hello' .= ' World'.

> and suspect
> that the cause for my problem lies somewhere there...
>
> Could someone please explain, why does the code below warns
> "Useless use of sort in scalar context at ./test_case.pl"?
>
> #!/usr/bin/perl -w
> use constant DEFAULT => qw(ARMI ARM4 THUMB WINS WINSCW);
> @platforms = (sort keys %prj_platforms) || (DEFAULT);

List vs Array is not really the problem, no.  The || operator forces
scalar context on its arguments.  An array in scalar context returns the
size of that array.  A list used scalar context evaluates each of its
members, from left to right, and discards all but the last value, which it
returns.  sort() returns a list.  But even if it returned an array, your
code would still not do what you want.

Your problem is not list vs. array, but rather list context vs. array
context.  The || operator is forcing scalar context, where you need list
context - so that one of your two lists can be assigned to @platforms.

(@platforms = sort keys %prj_platforms) || (@platforms = DEFAULT);

Now you have an expression on the left which is done in list context -
because of the assignment to @platforms.  Once that assignment is
completed, @platforms is evaluated in scalar context, as the argument to
the || operator.  Thus, it returns its new size.  If that size is 0, the
short-circuit nature of || causes its second argument to be evaluated,
causing DEFAULT to be assigned to @platforms instead.

Hope this helps,
Paul Lalli


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

Date: Wed, 4 Aug 2004 18:24:42 +0100
From: "davout" <davZZZYYYXXXout@dial.pipex.com>
Subject: any resources to assist with why perl is better?
Message-Id: <41111c01$0$26982$cc9e4d1f@news.dial.pipex.com>

Can anybody help point me at some web resources that explain why Perl is
better than say Python, TCL etc?




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

Date: 04 Aug 2004 18:47:48 +0100
From: Brian McCauley <nobull@mail.com>
Subject: Re: any resources to assist with why perl is better?
Message-Id: <u9n01avlq3.fsf@wcl-l.bham.ac.uk>

"davout" <davZZZYYYXXXout@dial.pipex.com> writes:

> Can anybody help point me at some web resources that explain why Perl is
> better than say Python, TCL etc?

I'd start with 

http://www.google.com/search?q=perl+advocacy

:-)

-- 
     \\   ( )
  .  _\\__[oo
 .__/  \\ /\@
 .  l___\\
  # ll  l\\
 ###LL  LL\\


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

Date: Wed, 04 Aug 2004 13:52:35 -0400
From: Uri Guttman <uri.guttman@fmr.com>
Subject: Re: any resources to assist with why perl is better?
Message-Id: <lihdrikcyk.fsf@fmr.com>

>>>>> "d" == davout  <davZZZYYYXXXout@dial.pipex.com> writes:

  d> Can anybody help point me at some web resources that explain why Perl is
  d> better than say Python, TCL etc?

it just is. accept it.

:)

uri



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

Date: Wed, 04 Aug 2004 09:38:27 -0700
From: Jim Gibson <jgibson@mail.arc.nasa.gov>
Subject: Re: Confused by sorting array elements
Message-Id: <040820040938273779%jgibson@mail.arc.nasa.gov>

In article <4110aed5_1@127.0.0.1>, Perl User <user@perl.org> wrote:

> I have a flat file database that consists of several
> variables per line entry.  It's sort of like an address book
> file, but has a lot of info in it.  Each line entry contains
> the following fields... 

[more description snipped]

> 
> What's the best way to pull each record line into an array of
> arrays (consisting of 25 or 26 elements each) and sort on the
> fourth variable of each record array for display only,
> maintaining the values of all 26 elements? 


You can read and select the data into an array of array references with
code like the following:

my @array;
while(<DATA>) {
  my @fields = split /,/;
  if( $fields[5] == 1982 ) {
    push( @array, [@fields] );
  }
}

This assumes that none of your fields have embedded commas. You may
want to modify the last name or maiden name field or add an extra sort
key field before the push statement to generate a sort key field. Other
posters have shown how to sort the rows in this array. Simplest method
might be to copy the last name value into the maiden name value if the
latter is null, then sort on the maiden name field.

To print the array:

use Data::Dumper
print Dumper(@array)

If you do have embedded commas escaped or enclosed in quotes, check out
the Text::CSV module on CPAN (www.cpan.org).


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

Date: 04 Aug 2004 18:05:32 +0100
From: Brian McCauley <nobull@mail.com>
Subject: Re: Confused by sorting array elements
Message-Id: <u9r7qmvnoj.fsf@wcl-l.bham.ac.uk>

Jim Gibson <jgibson@mail.arc.nasa.gov> writes:

> You can read and select the data into an array of array references with
> code like the following:
> 
> my @array;
> while(<DATA>) {
>   my @fields = split /,/;
>   if( $fields[5] == 1982 ) {
>     push( @array, [@fields] );
>   }
> }

You have declared @fields in the correct scope.  This is good.  It
means you don't need to push a reference to a _copy_of_ @fields onto
@array, you can push a reference to @fields itself.  Next time round
the loop you get a new @fields variable.

     push @array => \@fields;

-- 
     \\   ( )
  .  _\\__[oo
 .__/  \\ /\@
 .  l___\\
  # ll  l\\
 ###LL  LL\\


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

Date: Wed, 04 Aug 2004 11:39:22 -0400
From: Ted Zlatanov <tzz@lifelogs.com>
Subject: Re: creating shell scripts using #!/usr/local/env perl
Message-Id: <4nllguap5h.fsf@lifelogs.com>

On 03 Aug 2004, merlyn@stonehenge.com wrote:

> The only reason "env" exists is because the brain-dead csh can't add
> arbitrary env vars per command.  The One True Shell (/bin/sh) knew how
> to do it, but the boys at berkeley all liked the csh better I guess,
> so they worked around the per-command env settings by adding yet
> another tool instead of fixing csh.
> 
> In the bourne shell, you simply say this:
> 
>         $ ONEOFF=thisval TWOTHING=thatval some_command with these args
> 
> No need for a freaking env command.

It should be noted that env will work in ANY shell, not just csh.
That makes it a more useful tool than you imply.

Ted


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

Date: 04 Aug 2004 10:53:39 -0700
From: merlyn@stonehenge.com (Randal L. Schwartz)
Subject: Re: creating shell scripts using #!/usr/local/env perl
Message-Id: <86oelqeqn0.fsf@blue.stonehenge.com>

>>>>> "Ted" == Ted Zlatanov <tzz@lifelogs.com> writes:

Ted> It should be noted that env will work in ANY shell, not just csh.
Ted> That makes it a more useful tool than you imply.

Well, I think I'm trying to imply that it's not needed in *decent*
shells.  It's needed only in *broken* shells.  Hence, merely
a workaround for csh's dain-bramage (one of many).

print "Just another Perl hacker,"; # the original

-- 
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!


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

Date: Wed, 04 Aug 2004 12:38:27 +0000
From: Fred <noemail@#$&&!.net>
Subject: CRLF problem with DOS files
Message-Id: <pan.2004.08.04.12.38.26.788140@#$&&!.net>

I know this topic has been covered rather much but I couldn't find my
specific question answered.

Here is the code:

 # we are trying to make '0d 0a' in the output file be # only a '0a'
        #$Fld1 =~ s/\r|\n|\r\n/\n/g;
        #$Fld1 =~ s/\015//g;
        #$Fld1 =~ s/\015\012/\n/g;
        #$Fld1 =~ tr/\r\n/ /s;
        #$Fld1 =~ tr/\015\012//d;
        #chomp($Fld1);
        #chop($Fld1);
        #$Fld1."\n";

         $Fld1 =~ s/\cM//g;
        &Open_File( '>>', $filename ); # returns fh as filehandle
        binmode $fh ;     # open the binmode file and write to it; 
       ( printf $fh "%s\r", $Fld1;)
        $count++; # counting lines... this is all in a while loop

I have used the binmode trick, and with it tried every single one of the
above examples. My lines in the file are terminated with HEX 0d 0a and
like I said I need them to be 0a.

I am using perl on windows to create the output file, but my output file
is going into a COBOL program that can't handle any
other line terminating char.
I have begun to suspect what I am trying to do can't be done with perl and
windows but I wanted to post to be sure.

Thanks to all, very much.


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

Date: 04 Aug 2004 18:58:32 +0100
From: Brian McCauley <nobull@mail.com>
Subject: Re: CRLF problem with DOS files
Message-Id: <u9isbyvl87.fsf@wcl-l.bham.ac.uk>

Fred <noemail@#$&&!.net> writes:

> I know this topic has been covered rather much but I couldn't find my
> specific question answered.
> 
> Here is the code:
> 
>  # we are trying to make '0d 0a' in the output file be # only a '0a'
>         #$Fld1 =~ s/\r|\n|\r\n/\n/g;
>         #$Fld1 =~ s/\015//g;
>         #$Fld1 =~ s/\015\012/\n/g;
>         #$Fld1 =~ tr/\r\n/ /s;
>         #$Fld1 =~ tr/\015\012//d;
>         #chomp($Fld1);
>         #chop($Fld1);
>         #$Fld1."\n";
> 
>          $Fld1 =~ s/\cM//g;
>         &Open_File( '>>', $filename ); # returns fh as filehandle

Do not use & to call subroutines unless you know what it means and
want those semantics.

Returning the file handle using a shared variable is ugly, ugly, ugly.

>         binmode $fh ;     # open the binmode file and write to it; 

Er, what is the meaning of that comment?

>        ( printf $fh "%s\r", $Fld1;)
>         $count++; # counting lines... this is all in a while loop
> 
> I have used the binmode trick, and with it tried every single one of the
> above examples. My lines in the file are terminated with HEX 0d 0a and
> like I said I need them to be 0a.

Have you been messing with $\ ?

Please show a _minimal_ but _complete_ script that you have run and
found to produce the problem.

-- 
     \\   ( )
  .  _\\__[oo
 .__/  \\ /\@
 .  l___\\
  # ll  l\\
 ###LL  LL\\


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

Date: 4 Aug 2004 10:02:24 -0700
From: krakle@visto.com (krakle)
Subject: Re: delimited data into nested array
Message-Id: <237aaff8.0408040902.25cd8ad2@posting.google.com>

Gunnar Hjalmarsson <noreply@gunnar.cc> wrote in message news:<2nbomfFujpv4U1@uni-berlin.de>...
> How about this instead:
> 
> #!/usr/local/bin/perl

How about this instead:
#!/usr/local/bin/perl -Tw


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

Date: Wed, 4 Aug 2004 01:43:11 -0400
From: "John Meyer" <meyer_j@allthis.net>
Subject: eO( Almost FREE MONEY !! eO(
Message-Id: <Tl9Qc.16674$a%1.15279@fe39.usenetserver.com>

MAKE MONEY!!!

MAKE THOUSANDS!!!

I found this on a bulletin board and decided to try it: I don't care about
the useless pre-fabricated crap this message usually says. All I say is, it
works. Continue pre-fab crap.

WELL GUESS WHAT!!!

Within seven days, I started getting money in the mail!! I
was shocked!! I figured it would end soon, but the money just kept
coming in. In my first week, I made about $25.00. By the end of the second
week I had made a total of more than $1000.00!!

Let me tell you how this works and most important, why it works..........
also make sure you print this out NOW, so you can get the information off
of it, as you will need it. I promise you that if you follow the directions
exactly that you will start making more money than you thought possible by
doing something
so easy!!

Suggestion: Read this entire message carefully!! (Print it out or download
it)

Follow the simple directions and watch the money come in!! It's easy.
It's legal. And, your investment is only $6.00 (Plus postage) !!!

You can use any currancy as people can always change it..

IMPORTANT:

This is not a rip-off, it is decent; it's legal; and it is virtually no
risk - it really works!! If all the following instructions are adhered to,
you will receive extraordinary dividends.

PLEASE NOTE:

Please follow the directions EXACTLY, and $50,000 or more can be yours
in 20 to 60 days. This program remains successful because of the honesty
and integrity of the participants. Please continue its success by carefully
adhering to the instructions. You will now become apart of the Mail Order
business.
You are in the business of developing Mailing Lists. Many large corporations
are happy to pay big bucks for quality lists. However, the money made from
the
mailing lists is secondary to income which is made from people like you
and me asking to be included in that list. Here are the four easy steps to
success.

STEP ONE:

Get six separate pieces of paper and write the following on
each piece of paper "PLEASE PUT ME ON YOUR MAILING LIST."
Now get 6 U.S. $1.00 bills and place ONE inside of EACH of the six pieces
of paper so the bill will not be seen through the envelope (to prevent
thievery). Next, place one paper in each of the six envelopes and seal them.
You now should have six sealed envelopes, each with a piece of paper stating
the above phrase, your name and address, and a $1.00 bill. What you are
doing is creating a service.

THIS IS ABSOLUTELY LEGAL!!!!!

You are requesting a legitimate service and you are paying for it!! Like
most of us I was a little skeptical and little worried about the legal
aspects of it all. So I checked it out with the U.S. Post Office
(1-800-238-5355)
and they confirmed that it is indeed legal!!

Mail the six envelopes to the following addresses:




Matthew Dutton
46 Hayworth St
Point Vernon, Hervey Bay
QLD, 4390
Australia



R. Visser
P.O. Box 274
Nobby Beach
QLD, 4218
Australia



S. Phillips
77 Manly Drive
Robina, QLD 4226
Australia


Chris Pittman
7651 Abigail Glen Dr.
Charlotte, NC 28212
USA


Mike Vango
29 Pebblewood Ave
Scarborough, ON M1V-2A7
Canada



C. Wehler
137 Sara Rd
St. Marys, PA 15857
USA




STEP TWO:Now take the #1 name off the list that you see above, move the
other names up (six becomes 5, 5 becomes 4, and etc.) and add YOUR NAME as
number 6 on the list.

STEP THREE:
Change anything you need to but try to keep this article as close to
original as possible. Now post your amended article to at least 200 news
groups. : (I think there are close to 24,000 groups) All you need is 200,
but
remember, the more you post, the more money you make!! This is perfectly
legal!! If you have any doubts, refer to Title 18 Sec. 1302 & 1341 of the
Postal Lottery laws. Keep a copy of these steps for yourself and whenever
you need money, you can use it again, and again. PLEASE REMEMBER that this
program remains successful because of the honesty and integrity of the
participants and by their carefully adhering to directions. Look at it this
way. If you were of integrity, the program will continue and the money that
so many others have received will come your way.

NOTE: You may want to retain every name and address sent to you,> either on
a computer or hard copy and keep the notes people send you.
This VERIFIES that you are truly providing a service. (Also, it might be
a good idea to wrap the $1 bill in dark paper to reduce the risk of mail
theft). So, as each post is downloaded and the directions carefully
followed, all members will be reimbursed for their participation as a List
Developer with one dollar each. Your name will move up the list
geometrically so that when your name reaches the #1 position you will be
receiving thousands of dollars in CASH!!! What an opportunity for only $6.00
( $1.00 for each of the first six people listed above) Send it now, add your
own name to the list and you're in business!!!


*****DIRECTIONS FOR HOW TO POST TO NEWS GROUPS!!!*****

STEP ONE: You do not need to re-type this entire letter to do your own
posting. Simply put your cursor at the beginning of this letter and drag
your cursor to the bottom of this document, and select 'copy' from the edit
menu. This will copy the entire letter into the computer's memory.

STEP TWO:
Open a blank 'notepad' file and place your cursor at the top
of the blank page. From the 'edit' menu select 'paste'. This will paste a
copy of the letter into the notepad so that you will add your name to the
list.

STEP THREE:
Save your new notepad file as a text file. If you want to do your posting
in different settings, you'll always have this file to go back to.

STEP FOUR:
You can use a program like "postXpert" to post to all the newsgroups at
once. You can find this program at <<http://www.download.com>>.

Use Netscape or Internet Explorer and try searching for various new
groups (on- line forums, message boards, chat sites, discussions.)

STEP FIVE:
Visit message boards and post this article as a new message by
highlighting the text of this letter and selecting paste from the edit menu.
Fill in the subject, this will be the header that everyone sees as they
scroll through the list of postings in a particular group, click the post
message button. You're done.

Congratulations!!!!!!

THAT'S IT!! All you have to do, and It Really works!!!


BEST WISHES ...




ouYj\



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

Date: 4 Aug 2004 08:59:57 -0700
From: s99999999s2003@yahoo.com (mike)
Subject: Re: getting line between 2 patterns
Message-Id: <dfd17ef4.0408040759.7c256905@posting.google.com>

anno4000@lublin.zrz.tu-berlin.de (Anno Siegel) wrote in message news:<ceqb79$iqg$1@mamenchi.zrz.TU-Berlin.DE>...
> John W. Krahn <someone@example.com> wrote in comp.lang.perl.misc:
> > mike wrote:
> > > 
> > > i have a file like this:
> > > 
> > > 2004nddjjf99jdlkdf   <---- 99 is at character position 11 to 12
> > > 2004abcdefghijklnmnopqrstuvwxyz
> > > 2004ldfhanvsduhkjgndfnspqiekfnv
> > > 2003nmvkdmcnfjfbndmdkvndnmvkdbn
> > > 2004nddgdf99dkgfjs  
> > > 
> > > i wanted to get the text in between the 2 lines that have the number
> > > "99" at the
> > > 11th and 12th position. 
> > > 
> > > i looked at FAQ ,
> > > 
> > > perl -ne 'print if /START/ .. /END/' file1 ...
> > > 
> > > how can i define the START and END such that it must check for
> > > character position 11 and 12 to look for 99 ??
> > 
> > perl -ne 'print if /^.{10}99/ ... /^.{10}99/' file1 ...
> 
> That prints the delimitling lines (the ones that contain "99").
> Depending on what the OP means by "in between", it might be
> necessary to do
> 
>     perl -ne 'print if /^.{10}99/ ... /^.{10}99/ and not  /^.{10}99/' file1
> 
> Anno


thanks for the advise.

I have another requirement

2004nddjjf99jdlkdf   <---- first location that have '99' at char pos
11-12
2004abcdefghijklnmnopqrstuvwxyz
2004ldfhanvsduhkjgndfnspqiekfnv
2003nmvkdmcnfjfbndmdkvndnmvkdbn
2004nddgdf99dkgfjs  <----------- (2)
2001lksdnvnvkxlxmncxkxlxknlxxcl
1999kldkdkfsksjdkjvkjslkjdflkjl
2002nodmen99ddklss <------------(3)

I wanted to get the text between the first location ( where '99' is at
char pos 11-12 ) and the second location (2), then put the text into a
file.
Then get the text between (2) and (3) and put to another file.
I have no idea how to keep track of the lines that have '99' at pos
11-12.
Any advise? A "psuedocode" would be a great help, cos i want to try to
code the rest of it myself...
thanks...


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

Date: Wed, 04 Aug 2004 09:52:25 -0700
From: Jim Gibson <jgibson@mail.arc.nasa.gov>
Subject: Re: getting line between 2 patterns
Message-Id: <040820040952254061%jgibson@mail.arc.nasa.gov>

[solution to previous problem snipped]

> thanks for the advise.
> 
> I have another requirement

This is called "requirements creep". Programmers hate this! :(

> 
> 2004nddjjf99jdlkdf   <---- first location that have '99' at char pos
> 11-12
> 2004abcdefghijklnmnopqrstuvwxyz
> 2004ldfhanvsduhkjgndfnspqiekfnv
> 2003nmvkdmcnfjfbndmdkvndnmvkdbn
> 2004nddgdf99dkgfjs  <----------- (2)
> 2001lksdnvnvkxlxmncxkxlxknlxxcl
> 1999kldkdkfsksjdkjvkjslkjdflkjl
> 2002nodmen99ddklss <------------(3)
> 
> I wanted to get the text between the first location ( where '99' is at
> char pos 11-12 ) and the second location (2), then put the text into a
> file.
> Then get the text between (2) and (3) and put to another file.
> I have no idea how to keep track of the lines that have '99' at pos
> 11-12.
> Any advise? A "psuedocode" would be a great help, cos i want to try to
> code the rest of it myself...
> thanks...

You haven't said what you want to do with the text following the last
'99' line. If that doesn't matter too much, you can do the following
(pseudo-code untested):

open input file 
set flag = 0
while( more input ) 
  read line from input file
  if line contains 99 then
    if flag == 1 then
      close current output file
    end if
    open output file
    set flag = 1
  else
    if flag == 1 then
      write line to output file
    end if
  end if
end if

close input file
if flag == 1 then
  close output file
end if
possibly delete last output file containing lines after last 99

As an alternative, if your input file is not too big, you can read it
all into an array and process the array similarly to the above but with
a foreach loop instead of a while loop.


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

Date: 04 Aug 2004 17:42:27 +0100
From: Brian McCauley <nobull@mail.com>
Subject: Re: join on space instead of comma
Message-Id: <u9zn5avor0.fsf@wcl-l.bham.ac.uk>

bowsayge <bowsayge@nomail.afraid.org> writes:
                   ^^^^^^^^^^^^^^^^^
                        127.0.0.127.... cute!


> my (@lines, @fields) = (<>);

I somehow find the technique of tagging extra variables into the LHS
of a list assigment in order to declare them just seems ugly.

Is there really any need to slup here anyhow?  Whould it not be
simpler to read the input linewise.

Isn't @fields being declared at the wrong scope anyhow - it should be
inside the loop.

> chomp @lines;
> 
> for (@lines) {
>     $fields[0] = substr $_,7,7;
>     $fields[1] = substr $_,39,10;
>     $fields[2] = substr $_,63;

For unpacking fixed position records you may want to consider unpack()
as an alternative to several substr().

-- 
     \\   ( )
  .  _\\__[oo
 .__/  \\ /\@
 .  l___\\
  # ll  l\\
 ###LL  LL\\


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

Date: Wed, 04 Aug 2004 09:57:09 -0700
From: Jim Gibson <jgibson@mail.arc.nasa.gov>
Subject: Re: join on space instead of comma
Message-Id: <040820040957091116%jgibson@mail.arc.nasa.gov>

In article <SnZPc.1991$La.5645@news1.mts.net>, LHradowy
<laura.hradowy@NOSPAM.mts.caaaaa> wrote:

> Right now I have a perl script that takes a comma separated file and adds a
> couple of things to it as will as takes away the data at the end.
> I have done this the hard way, by saving a file in excel and a comma
> separated file, then ftp it over, dos2ux file >file1.
> 
> And this is the outcome BEFORE I run my perl script.
> 3xxxx18,00 0 02 00,TELN NOT
> 3xxxx22,00 0 03 11,CUST HAS >
> 
> Then after all that I run my perl script against it prompts user for input,
> adds some data, then greps file for certain things, and creates 3 files.
> 
> What I want to do is elinate the first part of saving it as a comma
> separated file. I belive I can do this in perl, but I can not split on
> spaces since I have spaces that I need to be part of a column. So, (how to
> explain) instead of the above mention where there is a comma, I need to
> split this file, based on criteria, and also add a comma between the
> columns, so it looks like above...
> 
> This is the file I get before I save it as a comma separated file.
>        3xxxx33                         00 0 00 21              CUSTOMER HAS
> > 1
>        3xxxx63                         00 0 01 07              CUSTOMER HAS
> > 1
>        3xxxx75                         00 0 02 09              CUSTOMER HAS
> > 1
>        3xxxx85                         00 0 12 09              TELN NOT BILL
>        3xxxx28                         00 0 02 00              TELN NOT BILL


Look at the unpack function, good for extracting fixed-width fields.

perldoc -f unpack
perldoc -f pack (for format of template)


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

Date: 4 Aug 2004 17:39:03 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: join on space instead of comma
Message-Id: <cer6vn$8is$1@mamenchi.zrz.TU-Berlin.DE>

bowsayge  <bowsayge@nomail.afraid.org> wrote in comp.lang.perl.misc:
> LHradowy said to us:
> 
> [...]
> > What I want to do is elinate the first part of saving it as a comma
> > separated file. I belive I can do this in perl, but I can not split on
> > spaces since I have spaces that I need to be part of a column. 
> [...]
> 
> You can extract substrings from your input lines like so:

Ah, you're learning fast.  This begins to look like Perl code :)
Your solution is correct.  I'll add a few comments about style and
point out alternatives.

I am aware, if I read your postings right, that you are rather new to
Perl, if not to programming in general.  My (and other's) comments are
brief and often have the form of directions.  They're still in the spirit
of "you can also do it this way", not of "you should have done it like this".
So...

> my (@lines, @fields) = (<>);

You don't need to declare @fields here.  Instead, declare it in the
smallest possible scope, which would be the loop body.

But even if you had to declare it here, it isn't the done thing to
combine a mere declaration with a massive operation like slurping the
file.  Use an extra line.

The parens around "<>" aren't needed and un-idiomatic.

> chomp @lines;

"chomp" can be applied to an assignment, even a list assignment.  This
*is* idiomatic:

    chomp( my @lines = <>);

> for (@lines) {

This would be the place to declare @fields.  The array is cleared each
time my() happens at run-time, usually what you want.

>     $fields[0] = substr $_,7,7;
>     $fields[1] = substr $_,39,10;
>     $fields[2] = substr $_,63;

It is rare in Perl that you need to index into an array.  (Hashes are
different.) The more you think of an array as a whole, the better.
This is certainly not a place for indexing.

    my @fields = (
        substr( $_,7,7),
        substr( ...),
        substr( ...),
    );

But there is a better way.  See below...

>     local $" = ',';

Nothing wrong with that, especially since it's properly localized.  Still,
there's a tendency to avoid the "punctuation variables", with a few
exceptions.

>     print "@fields\n";

Without assignment to $"

    print join( ',', @fields), "\n";

> }

If you have to extract fields of fixed length at fixed positions,
the unpack() function is the right tool.  It can extract multiple
substrings in one step.

"pack" and "unpack" and their formats are a sub-language of its own.
No-one memorizes all of it, but a few idioms are worth memorizing.
One is, to extract a substring of length $length at position $pos,
the unpack template is "@${pos}a$length".  Putting it all together,
your solution becomes

    chomp( my @lines = <DATA>);
    for ( @lines ) {
        my @fields = unpack( '@7a7 @39a10 @63a*', $_);
        print join( ', ', @fields), "\n";
    }

Anno


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

Date: 4 Aug 2004 09:46:25 -0700
From: millueradfa@yahoo.com (U. A. R. Ruirarchzatrea)
Subject: Re: Kqueue interface module implementation
Message-Id: <efa550f7.0408040846.7aa558c5@posting.google.com>

Uri Guttman <uri@stemsystems.com> wrote in message news:<x73c33bigg.fsf@mail.sysarch.com>...

> check out using libevent (at http://monkey.org/~provos/libevent/)
> instead and wrapping that in perl via xs/swig/inline. that will be more
> effective in that it gives you /dev/poll, kqueue(2), select(2), poll(2)
> and epoll(4) support already and with one api wrapper you get all in
> perl. i would be willing to help out with this as i have written and
> wrapped event loops and done some (small) xs work (actually in swig).
> 

Thank you for the advice. I think doing a libevent interface i an
excellent idea. But I also think that there is still is a need for a
interface to kqueue, and that is on my list of things to study doing.
There are actually many event engines written in Perl that could
benefit from it, such as POE. Doing an engine in Perl has its
advantages, as it is eisier to understand the code and to improve upon
it, and there is less chance of memory buffer overflows.


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

Date: Wed, 4 Aug 2004 15:39:34 +0000 (UTC)
From: crichmon@filc8046.fm.intel.com (Chris Richmond - MD6-FDC ~)
Subject: name of perl jobs newsgroup?
Message-Id: <ceqvvm$f7p$1@news01.intel.com>

Hi Folks,

    Our internal news server has a truncated group list, and
I can't find the proper name for the perl jobs group.  Can
someone post it please?  I can check for it from home.

Thx, Chris

-- 
 Chris Richmond         | I don't speak for Intel & vise versa    


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

Date: Wed, 04 Aug 2004 20:41:18 +0530
From: Abhinav <matrix_calling@yahoo.dot.com>
Subject: Re: recursive functions
Message-Id: <x77Qc.39$vV.92@news.oracle.com>

steve_f wrote:
> OK thanks, now I have two working examples. I took a year of calculus,
> but don't think I ever encountered "proof by induction".
> 
> This concept has never really clicked for me. For example, I wouldn't
> recognize what type of problem would need a recursive solution.
> 

Some other examples which might help visualize the idea would be

1. Binary Search
2. Factorial
3. Tower of Hanoi problem
4. Directory search of a file system
5. Depth First Search (DFS) of a (binary) tree

I have not mentioned fibonacci series in the list, because that *generally* 
would be harder to visualize with the recursive routine ..

HTH

Regards

--

Abhinav


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

Date: 4 Aug 2004 15:19:24 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: recursive functions
Message-Id: <cequps$3ot$1@mamenchi.zrz.TU-Berlin.DE>

steve_f  <me@example.com> wrote in comp.lang.perl.misc:
> OK thanks, now I have two working examples. I took a year of calculus,
> but don't think I ever encountered "proof by induction".

Sounds unlikely.  There are lots of propositions in elementary calculus
that are best proved inductively.  Also, induction is so important in
all branches of mathematics that teachers tend to bring it up in any
elementary course.

> This concept has never really clicked for me. For example, I wouldn't
> recognize what type of problem would need a recursive solution.

If you have a problem that can't be solved immediately, one technique
to find a solution is often called "Divide and Conquer".  That means,
split the problem into two or more sub-problems, so that a solution
of the whole problem can be constructed when the subproblems are solved.
The hope is that the sub-problems will be easier.  The technique can
then repeatedly be applied to the sub-problems, simplifying at each
step until all remaining (sub-)problems are immediately solvable.

It may happen that one or more subproblems have the same structure
as the original problem.  The subproblems may still be simpler than
the original, for instance by having to deal with smaller numbers
or fewer things.

If that happens, it is an invitation to try a recursive solution.
The advantage is that the sub-problem, having the same structure as
the original, can again be split into sub-problems using the same
technique again, until elementary cases are reached.  If the sub-problems
are unrelated to the original, new methods must be found at each level.

> I know the concept is a function calls itself repeatedly until it
> runs out and now that there is a base case.

Strictly speaking, this is slightly too narrow.  A function doesn't
have to call itself to be recursive, it may call another function
which calls another which, eventually, calls the first function again.
Technically, a call to a function is recursive if another call to the
same function hasn't returned yet.

[examples snipped]

Anno


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

Date: 4 Aug 2004 15:30:57 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: recursive functions
Message-Id: <ceqvfh$3ot$2@mamenchi.zrz.TU-Berlin.DE>

Abhinav  <matrix_calling@yahoo.dot.com> wrote in comp.lang.perl.misc:

[recursion]

> Some other examples which might help visualize the idea would be
> 
> 1. Binary Search
> 2. Factorial
> 3. Tower of Hanoi problem
> 4. Directory search of a file system
> 5. Depth First Search (DFS) of a (binary) tree

These are good examples, with exception of number 2, which is only popular.
I have never quite understood why.

Nothing in multiplying the first few numbers together particularly invites
recursion, not any more than adding them up would.  Calculating the number
of permutations of n things (which happens to be n!) *is* a naturally
recursive problem.  Calculating factorials isn't.

Anno


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

Date: 4 Aug 2004 15:53:46 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: recursive functions
Message-Id: <cer0qa$4um$1@mamenchi.zrz.TU-Berlin.DE>

Richard Gration <richard@zync.co.uk> wrote in comp.lang.perl.misc:
> In article <i9n1h09q5obpj2di3o1hg2na6pbdj255ut@4ax.com>, "steve_f"
> <me@example.com> wrote:
> 
> > I could never really wrap my mind around the concept of recursive
> > functions. I'm not sure if this is the right place to ask...but if
> > anyone can at least clue me in a bit, I would really appreciate it.
> 
> The absolute classic example of a recursive algorithm is the factorial
> function. ...

Classic only in the sense of mythology.  Nothing about the factorial
invites a recursive algorithm, and the recursive implementation has
no advantages over an iterative one.

Anno


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

Date: Wed, 04 Aug 2004 12:09:50 -0400
From: steve_f <me@example.com>
Subject: Re: recursive functions
Message-Id: <0622h0pci1t57mnreq8mc0vl3cuggkd0dn@4ax.com>

wow....I kind of wrote my own recursive function...
well, I rewrote it from an example in some other
language...

#!c:\perl\bin\perl.exe -w

$m = 5;
$n = 10;

print multiply_em($m, $n);

sub multiply_em {
    my ($m, $n) = @_;
    if ($n == 1) {
        return $m;
    }
    return $m + multiply_em($m, $n - 1);
}

thanks everyone...it is begining to become clear to me.
yes, my calculus was so long ago, but I think that is what
makes perl attractive to me.

ok...I think the trick is in the $n-1 ...so it is counting down as
it is passing through the function almost like a for construction
for x = 0, x < 10, x++

here's the other list of examples:
compute the power of x to the n, where x and n are both integers 
print the characters of a string in reverse order 
sum the numbers of an array of doubles 
print the items of a linked list, assuming a toString()method is defined for the item part of a Node 
find the minumum value in an array of ints 
sort an array using the strategy of the selection sort 
search through a sorted arrya using the strategy of the binary search 

hmmmm....!! ok, yes this post was off topic, I really should of found a 
programming group!


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

Date: Wed, 04 Aug 2004 12:16:03 -0400
From: steve_f <me@example.com>
Subject: Re: recursive functions
Message-Id: <jr22h09q6pos0co3rbqat5auprn3ijgda3@4ax.com>

On Wed, 04 Aug 2004 12:09:50 -0400, steve_f <me@example.com> wrote:

>sub multiply_em {
>    my ($m, $n) = @_;
>    if ($n == 1) {
>        return $m;
>    }
>    return $m + multiply_em($m, $n - 1);
>}

yes, this is pretty much the same as:

for $x = 1; $x < $n; $x++ {
    count += $m
}


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

Date: Wed, 04 Aug 2004 17:43:18 +0100
From: "Richard Gration" <richard@zync.co.uk>
Subject: Re: recursive functions
Message-Id: <cer3n9$40g$1@news.freedom2surf.net>

In article <cer0qa$4um$1@mamenchi.zrz.TU-Berlin.DE>, "Anno Siegel"
<anno4000@lublin.zrz.tu-berlin.de> wrote:


> Richard Gration <richard@zync.co.uk> wrote in comp.lang.perl.misc:
>> The absolute classic example of a recursive algorithm is the factorial
>> function. ...
>
> Classic only in the sense of mythology.  Nothing about the factorial
> invites a recursive algorithm, and the recursive implementation has no
> advantages over an iterative one.
> Anno

But you have to agree it illustrates the concept of recursion well. A
computer is not the ideal tool to convert celsius to fahrenheit either,
yet I have written a few programs to do just that when learning a
language. :-)

Rich


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

Date: Wed, 04 Aug 2004 13:22:04 -0400
From: Sherm Pendley <spamtrap@dot-app.org>
Subject: Re: recursive functions
Message-Id: <57ydnRUXUOKhhozcRVn-pg@adelphia.com>

steve_f wrote:

> hmmmm....!! ok, yes this post was off topic, I really should of found a 
> programming group!

To bring it back on-topic, then, you might want to have a look at 
O'Reilly's "Mastering Algorithms with Perl". A number of recursive 
algorithms are discussed in it.

sherm--


-- 
Cocoa programming in Perl: http://camelbones.sourceforge.net
Hire me! My resume: http://www.dot-app.org


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

Date: 04 Aug 2004 17:56:43 +0100
From: Brian McCauley <nobull@mail.com>
Subject: Re: RegEx issue
Message-Id: <u9vffyvo38.fsf@wcl-l.bham.ac.uk>

Gunnar Hjalmarsson <noreply@gunnar.cc> writes:

> Charles DeRykus wrote:
> > Gunnar Hjalmarsson wrote:
> >>     print "No match\n" unless 'abc@def' =~ /^[^@?]+$/;
> >>     print "Match\n" if 'abcdef' =~ /^[^@?]+$/;
> >> Outputs:
> >> No match
> >> Match
> > Looks like you're right...
> 
> I seem to be right about /[^@?]/, but I apparently jumped at conclusions.
> 
> > perl -MO=Deparse -wle '/[@?]/'
> > /[\@?]/;
> > perl -MO=Deparse -wle '/[ab@]/'
> > /[ab\@]/;
> > perl -MO=Deparse -wle '/[@m]/'
> > Possible unintended interpolation of @m in string at -e line 1.
> > Name "main::m" used only once: possible typo at -e line 1.
> > /[@m]/;
> 
> Those warnings are displayed if strictures are not enabled and you
> haven't declared the @m variable.
> 
> So, I'm a little confused. The lesson here is that @ gets interpolated
> in regexes sometimes. Maybe a good enough reason to always escape that
> character, but a less ambigous conclusion would be nice. :)

I always escape @ that I don't want to interpolate in an interpolative
context.

I cannot find a full explaination of exactly when an unescaped @ in an
interpolative context will be treated as literal even in the "Gory
details of parsing quoted constructs".

Interpolating arrays into regex doesn't make a lot of sense.  The only
time I see it used is when using the @{[...]} construct.

-- 
     \\   ( )
  .  _\\__[oo
 .__/  \\ /\@
 .  l___\\
  # ll  l\\
 ###LL  LL\\


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

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 6834
***************************************


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