[24213] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 6405 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Apr 15 11:05:51 2004

Date: Thu, 15 Apr 2004 08:05:10 -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           Thu, 15 Apr 2004     Volume: 10 Number: 6405

Today's topics:
    Re: Changing from C thought to Perl (Anno Siegel)
    Re: Changing from C thought to Perl <rob_perkins@hotmail.com>
    Re: debian: how to install/maintain perl packages? <doc@CONSORTIUM.RedBrick.DCU.IE.small.carrots>
    Re: Earthquake and tornado data evaluation Perl program <edgrsprj@ix.netcom.com>
    Re: Earthquake and tornado data evaluation Perl program <edgrsprj@ix.netcom.com>
    Re: eval running external script <tadmc@augustmail.com>
    Re: eval running external script <shailesh@nothing.but.net>
    Re: Many filename arguments: EOF in "while(@slurp=<>){. <fma@doe.carleton.ca>
    Re: need to find word, and comment out next 5 lines (Anno Siegel)
    Re: need to find word, and comment out next 5 lines (Anno Siegel)
        One question <edgrsprj@ix.netcom.com>
    Re: OT: Re: Writing to STDIN <vek@station02.ohout.pharmapartners.nl>
    Re: Perl script to edit crontab <jcanfield@tshmail.com>
        question about substr <EatMeSpammers_cwtart@commpay.tv>
        regexpr question   is w2 taken <rbell01824@earthlink.net>
    Re: Tough (for me) regex case <Joe.Smith@inwap.com>
    Re: Two mini-golfish problems <pinyaj@rpi.edu>
    Re: Two mini-golfish problems <tassilo.parseval@rwth-aachen.de>
    Re: Two mini-golfish problems (Anno Siegel)
    Re: Two mini-golfish problems <jkrugman@yahbitoo.com>
    Re: Two mini-golfish problems (Anno Siegel)
    Re: Two mini-golfish problems <wherrera@lynxview.com>
    Re: Two mini-golfish problems <uri@stemsystems.com>
    Re: use of uninitialised value <xxala_qumsiehxx@xxyahooxx.com>
    Re: Variables in an array <tore@aursand.no>
    Re: Variables in an array <tadmc@augustmail.com>
    Re: Variables in an array <uri@stemsystems.com>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: 15 Apr 2004 12:01:44 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Changing from C thought to Perl
Message-Id: <c5ltj8$d2l$1@mamenchi.zrz.TU-Berlin.DE>

Richard Morse  <remorse@partners.org> wrote in comp.lang.perl.misc:
> In article <scrn701n7amaig8ism9l81588cblhvjrrc@4ax.com>,
>  Tigerhillside <Tigerhillsider@netscape.net> wrote:

[...]

> >I was "taught" that side effects and (essentially)
> > global variables are a "bad thing". ISTM that I have to keep some
> > internal (to me) table of these variables in mind when I code.

[...]

> I assume that the "global" variable you are talking about is "$_".  It's 
> probably better not to think of this as a variable, but rather as a 
> topic.  I seem to remember a language (perhaps it was Pascal?) which 
> allowed you to do something like:
> 
>    with my_record
>       begin
>          a = 5; { same as my_record.a = 5 }
>          b = 6; { same as my_recond.b = 6 }
>       end
> 
> (I know that Pascal has this construction, although it might not be 
> called "with").

Well, "WITH".  Pascal, Modula and Oberon have it, and it's a good thing.

>                  $_ can be considered in the same light -- it indicates 
> what the current thing we are talking about is.

Quite.  The one-shot "for" has similar uses:

    for ( $ridiculously->{ long}->[ $scalar]->{ $expression} ) {
        s/gaga/gugu/ unless ref;
        # etc...
     }

In Pascal (etc.) you can give multiple topics.  I never quite understood
how ambiguities are resolved if they happen, but otherwise it's handy.
Perl can't do that in the same way -- the compiler must know what fields
to expect in the records, but in Perl that's run-time.

Anno


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

Date: Thu, 15 Apr 2004 14:43:59 GMT
From: Rob Perkins <rob_perkins@hotmail.com>
Subject: Re: Changing from C thought to Perl
Message-Id: <vd7t701i49jktbvvt5ga4m6vig8pljgh3n@4ax.com>

Martien Verbruggen <mgjv@tradingpost.com.au> wrote:

>> In the context of Java or .NET's CLR, that makes Perl5 a "platform",
>> by a definition you are not using, but I am.
>
>And once again, you show the Humpty Dumpty attitude that is at the
>core of most of the verbosity in this thread.

