[19871] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 2066 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sun Nov 4 21:07:00 2001

Date: Sun, 4 Nov 2001 18:05:10 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <1004925910-v10-i2066@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Sun, 4 Nov 2001     Volume: 10 Number: 2066

Today's topics:
    Re: .cgi program <tim@vegeta.ath.cx>
    Re: Failed scripts leave Perl behind <jbritain@home.com>
    Re: Failed scripts leave Perl behind (Garry Williams)
    Re: Good Perl Tutorials ??? <graham.drabble@lineone.net>
    Re: Good Perl Tutorials ??? (Garry Williams)
    Re: Good Perl Tutorials ??? <mgjv@tradingpost.com.au>
    Re: Good Perl Tutorials ??? (Garry Williams)
    Re: Good Perl Tutorials ??? (Garry Williams)
    Re: Good Perl Tutorials ??? <mgjv@tradingpost.com.au>
    Re: Good Perl Tutorials ??? (Garry Williams)
    Re: Good Perl Tutorials ??? <mgjv@tradingpost.com.au>
        gtkperl finacial calculator NEW! <joseph@mandrake.cyberhose.com>
    Re: how to print out every second value of an array <nospam_kingony@yahoo.com>
    Re: how to print out every second value of an array <nospam_kingony@yahoo.com>
        HTTP Proxy Module <femello@mac.com>
    Re: HTTP Proxy Module <wyzelli@yahoo.com>
    Re: i do not understand it(the =~s/.../.../), thanx! <tim@vegeta.ath.cx>
        Passwd changes every 90 days (Tony)
    Re: Pattern matching with "(" complains... <bootsy52@gmx.net>
    Re: perl bots from Net::IRC  <overlord_q@hotmail.com>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Mon, 05 Nov 2001 00:52:11 GMT
From: Tim Hammerquist <tim@vegeta.ath.cx>
Subject: Re: .cgi program
Message-Id: <slrn9ubp31.ens.tim@vegeta.ath.cx>

John Smith <creafin1998@yahoo.com> graced us by uttering:
[ snip ]
>  I'm not getting any error messages from the server log that I have access to
>  on any of these 500 server errors I get through my browser.

Have you run it from the command line? Are you using the -w switch or
the strict pragma?  (See below.)

[ snip ]
>  #!/usr/local/bin/perl

Add -w and use strict:

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

If you ever have problems executing a script, these drastically increase
your chances of getting a clue as to what's wrong (as well as getting
output in the logfile).

Try running it outside of the web server at the command line:
On Win32:
    C:\> perl -w \path\to\script.cgi
On *nix:
    $ perl -w /path/to/script.cgi

Since you use CGI.pm, it allows you to enter data at the terminal to
use as form data.

>  use CGI qw(param);

CGI.pm does everything your parse() method does. (BTW, if form data
happens to be POSTed, your parse() routine won't have anything to read
from STDIN; CGI.pm already grabbed it when you imported it.)

[ snip ]
>  open (LOGFILE, "</path/to/datafile.csv");

Check return value. See below.

