[18572] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 740 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sun Apr 22 09:05:35 2001

Date: Sun, 22 Apr 2001 06:05:09 -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: <987944709-v10-i740@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Sun, 22 Apr 2001     Volume: 10 Number: 740

Today's topics:
    Re: calling subroutine problem (Jay Tilton)
    Re: calling subroutine problem <gellyfish@gellyfish.com>
    Re: Cant run hello world script :( <gellyfish@gellyfish.com>
    Re: Comparison of Time nobull@mail.com
    Re: File::Find complain about invalid top directory? (Gwyn Judd)
    Re: File::Find complain about invalid top directory? <gellyfish@gellyfish.com>
        foreach in a deep hash <m9652@abc.se>
    Re: foreach in a deep hash nobull@mail.com
    Re: Getting character codes (echo 'Rudolf Polzer'>/dev/null)
    Re: Getting character codes (echo 'Rudolf Polzer'>/dev/null)
    Re: help with htaccess <gtoomey@usa.net>
    Re: Is it a hash or not? <gellyfish@gellyfish.com>
    Re: LWP, getting the default index page name from a web <gellyfish@gellyfish.com>
    Re: Mail:Mailer / Net:SMTP speed issue (echo 'Rudolf Polzer'>/dev/null)
    Re: Mail:Mailer / Net:SMTP speed issue <gellyfish@gellyfish.com>
    Re: Multi dimensional array dimensions <iltzu@sci.invalid>
    Re: operators: != vs. ne, strange behaviour <bart.lateur@skynet.be>
    Re: pointer/reference question nobull@mail.com
    Re: pointer/reference question <ubl@schaffhausen.de>
    Re: pointer/reference question <abe@ztreet.demon.nl>
    Re: Programming perl modules (Damian James)
    Re: Programming perl modules <gellyfish@gellyfish.com>
    Re: Silly User Friendly module...any interest to put it (Gwyn Judd)
    Re: So what do YOU use Perl for? (echo 'Rudolf Polzer'>/dev/null)
    Re: split after a number of charachters? <gellyfish@gellyfish.com>
    Re: Which is faster/better? <xris@dont.send.spam>
    Re: Which is faster/better? <abe@ztreet.demon.nl>
    Re: Which is faster/better? <ubl@schaffhausen.de>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Sun, 22 Apr 2001 07:44:31 GMT
From: tiltonj@erols.com (Jay Tilton)
Subject: Re: calling subroutine problem
Message-Id: <3ae28542.66370830@news.erols.com>

On Sun, 22 Apr 2001 12:44:06 +0800, slok <slok00@yahoo.com> wrote:

>in my script, I called a subroutine problem, and it give me the 
>following message:
>
>main::display_results() called too early to check prototype at ...line..

Tacking the line 'use diagnostics;' at the beginning of your program
will cause perl to display a good explanation of what causes this
warning and suggest ways to solve it.  In a nutshell, you called a
function before the compiler was aware that it has a prototype.

Anyway, the sub has its own problems.

>display_results(@sorted, $num);
>
>sub display_results (@$) {
>   my @sorted = @_;

That will assign to @sorted the entire list of arguments recieved,
including the trailing scalar.

>   my $number = $_;

$_ is not an argument passed to the sub.
And $number isn't even used by the sub.  It uses $num instead.

For the sub to receive an array and a scalar, pass the scalar first,
e.g.

  sub display_results ($@) {
     my $number = shift;
     my @sorted = @_;
     ...
  }


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

Date: 22 Apr 2001 09:49:18 GMT
From: Jonathan Stowe <gellyfish@gellyfish.com>
Subject: Re: calling subroutine problem
Message-Id: <9bu9eu$n1i$5@neptunium.btinternet.com>

slok <slok00@yahoo.com> wrote:
> in my script, I called a subroutine problem, and it give me the 
> following message:
> 
> ==
> main::display_results() called too early to check prototype at ...line..
> ===
> 
> what could be the problem?
> the script proceed to run the routine and print out the results, but 
> what causes the message?
> 

From the perldiag manpage (where you should have checked first) :

       %s() called too early to check prototype
           (W prototype) You've called a function that has a pro­
           totype before the parser saw a definition or declara­
           tion for it, and Perl could not check that the call
           conforms to the prototype.  You need to either add an
           early prototype declaration for the subroutine in
           question, or move the subroutine definition ahead of
           the call to get proper prototype checking.  Alterna­
           tively, if you are certain that you're calling the
           function correctly, you may put an ampersand before
           the name to avoid the warning.  See the perlsub man­
           page.

That is to say you either move the definition of the subroutine to before
the first call to it - or you should put a prototype declaration near the
beginning of the file.

/J\
-- 
Jonathan Stowe                      |
<http://www.gellyfish.com>          |      This space for rent
                                    |


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

Date: 22 Apr 2001 09:31:55 GMT
From: Jonathan Stowe <gellyfish@gellyfish.com>
Subject: Re: Cant run hello world script :(
Message-Id: <9bu8eb$n1i$2@neptunium.btinternet.com>

[groups trimmed]

In comp.lang.perl.misc Preston Price <pric3596@cs.uidaho.edu> wrote:
> This is the script that I am trying to run. It works just fine when I call
> it from the command line but when I point to this .cgi script from a web
> browser I get an internal server error.
> Here is the script:
> #!usr/local/bin/perl

print "Content-Type: text/html\n\n";

> print qq(<HTML><BODY>HELLO WORLD</BODY></HTML>);
> 
> Here is the error:
> failed to open log file
> fopen: Permission denied

The above is a problem with the configuration of the server - you should
ask in comp.infosystems.www.servers.unix about how to fix it.

> httpd: [Sat Apr 21 18:13:01 2001] [error] [client 129.101.53.235] Premature
> end of script headers: /net/ugrads/pric3596/public_html/cgi-bin/remaid.cgi
> 

This should have given the clue.

BTW this question should have been asked in the group :

    comp.infosystems.www.authoring.cgi

Where I have set the followup.

/J\
-- 
Jonathan Stowe                      |
<http://www.gellyfish.com>          |      This space for rent
                                    |


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

Date: 22 Apr 2001 11:54:12 +0100
From: nobull@mail.com
Subject: Re: Comparison of Time
Message-Id: <u966fxb3xn.fsf@wcl-l.bham.ac.uk>

"KY" <kienyeny@uci.edu> writes:

> I wrote the code to output the time of 2 servers but now need to compare
> their time & output the time difference between them.

FAQ: "How can I compare two dates and find the difference?"

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


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

Date: Sun, 22 Apr 2001 07:07:05 GMT
From: tjla@guvfybir.qlaqaf.bet (Gwyn Judd)
Subject: Re: File::Find complain about invalid top directory?
Message-Id: <slrn9e50oo.ilu.tjla@thislove.dyndns.org>

In article <3AE22E84.5030604@yahoo.com>,
slok <slok00@yahoo.com> wrote:
>the script works fine if I don't supply the path argument
>but give an error message when I supply a path...

>    # if it matches slash or is a path    
>    if ( $argv =~ m/^\// ) {
>        push @paths, <$argv/*> unless @ARGV;

This is the problem here. It says, "If there is nothing in @ARGV, put
every file and directory inside the directory named $argv into the array
named @paths". I think what you really want to do is something like:

push @paths, $argv;

-- 
Gwyn Judd (print `echo 'tjla@guvfybir.qlaqaf.bet' | rot13`)
Monsters are the result of the sleep of reason.


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

Date: 22 Apr 2001 09:39:34 GMT
From: Jonathan Stowe <gellyfish@gellyfish.com>
Subject: Re: File::Find complain about invalid top directory?
Message-Id: <9bu8sm$n1i$3@neptunium.btinternet.com>

slok <slok00@yahoo.com> wrote:
> my script takes in command line arguments
> eg. myscript.pl -5 /home/slok
> 
> the script works fine if I don't supply the path argument
> but give an error message when I supply a path...
> 
> message as follows:
> ========
> invalid top directory at /usr/lib/per5/5.6.0/File/Find.pm line 279
> ===========
> 
> 
> 
> =======
> use File::Find;
> use strict;
> 
> my $path = "."; # default path
> my $num  = 10; # -n default number of users
> my $num_flag = 0;
> my @paths ;  # array to hold paths
> my $num_paths = 0;
> my @subpaths ;
> my $size = 0;
> 
> foreach my $argv (@ARGV) {
>     
>     # if it matches dash     
>     if ( $argv =~ m/^-/ ) {
>     $num_flag++;
>     if ($num_flag > 1) {
>             print STDERR "Cannot have more than one entry for number o
> +f users\n";
>         usage_exit(1);
>     }
>         $num = substr($argv, 1);
>         print ("num is, $num\n");
>     }
> 
>     # if it matches slash or is a path    
>     if ( $argv =~ m/^\// ) {
>         push @paths, <$argv/*> unless @ARGV;

Shouldnt this be simply :

          push @paths, $argv; ?


/J\
-- 
Jonathan Stowe                      |
<http://www.gellyfish.com>          |      This space for rent
                                    |


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

Date: Sun, 22 Apr 2001 10:38:48 +0200
From: kb <m9652@abc.se>
Subject: foreach in a deep hash
Message-Id: <3AE29898.52C16088@abc.se>


--------------6787792E8D68862D5C4C3C7B
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit

hi
sorry for this, i am a new to perl.

i cannot figure out how to use the foreach function when i have a hash
with more then 2 dimensions.

here is my hash
every Person has a name, any number of cars, and any number of bikes.

$Name, $CarBrand and $BikeBrand are set dynamically.
each car holds the values of its color and type.
each bike holds its name and number of gears and the type

this is the structure:
$Person{$Name}
$Person{$Name}{$CarBrand}{Color}
$Person{$Name}{$CarBrand}{Type}
$Person{$Name}{$BikeBrand}{NoOfGears}
$Person{$Name}{$BikeBrand}{Type}

lets say we end up like this.

$Person{Mike Mikeson} = Mike Mikeson
$Person{Mike Mikeson}{GMC}{Color} = "Blue"
$Person{Mike Mikeson}{GMC}{Type} = "Van"
$Person{Mike Mikeson}{Volvo}{Color} = "Black"
$Person{Mike Mikeson}{Volvo}{Type} = "Station vagon"
$Person{Mike Mikeson}{Scott}{NoOfGears} = 21
$Person{Mike Mikeson}{Scott}{Type} = Mountain bike
$Person{Mike Mikeson}{Wheeler}{NoOfGears} = 18
$Person{Mike Mikeson}{Wheeler}{Type} = Mountain bike

$Person{Anna Anderson} = Anna Anderson
$Person{Anna Anderson}{BMW}{Color} = "Blue"
$Person{Anna Anderson}{BMW}{Type} = "Station vagon"
$Person{Anna Anderson}{BMW}{Color} = "White"
$Person{Anna Anderson}{BMW}{Type} = "Convertible"
$Person{Anna Anderson}{Peugeot}{NoOfGears} = 12
$Person{Anna Anderson}{Peugeot}{Type} = Road bike


to print out every person prom the hash i use
foreach $each_person (%Person)
{
    print STDOUT $Person{$each_person};
}



but i cannot figure out how to do to print out every car and every bike
for each of the persons
foreach $each_person (%Person)
{
    print STDOUT $Person{$each_person};

    # what sould i do here?
    foreach $each_car in the hash (but only for the current person)
    {
        print STDOUT the name of the car
        print STDOUT $Person{$each_person}{$each_car}{Color};
        print STDOUT $Person{$each_person}{$each_car}{Type};
    }

    #and the same for each bike as for the cars
    foreach......
    {
    }

}


thanks
/konrad

--------------6787792E8D68862D5C4C3C7B
Content-Type: text/html; charset=us-ascii
Content-Transfer-Encoding: 7bit

<!doctype html public "-//w3c//dtd html 4.0 transitional//en">
<html>
hi
<br>sorry for this, i am a new to perl.
<p>i cannot figure out how to use the foreach function when i have a hash
with more then 2 dimensions.
<p>here is my hash
<br>every Person has a name, any number of cars, and any number of bikes.
<p>$Name, $CarBrand and $BikeBrand are set dynamically.
<br>each car holds the values of its color and type.
<br>each bike holds its name and number of gears and the type
<p>this is the structure:
<br>$Person{$Name}
<br>$Person{$Name}{$CarBrand}{Color}
<br>$Person{$Name}{$CarBrand}{Type}
<br>$Person{$Name}{$BikeBrand}{NoOfGears}
<br>$Person{$Name}{$BikeBrand}{Type}
<p>lets say we end up like this.
<p>$Person{Mike Mikeson} = Mike Mikeson
<br>$Person{Mike Mikeson}{GMC}{Color} = "Blue"
<br>$Person{Mike Mikeson}{GMC}{Type} = "Van"
<br>$Person{Mike Mikeson}{Volvo}{Color} = "Black"
<br>$Person{Mike Mikeson}{Volvo}{Type} = "Station vagon"
<br>$Person{Mike Mikeson}{Scott}{NoOfGears} = 21
<br>$Person{Mike Mikeson}{Scott}{Type} = Mountain bike
<br>$Person{Mike Mikeson}{Wheeler}{NoOfGears} = 18
<br>$Person{Mike Mikeson}{Wheeler}{Type} = Mountain bike
<p>$Person{Anna Anderson} = Anna Anderson
<br>$Person{Anna Anderson}{BMW}{Color} = "Blue"
<br>$Person{Anna Anderson}{BMW}{Type} = "Station vagon"
<br>$Person{Anna Anderson}{BMW}{Color} = "White"
<br>$Person{Anna Anderson}{BMW}{Type} = "Convertible"
<br>$Person{Anna Anderson}{Peugeot}{NoOfGears} = 12
<br>$Person{Anna Anderson}{Peugeot}{Type} = Road bike
<br>&nbsp;
<p>to print out every person prom the hash i use
<br>foreach $each_person (%Person)
<br>{
<br>&nbsp;&nbsp;&nbsp; print STDOUT $Person{$each_person};
<br>}
<br>&nbsp;
<br>&nbsp;
<p><b>but i cannot figure out how to do to print out every car and every
bike for each of the persons</b>
<br>foreach $each_person (%Person)
<br>{
<br>&nbsp;&nbsp;&nbsp; print STDOUT $Person{$each_person};
<p>&nbsp;&nbsp;&nbsp; # what sould i do here?
<br>&nbsp;&nbsp;&nbsp; foreach $each_car in the hash (but only for the
current person)
<br>&nbsp;&nbsp;&nbsp; {
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; print STDOUT the name of
the car
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; print STDOUT $Person{$each_person}{$each_car}{Color};
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; print STDOUT $Person{$each_person}{$each_car}{Type};
<br>&nbsp;&nbsp;&nbsp; }
<p>&nbsp;&nbsp;&nbsp; #and the same for each bike as for the cars
<br>&nbsp;&nbsp;&nbsp; foreach......
<br>&nbsp;&nbsp;&nbsp; {
<br>&nbsp;&nbsp;&nbsp; }
<p>}
<br>&nbsp;
<p>thanks
<br>/konrad</html>

--------------6787792E8D68862D5C4C3C7B--



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

Date: 22 Apr 2001 12:24:15 +0100
From: nobull@mail.com
Subject: Re: foreach in a deep hash
Message-Id: <u9zod99nz4.fsf@wcl-l.bham.ac.uk>

kb <m9652@abc.se> writes:

> i cannot figure out how to use the foreach function when i have a hash
> with more then 2 dimensions.

The evidence presented here suggests you don't even know how to use
single dimentional hashes.  Do not attempt to run before you walk.
 
> here is my hash
> every Person has a name, any number of cars, and any number of bikes.
> 
> $Name, $CarBrand and $BikeBrand are set dynamically.
> each car holds the values of its color and type.
> each bike holds its name and number of gears and the type
> 
> this is the structure:
> $Person{$Name}
> $Person{$Name}{$CarBrand}{Color}
> $Person{$Name}{$CarBrand}{Type}
> $Person{$Name}{$BikeBrand}{NoOfGears}
> $Person{$Name}{$BikeBrand}{Type}

This is a bad structure.  This has nothing to do with Perl :-) Well
actually to be fair it is to do with this sort of hierarchical data
strucutre which I guess you are most likely to meet in Perl.  As it
happens last time I tried to explain this I was talking about MUMPS
which has entities with the nearly same semantics as Perl hierachical
hashes.

The keys of each hash should be the same sort of thing.  You have
$CarBrand and $BikeBrand as keys of the same hash.

> but i cannot figure out how to do to print out every car and every bike
> for each of the persons

This is fundamentally impossible from your data structure as there is
no way to destinguish cars and bikes.

> lets say we end up like this.
> 
> $Person{Mike Mikeson} = Mike Mikeson
> $Person{Mike Mikeson}{GMC}{Color} = "Blue"

No that is impossible (in Perl, it's possible in MUMPS but that's
another story).

$Person{'Mike Mikeson'} can hold either a string or a hash, not both. 
Let's just ignore that first line.

> $Person{Mike Mikeson}{GMC}{Color} = "Blue"
> $Person{Mike Mikeson}{GMC}{Type} = "Van"
> $Person{Mike Mikeson}{Volvo}{Color} = "Black"
> $Person{Mike Mikeson}{Volvo}{Type} = "Station vagon"
> $Person{Mike Mikeson}{Scott}{NoOfGears} = 21
> $Person{Mike Mikeson}{Scott}{Type} = Mountain bike
> $Person{Mike Mikeson}{Wheeler}{NoOfGears} = 18
> $Person{Mike Mikeson}{Wheeler}{Type} = Mountain bike

You need to separate the cars and the bikes.  I'm still not wild about
using the car type as a key like this beacuse I know some who has two
almost idential cars.

$Person{Mike Mikeson}{Car}[0]{Brand} = "GMC"
$Person{Mike Mikeson}{Car}[0]{Color} = "Blue"
$Person{Mike Mikeson}{Car}[0]{Type} = "Van"
$Person{Mike Mikeson}{Car}[1]{Brand} = "Volvo"
$Person{Mike Mikeson}{Car}[1]{Color} = "Black"
$Person{Mike Mikeson}{Car}[1]{Type} = "Station vagon"
$Person{Mike Mikeson}{Bike}[0]{Brand} = "Scott"
$Person{Mike Mikeson}{Bike}[0]{NoOfGears} = 21
$Person{Mike Mikeson}{Bike}[0]{Type} = Mountain bike
$Person{Mike Mikeson}{Bike}[1]{Brand} = "Wheeler"
$Person{Mike Mikeson}{Bike}[1]{NoOfGears} = 18
$Person{Mike Mikeson}{Bike}[1]{Type} = Mountain bike

> to print out every person prom the hash i use
> foreach $each_person (%Person)
> {
>     print STDOUT $Person{$each_person};
> }

No you don't.  You are tying to run before you walk  

This will print something like "Mike MikesonHASH(0x9434539)" because
each record in %Person is a hash (reference), and you are printing
both the keys and the values.  You need the keys() function.

I think I'd better stop now and advise you to do back and work on the
tutorials again.

> Content-Type: text/html; charset=us-ascii

Wrong, this is a plain text newsgroup.

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


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

Date: Sat, 21 Apr 2001 23:35:30 +0200
From: rpolzer@durchnull.de (echo 'Rudolf Polzer'>/dev/null)
Subject: Re: Getting character codes
Message-Id: <slrn9e3v92.2mt.rpolzer@www42.t-offline.de>

Logan Shaw <logan@cs.utexas.edu> wrote:
> In article <slrn9e3mbp.gv7.rpolzer@www42.t-offline.de>,
> echo 'Rudolf Polzer'>/dev/null <null@durchnull.de> wrote:
> >Anno Siegel <anno4000@lublin.zrz.tu-berlin.de> wrote:
> >> According to Peter Reid  <peter.reid2000@ntlworld.com>:
> >> > Does anyone know how to get the character code of a letter (eg X is 88)
> >> > and also how to get a letter from its code ????
> >> 
> >> ord() and chr().
> >
> >Oh no, I always used pack and unpack for this :( 
> 
> That's sort of silly, but not nearly silly enough, I think.  If you do
> this:
> 
> 	$mapping = join ("", map (chr, 0 .. 255));
> 
> Then you can use
> 
> 	$code = index($mapping, $character);
> 
> and
> 
> 	$character = $mapping[$code];

That is not 100% silly. A variant of this can be used to get ANSI 
codes of ASCII characters or the other way round, and it saves the 
overhead of hashes.

-- 
#!/usr/bin/perl -W -- WARNING: This will print 22,307 bytes! <strictsafe!>
use strict;for(my$y=-1;$y<1;$y+=.1){for(my$x=-1.9;$x<.4;$x+=.03){print'+';
my$X=my$Y=0;for(0..99){($X,$Y)=($X*$X-$Y*$Y+$x,2*$X*$Y+$y);print"\b "if$X*
$X+$Y*$Y>9;}}print"\n"};print''.reverse"\nHPAJ \a!rezloP .R yb torblednaM"


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

Date: Sat, 21 Apr 2001 23:36:17 +0200
From: rpolzer@durchnull.de (echo 'Rudolf Polzer'>/dev/null)
Subject: Re: Getting character codes
Message-Id: <slrn9e3vah.2mt.rpolzer@www42.t-offline.de>

Logan Shaw <logan@cs.utexas.edu> wrote:
> In article <slrn9e3mbp.gv7.rpolzer@www42.t-offline.de>,
> echo 'Rudolf Polzer'>/dev/null <null@durchnull.de> wrote:
> >Anno Siegel <anno4000@lublin.zrz.tu-berlin.de> wrote:
> >> According to Peter Reid  <peter.reid2000@ntlworld.com>:
> >> > Does anyone know how to get the character code of a letter (eg X is 88)
> >> > and also how to get a letter from its code ????
> >> 
> >> ord() and chr().
> >
> >Oh no, I always used pack and unpack for this :( 
> 
> That's sort of silly, but not nearly silly enough, I think.  If you do
> this:

The silliest thing is: I was programming Pascal for years... and there 
ord and chr DO exist!


-- 
#!/usr/bin/perl -W -- WARNING: This will print 22,307 bytes! <strictsafe!>
use strict;for(my$y=-1;$y<1;$y+=.1){for(my$x=-1.9;$x<.4;$x+=.03){print'+';
my$X=my$Y=0;for(0..99){($X,$Y)=($X*$X-$Y*$Y+$x,2*$X*$Y+$y);print"\b "if$X*
$X+$Y*$Y>9;}}print"\n"};print''.reverse"\nHPAJ \a!rezloP .R yb torblednaM"


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

Date: Sun, 22 Apr 2001 22:27:19 +1000
From: "Gregory Toomey" <gtoomey@usa.net>
Subject: Re: help with htaccess
Message-Id: <LVzE6.8991$482.41450@newsfeeds.bigpond.com>

For the 'noone' problem, it happens on most Linux/Apache environments.
The main problem is that you cannot write to files you own if you are noone.

See http://www.perldoc.com/perl5.6/pod/perlsec.html


Basically, compile the following code in a file ,say peruid.c

#define REAL_PATH "/path/to/script"
    main(ac, av)
	char **av;
    {
	execv(REAL_PATH, av);
    }

Then you will need to
cc -o peruid peruid.c
chmod 6755 peruid

If you plan on using system() or backtick ``, read the section on taint in
the FAQ

gtoomey
------------
"Andy" <andrew.fase@btinternet.com> wrote in message
news:9bsho0$esn$1@uranium.btinternet.com...
> I'm trying to write a script which can add users to my .htaccess and
 .htpass
> files, whats the easiest ways of doing this?
>
> Bearing in mind i'm only using a hosted web server...not sure if i can set
> my script to have higher privilages than "noone" can I ? .....
>
> Any help appreciated even if its a link to a tutorial on this sort of
thing
>
> Cheers
>
> Andy
>
>
>




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

Date: 22 Apr 2001 11:35:50 GMT
From: Jonathan Stowe <gellyfish@gellyfish.com>
Subject: Re: Is it a hash or not?
Message-Id: <9bufmm$dc5$2@plutonium.btinternet.com>

Glenn Davis <glenn@surveystar.com> wrote:
> "John W. Krahn" wrote:
>> Glenn Davis wrote:
>> >
>> > I have a subroutine that deals with lists -- the list name is a variable
>> > that can be either a simple array or a hash.  However, I need to handle
>> > these slightly differently.
>> >
>> > I am using...
>> >
>> >          if (keys(%$listname)) {
>>
>> if ( ref( $listname ) eq 'HASH' ) {
>>
>> >            $hash=1;
>> >            }
>> >         if ($hash) ...
>> >
>> > ...which seems to work fine in my testing, but I wonder whether this
>> > will always work, or if there are any risks of using the % syntax in
>> > situations where $listname is not a hash.
>>
>> perldoc -f ref
>>
> ref() didn't work.
> tried...
>     $reftype=ref($listname);
>     print"$listname is $reftype";
> ...reftype is empty. ???
> 

ref() did work - that it returns undef means that $listname does not
contain a reference.

perldoc -f ref ; # again

/J\
-- 
Jonathan Stowe                      |
<http://www.gellyfish.com>          |      This space for rent
                                    |


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

Date: 22 Apr 2001 11:39:45 GMT
From: Jonathan Stowe <gellyfish@gellyfish.com>
Subject: Re: LWP, getting the default index page name from a web directry.
Message-Id: <9bufu1$dc5$3@plutonium.btinternet.com>

Steve <steve@zeropps.uklinux.net> wrote:
> On 20 Apr 2001 18:05:35 +0100, nobull@mail.com wrote:
>>steve@zeropps.uklinux.net (Steve) writes:
>>
>>> Using LWP, I can get content from web servers and parse it with
>>> HTML::Parser etc, but the one thing that I can't get is the 
>>> name of the page that I'm getting if the input is just something
>>> like "http://www.perl.com".  
>>
>>But the name of the page _is_ http://www.perl.com/
>>
>>This has nothing to do with Perl.
> 
> If you're trying to get the results with perl it has everything to
> do with perl! 
> 

Rubbish, its to do with the HTTP specification and the implementaion of
the HTTP server.

/J\
-- 
Jonathan Stowe                      |
<http://www.gellyfish.com>          |      This space for rent
                                    |


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

Date: Sun, 22 Apr 2001 11:06:40 +0200
From: rpolzer@durchnull.de (echo 'Rudolf Polzer'>/dev/null)
Subject: Re: Mail:Mailer / Net:SMTP speed issue
Message-Id: <slrn9e57p0.1vc.rpolzer@www42.t-offline.de>

Matthew Kilbride <kilbride@principia-MAPS-ON.edu> wrote:
> I was avoiding using sendmail because I know nothing about setting it up, but I guess I'll
> give it a try.  Thanks for the help.

Which Linux distribution do you use? Many have ready-made sendmail 
configuration programs. Maybe I can help, but I also do not understand 
sendmail.cf

-- 
#!/usr/bin/perl -W -- WARNING: This will print 22,307 bytes! <strictsafe!>
use strict;for(my$y=-1;$y<1;$y+=.1){for(my$x=-1.9;$x<.4;$x+=.03){print'+';
my$X=my$Y=0;for(0..99){($X,$Y)=($X*$X-$Y*$Y+$x,2*$X*$Y+$y);print"\b "if$X*
$X+$Y*$Y>9;}}print"\n"};print''.reverse"\nHPAJ \a!rezloP .R yb torblednaM"


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

Date: 22 Apr 2001 09:24:31 GMT
From: Jonathan Stowe <gellyfish@gellyfish.com>
Subject: Re: Mail:Mailer / Net:SMTP speed issue
Message-Id: <9bu80f$n1i$1@neptunium.btinternet.com>

Matthew Kilbride <kilbride@principia-maps-on.edu> wrote:
> I just started working with the Mail:Mailer module so that I could
> send form data.   I have found that there is a 25 second pause when I
> submit the form.

<snip>

> Is this delay a known issue, or is there some optimization that I
> should look into?  Any assistance would be greatly appreciated....

If I run a small test program it doesnt manifest this behaviour - so I would
say that this is some issue with your system's configuration, probably DNS.

What happens if you run the program from the command line, BTW ?

/J\
-- 
Jonathan Stowe                      |
<http://www.gellyfish.com>          |      This space for rent
                                    |


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

Date: 22 Apr 2001 12:13:49 GMT
From: Ilmari Karonen <iltzu@sci.invalid>
Subject: Re: Multi dimensional array dimensions
Message-Id: <987940684.22688@itz.pp.sci.fi>

In article <9bslqe$ltd$5@mamenchi.zrz.TU-Berlin.DE>, Anno Siegel wrote:
>According to  <nobull@mail.com>:
> 
>> I bet even most Perl programmers couldn't with certainty what the
>> semantics of a slice are in a scalar context without checking.
>
>Why?  A slice is a list, which evaluates to its last element in
>scalar context.

Better stated as:  "It does what I expect, which is the same as the
comma operator in scalar context."

You know there's no such thing as a "list in scalar context", and I know
it, but the newbies might get funny ideas from your post.


The following code is intended to demonstrate that when we say scalar
context propagates until a scalar is supplied, we really do mean it.

  sub foo { $_[0] .. $_[1] }

  print scalar foo(0, 5), "\t toggle off\n";
  print        foo(0, 5), "\t print '012345'\n";
  print scalar foo(0, 0), "\t still turned off\n";
  print scalar foo(5, 0), "\t toggle on\n";
  print        foo(0, 5), "\t print '012345'\n";
  print scalar foo(0, 0), "\t still turned on\n";

-- 
Ilmari Karonen - http://www.sci.fi/~iltzu/
Please ignore Godzilla / Kira -- do not feed the troll.


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

Date: Sun, 22 Apr 2001 11:00:29 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: operators: != vs. ne, strange behaviour
Message-Id: <30e5etsi7rfi6jd6lplto2qe9j4jtn45eg@4ax.com>

Kristian wrote:

>  if ($qry_id != $query_id) {
>      print "$qry_id != $query_id !!!!\n";
>      die;
>    }
>
>and, when i run this on my data I get the following error:
>
>NANA_STRPN-381-392 != NANA_STRPN-381-392 !!!!

I don't quite get it, because these two ought to be the same, as both
sides evaluate to zero. Yes, zero! They both start with some letters,
that's why.

If your want to compare just the numbers, then you have to *extract*
just the numbers. I'm just not sure what number "381-392" is supposed to
represent.

So I think you want to compare the "381" part and the "392" part.

  ($a, $b) = map { [ $_, /(\d+)/g ] }
    'NANA_STRPN-381-392', 'SOMETHING_ELSE-381-392';

  print "$a->[0] and $b->[0] contain the same numbers: @{$a}[1..$#$a]\n"
    if @$a == @$b && not grep { $a->[$_] != $b->[$_] } 1 .. $#$a;

-- 
	Bart.


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

Date: 22 Apr 2001 11:57:20 +0100
From: nobull@mail.com
Subject: Re: pointer/reference question
Message-Id: <u93db1b3sf.fsf@wcl-l.bham.ac.uk>

xris <xris@dont.send.spam> writes:

> another silly question that I can't seem to find in my books...  Is 
> there any way, OTHER than using globs, to assign two variables to the 
> same memory space?
> 
> something like:
> 
> \$x = \$y;

ISTR that's been proposed for Perl6

> I'd love to be able to pass more things to subroutines by reference, but 
> don't want to mess with the TONS of dereferencing that would need to be 
> done in some larger ones.

TONS of de-referencing?  It's only a case of changing $ to $$ (or % to
%$ and so on).

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


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

Date: Sun, 22 Apr 2001 14:07:59 +0100
From: Malte Ubl <ubl@schaffhausen.de>
Subject: Re: pointer/reference question
Message-Id: <3AE2D7AF.A2CF99D@schaffhausen.de>

xris schrieb:
> I'd love to be able to pass more things to subroutines by reference, but
> don't want to mess with the TONS of dereferencing that would need to be
> done in some larger ones.

Parameters are always passed by reference. So you can work on the passed 
variables directly via the $_[n] notation inside a subroutine.

->malte


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

Date: Sun, 22 Apr 2001 14:34:44 +0200
From: Abe Timmerman <abe@ztreet.demon.nl>
Subject: Re: pointer/reference question
Message-Id: <b3h5et88brit3gnr0pcbr978db41gsg31p@4ax.com>

On Sat, 21 Apr 2001 23:11:46 -0500, xris <xris@dont.send.spam> wrote:

> In article <9btbef$e2r$1@mamenchi.zrz.TU-Berlin.DE>,
>  anno4000@lublin.zrz.tu-berlin.de (Anno Siegel) wrote:
> 
> > Aliasing via typeglobs does what you want.  It's also not a terribly
> > good idea because it can't be done with lexicals (on the receiving end).
> 
> exactly why I don't want to use them.
> 
> > If de-referencing becomes a pain it is often a sign of an unfortunate
> > data structure design and/or subroutine layout.  Sometimes a simple
> > measure like passing a hashref instead of many parameters is all it
> > takes.  Sometimes a deeper redesign is indicated.  Using an aliasing
> > mechanism would only cure the symptom, not the disease.
> 
> It's not a matter of passing in a lot of variables to a routine, just 
> accessing the one or two variables I do pass in a bunch of times.  My 
> main concern is that I'll forget the extra $ to dereference something 
> and it'll cost me hours of bug testing to find the typo.  :)

There are ways to avoid this problem when passing simple scalars (not
refs) to subs. 

One, is to make the sub return the new value and re-assign it:

	sub return_it {
		my( $x ) = @_;
		# do stuf with $x
		return $x;
	}

	$y = return_it( $y );

Another one is to re-assign the new value to the right element of @_:

	sub re_assign {
		my( $x ) = @_;
		# do stuf with $x
		$_[0] = $x;
	}

	re_assign( $y );

Both will do two copy's of the data. So if $y is large enough it will
slow down and cost memory.

If you are happy to directly manipulate the contents of your variable,
you can use the individual elements of @_ as they are an 'alias' for the
original variable:

	sub change_it {
		# do stuf with $_[0]
	}

	change_it( $y );

Both cases, where one (re)assigns to @_, are IMHO bordering on what is
known as 'side effects' in this case where simple scalars are involved.

I try to avoid the situation where I have to pass large chucks of data
around, by either trying to process smaller pieces of the data or
sticking that data in some datastructure (array, hash, object, ...) and
passing a reference to that structure.

-- 
Good luck, Abe
Amsterdam Perl Mongers http://amsterdam.pm.org
perl -wle '$_=q@Just\@another\@Perl\@hacker@;print qq@\@{[split/\@/]}@'


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

Date: 22 Apr 2001 07:19:24 GMT
From: damian@qimr.edu.au (Damian James)
Subject: Re: Programming perl modules
Message-Id: <slrn9e51cs.bab.damian@puma.qimr.edu.au>

Bastian Ballmann chose Sun, 22 Apr 2001 05:13:41 +0200 to say this:
>Im Artikel <nrrE6.60$UA4.208711680@news.frii.net> schrieb "Chris Fedde"
><cfedde@fedde.littleton.co.us>:
>
>> ...
>> The absolute simplest thing that might be called a module would be a
>> file that contains something like the following:
>> 
>>     package PackageName;
>> 
>>     1;
>> 
>> ...
>
>I try to do the following:
>
>package testmodul;
>
>sub new
>{
>print "Test\n";
>return1;
>}
>
>----->Cut Now the Perl script <------
>
>
>Than I get the error: testmodul do not return a true value.
>But I am returning a true value of 1...

No, the *module* needs to return a true value, not any given sub/method from
it you might call. See Chris' example above. Your subs can return anything you
like, but when you use() or require() a module, it needs to return a true
value.

Hence the advice in the docs (which you claim to have read) to include:

	1;

on the last line of the module file.

HTH,

Cheers,
Damian
-- 
@:=grep!($;+=m!$/|#!),split//,<DATA>;@;=0..$#:;while(@;){for($;=@;;--$;;)
{@;[$;,$:]=@;[$:,$;]if($:=rand$;+$|)!=$;}push@|,shift@;if$;[0]==@|;select
$,,$,,$,,1/80;print qq x\bxx((@;+@|)*$|++),@:[@|,@;],!@;&&$/} __END__
Just another Perl Hacker # rev 3.1 -- a JAPH in progress, I guess...


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

Date: 22 Apr 2001 09:44:55 GMT
From: Jonathan Stowe <gellyfish@gellyfish.com>
Subject: Re: Programming perl modules
Message-Id: <9bu96n$n1i$4@neptunium.btinternet.com>

In comp.lang.perl.misc Bastian Ballmann <djsyntax@crazydj.de> wrote:
> Im Artikel <nrrE6.60$UA4.208711680@news.frii.net> schrieb "Chris Fedde"
> <cfedde@fedde.littleton.co.us>:
> 
>> In article <20010422.032921.1494613810.2785@Syntaxerror.crazydj.de>,
>> Bastian Ballmann <djsyntax@crazydj.de> wrote:
>>>Hi @ll!!
>>>Can anyone tell me how to program a perl module? I know the file must
>>>begin with the keyword package $packagefilename And I must(?) use the
>>>BEGIN and END subroutines. Are there other neccessary commands to build
>>>up a package? I know that there is a manual page about this topic but I
>>>dont understand it...
>>>Greetz
>>>
>>>
>> I think that you need to look at the manual pages a bit more. perlmod(1)
>> Has lots of great info but it's at a pretty high level.
>> 
>> The absolute simplest thing that might be called a module would be a
>> file that contains something like the following:
>> 
>>     package PackageName;
>> 
>>     1;
>> 
>> good luck!
>> chris
>> 
> 
> I try to do the following:
> 
> package testmodul;
> 
> sub new
> {
> print "Test\n";
> return1;
> }
> 
> ----->Cut Now the Perl script <------
> 
> #!/usr/bin/perl -w
> use testmodul;
> 
> testmodul->new();
> 
> ----->EOF<------
> 
> Than I get the error: testmodul do not return a true value.
> But I am returning a true value of 1...

No you arent.  The subroutine 'new' is but what the message refers to is
the requirement that the file itself returns a true value - you should
put :

1;

As the last executable line of your file.


By the way if you run h2xs it will create a skeleton module for you - try:

   h2xs -AXn Testmodule

and then examine the files created.

Then read the perlmod manpage - it is easier if you then come back to us
with the things that you dont understand.

/J\
-- 
Jonathan Stowe                      |
<http://www.gellyfish.com>          |      This space for rent
                                    |


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

Date: Sun, 22 Apr 2001 07:23:40 GMT
From: tjla@guvfybir.qlaqaf.bet (Gwyn Judd)
Subject: Re: Silly User Friendly module...any interest to put it on CPAN?
Message-Id: <slrn9e51nq.ilu.tjla@thislove.dyndns.org>

In article <te21dqd7vthq34@news.supernews.com>,
Zenin <zenin@rhps.org> wrote:
>Being a User Friendly fan (www.userfriendly.org for the uninitiated), I
>hacked a quick module up to help me automate setting my desktop wallpaper to
>the UF cartoon of the day.  Would anyone else be interested in it?  If so,
>I'll upload it to CPAN.  For now, Silly::UserFriendly can be found at:
>
>	ftp://thrush.omix.com/pub/perl/modules/Silly-UserFriendly-1.001.tar.gz

Interesting way of doing it. I would say it's probably a little too one
purpose for my taste and the interface is, well, different. Take a
look at this for an alternative method. I'm sure it would be simple to
modify this to set the desktop back ground and so on, rather than
emailing it. The bonus here is that it works with many different kinds
of cartoons and is easily extensible. I wont argue the point of whether
the script is optimal for size or readability or even Perlishness, I
still admit to not really understanding how modules work :)

#!/usr/bin/perl -ws
use strict;
use LWP::Simple;
use HTML::TokeParser;
use MIME::Lite;

# usage: comics.pl -d -m 'some match string' -i ' some string to ignore'
#                       -g -l
# -g option doesn't fetch, -l lists urls (overwrites the file called
# list.html in the current directory)

# Changes:
#
# $Log: comics.pl,v $
# Revision 1.4  2001/04/14 15:32:15  gwyn
# added list urls feature
#
# Revision 1.3  2001/04/14 15:04:52  gwyn
# added log
#

my $VERSION_ID = q$Id: comics.pl,v 1.4 2001/04/14 15:32:15 gwyn Exp $;
my $VERSION = (qw$Revision: 1.4 $ )[-1];

use vars qw/$d $m $i $g $l $document $image $src $parser/;

# if debugging
close STDOUT unless ($d || $l || $g);
no warnings 'closed';

my $module = $m;
my $ignore = $i;
my $dont_get = $g;
my $list_urls = $l;

if ($list_urls)
{
    open LIST, ">list.html" or die
        "Cannot open list.html: $!";
}

my $mail_addr = 'gwyn';

# loop through the 'comics' directory and load each file there in turn
# each one defines two variables $server and $document telling us what
# it is we are going to download and a function 'match'. The function
# match is called and will return a true value if the tag we are
# currently looking at is the one we want. This obviously changes
# depending on the comic strip so there will be different criteria to
# look at.
my $dir = '/home/gwyn/bin/comics';
MODULE: for (<$dir/*>)
{
    next MODULE unless /$module/;
    next MODULE if defined $ignore && /$ignore/;
    require $_;
    
    my ($package) = m/^.*\/(.*)\.pm$/;

    print "\$package is $package\n";

    # import the variables/functions from the package
    undef *match;
    undef $image;
    undef $src;
    import $package;
   
    do {
        print LIST qq[<a href="$document">$package,</a> \n];
        next MODULE;
    } if $list_urls;

    if (defined $image)
    {
        print "\$image = $image\n";
        $src = $image;
    }
    else
    {
        print "\$document = $document\n";
       
        my $text = get $document || 
            do {
                warn "Couldn't get $document";
                next MODULE;
            };

        $parser = new HTML::TokeParser(\$text);
    }
    
    TAG: while ($src or my $tag = $parser->get_tag('img'))
    {
        # ask the module if this is the correct link
        if ($src || match($tag))
        {
            $src ||= $tag->[1]{src};

            print "\$src is $src\n";

            if ($src !~ /^http:\/\//)
            {   
                # doesn't start with '/'
                print "relative URL\n";

                if ($src !~ /^\//)
                {
                    $document .= '/' 
                        if $document =~ /^http:\/\/[^\/]*$/;
                    
                    (my $base) = $document =~ /^(http:\/\/.*\/)/;

                    $base =~ s/[^\/]*\/$// while $src =~ s/^\.\.\///;
                    
                    print "\$base is $base\n";
                    
                    $src = $base . $src;
                }
                else
                {
                    # does start with '/'
                    (my $base) = $document =~ /^(http:\/\/[^\/]*)/;

                    print "\$base = $base\n";

                    $src = $base . $src;
                }
            }
           
            print "image is $src\n";
 
            my ($type) = $src =~ m/\.([^.]*)$/;
            
            print "Type is $type\n";
            
            $type = 'jpeg' if $type eq 'jpg';
            
            do { 
                head $src or warn "Couldn't get $src";
                next MODULE;
            } if $dont_get;
            
            my $data = get $src || 
                do {
                    warn "Couldn't get $src";
                    next MODULE;
                };

            my $msg = MIME::Lite->new(
                    From    =>      $package.'@localhost',
                    To      =>      $mail_addr,
                    Subject =>      "A new $package image!",
                    Type    =>      'multipart/mixed'
            );

            $msg->attach(
                    Type    =>      'TEXT',
                    Data    =>      "Attached please find the " .
                                "latest $package cartoon\n"
            );

            $msg->attach(
                                Type    =>      'image/' . $type,
                                Data    =>      $data
            );

            $msg->send;
            
            last TAG;
        }
    }
}

__END__

#!/usr/bin/perl -w
package user_friendly;

use Exporter;

@ISA = qw/Exporter/;

@EXPORT = qw/$document match/;

$document = 'http://www.userfriendly.org/static/index.html';

sub match
{
    $_[0]->[1]{alt} =~ /Latest Strip/ if exists $_[0]->[1]{alt};
}

1;

-- 
Gwyn Judd (print `echo 'tjla@guvfybir.qlaqaf.bet' | rot13`)
"Go to Heaven for the climate, Hell for the company."
		-- Mark Twain


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

Date: Sun, 22 Apr 2001 11:05:42 +0200
From: rpolzer@durchnull.de (echo 'Rudolf Polzer'>/dev/null)
Subject: Re: So what do YOU use Perl for?
Message-Id: <slrn9e57n6.1vc.rpolzer@www42.t-offline.de>

E.Chang <echang@netstorm.net> wrote:
> rename and perldoc -f s).  (Oh, and a hint:  .html is preferred over .htm 
> as an extension for web documents - unless you're running your server on a 
> Windows 3.x machine)

Why? I always use .htm because it is shorter. The same with .jpg and 
 .sht. But I do not restrict me to 8 chars in the name...

-- 
#!/usr/bin/perl -W -- WARNING: This will print 22,307 bytes! <strictsafe!>
use strict;for(my$y=-1;$y<1;$y+=.1){for(my$x=-1.9;$x<.4;$x+=.03){print'+';
my$X=my$Y=0;for(0..99){($X,$Y)=($X*$X-$Y*$Y+$x,2*$X*$Y+$y);print"\b "if$X*
$X+$Y*$Y>9;}}print"\n"};print''.reverse"\nHPAJ \a!rezloP .R yb torblednaM"


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

Date: 22 Apr 2001 11:22:44 GMT
From: Jonathan Stowe <gellyfish@gellyfish.com>
Subject: Re: split after a number of charachters?
Message-Id: <9bueu4$dc5$1@plutonium.btinternet.com>

Abe Timmerman <abe@ztreet.demon.nl> wrote:
> On Sun, 22 Apr 2001 00:01:20 +0200, kb <m9652@abc.se> wrote:
> 
>> hi
> 
> Hi,
> 
>> how can i use the split function to split after a number of characters?
> 
> That is not the task split was designed for.
>  
>> lets say i have the string: "0123456789"
>> i dont have any good separators within the string but i would like to
>> split it after lets say 8 characters
>> 
>> $string = "0123456789";
>> ($part1, $part2) = split(split after 8 characters, $string);
> 
> 	( $part1, $part2 ) = unpack 'A8 A*', $string;
> 

Alternatively :

   ( $part1, $part2) = $string =~ /^(.{8})(.*)/;

/J\
-- 
Jonathan Stowe                      |
<http://www.gellyfish.com>          |      This space for rent
                                    |


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

Date: Sun, 22 Apr 2001 02:35:19 -0500
From: xris <xris@dont.send.spam>
Subject: Re: Which is faster/better?
Message-Id: <xris-F4384D.02351822042001@news.evergo.net>

In article <Xns908B9A349FCmememeyeahme@206.165.3.70>,
 me@nospam.com (Me) wrote:

> So in those 6 years, did you ever hear of the Benchmark module?

sorry, been too busy actually getting paid to write working code.  oh, 
and working on my MA in anthropology (ok, so that was just this year).  
You think it would REALLY do any good, though?  to benchmark ONE 
statement?

Besides, if you had read my entire post, you would have seen that I'm 
not just looking for which is FASTER, I want to know which is better, 
more efficient, works with larger pieces of data, etc.  The perl book 
clearly says that join() is faster, but I was wondering if it was 
*always* faster.

-xris



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

Date: Sun, 22 Apr 2001 13:31:44 +0200
From: Abe Timmerman <abe@ztreet.demon.nl>
Subject: Re: Which is faster/better?
Message-Id: <19e5ets098urtarg8ghatepm0uv2htlka9@4ax.com>

On Sun, 22 Apr 2001 02:35:19 -0500, xris <xris@dont.send.spam> wrote:

> In article <Xns908B9A349FCmememeyeahme@206.165.3.70>,
>  me@nospam.com (Me) wrote:
> 
> > So in those 6 years, did you ever hear of the Benchmark module?
> 
> sorry, been too busy actually getting paid to write working code.  oh, 
> and working on my MA in anthropology (ok, so that was just this year).  

You seem to have time to wait for an answer ;-)

> Besides, if you had read my entire post, you would have seen that I'm 
> not just looking for which is FASTER, I want to know which is better, 
> more efficient, works with larger pieces of data, etc.  The perl book 
> clearly says that join() is faster, but I was wondering if it was 
> *always* faster.

That was the whole point. Write a benchmark and decide for yourself
which tradeoff you want to make in speed vs. maintainability.

Maybe this example will get you going:

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

use Benchmark;
use vars qw( $s1 $s2 $s3 $s4 );

my $factor = 1_000_000; # I don't known what _very large_ is
$s1 = $s2 = $s3 = $s4 = 'a' x $factor;

printf "String size: $factor\n";
timethese -2, {
	'A_join'   => sub { 
		my $str = join "", $s1, $s2, $s3, $s4; 
	},
	'B_append' => sub {
		my $str = $s1; $str .= $s2; $str .= $s3; $str .= $s4;
	},
	'C_concat' => sub {
		my $str = $s1 . $s2 . $s3 . $s4;
	},
	'D_stringify' => sub {
		my $str = "$s1$s2$s3$s4";
	},
};

-- 
Good luck, Abe
Amsterdam Perl Mongers http://amsterdam.pm.org
perl -wle '$_=q@Just\@another\@Perl\@hacker@;print qq@\@{[split/\@/]}@'


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

Date: Sun, 22 Apr 2001 14:01:48 +0100
From: Malte Ubl <ubl@schaffhausen.de>
Subject: Re: Which is faster/better?
Message-Id: <3AE2D63B.E8D7C57D@schaffhausen.de>

xris schrieb:
> 
> In article <Xns908B9A349FCmememeyeahme@206.165.3.70>,
>  me@nospam.com (Me) wrote:
> You think it would REALLY do any good, though?  to benchmark ONE
> statement?

For this part, yes it does, because you can repeat this statement as many
times as you want. In fact, you need to alway do that in order to get
results which actually mean something.

> Besides, if you had read my entire post, you would have seen that I'm
> not just looking for which is FASTER, I want to know which is better,
> more efficient, works with larger pieces of data, etc.  The perl book
> clearly says that join() is faster, but I was wondering if it was
> *always* faster.

Sorry, I dont know an answer to this. What you might want to take under
consideration (if this is possible in your case) is to avoid the concatenation
alltogether and use a statement like this instead:
print $somewhere $string1, $string2, $string3
or even better do that and avoid having all strings in memory at the
same time.

->malte


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

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


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