Now. It's a minor point, but the definition of "platform" I'm using is
hardly just my own. The context is as old as software-emulated
systems, far older than Java, which popularized the idea.

There's kind of a "conform or die" attitude around here, which
troubles me a lot. Some of you don't treat newcomers very well at
all...

Rob


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

Date: 15 Apr 2004 09:53:06 GMT
From: Dave O Connor <doc@CONSORTIUM.RedBrick.DCU.IE.small.carrots>
Subject: Re: debian: how to install/maintain perl packages?
Message-Id: <slrnc7sms2.sae.doc@carbon.redbrick.dcu.ie>

Michael Friendly said this: 
> I'm confused about how to install perl packages on a debian system, to 
> allow easy maintenance and upgrades.
> 
Have a look at the 'dh-make-perl' package. It takes most perl modules (even
fetches them from CPAN for you!), and builds a .deb from it. Then, if you've a
lot of machines, you can use it in your local apt repository, if you have one.

	- DoC


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

Date: Thu, 15 Apr 2004 14:39:49 GMT
From: "edgrsprj" <edgrsprj@ix.netcom.com>
Subject: Re: Earthquake and tornado data evaluation Perl program  Apr. 14, 2004
Message-Id: <V8xfc.7581$l75.1096@newsread2.news.atl.earthlink.net>

"A. Sinan Unur" <1usa@llenroc.ude> wrote in message
news:Xns94CBCB008812asu1cornelledu@132.236.56.8...
> "edgrsprj" <edgrsprj@ix.netcom.com> wrote in
> news:YZcfc.7030$zj3.3864@newsread3.news.atl.earthlink.net:
>
> Well, your program managed to make me cry. Just two samples:

And it should make you cry, but for a reason which I suspect you are not
considering.

There are quite a few countries around the world where cities and even
entire governments could be decimated by an earthquake in just a few minutes
time.  And to some extent that includes the United States.

One would think that rather than suffer such a fate they would be looking
everywhere for ways to solve the problem.  So, here is a computer program
which I believe we can easily prove works for providing us with invaluable
information regarding approaching earthquakes.

Do you see any governments rushing to get it developed for their own use?

The answer, obviously, is "No."  And that is something to cry about.

Here is something else to cry about.

Some of the people reading this thread are probably expert computer
programmers who live in cities around the world where an earthquake could
cost them their own lives in a matter of minutes.  And if you read that
301.html Web page, towards the end there is a fairly lengthy list of things
that need to be done in order to get this program to work better including
improving it source code.  Even amateur computer programmers could do many
of those things.

Do you see any expert computer programmers whose lives are threatened by
earthquakes who are rushing to do any of those things in my suggestion list?

Once again, the answer is close to being "No."  And that is really something
to cry about.  When a life threatening situation exits and people are given
an opportunity to do something which might enable them to save their own
lives, how can they just ignore that?

As I said, the answer is "close to being No."  That is because I am actually
working with an expert computer programmer who is threatened by earthquakes.
And it sounds like he is about 80% of the way through the process of
converting my source code into a compiled version of Basic.  I am expecting
his program to be quite important as it will enable people to run the data
evaluation program without having to have Perl on their system.  On the
negative side, as it will be a compiled program they will also not be able
to make any modifications to it.  However I believe that we will be making
his source code available.  And that might enable people who have that
particular version of Basic to do some work on the program.




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

Date: Thu, 15 Apr 2004 14:39:50 GMT
From: "edgrsprj" <edgrsprj@ix.netcom.com>
Subject: Re: Earthquake and tornado data evaluation Perl program  Apr. 14, 2004
Message-Id: <W8xfc.7582$l75.6805@newsread2.news.atl.earthlink.net>

"Tad McClellan" <tadmc@augustmail.com> wrote in message
news:slrnc7rnbr.cao.tadmc@magna.augustmail.com...
> edgrsprj <edgrsprj@ix.netcom.com> wrote:

I have a copy of your note.  Thanks for taking some time to make those
recommendations.

Here is the main problem which I am facing.  And just like with everyone
else it has to do with the amount of time which is available.

I am of the opinion that at the moment, this Perl computer program probably
represents about the only hope that many people around the world have of
getting any warning at all before a destructive earthquake occurs near them.
And if you are wondering if this technology is actually worth anything I
will point out that I was invited to make a presentation on it at an
important scientific conference in the People's Republic of China, held late
last December.  China is probably has the most ambitious earthquake
forecasting program of any country.  And as far as I am aware I am the only
U.S. scientist who was invited to make a presentation at that conference.