>  @lognfile = <LOGFILE>;
>  
>  # Main for loop starts with 2nd line of input data file
>  
>  for ($z = 1; $z <= $#lognfile; $z++) {

Just a reminder that perl arrays start indexing at 0, not 1...unless you
wanted to skip the first line of the data file.

Loading the whole file into memory at once gets dramatically slower and
bulkier as the size of the data increases.  It's no big deal for 10-20
lines, but 40,000 lines can make a huge difference.

open LOGFILE, "< /path/to/datafile.csv"
    or die "Can't open datafile.csv: $!\n";
while (<LOGFILE>) {
    # process each line, as you do anyway.  each consecutive line is in
    # $_ rather than $lognfile[$z]
}
close LOGFILE or die "Can't close datafile.csv: $!\n";

[ snip ]
>  ($text01, $text02, $data01, $data02, $data03, $data04, $data05) = split /,/,
>  $lognfile[$z];

Using the while loop I described above, the above would be:

    ($text01, $text02, $data01, $data02, $data03, $data04, $data05)
        = split /,/;

[ snip ]
>  ($text1, $text2, $data1, $data2, $data3, $data4, $data5) = split /,/,
>  $lognfile[$z];

Same as above, but with different lvalues.

[ snip ]
>  open (OUT, ">>/path/to/outdatafile.csv") or die "can't open output file:
>  $!";
>  
>  print OUT "$text01,$text02,$tv,$tc\n";
>  
>  close (OUT);

On a 40,000 line input file, you open and close outdatafile.csv 40,000
times.  This is terribly bad practice.  Surely you can open it once at
the beginning of the script and close it at the end, as you only write
to it sequentially anyway?

At a cursory glance, your dual for-loop is a terribly inefficient
algorithm. Is this necessary?

Also, idiomatic perl usage might help increase both your coding and
execution speed dramatically.

To iterate over an array:
    foreach my $element (@array) {
        # process $element
    }

To iterate over a data file:
    open FILE, "< file" or die "can't open file: $!\n";
    while (<FILE>) {
        my $line = $_;
        # process $line
    }
    close FILE or die "can't close file: $!\n";

And read perlstyle, notably the section on indentation.  The perl parser
may not care, but anyone proofing your code greatly appreciates a clear
visual layout of your logic.

If you have local documentation:

    $ perldoc perlstyle
    $ perldoc perlsyn
    $ perldoc perlopentut
    $ perldoc CGI

If not:

    http://www.perldoc.com/perl5.6.1/pod/perlstyle.html
    http://www.perldoc.com/perl5.6.1/pod/perlsyn.html
    http://www.perldoc.com/perl5.6.1/pod/perlopentut.html
    http://www.perldoc.com/perl5.6.1/lib/CGI.html

Even if your code works, these PODs should be able to tell you how you
can improve your coding to get better performance.

[ snip ]

HTH
Tim Hammerquist
-- 
You're quite free to convert your strings to byte arrays and do the
entire pattern tree by hand in pure logic code if you'd like. By the
time you finish most of the rest of us will be doing contract work on
Mars.
    -- Zenin, comp.lang.perl.misc


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

Date: Sun, 04 Nov 2001 23:51:39 GMT
From: Jim Britain <jbritain@home.com>
Subject: Re: Failed scripts leave Perl behind
Message-Id: <rqkbut46n37q0tokrsdcgbclrimrr00o7i@4ax.com>

On Sun, 04 Nov 2001 17:11:16 -0500, Ken <perl@omnibus-systems.net>
wrote:

>On Fri, 2 Nov 2001 09:56:53 -0000, "Kevin Brownhill"
><BROWNHIK@Syntegra.Bt.Co.Uk> wrote:
>
>>I think it's Windows. I had a similar problem when writing CGI programs on
>>IIS, using visual C++ on NT4. If the program failed, the process was left
>>open, leaving lots of processes which could only be killed from task
>>manager.
>>
>>Hope this helps (though I didn't find a solution).
>>
>>Kevin Brownhill
>>
>
>Its not a Windows problem, its a Perl problem. Try this, write a Perl
>cgi script that contains an infinite loop. When you access the page
>the script begins but it will never stop! Leaving the page does not
>stop a script on any server that I am aware of. Basically, I need a
>process scanner to catch orphaned processes.

Yup, it's a Perl problem all right, just like the bent nail is a
hammer problem.



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

Date: Mon, 05 Nov 2001 00:31:58 GMT
From: garry@ifr.zvolve.net (Garry Williams)
Subject: Re: Failed scripts leave Perl behind
Message-Id: <slrn9ubnfu.32d.garry@zfw.zvolve.net>

On Sun, 04 Nov 2001 17:11:16 -0500, Ken <perl@omnibus-systems.net>
wrote:

> On Fri, 2 Nov 2001 09:56:53 -0000, "Kevin Brownhill"
> <BROWNHIK@Syntegra.Bt.Co.Uk> wrote:
> 

>>I think it's Windows. I had a similar problem when writing CGI
>>programs on IIS, using visual C++ on NT4. If the program failed, the
>>process was left open, leaving lots of processes which could only be
>>killed from task manager.
>>
>>Hope this helps (though I didn't find a solution).
>>
>>Kevin Brownhill
> 
> Its not a Windows problem, its a Perl problem. Try this, write a
> Perl cgi script that contains an infinite loop. When you access the
> page the script begins but it will never stop! Leaving the page does
> not stop a script on any server that I am aware of. Basically, I
> need a process scanner to catch orphaned processes.

  #!/bin/sh
  while true;do :;done

Hmm.  Another Perl problem?  

-- 
Garry Williams


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

Date: 4 Nov 2001 23:30:39 GMT
From: Graham Drabble <graham.drabble@lineone.net>
Subject: Re: Good Perl Tutorials ???
Message-Id: <Xns914FEE000516Fgrahamdrabblelineone@ID-77355.user.dfncis.de>

Martien Verbruggen <mgjv@tradingpost.com.au> wrote in
news:slrn9ubh5q.ctg.mgjv@verbruggen.comdyn.com.au: 

> On 3 Nov 2001 20:17:06 GMT,
>      Graham Drabble <graham.drabble@lineone.net> wrote:

<big snip>
> 
>><URL:http://www.inlink.com/~perlguy/internet99/part1.html> and
>>found 
>> them OK. I'll let someone more qualified say whether or not they
>> teach good practices. 
> 
> This one does not teach good practices.
> 

I have an excuse for my bad scripts then! I'll read the other one 
mentioned and see if it makes things better.

-- 
Graham Drabble
If you're interested in what goes on in other groups or want to find 
an interesting group to read then check news.groups.reviews for what 
others have to say or contribute a review for others to read.


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

Date: Mon, 05 Nov 2001 00:13:50 GMT
From: garry@ifr.zvolve.net (Garry Williams)
Subject: Re: Good Perl Tutorials ???
Message-Id: <slrn9ubmdt.32d.garry@zfw.zvolve.net>

On Sun, 04 Nov 2001 22:44:02 GMT, Martien Verbruggen
<mgjv@tradingpost.com.au> wrote:
> On 3 Nov 2001 20:17:06 GMT,
> 	Graham Drabble <graham.drabble@lineone.net> wrote:
>> brown@mad.scientist.com (brown) wrote in
>> news:4ad84303.0111031149.7a4fd97e@posting.google.com: 
>> 
>>> Hi does anyone knows a good site that offers Perl Tutorials, well
>>> done, easy to naviguate and accurate???
>>> 
>> I've found
>> 
>><URL:http://www.netcat.co.uk/rob/perl/win32perltut.html> and
> 
> \begin{review}

[ snip ]

> There is confusion about what lists are in Perl. The author calls
> both arrays and hashes lists. This confusion keeps popping up. He
> also seems to be confused about what parens do:
> 
>     @names=("Muriel","Gavin","Susanne","Sarah","Anna");
>     print "The elements of \@names are @names\n";
>     print "The first element is $names[0] \n";
>     print "The third element is $names[2] \n";
>     print 'There are ',scalar(@names)," elements in the array\n";

[ snip ]

> The parens do not produce list context. The assignment to an array
> does. The parens are not necessary because of the list context.
            ^^^^^^^^^^^^^^^^^^^^^^^^

    $ perl -wle '@names="Muriel","Gavin","Susanne";print "@names"' 
    Useless use of a constant in void context at -e line 1.
    Useless use of a constant in void context at -e line 1.
    Muriel
    $ perl -wle '@names=("Muriel","Gavin","Susanne");print "@names"'  
    Muriel Gavin Susanne
    $ 

It seems the parentheses *are* necessary here.  In spite of the fact
that the assignment *does* create the (list) context.  The perlop
manual page mentions the need for parentheses to make _comma_ a list
argument separator.  (See "Comma Operator" section.)  

-- 
Garry Williams


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

Date: Mon, 05 Nov 2001 00:31:01 GMT
From: Martien Verbruggen <mgjv@tradingpost.com.au>
Subject: Re: Good Perl Tutorials ???
Message-Id: <slrn9ubnee.ctg.mgjv@verbruggen.comdyn.com.au>

On Mon, 05 Nov 2001 00:13:50 GMT,
	Garry Williams <garry@ifr.zvolve.net> wrote:
> On Sun, 04 Nov 2001 22:44:02 GMT, Martien Verbruggen
><mgjv@tradingpost.com.au> wrote:
>> On 3 Nov 2001 20:17:06 GMT,
>> 	Graham Drabble <graham.drabble@lineone.net> wrote:
>>> brown@mad.scientist.com (brown) wrote in
>>> news:4ad84303.0111031149.7a4fd97e@posting.google.com: 
>>> 
>>>> Hi does anyone knows a good site that offers Perl Tutorials, well
>>>> done, easy to naviguate and accurate???
>>>> 
>>> I've found
>>> 
>>><URL:http://www.netcat.co.uk/rob/perl/win32perltut.html> and
>> 
>> \begin{review}
> 
> [ snip ]
> 
>> There is confusion about what lists are in Perl. The author calls
>> both arrays and hashes lists. This confusion keeps popping up. He
>> also seems to be confused about what parens do:
>> 
>>     @names=("Muriel","Gavin","Susanne","Sarah","Anna");
>>     print "The elements of \@names are @names\n";
>>     print "The first element is $names[0] \n";
>>     print "The third element is $names[2] \n";
>>     print 'There are ',scalar(@names)," elements in the array\n";
> 
> [ snip ]
> 
>> The parens do not produce list context. The assignment to an array
>> does. The parens are not necessary because of the list context.
>             ^^^^^^^^^^^^^^^^^^^^^^^^
                                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^

Note the bit I underlined as well. The whole sentence is important.

>     $ perl -wle '@names="Muriel","Gavin","Susanne";print "@names"' 
>     Useless use of a constant in void context at -e line 1.
>     Useless use of a constant in void context at -e line 1.
>     Muriel
>     $ perl -wle '@names=("Muriel","Gavin","Susanne");print "@names"'  
>     Muriel Gavin Susanne
>     $ 
> 
> It seems the parentheses *are* necessary here.  In spite of the fact

Yes, they are, but NOT because of the list context. They're necessary
for grouping, because of precedence.

This was the point I was making. The author of the tutorial puts a lot
of information in the tutorial that is either half complete,
misleading or incorrect. This statement falls in the "misleading"
category. The list context is a red herring.

The author stated that the parentheses were necessary because of the
list context, and I am stating they aren't.  They are needed for
precedence, since comma binds less tightly than =.

> that the assignment *does* create the (list) context.  The perlop
> manual page mentions the need for parentheses to make _comma_ a list
> argument separator.  (See "Comma Operator" section.)  

I don't have any mention of parentheses in the section 'Comma
Operator' in my perlop (5.6.1), and I certainly don't have anything
that says that the parentheses _make_ the comma a list operator. If I
did, I'd probably submit a bug report. The comma is invoked in a list
context because of the assignment to an array.

From perlop's precedence table:

[snip]
           right       ?:
           right       = += -= *= etc.
           left        , =>
           nonassoc    list operators (rightward)
[snip]

Without the parentheses, your examples parse as:

(@names = "Muriel"), "Gavin", "Susanne";

which explains the warnings you get about constants in void context,
as well as the result you see.

Martien
-- 
                                | 
Martien Verbruggen              | If at first you don't succeed, try
Trading Post Australia Pty Ltd  | again. Then quit; there's no use
                                | being a damn fool about it.


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

Date: Mon, 05 Nov 2001 00:39:18 GMT
From: garry@ifr.zvolve.net (Garry Williams)
Subject: Re: Good Perl Tutorials ???
Message-Id: <slrn9ubntm.32d.garry@zfw.zvolve.net>

On Mon, 05 Nov 2001 00:31:01 GMT, Martien Verbruggen
<mgjv@tradingpost.com.au> wrote:

> On Mon, 05 Nov 2001 00:13:50 GMT,
> 	Garry Williams <garry@ifr.zvolve.net> wrote:
> 
>> that the assignment *does* create the (list) context.  The perlop
>> manual page mentions the need for parentheses to make _comma_ a list
>> argument separator.  (See "Comma Operator" section.)  
> 
> I don't have any mention of parentheses in the section 'Comma
> Operator' in my perlop (5.6.1), and I certainly don't have anything
> that says that the parentheses _make_ the comma a list operator. If I
> did, I'd probably submit a bug report. The comma is invoked in a list
> context because of the assignment to an array.

    $ perldoc perlop
    ...
	 Comma Operator

	 Binary "," is the comma operator.  In scalar context it
	 evaluates its left argument, throws that value away, then
	 evaluates its right argument and returns that value.  This
	 is just like C's comma operator.

-->	 In list context, it's just the list argument separator, and
-->	 inserts both its arguments into the list.

-- 
Garry Williams


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

Date: Mon, 05 Nov 2001 00:42:39 GMT
From: garry@ifr.zvolve.net (Garry Williams)
Subject: Re: Good Perl Tutorials ???
Message-Id: <slrn9ubo3v.32d.garry@zfw.zvolve.net>

On Mon, 05 Nov 2001 00:31:01 GMT, Martien Verbruggen
<mgjv@tradingpost.com.au> wrote:

> On Mon, 05 Nov 2001 00:13:50 GMT,
> 	Garry Williams <garry@ifr.zvolve.net> wrote:

[ snip ]

> 
>>     $ perl -wle '@names="Muriel","Gavin","Susanne";print "@names"' 
>>     Useless use of a constant in void context at -e line 1.
>>     Useless use of a constant in void context at -e line 1.
>>     Muriel
>>     $ perl -wle '@names=("Muriel","Gavin","Susanne");print "@names"'  
>>     Muriel Gavin Susanne
>>     $ 

[ snip ]

> From perlop's precedence table:
> 
> [snip]
>            right       ?:
>            right       = += -= *= etc.
>            left        , =>
>            nonassoc    list operators (rightward)
> [snip]
> 
> Without the parentheses, your examples parse as:
> 
> (@names = "Muriel"), "Gavin", "Susanne";
> 
> which explains the warnings you get about constants in void context,
> as well as the result you see.

Yes.  It's a precedence issue.  

-- 
Garry Williams


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

Date: Mon, 05 Nov 2001 00:47:51 GMT
From: Martien Verbruggen <mgjv@tradingpost.com.au>
Subject: Re: Good Perl Tutorials ???
Message-Id: <slrn9uboe0.ctg.mgjv@verbruggen.comdyn.com.au>

On Mon, 05 Nov 2001 00:39:18 GMT,
	Garry Williams <garry@ifr.zvolve.net> wrote:
> On Mon, 05 Nov 2001 00:31:01 GMT, Martien Verbruggen
><mgjv@tradingpost.com.au> wrote:
> 
>> On Mon, 05 Nov 2001 00:13:50 GMT,
>> 	Garry Williams <garry@ifr.zvolve.net> wrote:
>> 
>>> that the assignment *does* create the (list) context.  The perlop
>>> manual page mentions the need for parentheses to make _comma_ a list
>>> argument separator.  (See "Comma Operator" section.)  
>> 
>> I don't have any mention of parentheses in the section 'Comma
>> Operator' in my perlop (5.6.1), and I certainly don't have anything
>> that says that the parentheses _make_ the comma a list operator. If I
>> did, I'd probably submit a bug report. The comma is invoked in a list
>> context because of the assignment to an array.
> 
>     $ perldoc perlop
>     ...
> 	 Comma Operator
> 
> 	 Binary "," is the comma operator.  In scalar context it
> 	 evaluates its left argument, throws that value away, then
> 	 evaluates its right argument and returns that value.  This
> 	 is just like C's comma operator.
> 
> -->	 In list context, it's just the list argument separator, and
> -->	 inserts both its arguments into the list.

And where does this mention parentheses? I have already explained that
the list context does not come from the parentheses, but from the
assignment to an array. The parentheses group the arguments and comma
separators together.

Again: Yes, the parens are necessary, but _not_ to create list
context. The list context is already there.

Martien
-- 
                                | 
Martien Verbruggen              | 42.6% of statistics is made up on the
Trading Post Australia Pty Ltd  | spot.
                                | 


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

Date: Mon, 05 Nov 2001 01:10:35 GMT
From: garry@ifr.zvolve.net (Garry Williams)
Subject: Re: Good Perl Tutorials ???
Message-Id: <slrn9ubpoa.34h.garry@zfw.zvolve.net>

On Mon, 05 Nov 2001 00:47:51 GMT, Martien Verbruggen
<mgjv@tradingpost.com.au> wrote:

> On Mon, 05 Nov 2001 00:39:18 GMT,
> 	Garry Williams <garry@ifr.zvolve.net> wrote:
>> On Mon, 05 Nov 2001 00:31:01 GMT, Martien Verbruggen
>><mgjv@tradingpost.com.au> wrote:
>> 
>>> On Mon, 05 Nov 2001 00:13:50 GMT,
>>> 	Garry Williams <garry@ifr.zvolve.net> wrote:
>>> 
>>>> that the assignment *does* create the (list) context.  The perlop
>>>> manual page mentions the need for parentheses to make _comma_ a list
>>>> argument separator.  (See "Comma Operator" section.)  
>>> 
>>> I don't have any mention of parentheses in the section 'Comma
>>> Operator' in my perlop (5.6.1), and I certainly don't have anything
>>> that says that the parentheses _make_ the comma a list operator. If I
>>> did, I'd probably submit a bug report. The comma is invoked in a list
>>> context because of the assignment to an array.
>> 
>>     $ perldoc perlop
>>     ...
>> 	 Comma Operator
>> 
>> 	 Binary "," is the comma operator.  In scalar context it
>> 	 evaluates its left argument, throws that value away, then
>> 	 evaluates its right argument and returns that value.  This
>> 	 is just like C's comma operator.
>> 
>> -->	 In list context, it's just the list argument separator, and
>> -->	 inserts both its arguments into the list.
> 
> And where does this mention parentheses? I have already explained that
> the list context does not come from the parentheses, but from the
> assignment to an array. The parentheses group the arguments and comma
> separators together.
> 
> Again: Yes, the parens are necessary, but _not_ to create list
> context. The list context is already there.

Okay, we're not arguing.  I didn't say that "parentheses created
context".  I said the assignment (to an array) creates the context.
Without parentheses in 

  @a = (1, 2, 3);

the commas are the binary operator.  This is the effect of operator
precedence.  (I didn't make *that* clear.)  

The tutorial reference you commented on *was* confusing the two.  

-- 
Garry Williams


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

Date: Mon, 05 Nov 2001 01:24:54 GMT
From: Martien Verbruggen <mgjv@tradingpost.com.au>
Subject: Re: Good Perl Tutorials ???
Message-Id: <slrn9ubqjf.ctg.mgjv@verbruggen.comdyn.com.au>

On Mon, 05 Nov 2001 01:10:35 GMT,
	Garry Williams <garry@ifr.zvolve.net> wrote:
> On Mon, 05 Nov 2001 00:47:51 GMT, Martien Verbruggen
><mgjv@tradingpost.com.au> wrote:
> 
>>>> I don't have any mention of parentheses in the section 'Comma
>>>> Operator' in my perlop (5.6.1), and I certainly don't have anything

>>>     $ perldoc perlop

>>> -->	 In list context, it's just the list argument separator, and
>>> -->	 inserts both its arguments into the list.
>> 
>> And where does this mention parentheses? I have already explained that

> Okay, we're not arguing.  I didn't say that "parentheses created
> context".  I said the assignment (to an array) creates the context.

Sorry, I misunderstood the exchange above as if we were arguing :)

Martien
-- 
                                | 
Martien Verbruggen              | Hi, Dave here, what's the root
Trading Post Australia Pty Ltd  | password?
                                | 


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

Date: Mon, 05 Nov 2001 00:29:28 GMT
From: "joseph" <joseph@mandrake.cyberhose.com>
Subject: gtkperl finacial calculator NEW!
Message-Id: <I3lF7.14607$S4.1351150@newsread1.prod.itd.earthlink.net>

Hi everyone I just finished writing most of the code for a gtkperl
calculator. I will keep working on it until it kicks butt. now it has pv
fv and pmt options but no irr. it works great in linux i think it has
some future. the code is at www.cpacoop.com/calc.pl feel free to play
with it


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

Date: Sun, 04 Nov 2001 23:52:04 GMT
From: "Aaron Dancygier" <nospam_kingony@yahoo.com>
Subject: Re: how to print out every second value of an array
Message-Id: <EwkF7.37228$XA5.8326814@typhoon.nyc.rr.com>

Try this
first off you dont need any pattern matching.  As I understand it you just
want to join the lines.  Here goes.
#slurp in all lines.
my @lines = <FILE>;
my @joined_lines;
joins consecutive lines sort of an n map.
map { ($_ % 2) and push(@joinedlines, join( '', ($lines[$_] , $lines[$_ +
1]))) } (0 .. $#lines);

Aaron

"gixxer600" <infullflight@12000rpm.com> wrote in message
news:3be3e052@news.iprimus.com.au...
> Hi all,
>
> Could someone please help me out with this problem:
>
> My datafile has the following lines:-
>
> line1:  000000  XXXX  CC  FFFF
> line2:  000000000000000 XXXX  CC  FFFF  GGGGGGGGGGG HHHHHHHH
> line3:  000000  XXXX  CC  FFFF
> line4:  000000000000000 XXXX  CC  FFFF GGGGGGGG HHHHHHHH
> ...
>
> The first field of every "odd numbered" lines is always made up of 6
digits.
> The first field of every second line can be any length but is always
longer
> than 6 digits.
>
> I wish to join line1 and line2, line3 and line4 and so on..
>
> e.g.
>
> 000000  XXXX  CC  FFFF 000000000000000 XXXX  CC  FFFF  GGGGGGGGGGG
HHHHHHHH
> 000000  XXXX  CC  FFFF 000000000000000 XXXX  CC  FFFF GGGGGGGG HHHHHHHH
>
> I tried to load the content of the whole file into an array and then tried
> to use pattern matching to obtain the different lines but I'm not having
any
> success.  Could someone offer some ideas on how this can be done??
>
> Thanks
>
>




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

Date: Mon, 05 Nov 2001 00:43:07 GMT
From: "Aaron Dancygier" <nospam_kingony@yahoo.com>
Subject: Re: how to print out every second value of an array
Message-Id: <vglF7.37429$XA5.8358458@typhoon.nyc.rr.com>

Ive got a better solution for fun.
this will join every n lines in an array.
Enjoy.

Aaron Dancygier

#!/usr/bin/perl
use strict;

#my @lines = <FILE>;

my @lines = qw(as af er 234 cvb df 234 sfdg dfg 35 dfg 35);
my $n = 3;

my @joined = njoin($n, \@lines);
print map "$_\n" => @joined;

sub njoin {
  my ($n, $list) = @_;
  my @joined_lines;

    map {
      my $index = $_;
      !($index % $n) and
        push(@joined_lines,
          join( '',
            (map $list->[$index + $_] => (0 .. $n - 1))
          )
        )
    } (0 .. $#{$list});

  return (@joined_lines);
}

"Aaron Dancygier" <nospam_kingony@yahoo.com> wrote in message
news:EwkF7.37228$XA5.8326814@typhoon.nyc.rr.com...
> Try this
> first off you dont need any pattern matching.  As I understand it you just
> want to join the lines.  Here goes.
> #slurp in all lines.
> my @lines = <FILE>;
> my @joined_lines;
> joins consecutive lines sort of an n map.
> map { ($_ % 2) and push(@joinedlines, join( '', ($lines[$_] , $lines[$_ +
> 1]))) } (0 .. $#lines);
>
> Aaron
>
> "gixxer600" <infullflight@12000rpm.com> wrote in message
> news:3be3e052@news.iprimus.com.au...
> > Hi all,
> >
> > Could someone please help me out with this problem:
> >
> > My datafile has the following lines:-
> >
> > line1:  000000  XXXX  CC  FFFF
> > line2:  000000000000000 XXXX  CC  FFFF  GGGGGGGGGGG HHHHHHHH
> > line3:  000000  XXXX  CC  FFFF
> > line4:  000000000000000 XXXX  CC  FFFF GGGGGGGG HHHHHHHH
> > ...
> >
> > The first field of every "odd numbered" lines is always made up of 6
> digits.
> > The first field of every second line can be any length but is always
> longer
> > than 6 digits.
> >
> > I wish to join line1 and line2, line3 and line4 and so on..
> >
> > e.g.
> >
> > 000000  XXXX  CC  FFFF 000000000000000 XXXX  CC  FFFF  GGGGGGGGGGG
> HHHHHHHH
> > 000000  XXXX  CC  FFFF 000000000000000 XXXX  CC  FFFF GGGGGGGG HHHHHHHH
> >
> > I tried to load the content of the whole file into an array and then
tried
> > to use pattern matching to obtain the different lines but I'm not having
> any
> > success.  Could someone offer some ideas on how this can be done??
> >
> > Thanks
> >
> >
>
>




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

Date: Sun, 04 Nov 2001 23:41:08 GMT
From: OSx <femello@mac.com>
Subject: HTTP Proxy Module
Message-Id: <omkF7.4829$MI.1873113@typhoon.ne.mediaone.net>

Hi,

I saw the SOCKS module on CPAN and I was wondering if there's a HTTP proxy 
module..

Thanks


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

Date: Mon, 5 Nov 2001 09:46:49 +0930
From: "Wyzelli" <wyzelli@yahoo.com>
Subject: Re: HTTP Proxy Module
Message-Id: <8TkF7.29$pS5.396@wa.nnrp.telstra.net>


"OSx" <femello@mac.com> wrote in message
news:omkF7.4829$MI.1873113@typhoon.ne.mediaone.net...
> Hi,
>
> I saw the SOCKS module on CPAN and I was wondering if there's a HTTP proxy
> module..

Not a module as such, but you might find this interesting:-

http://www.stonehenge.com/merlyn/WebTechniques/col11.html

Wyzelli
--
push@x,$_ for(a..z);push@x,' ';
@z='092018192600131419070417261504171126070002100417'=~/(..)/g;
foreach $y(@z){$_.=$x[$y]}y/jp/JP/;print;




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

Date: Mon, 05 Nov 2001 01:10:07 GMT
From: Tim Hammerquist <tim@vegeta.ath.cx>
Subject: Re: i do not understand it(the =~s/.../.../), thanx!
Message-Id: <slrn9ubq4l.ens.tim@vegeta.ath.cx>

Uri Guttman <uri@stemsystems.com> graced us by uttering:
> >>>>> "TH" == Tim Hammerquist <tim@vegeta.ath.cx> writes:
>  
>   TH> Me parece que hugh1 <weiwe1@yeah.net> dijo:
>   >> i can not know how to understand it:
>  
>  <snip of bad GCI parser>
>  
>   TH> This code is broken.
>  
>  then tell him to use CGI.pm.

He could have extracted that code from CGI.pm and typed it out wrong.
The post suggested he didn't write it. While learning perl, I remember
doing the same thing: looking through module files, trying to figure out
_how_ they work, since the POD explains _what_ they do.

He also didn't ask how to decode URL data; he asked what the code did.  
I could've just told him it croaked with a syntax error.  ;)

OTOH, rather than see a whole new generation of people re-invent the
URL-decoding wheel cgi-lib.pl style:

#v+

IMPORTANT MESSAGE FOR PEOPLE STILL INVENTING WHEELS

    If you're doing CGI work, use a CGI module!  If you don't, make sure
    you have a *good* reason not to.  Reasons like "I wanted to do it
    myself" are not good enough, and won't convince most of us to help
    you reinvent the wheel Lincoln D. Stein has worked so hard on.

    If CGI.pm is too slow for you, there's a whole CGI:: namespace of
    modules at CPAN that are less robust but much smaller.

#v-

And if anyone wants to know how regex's work:

"Mastering Regular Expressions", Jeffrey Friedl (ORA)
    explains the workings and concepts behind regular expressions, and
    Ch. 7 covers Perl-specific details.
`perldoc perlre`
    covers perl's implementation of regular expressions
`perldoc perlop`
    covers perl regex operators such as substitution (s///),
    translation (tr/// or y///), and matching (m//).

>  uri

Tim Hammerquist
-- 
Perl gives you enough rope to hang yourself and your neighbor.
    -- Randal L. Schwartz


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

Date: 4 Nov 2001 17:32:37 -0800
From: tadermann@hotmail.com (Tony)
Subject: Passwd changes every 90 days
Message-Id: <6db8eeaf.0111041732.3425c2a@posting.google.com>

Hi All,

Looking for a script that would change a users passwd every 90 days,
and do the following.

1. Check the password against a mask.
2. Check that the same passwd not used before for that user.

We are unable to use C2 secuirty (tru64) because some of our
middleware doesn't function properly when passwd passes 8 characters.

Thanks in advance,
Tony


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

Date: Mon, 05 Nov 2001 00:19:42 +0100
From: "Carsten Menke" <bootsy52@gmx.net>
Subject: Re: Pattern matching with "(" complains...
Message-Id: <pan.2001.11.05.00.19.41.505.1281@gmx.net>

On Sun, 04 Nov 2001 22:47:25 +0100, Tina Mueller wrote:
> 
> yes, i said: "supposing", meaning providing, assumed, in case. i was
> aiming at the fact that m/^PATTERN/ is just enough and that
> m/^PATTERN.*$/, like you proposed, is the same but unnecessary and
> probably slower. and even more, it makes a difference if the text that
> you are matching against contains newlines.

Truly said, I looked not detailed enough and as a regular behavior I use
alsways /^pattern$/ I know that this is slower. I use it mostly because
when getting user input (let's say from STDIN in for example the input
'add' should do a specific action. Then I only want that the parameter
'add' does the action, and not 'addition' for example. So when using
/^add$/ after chomp I feel myself much better. But really I think I
should take a nap, sitting too long in front of the computer and loosing
my concentration. See ya in dclpc.

> 
> he can use '', or "", AFAIR it doesn't make a difference concerning
> efficiency. ok, i tend to use '', too, if i don't have a variable to
> interpolate, but here i was aiming at the fact that your proposal
> sounded like the OP's problems would go away just by using single

What should OP, be?
> quotes. ok, that's overstated. but what difference should there be
> between "test(" and 'test(' ?
> 
Don't know as I said untested in this case, know only that you'll have
problems when using "test\45" for example so why not expect problems
here?

Carsten


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

Date: Sun, 04 Nov 2001 23:26:14 GMT
From: "Evil Overlord" <overlord_q@hotmail.com>
Subject: Re: perl bots from Net::IRC 
Message-Id: <q8kF7.399886$ME2.45197219@typhoon.kc.rr.com>

sub on_names {
        my ($self, $event) = @_;
        my (@list, $channel) = ($event->args);

        ($channel, @list) = splice @list, 2;
        foreach $Var (@list) { $Var =~ s/\@//g; };
        @users = split(/ /, $list[0]);
}

$conn->add_handler('353', \&on_names);

--
-------------------------------
Newsgroup: alt.eo
For all your Evil Overlord Needs
http://www.thedarkcitadel.com

"Peter Moore" <moorepete@telocity.com> wrote in message
news:5WrE7.907$e6.599403@newsrump.sjc.telocity.net...
> Ive been playing with the Net::IRC perll module which im making a bot
from.
> One of the things ive not been able to work out is how to get
> $conn->who("#channel")  to work on it. My problem is that i need to
respond
> to the person with a "I dont understand" message if he is not on the
> #channel. So  I need to fetch the names from the channel for this but im
not
> having any luck.
>
> Anyone know what im talking about and know how to do it ?
> thanks in advance
>
> sinple to IRC connect,
>
> use Net::IRC;
> $irc = new Net::IRC;
> $conn = $irc->newconn(Nick => "somenick", Server  => 'irc.server.com',
Port
> =>  6667 );
>
> $conn->add_handler('msg', \&on_msg);

should be at the end

> $conn->join("#test");
should be in a sub on_connect subroutine, with a
$conn->add_handler('376', \&on_connect);
at the end.

> $irc->start;

should be the LAST thing in the script.

>
> sub on_msg {
>     my ($self, $event) = @_;
>     my ($nick) = $event->nick;
>
>     print "*$nick*  ", ($event->args), "\n";
>     $self->privmsg($nick, "hello $nick");
>     print $self->who("#test");  # <<<<<<<<<<<<< doesn't work although it
> prints a number
>
sub on_msg {
    my ($self, $event) = @_;
    my ($nick) = $event->nick;

    print "*$nick*  ", ($event->args), "\n";

    #put a if/for/etc loop here to look through @users to see if the person
is on the channel.
}

>
>
>
>




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

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.  

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


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