[18801] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 969 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed May 23 14:10:49 2001

Date: Wed, 23 May 2001 11:10:22 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <990641422-v10-i969@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Wed, 23 May 2001     Volume: 10 Number: 969

Today's topics:
    Re: Multiple Line printing <christoph.neubauer@siemens.at>
    Re: Multiple Line printing <godzilla@stomp.stomp.tokyo>
    Re: Multiple Line printing <uri@sysarch.com>
    Re: Multiple Line printing (Abigail)
    Re: Multiple Line printing (Gary)
    Re: Multiple Line printing <godzilla@stomp.stomp.tokyo>
        parsing perl again (Jordan Dimov)
    Re: Perl equivalent of a C/C++ operation nobull@mail.com
        perl tattoo <jhall@ifxonline.com>
    Re: Problem using "use constant => ..." with mod_perl ( <sharding@ccbill.com>
        Problem with scalar variables <mark.patton@program-products.co.uk>
    Re: Problem with scalar variables <sharding@ccbill.com>
    Re: Problem with scalar variables <uri@sysarch.com>
    Re: Redirecting STDERR to sendmail (Villy Kruse)
    Re: Redirecting STDERR to sendmail <mike@gatrell.org>
    Re: Redirecting STDERR to sendmail nobull@mail.com
        referencing an array in a hash. <smrtalec@nospam.earthlink.net>
    Re: referencing an array in a hash. <uri@sysarch.com>
    Re: referencing an array in a hash. <smrtalec@nospam.earthlink.net>
    Re: referencing an array in a hash. <uri@sysarch.com>
    Re: regexp for triming domainnames <godzilla@stomp.stomp.tokyo>
    Re: regexp for triming domainnames <godzilla@stomp.stomp.tokyo>
        Split versus Regex <mike@gatrell.org>
    Re: url parsing (Gary E. Ansok)
    Re: VMSPerl v5.7.0 built for VMS_VAX / CGI.pm v2.72 err <Jac@Oppers.nl>
    Re: Warning/Danger -- Don't use Perl for CGI (Craig Berry)
        Wasted regex modifiers (was Re: How can I convert a dat <jeffp@crusoe.net>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Wed, 23 May 2001 17:22:50 +0200
From: Christoph Neubauer <christoph.neubauer@siemens.at>
Subject: Re: Multiple Line printing
Message-Id: <3B0BD5C9.6B690752@siemens.at>



Anno Siegel wrote:

> <snip>
>
> > open(FILE, "<file.txt");
> > @array = <FILE>;
> > close(FILE)
>
> Why read the file into an array, and then process it line-wise?  This
> "false idiom" is spreading like wildfire.  It is idiotic.
>

<snip>

Why is it idiotic ?
I thought, it's just a faster way than reading/processing line by line.

Chris



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

Date: Wed, 23 May 2001 09:30:02 -0700
From: "Godzilla!" <godzilla@stomp.stomp.tokyo>
Subject: Re: Multiple Line printing
Message-Id: <3B0BE58A.397D0D40@stomp.stomp.tokyo>

Christoph Neubauer wrote:
> 
> Anno Siegel wrote:
 
> > <snip>

> > > open(FILE, "<file.txt");
> > > @array = <FILE>;
> > > close(FILE)

> > Why read the file into an array, and then process it line-wise?  This
> > "false idiom" is spreading like wildfire.  It is idiotic.

> <snip>
 
> Why is it idiotic ?
> I thought, it's just a faster way than reading/processing line by line.


Use of "slurp" to create an array is not idiotic. What Siegel
is spreading is stereotypical Perl 5 Cargo Cult. He is a well
known Cargo Cult Fanatic.

There is a very shadowy division line between efficiency
of slurp looping and efficiency of while looping, as to
which is more efficient. This division line is broad and
hard to draw. Externalities such as actual data size,
nature of the contents of the data and degree of needed
processing, all effect an efficiency comparison.

In general, small data reads are handled just as effectively
by a slurp as are handled by a while. Inherently, both
slurp and while have pros and cons. Neither can do all
which the other can do. Use of benchmark is a good tool
to help make a decision on which is best for use.

Don't be fooled by those zealots whom spread Perl 5 Cargo Cult.
Test their dictates and discover your own truths.

Additionally, don't fool yourself by not truly testing your
code before posting it and, don't be fooled into thinking
you will catch all mistakes and bugs; you are quite human.


Godzilla!
-- 
@ø=(a .. z);@Ø=qw(6 14 3 25 8 11 11 0 17 14 2 10 18);
$§="\n";$ß="\b";undef$©;print$§x($Ø[4]/2);
for($¡=0;$¡<=$Ø[2];$¡++){foreach$¶(@Ø){
$ø[$¶]=~tr/A-Z/a-z/;if(($¡==1)||($¡==$Ø[2]))
{$ø[$¶]=~tr/a-z/A-Z/;}print$ø[$¶];if($¶==0)
{print" ";}if($¶==$Ø[12]){print" !";}&D;}
print$ßx($Ø[4]*2);}print$§x($Ø[10]*2);
sub D{select$©,$©,$©,.25;}exit;


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

Date: Wed, 23 May 2001 16:29:54 GMT
From: Uri Guttman <uri@sysarch.com>
Subject: Re: Multiple Line printing
Message-Id: <x77kz858ql.fsf@home.sysarch.com>

>>>>> "CN" == Christoph Neubauer <christoph.neubauer@siemens.at> writes:

  CN> Anno Siegel wrote:

  >> <snip>
  >> 
  >> > open(FILE, "<file.txt");
  >> > @array = <FILE>;
  >> > close(FILE)
  >> 
  >> Why read the file into an array, and then process it line-wise?  This
  >> "false idiom" is spreading like wildfire.  It is idiotic.
  >> 

  CN> Why is it idiotic ?
  CN> I thought, it's just a faster way than reading/processing line by line.

where did you get that idea? try it on a VERY large file. then sit back
and wait.

do you know anything about memory use and swapping?

uri

-- 
Uri Guttman  ---------  uri@sysarch.com  ----------  http://www.sysarch.com
SYStems ARCHitecture and Stem Development ------ http://www.stemsystems.com
Learn Advanced Object Oriented Perl from Damian Conway - Boston, July 10-11
Class and Registration info:     http://www.sysarch.com/perl/OOP_class.html


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

Date: Wed, 23 May 2001 16:43:16 +0000 (UTC)
From: abigail@foad.org (Abigail)
Subject: Re: Multiple Line printing
Message-Id: <slrn9gnq54.ngi.abigail@tsathoggua.rlyeh.net>

Gary (grobitaille@mail.com) wrote on MMDCCCXXII September MCMXCIII in
<URL:news:a2051d6.0105230401.5f5a46c7@posting.google.com>:
][  I need to parse a text file and when a pattern is matched I need to
][  print that line and the next 6 lines. Can someone provide me with a
][  perl solution


Forget the people needing more than one line for this simple problem.

    perl -nwe 'INIT {$i = 6} print if /pattern/ .. !$i --' file



Abigail
-- 
# Perl 5.6.0 broke this.
%0=map{reverse+chop,$_}ABC,ACB,BAC,BCA,CAB,CBA;$_=shift().AC;1while+s/(\d+)((.)
(.))/($0=$1-1)?"$0$3$0{$2}1$2$0$0{$2}$4":"$3 => $4\n"/xeg;print#Towers of Hanoi


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

Date: 23 May 2001 10:02:55 -0700
From: grobitaille@mail.com (Gary)
Subject: Re: Multiple Line printing
Message-Id: <a2051d6.0105230902.39a24bdd@posting.google.com>

Vinny Murphy <vmurphy@Cisco.Com> wrote in message out each matched line.
> 
> A better way would be to do:
> #!/usr/bin/perl -w
> 
> use strict;
>  
> my $file        = shift @ARGV;
> my $search_for  = shift @ARGV;
> my $lines_below = 6;
>  
> my $to = -1;
> open( IN, $file ) || die;
> while(<IN>) {
>    $to = $. + $lines_below if /$search_for/; 
>    print "$. : $_" if $. <= $to;
> }
> close IN;
> 
> I remember last year, around August or September (maybe), Tom
> Christiansen had given out a one-liner on this newsgroup doing something
> like the above.  
> 
> HTH.
> 
> 
> > "Gary" <grobitaille@mail.com> wrote in message
> > news:a2051d6.0105230401.5f5a46c7@posting.google.com...
> > > I need to parse a text file and when a pattern is matched I need to
> > > print that line and the next 6 lines. Can someone provide me with a
> > > perl solution
> > >
> > >
> > > Thanks
> > 
> >

Thank you very much it works great and does exactly what I needed it to 

Thanks again


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

Date: Wed, 23 May 2001 10:26:53 -0700
From: "Godzilla!" <godzilla@stomp.stomp.tokyo>
Subject: Re: Multiple Line printing
Message-Id: <3B0BF2DD.C9A6B885@stomp.stomp.tokyo>



Should this article post twice, lay blame on
Suckernew's clothes dryer, or article dryer,
if this humors you.

**

Christoph Neubauer wrote:
 
> Anno Siegel wrote:
 
> > <snip>

> > > open(FILE, "<file.txt");
> > > @array = <FILE>;
> > > close(FILE)

> > Why read the file into an array, and then process it line-wise?  This
> > "false idiom" is spreading like wildfire.  It is idiotic.

> <snip>
 
> Why is it idiotic ?
> I thought, it's just a faster way than reading/processing line by line.


Use of "slurp" to create an array is not idiotic. What Siegel
is spreading is stereotypical Perl 5 Cargo Cult. He is a well
known Cargo Cult Fanatic.

There is a very shadowy division line between efficiency
of slurp looping and efficiency of while looping, as to
which is more efficient. This division line is broad and
hard to draw. Externalities such as actual data size,
nature of the contents of the data and degree of needed
processing, all effect an efficiency comparison.

In general, small data reads are handled just as effectively
by a slurp as are handled by a while. Inherently, both
slurp and while have pros and cons. Neither can do all
which the other can do. Use of benchmark is a good tool
to help make a decision on which is best for use.

Don't be fooled by those zealots whom spread Perl 5 Cargo Cult.
Test their dictates and discover your own truths.

Additionally, don't fool yourself by not truly testing your
code before posting it and, don't be fooled into thinking
you will catch all mistakes and bugs; you are quite human.


Godzilla!
-- 
@ø=(a .. z);@Ø=qw(6 14 3 25 8 11 11 0 17 14 2 10 18);
$§="\n";$ß="\b";undef$©;print$§x($Ø[4]/2);
for($¡=0;$¡<=$Ø[2];$¡++){foreach$¶(@Ø){
$ø[$¶]=~tr/A-Z/a-z/;if(($¡==1)||($¡==$Ø[2]))
{$ø[$¶]=~tr/a-z/A-Z/;}print$ø[$¶];if($¶==0)
{print" ";}if($¶==$Ø[12]){print" !";}&D;}
print$ßx($Ø[4]*2);}print$§x($Ø[10]*2);
sub D{select$©,$©,$©,.25;}exit;


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

Date: 23 May 2001 10:12:33 -0700
From: jdimov@cis.clarion.edu (Jordan Dimov)
Subject: parsing perl again
Message-Id: <7447a59a.0105230912.726572d3@posting.google.com>

I know this topic has been played many times over, but I need to parse perl.  

  Actually, what I need is this:  given a list of functions and an arbitrary 
Perl 5 script, I want to be able to extract another list of all the occurances 
of these functions inside the script, together with line number and the 
arguments with which each function was called.  And all this without actually 
running the script.  

  After playing with regexes for a while I concluded that, um.. I need to 
parse perl.

  I think I've heard rummors that there's a Perl 5 grammar for Damian's 
Parse::RecDescent?


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

Date: 23 May 2001 18:07:16 +0100
From: nobull@mail.com
Subject: Re: Perl equivalent of a C/C++ operation
Message-Id: <u9g0dw6lkr.fsf@wcl-l.bham.ac.uk>

"Mark Riehl" <mriehl@home.com> writes:

> I'm kind of new to Perl but have done a lot of C/C++ network programming.
> If you're using a TCP socket in C/C++, you need to build what looks like a
> IP packet that contains different fields.

This is not true.

If you are using an application layer protocol that uses a binary data
you need to build binary structures. Usually you'd do this with
mult-byte values represented in network byte order.  This is
independant of whether you are using TCP sockets, pipes, Unix-domain
sockets, X400, message queues, shared memory segments, files, or
whatever.  Conversely if you are using an application layer protcol
like SMTP over TCP you don't.

> For example, the first 2 bytes
> might be the packet type, the next four might be the packet size, and the
> rest would be the payload.
> 
> In C/C++, I can use a buffer and a pointer and build the packet in the
> buffer.  I can walk down the buffer using a pointer, know where I am, and
> then write the proper values in the proper locations.
> 
> What's the closest equivalent to this in Perl?  Would I need to use pack()?

You don't _need_ to use pack() any more than you _need_ to use a
hammer to drive nails, but it is the tool that has been specifically
designed with the job you are trying to do in mind.

> Or, can I just use a scalar such as $buf, and just add the
> components to it?

If you like, but it's a lot less efficient.

> Can anyone point me off to any samples?

Net::DNS

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


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

Date: Wed, 23 May 2001 17:34:52 GMT
From: "John Hall" <jhall@ifxonline.com>
Subject: perl tattoo
Message-Id: <0xSO6.27782$vf6.2760109@news1.rdc1.sdca.home.com>

If I got the 7 line perl DECSS code tattoo'ed on my chest, if I went to the
beach, would I be arrested by the feds?



I guess I could always just get a really complex perl poem that printed 'da
plane! da plane!'

 http://moron.shutdown.com






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

Date: Wed, 23 May 2001 10:34:54 -0700
From: "Shay Harding" <sharding@ccbill.com>
Subject: Re: Problem using "use constant => ..." with mod_perl (Apache).
Message-Id: <9egrqn$12i8$1@node17.cwnet.roc.gblx.net>

"Craig Manley" <c.manley@_NO_SPAM_chello.nl> wrote in message
news:3B0BB363.4EEF421B@_NO_SPAM_chello.nl...
>
> Hi all,
>
> I've got a CGI application that uses some constants exported from some
> .pm files. When running this application in mod_perl  I keep getting
> this error in the httpd errorlog:
>
> Prototype mismatch: sub Apache::ROOT::CSD::mod_2dperl::test_2ecgi::BLA
> vs () at /usr/lib/perl5/5.6.0/constant.pm line 91.
>
>
> This is my test script that causes the error above:
>
> #############################
> use strict;
> use constant BLA => '?';
>
> print "Content-type: text/plain\n\n";
> print BLA . "\n";
> #############################
>
> Can anybody explain what's going wrong and how to solve this problem?

If I take the exact code above and run it under under Apache 1.3.19, perl
5.6.0, mod_perl 1.25 on my Mandrake 7.2 box it works fine. I get the
expected output.


Shay






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

Date: Wed, 23 May 2001 17:41:33 +0100
From: Mark Patton <mark.patton@program-products.co.uk>
Subject: Problem with scalar variables
Message-Id: <3B0BE83D.4A686B0A@program-products.co.uk>

This is a multi-part message in MIME format.
--------------47388CC9854526C10C251491
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit

I'm struggling crossing over from shell scripting to perl. Stuff I know
works in ksh is causing problems.
What I want to do is

assign a variable...
$variable=3
use the value of the variable to make an array name unique.
then
Increment the variable so the next array name is unique as I work
through another array.

but

@array$variable does not evaluate to an arrayname of @array3.

Can anyone help me please?


--------------47388CC9854526C10C251491
Content-Type: text/x-vcard; charset=us-ascii;
 name="mark.patton.vcf"
Content-Transfer-Encoding: 7bit
Content-Description: Card for Mark Patton
Content-Disposition: attachment;
 filename="mark.patton.vcf"

begin:vcard 
n:Patton;Mark
tel;work:+44 (0)1932 345566
x-mozilla-html:FALSE
org:Program Products
version:2.1
email;internet:Mark.Patton@program-products.co.uk
title:Customer Support
adr;quoted-printable:;;Enterprise House=0D=0AStation Approach;West Byfleet;Surrey;KT14 6NJ;United Kingdom
fn:Mark Patton
end:vcard

--------------47388CC9854526C10C251491--



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

Date: Wed, 23 May 2001 10:08:48 -0700
From: "Shay Harding" <sharding@ccbill.com>
Subject: Re: Problem with scalar variables
Message-Id: <9egq9p$1rsq$1@node17.cwnet.roc.gblx.net>

"Mark Patton" <mark.patton@program-products.co.uk> wrote in message
news:3B0BE83D.4A686B0A@program-products.co.uk...
> I'm struggling crossing over from shell scripting to perl. Stuff I know
> works in ksh is causing problems.
> What I want to do is
>
> assign a variable...
> $variable=3
> use the value of the variable to make an array name unique.
> then
> Increment the variable so the next array name is unique as I work
> through another array.
>
> but
>
> @array$variable does not evaluate to an arrayname of @array3.
>
> Can anyone help me please?

Would actually be:

@{ "array$variable" }

or if you wanted to increment the $variable part (like if you did this in a
loop):

for (1..3){
    @{ 'array' . $variable++ } = qw(1 2 3 4 5);
}

Basically everything between the { } is parsed first and then the @ is
applied giving you the correct array name.


Shay







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

Date: Wed, 23 May 2001 17:36:19 GMT
From: Uri Guttman <uri@sysarch.com>
Subject: Re: Problem with scalar variables
Message-Id: <x7u22c3r3l.fsf@home.sysarch.com>

>>>>> "SH" == Shay Harding <sharding@ccbill.com> writes:

  >> @array$variable does not evaluate to an arrayname of @array3.

  SH> @{ "array$variable" }

i was betting on which type of answer would be posted first. some lame
newbie telling him the correct syntax for symrefs or someone else
telling him that symrefs are evil and he should use a hard ref.

i lost.

SYMBOLIC REFERENCES ARE NOT FOR USE IN PERL DATA STRUCTURES!!!

search news.google.com for MANY posts in this very topic. did you (this
poster) ever do that? is your code riddled with symrefs? you seem so
glib with this answer that i fear that is true. gawd help you in 6
months when your code is broken all over and you can't figure out why.

uri

-- 
Uri Guttman  ---------  uri@sysarch.com  ----------  http://www.sysarch.com
SYStems ARCHitecture and Stem Development ------ http://www.stemsystems.com
Learn Advanced Object Oriented Perl from Damian Conway - Boston, July 10-11
Class and Registration info:     http://www.sysarch.com/perl/OOP_class.html


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

Date: 23 May 2001 15:09:21 GMT
From: vek@pharmnl.ohout.pharmapartners.nl (Villy Kruse)
Subject: Re: Redirecting STDERR to sendmail
Message-Id: <slrn9gnkl0.bad.vek@pharmnl.ohout.pharmapartners.nl>

On Wed, 23 May 2001 15:15:19 +0100, M <mike@gatrell.org> wrote:
>On Tue, 22 May 2001 18:41:24 +0100, "Unknown" <nobull@mail.com> wrote:
>
><snip>
>> BTW: You never use $date.
>
>why not??
>



That was an observation, not an advise, as far as I can read.  Setting the
$date to some value and not using it later doesn't make much sense.



Villy


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

Date: Wed, 23 May 2001 17:00:57 +0100
From: "M" <mike@gatrell.org>
Subject: Re: Redirecting STDERR to sendmail
Message-Id: <9egmrr$5n4$1@taliesin.netcom.net.uk>

On Wed, 23 May 2001 16:09:21 +0100, "Villy Kruse"
<vek@pharmnl.ohout.pharmapartners.nl> wrote:
> On Wed, 23 May 2001 15:15:19 +0100, M <mike@gatrell.org> wrote:
>>On Tue, 22 May 2001 18:41:24 +0100, "Unknown" <nobull@mail.com> wrote:
>>
>><snip>
>>> BTW: You never use $date.
>>
>>why not??
 
> That was an observation, not an advise, as far as I can read.  Setting
> the
> $date to some value and not using it later doesn't make much sense.

<nod> agreed.. my bad parsing.

M
-- 
Don't vote... you'll only encourage them.


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

Date: 23 May 2001 17:45:50 +0100
From: nobull@mail.com
Subject: Re: Redirecting STDERR to sendmail
Message-Id: <u9lmno6mkh.fsf@wcl-l.bham.ac.uk>

Philip Newton <pne-news-20010523@newton.digitalspace.net> writes:

> On 22 May 2001 18:41:24 +0100, nobull@mail.com wrote:
> 
> > You probably should unbuffer STDERR too.
> 
> Why? It's usually unbuffered by default.

Yes, I suppose I would have expected that to be the case if I'd
thought about it.  Oops.

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


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

Date: Wed, 23 May 2001 16:18:27 GMT
From: "R" <smrtalec@nospam.earthlink.net>
Subject: referencing an array in a hash.
Message-Id: <npRO6.25983$BN6.1167341@newsread1.prod.itd.earthlink.net>


here is a fairly simple program, below made much simplier for debug
purposes. all I am trying to do is extract a hash from a subroutine, as a
reference then place them in a array, which is then referenced to a hash. I
have broken the problem down to the following few lines of code. showing
both code and result. I have mulled over this for the past day and have yet
to figure out what I am doing wrong.

<code>
my @client_number=(1,2,3);
 $user{1}=\@client_number;
 #################################
 print "test cycle -3 \n";
 print Dumper \%user;
 $rowan=$user{1}->[0];
 print $rowan;
</code>

<result>

test cycle -3
$VAR1 = {
          1 => 'ARRAY(0x817df78)'
        };
Use of uninitialized value at ./aewest2.pl line 46, <STDIN> chunk 8.
rowan@linux-srv:~/pl >

</result>




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

Date: Wed, 23 May 2001 16:43:24 GMT
From: Uri Guttman <uri@sysarch.com>
Subject: Re: referencing an array in a hash.
Message-Id: <x7zoc43tjm.fsf@home.sysarch.com>

>>>>> "R" == R  <smrtalec@nospam.earthlink.net> writes:

  R> here is a fairly simple program, below made much simplier for debug
  R> purposes. all I am trying to do is extract a hash from a
  R> subroutine, as a reference then place them in a array, which is
  R> then referenced to a hash. I have broken the problem down to the
  R> following few lines of code. showing both code and result. I have
  R> mulled over this for the past day and have yet to figure out what I
  R> am doing wrong.

  R> <code>
  R> my @client_number=(1,2,3);
  R>  $user{1}=\@client_number;
  R>  #################################
  R>  print "test cycle -3 \n";
  R>  print Dumper \%user;
  R>  $rowan=$user{1}->[0];
  R>  print $rowan;
  R> </code>

  R> <result>

  R> test cycle -3
  R> $VAR1 = {
  R>           1 => 'ARRAY(0x817df78)'
  R>         };
  R> Use of uninitialized value at ./aewest2.pl line 46, <STDIN> chunk 8.
  R> rowan@linux-srv:~/pl >

i get:

test cycle -3 
$VAR1 = {
          1 => [
                 1,
                 2,
                 3
               ]
        };
1

which is exactly what i expected.

your output from Dumper is odd. you should not see an array ref look
like a string. that is the cause of the unii value error.

you are doing something other than what you showed here. like assigning
the array ref as a string somewhere and then using it.

uri

-- 
Uri Guttman  ---------  uri@sysarch.com  ----------  http://www.sysarch.com
SYStems ARCHitecture and Stem Development ------ http://www.stemsystems.com
Learn Advanced Object Oriented Perl from Damian Conway - Boston, July 10-11
Class and Registration info:     http://www.sysarch.com/perl/OOP_class.html


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

Date: Wed, 23 May 2001 17:25:23 GMT
From: "R" <smrtalec@nospam.earthlink.net>
Subject: Re: referencing an array in a hash.
Message-Id: <7oSO6.13573$9D5.1221151@newsread2.prod.itd.earthlink.net>


ok on further research this statement

 tie (%user, 'DB_File',$file, O_RDWR|O_CREAT, 0666, $DB_BTREE);

is causing the problem below, I can probable circumvent this by placing the
statement after I set up my references but why does this happen. ???

R <smrtalec@nospam.earthlink.net> wrote in message
news:npRO6.25983$BN6.1167341@newsread1.prod.itd.earthlink.net...
>
> here is a fairly simple program, below made much simplier for debug
> purposes. all I am trying to do is extract a hash from a subroutine, as a
> reference then place them in a array, which is then referenced to a hash.
I
> have broken the problem down to the following few lines of code. showing
> both code and result. I have mulled over this for the past day and have
yet
> to figure out what I am doing wrong.
>
> <code>
> my @client_number=(1,2,3);
>  $user{1}=\@client_number;
>  #################################
>  print "test cycle -3 \n";
>  print Dumper \%user;
>  $rowan=$user{1}->[0];
>  print $rowan;
> </code>
>
> <result>
>
> test cycle -3
> $VAR1 = {
>           1 => 'ARRAY(0x817df78)'
>         };
> Use of uninitialized value at ./aewest2.pl line 46, <STDIN> chunk 8.
> rowan@linux-srv:~/pl >
>
> </result>
>
>
>




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

Date: Wed, 23 May 2001 17:32:24 GMT
From: Uri Guttman <uri@sysarch.com>
Subject: Re: referencing an array in a hash.
Message-Id: <x7wv783r9z.fsf@home.sysarch.com>

>>>>> "R" == R  <smrtalec@nospam.earthlink.net> writes:

  R> ok on further research this statement

  R>  tie (%user, 'DB_File',$file, O_RDWR|O_CREAT, 0666, $DB_BTREE);

  R> is causing the problem below, I can probable circumvent this by placing the
  R> statement after I set up my references but why does this happen. ???

first off, don't jeopardy post. put your comments AFTER the quoted text.

basic tied DB's can only used strings for values. you are assigning a
ref to one and then later retrieving it as a string (just like i
surmised).

you have to make that array storable as a string or use MLDBM or
soemthing else to deal with saving perl data structures in a file. there
are many solutions to that.

uri

-- 
Uri Guttman  ---------  uri@sysarch.com  ----------  http://www.sysarch.com
SYStems ARCHitecture and Stem Development ------ http://www.stemsystems.com
Learn Advanced Object Oriented Perl from Damian Conway - Boston, July 10-11
Class and Registration info:     http://www.sysarch.com/perl/OOP_class.html


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

Date: Wed, 23 May 2001 08:14:50 -0700
From: "Godzilla!" <godzilla@stomp.stomp.tokyo>
Subject: Re: regexp for triming domainnames
Message-Id: <3B0BD3EA.608FE209@stomp.stomp.tokyo>

Patrick Erler wrote:


Rather oxymoronic email name.

(snipped)

> i have a regexp problem which is rather tricky, at least for me:
 
> i would like to strip from a domainname:
 
> www.test.com   or   foo.bar.test.com

> everything but "test".

> but i just get a smoking head her when i try to create the regexp..


There is a good chance what you are smoking is contributing
to your inability to write code for this.

Lacking any coherent parameters stated by you, a presumption
is made you have already stripped trailing paths. I don't
feel comfortable making a presumption you realize some
url formats contain only one period.

You are aware a domain in format of godzilla.rocks.net.ru
will not return what you appear to expect?


Godzilla!
--

TEST SCRIPT:
____________

#!perl

print "Content-type: text/plain\n\n";

$domain = "godzilla.really.rocks!.net";

if (($domain =~ tr/.//) <= 1)
 { print "You Are An Idiot."; exit; }
else
 {
  $stop = rindex ($domain, ".");
  $start = rindex ($domain, ".", $stop - 1) +1;
  $target = substr ($domain, $start, $stop - $start);
  print $target;
 }

exit;


PRINTED RESULTS:
________________

rocks!


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

Date: Wed, 23 May 2001 08:19:20 -0700
From: "Godzilla!" <godzilla@stomp.stomp.tokyo>
Subject: Re: regexp for triming domainnames
Message-Id: <3B0BD4F8.1DCE45A6@stomp.stomp.tokyo>

Patrick Erler wrote:
 
> Philip Newton wrote:
 
> >     $host = (split /\./, $domain)[-2];
> >     # or, alternatively,
> >     $host = (reverse split /\./, $domain, 3)[1];

> this is the perfect solution! (i forgot to mention that i want to catch
> example.com too)


It is prudent to test posted code before announcing
it a perfect solution and certainly before using it.

Godzilla!


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

Date: Wed, 23 May 2001 17:26:37 +0100
From: "M" <mike@gatrell.org>
Subject: Split versus Regex
Message-Id: <9egoc0$9ee$1@taliesin.netcom.net.uk>

I keep on having to pull variables from a csv and file do stuff with
them.

I sometimes need to do stuff to all the variables in each line of the
file, but more normally am interested in the first and last. Which is
more efficient to do??

while (<FOO>){
	@foo = split(/,/,$_);
	$first = $foo[0];
	$last = $foo[$#foo];
	}

or 

while (<FOO>){
	/(.*?),.*,(.*?)$/;
	$first = $1;
	$last = $2;
	}

NB I'm still very new to this perl malarky and haven't tested the code
above so it's quite likely flawed in some way.

any comments welcome.
M
-- 
Don't vote... you'll only encourage them.


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

Date: 23 May 2001 17:58:59 GMT
From: ansok@alumni.caltech.edu (Gary E. Ansok)
Subject: Re: url parsing
Message-Id: <9egtp3$cra@gap.cco.caltech.edu>

In article <lzAO6.57035$I5.12466254@news1.rdc1.tn.home.com>,
Todd Smith <todd@designsouth.net> wrote:
>
>"Patrick Joyce" <joycefive@earthlink.net> wrote in message
>news:riAO6.22326$BN6.938446@newsread1.prod.itd.earthlink.net...
>> $urla = 'https://www.boston.com/foo/me/who?hg=ww;
>> ($url = $urla) =~ s|.*//(.*?)/.*|$1|;
>> print "$url\n";
>
>That's too much. But I did forget about ftp:// and https://, so let's do
>this:
>
>$url =
>protocol://prefix.domain.suffix1.suffix2/dir1/dir2/script.scipt_ext?arg1=val
>1
>
>$url =~ m|/(.+?)/|;
>$domain = $1 if $1;
>
>the first set of characters between /'s should be the domain, right? And if
>$1 doesn't match, $domain will stay undefined. Everybody wins.

No, if the match doesn't succeed, $1 will be leftover from the last
successful match.

Also, the regex should start with *two* slashes, otherwise the matched
domain would be "/prefix.domain.suffix1.suffix2", which is probably not
what you want.

my ($domain) = ($url =~ m|//(.+?)/|);

This does not take into account URL's like "http://www.example.com",
"http://www.example.com:8000/path", "ftp://user@ftp.example.com/file",
and "file:///dir/file".

There could also be relative URL's where the regexp would return
the wrong answer:  "redirect.cgi?target=http://host/path".

I don't know whether the OP needs to worry any of those, but to
get a completely correct answer, I'd second the recommendation to
use an existing module like URI.

-- Gary Ansok


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

Date: Wed, 23 May 2001 19:14:13 +0200
From: Jac.m.a.m. Oppers <Jac@Oppers.nl>
Subject: Re: VMSPerl v5.7.0 built for VMS_VAX / CGI.pm v2.72 error : "CGI open of tmpfile: file specification syntax error".
Message-Id: <fusLOwnLx10J1JaqB=oil5zOcr58@4ax.com>

On Wed, 23 May 2001 14:43:51 GMT, Dan Sugalski <dan@tuatha.sidhe.org>
wrote:

>Jac.m.a.m.Oppers <jac.oppers@philips.com> wrote:
>
>> Hi,
>
>> VMSPerl v5.7.0 built for VMS_VAX gives the following error in CGI.pm
>> v2.72 when I try to run the standard "File Upload Example" using the
>> relative old OpenVMS V5.5-2H4 with DEC C v5.2-003 and USO HTTPDServer
>> 2.0-A :
>
>5.7.0 is a development version of perl, and it has a number of oddities
>and bugs. (Hence the development label :)  Don't use it in production.
>Instead, grab perl 5.6.1, which should work OK.
>
>You might potentially run into problems, given that VMS 5.5 is positively
>antique, and Dec C 5.2 isn't that much newer. If it gives you a problem,
>grab perl 5.005_03 instead and use that. It's a little older, but I know
>that it builds properly with VMS 5.5/Dec C 5.2.
>
>					Dan

For those antique machines the last sentence is the most important
one. Thanks ! 

Have to wait until the beginning of next week to be able to start with
installing perl version 5.005_03, and see if two equal machines as
described are able to deliver proper builts. Then I will run the same
scripts and have a chance to take look at the results and be able to
check the corresponding code.

Jac.
jac.oppers@philips.com (replaces jac@natlab.research.philips.com)
j.m.a.m.oppers@(hccnet|hetnet|chello).nl



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

Date: Wed, 23 May 2001 16:59:07 -0000
From: cberry@cinenet.net (Craig Berry)
Subject: Re: Warning/Danger -- Don't use Perl for CGI
Message-Id: <tgnr2r58cgml14@corp.supernews.com>

W K (bill.kemp@wire2.com) wrote:
: have I understood this?
: They are saying don't have pErL* in a cgi-bin directory, as in
: "/usr/local/apache/cgi-bin/perl"
: Rather than having it somewhere like
: "/usr/bin/perl"

That's write.  Otherwise I can execute arbitrary perl code on your
system...which most people would consider to be a disadvantage. :)

: Does anyone use the first variant anyway?

Some do, though Darwinian selection typically intervenes pretty quickly.

-- 
   |   Craig Berry - http://www.cinenet.net/~cberry/
 --*--  "God becomes as we are that we may be as he is."
   |               - William Blake


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

Date: Wed, 23 May 2001 13:23:47 -0400
From: Jeff Pinyan <jeffp@crusoe.net>
Subject: Wasted regex modifiers (was Re: How can I convert a date (MM/DD/YYYY) to UTC time?)
Message-Id: <Pine.GSO.4.21.0105231322220.17307-100000@crusoe.crusoe.net>

[posted & mailed]

On May 23, Sgluarb said:

>if (/(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2}).txt/o) {

The /o modifier there does nothing for the regex -- /o only has a purpose
when there are variables being interpolated inside your regex.

  http://www.pobox.com/~japhy/docs/LPRE.html#regex%20compilation

-- 
Jeff "japhy" Pinyan      japhy@pobox.com      http://www.pobox.com/~japhy/
Are you a Monk?  http://www.perlmonks.com/     http://forums.perlguru.com/
Perl Programmer at RiskMetrics Group, Inc.     http://www.riskmetrics.com/
Acacia Fraternity, Rensselaer Chapter.         Brother #734
** I need a publisher for my book "Learning Perl's Regular Expressions" **




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

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


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