I could not attend myself.  But one of my research colleagues who lives
there got my reports translated into Chinese and did the presentation
for me.

The following things need to be done, among other things:

1.  Improve the program source code, something that you yourself proposed.

2.  Add routines to it which will enable it to do things such as generate
data regarding sun and moon locations so that they do not have to be read
from enormous precompiled lists.

3.  The program contains "weight" factors which tell it how it needs to do
the calculations.  I have it set to use the same weight factors for
earthquakes occurring everywhere.  But it should probably have customized
lists of weight factors for earthquakes occurring in different areas.  And
someone has to determine what those values are.

4.  Additional calculation routines need to be added to the program.  Mine
just represent a starting point.

5.  Information regarding the existence of the program needs to be
circulated to researchers and computer programmers around the world who can
use it and/or improve it.

Of those things, at the moment I am probably the only person who can work on
steps 4 and 5.  But even amateur computer programmers could work on any of
the other steps.

So, if earthquakes are on the average claiming one life every hour, 24 hours
a day, 365 days a year.  And if I can devote just an hour or two to this
project every day, then where should I focus my available time in order to
save the maximum number of lives?

A.  Should I focus that time on improving the computer code, something which
thousands and perhaps even tens of thousands of other people around the
world could do probably better than me?

B.  Or should I focus that time on steps 4 and 5 and try to encourage some
of those computer programmers to help with generating better computer code?

This is not a hypothetical matter.  Large numbers of real people are
perishing during earthquakes.  More than 25,000 in Bam, Iran reportedly went
off to their eternal rewards late last December when a powerful and
destructive earthquake occurred there.  And the answers to questions A and B
could, I personally believe, have a considerable impact on just how people
many might perish like that in the future.




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

Date: Thu, 15 Apr 2004 08:29:25 -0500
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: eval running external script
Message-Id: <slrnc7t3hl.e00.tadmc@magna.augustmail.com>

Shailesh <shailesh@nothing.but.net> wrote:
>> You *do* realize that the URL you referenced is an *illegal* copy of an
>> O'Reilly book, right?

> Not until you told me.  


Who is "you"?

Please provide an attribution when you quote someone.


> Though this worked, the version below does not work, even though your 
> link says: "With system(), both STDOUT and STDERR will go the same 
> place as the script's STDOUT and STDERR."  


If your program has its STDOUT and STDERR going to the terminal,
then the external program's output will go to the terminal, just
like the docs say.


> God I hate perl


Then choose some other language to use.


-- 
    Tad McClellan                          SGML consulting
    tadmc@augustmail.com                   Perl programming
    Fort Worth, Texas


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

Date: Thu, 15 Apr 2004 14:09:24 GMT
From: Shailesh <shailesh@nothing.but.net>
Subject: Re: eval running external script
Message-Id: <oIwfc.1794$kt.102@fe2.columbus.rr.com>

Tad McClellan wrote:

> If your program has its STDOUT and STDERR going to the terminal,
> then the external program's output will go to the terminal, just
> like the docs say.
> 
> 
> 

Never mind, I wasn't paying attention.  I realized WinXP supports 
console IO redirection on the command line too.  This version works 
perfectly on both WinXP and Linux:

----------------TASK_SCHEDULER.PL
$output = `perl run_task.pl myparam 2>&1`;
print "output is: ".$output;

----------------RUN_TASK.PL

# Purposely do a division by zero.
$i = 0;
$a = 1 / $i;
print "vals: ".$a.$i."\n";

----------------OUTPUT of running task_scheduler.pl
output is: Illegal division by zero at run_task.pl line 5.



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

Date: 15 Apr 2004 07:20:29 GMT
From: Fred Ma <fma@doe.carleton.ca>
Subject: Re: Many filename arguments: EOF in "while(@slurp=<>){..}"?
Message-Id: <407E37B6.A32985BF@doe.carleton.ca>

James Willmore wrote:
> 
> >> > I wish there was an index that tells you what perldoc sections to
> >> > look in.
> >>
> >> I make my own index:
> >>
> >>    perldoc -l perlfunc   # find out where the .pods are
> >>    cd .../pod            # go to where the pods are
> >>    perl -ne 'print "$ARGV: $_" if /^=/' *.pod >all.heads
> >>    (or: grep ^= *.pod >all.heads)
> >>
> >> Then I search it with grep:
> >>
> >>    grep SOMETHING all.heads
> >>
> >> or with grep written in Perl:
> >>
> >>    perl -ne 'print if /SOMETHING/' all.heads
> 
> > Thanks for the tip.  I still believe, however, that a
> > conventional hyperlinked index would be invaluable to
> > people getting into Perl.
> 
> Use the ActiveState distro of Perl for Windows :-)

I'm actually on sparc solaris machines alot.

> It comes with HTML
> pages of all the documentation.  Not sure if it's the same for the other
> ActiveState offerings for other platforms.
> 
> And ... as always ... you could visit http://perldoc.com/ :-)

Yes, I visited there alot.  That's where I was looking for a
concept index.  Then I started to use less's search on perltoc,
local text version.

> OTOH, Tad's code is pretty slick :-)  I like it and will start using it
> ... even if you won't :-)

I don't recall saying I won't.  But an indexed help database would
remove a barrier to those who are getting into Perl.  Not all
online docs have it, but when it exists (e.g. STL documentation
databases, lots of gnu documentation), it is *great*, even when
you're not quite a newbie.  It probably takes alot of work to
assemble one, though.

Fred
-- 
Fred Ma
Dept. of Electronics, Carleton University
1125 Colonel By Drive, Ottawa, Ontario
Canada, K1S 5B6


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

Date: 15 Apr 2004 13:00:27 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: need to find word, and comment out next 5 lines
Message-Id: <c5m11b$fdq$1@mamenchi.zrz.TU-Berlin.DE>

Glenn Jackman  <xx087@freenet.carleton.ca> wrote in comp.lang.perl.misc:
> joe shaboo <jshaboo@hotmail.com> wrote:
> [...]
> >  example
> >  
> >  zone "mydomain.com" {
> >      type master;
> >      file "path/to/zone"
> >      notify yes;
> >  }
> >  
> >  what I'd like to do
> >  
> >  // Domain commented out by `finger `logname` | grep real | awk '{print
> >  $7" "$8}'` on date.
> >  // zone "mydomain.com"
> >  //       type master;
> >  //       file "path/to/zone"
> >  //       notify yes;
> >  //}
> 
> Here's one approach:
> 
>     #!/usr/local/bin/perl
>     use strict;
>     use warnings;
> 
>     my $re = qr{domain2};
>     my $commenting = 0;
> 
>     while (<DATA>) {
>         if (/$re/) {
>             $commenting = 1;
>             print "// some useful comment\n";
>         }
>         print "//" if $commenting;
>         print;
>         $commenting = 0 if /^\s*}/;
>     }

The loop can be tightened a bit, using the ".." operator instead of
the auxiliary variable $commenting:

    while ( <DATA> ) {
        print "// some useful comment\n" if /$re/;
        $_ = "// $_" if /$re/ .. /^\s*}/;
        print;
    }

[DATA snipped]

Anno


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

Date: 15 Apr 2004 13:08:14 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: need to find word, and comment out next 5 lines
Message-Id: <c5m1fu$fdq$2@mamenchi.zrz.TU-Berlin.DE>

Tad McClellan  <tadmc@augustmail.com> wrote in comp.lang.perl.misc:

[...]

> my $comment = 'Domain commented out by ...';
> 
> while ( <DATA> ) {
>    if ( /zone "mydomain\.com"/ ) {
>       print "// $comment\n";
>       print "// $_";
>       foreach my $i ( 1 .. 4 ) {  # the next four lines
>          my $line = <DATA>;

I would write that

           my $line = <DATA> or last;

since the while-condition doesn't check these reads.

>          print "// $line";
>       }
>       next;
>    }
>    print;
> }

Anno


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

Date: Thu, 15 Apr 2004 14:39:51 GMT
From: "edgrsprj" <edgrsprj@ix.netcom.com>
Subject: One question
Message-Id: <X8xfc.7583$l75.5918@newsread2.news.atl.earthlink.net>

In my first note I asked an important question.  So far there have not been
any answers.

Q:  Can anyone else get that program to run on their computer?

I am in the process of discussing the program with people around the world.
And it would be helpful if I could tell people the answer to that question
for operating systems other than Windows XP and Windows 98.

http://www.freewebz.com/eq-forecasting/311.zip

That is the program's download address.  It has to be there in a zip file
because one of its data files is about 2 million bytes in size.  And it
would probably take forever to download it from that site which I have found
can run a little slow (but it is free, so I can't complain).

I have the program running on a Windows XP system.  And I am going to assume
that this means that it will run on any other Windows XP system.   A
computer programmer who is developing a compiled Basic version of the
program says it is running with his Windows 98 system.  But as expected, it
does not do a very good job of automatically opening the output file in a
text editor when a run is finished.  That problem can be solved.

I am assuming that many or most of the people posting notes to this Perl
Newsgroup actually have Perl running on their computers.

So, will the program run on other operating systems such as Unix etc.?

It is simply an application for Perl.  It does not install anything on the
computer etc.  And you can see what it does and what it looks like by
examining the following Web page where a copy of the source code is
presently stored:

http://www.freewebz.com/eq-forecasting/303.html

As I said in my first posting, I believe that it is always a good
idea to scan any zip file for viruses before you open it.




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

Date: 15 Apr 2004 08:16:18 GMT
From: Villy Kruse <vek@station02.ohout.pharmapartners.nl>
Subject: Re: OT: Re: Writing to STDIN
Message-Id: <slrnc7sh6i.hm.vek@station02.ohout.pharmapartners.nl>

On 13 Apr 2004 18:32:18 GMT,
    A. Sinan Unur <1usa@llenroc.ude> wrote:


>
> bash deals with user input using the readline library. You can download 
> that library and inspect it instead of thinking about it accomplishes 
> certain tasks.
>


You can also get the Perl module Term::ReadLine::Gnu from CPAN to get 
command line history and editing in your perl program.  The perl module
CPAN uses that library if available.

Villy


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

Date: Thu, 15 Apr 2004 08:37:16 -0500
From: "Jim Canfield" <jcanfield@tshmail.com>
Subject: Re: Perl script to edit crontab
Message-Id: <107t40cokmp471e@corp.supernews.com>

Thanks!

CPAN search gave me exactly what I was looking for.

"J. Gleixner" <glex_nospam@qwest.invalid> wrote in message
news:otjfc.70$IQ6.103871@news.uswest.net...
> Jim Canfield wrote:
> > Greetings,
> >
> > Anyone here have perl/cgi script for editing cron events? So far the
only
> > thing I have been able to find is the cron module in webmin, but it does
too
> > much.  Just a thought before I start from he ground up.
> >
> > Thanks.
> >
> >
>
> When looking to see if something has been done before, start with CPAN
> or Google.
>
> http://search.cpan.org
>
> Searching on "crontab"
>
> http://search.cpan.org/~scottw/Config-Crontab-1.03/Crontab.pm
>
> Much quicker than posting here and waiting for a response.
>
> See ya




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

Date: Thu, 15 Apr 2004 10:04:37 -0500
From: "Chuck" <EatMeSpammers_cwtart@commpay.tv>
Subject: question about substr
Message-Id: <0wxfc.985$KG2.1629@reggie.win.bright.net>

I am a new perl learner and have a question about substr

Does the starting string position x in substr("string",x,y) need to be set
to zero to start reading at the 1st postion or set to one? I found some
examples that seem to show it both ways - am I assuming correctly that the
starting postion parameter is always one less than the position you want to
start at?

-- 

regards,

Chuck




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

Date: Thu, 15 Apr 2004 14:52:23 GMT
From: Richard Bell <rbell01824@earthlink.net>
Subject: regexpr question   is w2 taken
Message-Id: <fr7t7050jda6lusl1ue37ooadukvlepc7l@4ax.com>


I'm a bit new to perl and am trying to emulate the behavior of a free
text search engine that has a feature

	is w2 taken

taken to mean the word 'is' within 2 words of the word 'taken' where
the distance (2) and the words ('is', 'taken') are arbitrary.

I've a variable that looks like this

'one two three four and so on words seperated by spaces that goes on
and on and on and on for a very long way'

that I'm tring to process.

I'm having a problem finding a regular expression that handles this
case.  Something like

"\bis\b(what goes here){0,2}\btaken\b"

Can someone point me in the right direction?

I assume that $pos will point to the last character matched.  Is this
correct?  How can I know the index of the first character matched? Can
I know what '(what goes here)' matched?  How?  As part of this
process, I'm trying to track what characters in the string were
matched by a number of regular expressions by getting $pos and keeping
a bit map of the characters matched.

Thanks.

Richard


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

Date: Thu, 15 Apr 2004 08:08:47 GMT
From: Joe Smith <Joe.Smith@inwap.com>
Subject: Re: Tough (for me) regex case
Message-Id: <iqrfc.41013$wP1.190672@attbi_s54>

Rob Perkins wrote:

> Didn't know Python had regular expressions.
> 
>>Even javascript has them.
> Didn't know that, either.

Lots of programs have Perl-Compatible Regular Expressions.
http://www.pcre.org/

>>>What of those using ActivePerl on the .NET framework? Which
>>>implementation will they hit?

Perl does _NOT_ the system-supplied routines.  It uses its own.
It has to, in order to provide consistent results on all platforms.

Check the PLATFORMS section of "perldoc perlport" to get an idea
of all the non-.NET platforms perl has compatiblity with.

	-Joe


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

Date: Thu, 15 Apr 2004 04:12:40 -0400
From: Jeff 'japhy' Pinyan <pinyaj@rpi.edu>
Subject: Re: Two mini-golfish problems
Message-Id: <Pine.SGI.3.96.1040415041147.257102A-100000@vcmr-64.server.rpi.edu>

On 15 Apr 2004, Tassilo v. Parseval wrote:

>Also sprach Bill:
>
>> J Krugman wrote:
>> 
>>> OK, here's a little problem that I'd like to propose in the Perl
>>> golf (mini-golf?) vein.
>>> 
>> 
>>> Given a string $x that we may assume contains no newline characters,
>>> split it into chunks of $n characters long separated my newlines.
>> 
>> $x = 'fubar';
>> $x=~s/(..)/$1\n/g;print $x;
>
>That should be:
>
>    $x=~s/(..?)/$1\n/g;
>
>Otherwise it omits the last newline for words of uneven length.

So?  Krugman said "separated".  She didn't say that each chunk has a
newline, just that they're separated.

-- 
Jeff Pinyan             RPI Acacia Brother #734             2004 IT Chairman
"And I vos head of Gestapo for ten     | Michael Palin (as Heinrich Bimmler)
 years.  Ah!  Five years!  Nein!  No!  | in: The North Minehead Bye-Election
 Oh.  Was NOT head of Gestapo AT ALL!" | (Monty Python's Flying Circus)



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

Date: 15 Apr 2004 08:51:16 GMT
From: "Tassilo v. Parseval" <tassilo.parseval@rwth-aachen.de>
Subject: Re: Two mini-golfish problems
Message-Id: <c5lie4$33bmk$1@ID-231055.news.uni-berlin.de>

Also sprach Jeff 'japhy' Pinyan:

> On 15 Apr 2004, Tassilo v. Parseval wrote:
> 
>>Also sprach Bill:
>>
>>> J Krugman wrote:
>>> 
>>>> OK, here's a little problem that I'd like to propose in the Perl
>>>> golf (mini-golf?) vein.
>>>> 
>>> 
>>>> Given a string $x that we may assume contains no newline characters,
>>>> split it into chunks of $n characters long separated my newlines.
>>> 
>>> $x = 'fubar';
>>> $x=~s/(..)/$1\n/g;print $x;
>>
>>That should be:
>>
>>    $x=~s/(..?)/$1\n/g;
>>
>>Otherwise it omits the last newline for words of uneven length.
> 
> So?  Krugman said "separated".  She didn't say that each chunk has a
> newline, just that they're separated.

Well, what is a chunk separated by a newline anyway? Did she mean:

    "fu\n",
    "ba\n",
    "r\n"

or did she mean

    "fu\nba\nr\n"

or rather

    "fu",
    "ba",
    "r"

Note that there are no newlines in the last alternative, but she
explicitely mentions them.

Apparently you know what she meant. Care to enlighten me? :-)

Tassilo
-- 
$_=q#",}])!JAPH!qq(tsuJ[{@"tnirp}3..0}_$;//::niam/s~=)]3[))_$-3(rellac(=_$({
pam{rekcahbus})(rekcah{lrePbus})(lreP{rehtonabus})!JAPH!qq(rehtona{tsuJbus#;
$_=reverse,s+(?<=sub).+q#q!'"qq.\t$&."'!#+sexisexiixesixeseg;y~\n~~dddd;eval


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

Date: 15 Apr 2004 10:44:51 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Two mini-golfish problems
Message-Id: <c5lp33$96u$1@mamenchi.zrz.TU-Berlin.DE>

Uri Guttman  <uri@stemsystems.com> wrote in comp.lang.perl.misc:
> >>>>> "JK" == J Krugman <jkrugman@yahbitoo.com> writes:
> 
>   JK> OK, here's a little problem that I'd like to propose in the Perl
>   JK> golf (mini-golf?) vein.
> 
>   JK> Given a string $x that we may assume contains no newline characters,
>   JK> split it into chunks of $n characters long separated my newlines.
>   JK> E.g. if $n == 2,
> 
> <untested> and prolly long but at least it is clear
> 
> my @lines = map "$_\n", $x =~ /(.{1,2})/g ;

Same length, no regex:

    my @lines = map "$_\n", unpack '(A2)*', $x;

If it's less clear, then only because nobody knows the pack formats
by heart :)

Anno


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

Date: Thu, 15 Apr 2004 11:39:38 +0000 (UTC)
From: J Krugman <jkrugman@yahbitoo.com>
Subject: Re: Two mini-golfish problems
Message-Id: <c5ls9q$6d3$1@reader2.panix.com>




I am sorry about the confusing statement.  I meant "fu\nba\nr".

I originally tried s/(?<=[^\n]{2})/\n/g, but this failed miserably;
my mistake was to conclude from this that regexps were not the way
to go.  I'm still amazed that the regexp above gives different
results from s/(.{2})/$1\n/g.  I often use zero-width look-ahead
and look-behinds to avoid carrying $1's over to the second slot of
a s/// expression.  It's perverse, I know, but until this case I
always got the desired results, but I guess I'd never tried this
trick with a s///g substitution.

Thanks,

jill

-- 
To  s&e^n]d  me  m~a}i]l  r%e*m?o\v[e  bit from my a|d)d:r{e:s]s.



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

Date: 15 Apr 2004 12:06:38 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Two mini-golfish problems
Message-Id: <c5ltse$d2l$2@mamenchi.zrz.TU-Berlin.DE>

Anno Siegel <anno4000@lublin.zrz.tu-berlin.de> wrote in comp.lang.perl.misc:
> Uri Guttman  <uri@stemsystems.com> wrote in comp.lang.perl.misc:
> > >>>>> "JK" == J Krugman <jkrugman@yahbitoo.com> writes:
> > 
> >   JK> OK, here's a little problem that I'd like to propose in the Perl
> >   JK> golf (mini-golf?) vein.
> > 
> >   JK> Given a string $x that we may assume contains no newline characters,
> >   JK> split it into chunks of $n characters long separated my newlines.
> >   JK> E.g. if $n == 2,
> > 
> > <untested> and prolly long but at least it is clear
> > 
> > my @lines = map "$_\n", $x =~ /(.{1,2})/g ;
> 
> Same length, no regex:
> 
>     my @lines = map "$_\n", unpack '(A2)*', $x;
> 
> If it's less clear, then only because nobody knows the pack formats
> by heart :)

Let me retract that, it's cheating.  The last chunk is filled with
invisible null bytes.  That bites.

Anno


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

Date: Thu, 15 Apr 2004 07:30:35 -0600
From: Bill <wherrera@lynxview.com>
Subject: Re: Two mini-golfish problems
Message-Id: <2s2dnQFbMvQfE-PdRVn-hw@adelphia.com>

Uri Guttman wrote:

>>>>>>"B" == Bill  <wherrera@lynxview.com> writes:
> 
> 
> 
>   B> Remember: succint, maintainable, fast. Choose 2 of 3 :)
> 
> how about correct?
> 
>   B> $x = 'fubar';
>   B> $x=~s/(..)/$1\n/g;print $x;
> 
> what happens to the 'r'?
> 
> uri
> 

On my system, the OS inserts a \n at script exit, so that one does not 
need to be added by perl in the print. Yes, I know it's not perfect 
otherwise :).




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

Date: Thu, 15 Apr 2004 13:43:19 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: Two mini-golfish problems
Message-Id: <x7vfk18ih4.fsf@mail.sysarch.com>

>>>>> "J'P" == Jeff 'japhy' Pinyan <pinyaj@rpi.edu> writes:

  >>>> Given a string $x that we may assume contains no newline characters,
  >>>> split it into chunks of $n characters long separated my newlines.
  >>> 
  >>> $x = 'fubar';
  >>> $x=~s/(..)/$1\n/g;print $x;
  >> 
  >> That should be:
  >> 
  >> $x=~s/(..?)/$1\n/g;
  >> 
  >> Otherwise it omits the last newline for words of uneven length.

  J'P> So?  Krugman said "separated".  She didn't say that each chunk has a
  J'P> newline, just that they're separated.


and she drew this little picture which of course looks like the last
part has a newline. poor specs are too blame and she has copped to that
in another post.

               'fu'
  'fubar' ---> 'ba'
               'r'

uri

-- 
Uri Guttman  ------  uri@stemsystems.com  -------- http://www.stemsystems.com
--Perl Consulting, Stem Development, Systems Architecture, Design and Coding-
Search or Offer Perl Jobs  ----------------------------  http://jobs.perl.org


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

Date: Thu, 15 Apr 2004 08:29:25 GMT
From: Ala Qumsieh <xxala_qumsiehxx@xxyahooxx.com>
Subject: Re: use of uninitialised value
Message-Id: <FJrfc.22767$Id1.14840@newssvr27.news.prodigy.com>

Cognition Peon wrote:
> I am getting desried output for the following piece, but -w switch to perl
> is reporting that 'if />.*/' in the code uses uninitialized value. The
> input file follows. I also tried another combination of if statement, but
> the error still persists. 'if /^(>.*)/' accessing the match from $1.
> 
> 
> while(<FILE>) {
>         my ($header, ) = ();
>         next if /^$/;
>         chomp;
> 
>         if (/>.*/) { # Use of uninitialized value here
>                 $header = $&;
>                 $bin = (split('[_-]', $header))[1];
>                 push @{$bins{$bin}}, $header;
>         } else {
>                 $fasta{$header} = $_;

This line causes your warnings. What happens if the line didn't match 
your regexp? $header will be undef. It needs to be scoped outside the 
while loop.

--Ala



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

Date: Thu, 15 Apr 2004 10:13:57 +0200
From: Tore Aursand <tore@aursand.no>
Subject: Re: Variables in an array
Message-Id: <pan.2004.04.15.08.13.06.420469@aursand.no>

On Thu, 15 Apr 2004 06:25:35 +0000, Uri Guttman wrote:
> you need to learn how to learn and also be more flexible. one solution
> is never right for all problems. a good rule to learn is solve in the
> general and apply in the specific.

Wise words.  Your words somehow remind me of something Bruce Lee once
wrote (and which I frequently use in my signature);

  "A teacher is never a giver of truth - he is a guide, a pointer to
   the truth that each student must find for himself.  A good teacher
   is merely a catalyst."


-- 
Tore Aursand <tore@aursand.no>


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

Date: Thu, 15 Apr 2004 01:45:11 -0500
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: Variables in an array
Message-Id: <slrnc7sbrn.d55.tadmc@magna.augustmail.com>

Cosmic Cruizer <XXjbhuntxx@white-star.com> wrote:
> "Jürgen Exner" <jurgenex@hotmail.com> wrote in <uPnfc.34506$F9.1129
> @nwrddc01.gnilink.net>:


[ snip: use a hash instead of symrefs ]


> As hard as I try, the various data structures are a challenge 
> for me. 


Keep at it.

Choosing the correct data structure can make the code easier 
to write and maintain.


-- 
    Tad McClellan                          SGML consulting
    tadmc@augustmail.com                   Perl programming
    Fort Worth, Texas


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

Date: Thu, 15 Apr 2004 13:45:28 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: Variables in an array
Message-Id: <x7smf58idj.fsf@mail.sysarch.com>

>>>>> "TA" == Tore Aursand <tore@aursand.no> writes:

  TA> On Thu, 15 Apr 2004 06:25:35 +0000, Uri Guttman wrote:
  >> you need to learn how to learn and also be more flexible. one solution
  >> is never right for all problems. a good rule to learn is solve in the
  >> general and apply in the specific.

  TA> Wise words.  Your words somehow remind me of something Bruce Lee once
  TA> wrote (and which I frequently use in my signature);

  TA>   "A teacher is never a giver of truth - he is a guide, a pointer to
  TA>    the truth that each student must find for himself.  A good teacher
  TA>    is merely a catalyst."

try this one from the famous rabbi hillel (circa 2k years ago):

	i learned a lot from my teachers,
	more from my peers
	and the most from my students.

i espouse that often and it is so true. try teaching and you will learn
more about the subject than you could imagine.

uri

-- 
Uri Guttman  ------  uri@stemsystems.com  -------- http://www.stemsystems.com
--Perl Consulting, Stem Development, Systems Architecture, Design and Coding-
Search or Offer Perl Jobs  ----------------------------  http://jobs.perl.org


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

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


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