[22933] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 5153 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sun Jun 29 18:06:03 2003

Date: Sun, 29 Jun 2003 15:05:07 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Sun, 29 Jun 2003     Volume: 10 Number: 5153

Today's topics:
    Re: <STDIN> blues (Tan Rezaei)
    Re: BTree examples ?? (Mark Jason Dominus)
    Re: BTree examples ?? <joerg@objectpark.org>
    Re: directory access problem <eric-amick@comcast.net>
    Re: How do you sort a 2D array with column headers? Dennis@NoSpam.com
    Re: How do you sort a 2D array with column headers? (Greg Bacon)
        How to create a file <levin.spambox@telia.com>
    Re: How to create a file <mbudash@sonic.net>
    Re: How to create a file <tony_curtis32@yahoo.com>
    Re: How to create a file (Jay Tilton)
    Re: Module for sorting (while either reading from or wr (Mark Jason Dominus)
    Re: Not following "if" <eric-amick@comcast.net>
    Re: Not following "if" <eric-amick@comcast.net>
        objects vs sub routines in loop <coo_t2-NO-LIKE-SPAM@yahoo.com>
    Re: objects vs sub routines in loop <bwalton@rochester.rr.com>
    Re: Perl 5.6 and Perl 5.8 <flavell@mail.cern.ch>
    Re: Perl keeps me from throwing up while programming ja <asu1@c-o-r-n-e-l-l.edu>
    Re: perl\site\lib\auto\...  (DLLs, LIB, EXP etc)  to an (Kenjis Kaan)
    Re: perl\site\lib\auto\...  (DLLs, LIB, EXP etc)  to an <kalinabears@hdc.com.au>
    Re: perl\site\lib\auto\...  (DLLs, LIB, EXP etc)  to an <randy@theoryx5.uwinnipeg.ca>
    Re: URL checking (Mark Jason Dominus)
    Re: Yet another "undefined reference to `_WinMain@16'"  <asu1@c-o-r-n-e-l-l.edu>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: 29 Jun 2003 12:15:44 -0700
From: trezaei@hotmail.com (Tan Rezaei)
Subject: Re: <STDIN> blues
Message-Id: <8c92d509.0306291115.7ede86d4@posting.google.com>

"ThePotPlants" <thepotplants@yahoo.com> wrote in message news:<m3tLa.57155$JA5.1015363@news.xtra.co.nz>...
> "Tan Rezaei" <trezaei@hotmail.com> wrote:
> > I have this bit of code on a win2k Server:
> >
> > -----------------------------------------
> > #!E:\Perl\bin\perl.exe
> > print "\n\n Productline (QA, PROD, ...)?\n ";
> > chop($opt_p=<STDIN>);
> >
> > print "\n\n Company (0001, 1000, 1001, \.\.\.) ? \n";
> > chop($opt_c=<STDIN>);
> >
> > if ($opt_c =~ /\D/) { warn "Company number contains non digits"}
> >
> > print "\n\n Ready to Process Company $opt_c in Productline $opt_p
> > (Y/N)?  \n";
> > chop($run=<STDIN>);
> > -----------------------------------------
> >
> > Now when I run this, it does not prompt me for the variables but if I
> > enter all three of them then I will get the questions.
> >
> > If I comment out all the lines with <STDIN> then I get all the promts
> > immediately.
> >
> > Now this actually works fine on one machine and I only get this
> > problem when I put the file on the server.
> >
> > Is there something about terminal settigs or clearing the buffer that
> > might be the issue. If so, how do I clear the screen buffer? This is
> > one of those things that you just don't want to waste your time on.
> > And it is really killing me.
> >
> > Any help at all would be greatly appreciated.
> >
> > thanks in advance
> >
> > T
> 
> Looking at it a little differently...
> 
> It looks to me like you are mixing the use of @ARGV and GETOPT::STD (given
> away by your variables $opt_c & $opt_p)
> I posted a question related to getopt, have a look at it, you may want to
> consider using that instead.
> Ask yourself if you want to execute the programme and pass it variables, or
> if you want to prompt the user for input.
> 
> P

Yes, I was using the GETOPT::STD before until I found out who the
users are. They are asking to get prompted for every question as
opposed to run time parameters.

I had to fix this yesterday, so I ended up using warn statements
instead of print and those had no trouble showing up. I know its a
cheap way out but it worked for yesterday. I am going to try some of
people's suggestions today. Thank you all, those are all some great
suggestions. I've been using Perl for a couple of years but have never
really needed to do anything advanced so I am stuck using the most
elementary functions.

P.S. Where is a good place to get some good example code?

Thanks


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

Date: Sun, 29 Jun 2003 18:26:45 +0000 (UTC)
From: mjd@plover.com (Mark Jason Dominus)
Subject: Re: BTree examples ??
Message-Id: <bdnb15$3j3$1@plover.com>

In article <6a8ba9f8.0306282250.6b78a4f8@posting.google.com>,
Kenjis Kaan <tivolinewbie@canada.com> wrote:
>There has go to be a way to use BTree.pm (its floating around the
>internet) without resorting to the fancy DB_File with all the bells
>and whistles. 

Are you talking about the BTree.pm at

        http://perl.plover.com/BTree/

? Or have you found some other package?  If you want help with a piece
of software, you need to tell people what and where it is or else they
won't know and they can't help you with it.

>Its beyond me that some guy would write the BTree.pm but left out the
>delete operations.  I know its a bit harder to implement, but if you
>are going to do it, might as well make it complete so people can use
>it.

If you *are* talking about the BTree.pm at
http://perl.plover.com/BTree/, then I can tell you the answer to your
question.  The BTree.pm module was written as example code to
accompany a magazine article about how B-Trees work.  It was not
intended to be used for real projects, because any such use would be
silly even if the module did contain 'delete'.  The author left out
'delete' to keep the code short enough for publication and because the
article didn't deal with 'delete'.

However, if you really think that a complete BTree.pm is what you
need, I expect that for a fee, the module author would be willing to
add those functions to the module, and also extend it to store its
values on the disk instead of in memory.  You could spend some of the
money you are saving by not using an RDBMS.





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

Date: Sun, 29 Jun 2003 16:15:27 +0000
From: =?ISO-8859-1?Q?J=F6rg?= Westheide <joerg@objectpark.org>
Subject: Re: BTree examples ??
Message-Id: <0306TkwSnLRWotoG6VTMCrJhQg@objectpark.org>

Hi!

>> The only backdraw I discovered, is the really bad performance on
>> Win(2K), it's fine on Linux though
>
> But Win2k is what I am doing all this on.  Using Activestate Perl.

Then you should search for another solution since I too use Activestate =
Perl

J=F6rg



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

Date: Sun, 29 Jun 2003 11:31:07 -0400
From: Eric Amick <eric-amick@comcast.net>
Subject: Re: directory access problem
Message-Id: <4e1ufv0d4r9s549isrds8gt6dduemla0ap@4ax.com>

On 29 Jun 2003 07:43:56 -0700, iaegger@hta.fhz.ch (stegger) wrote:

>I am a perl newbie and should solve a script problem.
>
>I have defined a directory in the smbldap_conf.pm file similar to the
>following line:
>$mk_ntpasswd = "/usr/local/sbin/mkntpwd";
>
>Then in the smbldap-passwd.pl the line below generates an unexpected
>output and the script behaves not like expected
>
>Perl line which gerates the error:
>my $ntpwd = `$mk_ntpasswd '$pass'`;
>
>The error (or output)
>sh: /usr/local/sbin/mkntpwd: is a directory

The error message seems clear enough to me--you're trying to use the
name of a directory as if it were a program or shell script.  Perhaps
the program you want to run is in that directory?

-- 
Eric Amick
Columbia, MD


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

Date: Sun, 29 Jun 2003 15:52:10 -0500
From: Dennis@NoSpam.com
Subject: Re: How do you sort a 2D array with column headers?
Message-Id: <q4iufvkdmm9etdlqbdbliidf7u6prdhs0l@4ax.com>

gbacon@hiwaay.net (Greg Bacon) wrote:

>In article <liurfvo9qc5miq038r5f3taoq9b302g8rs@4ax.com>,
>     <Dennis@NoSpam.com> wrote:
>
>: [...]
>:
>: A lot of neat code. Some of the perl syntax is new to me but I'll get
>: to work with my Perl books and learn.  Thanks again.
>
>Anything in particular that gave you trouble?  This is a discussion
>group, after all. :-)  If you'll permit a guess, reading the perlref,
>perllol, and perldsc manpages will help your understanding.

Greg,

Well I read your above perl manpages and the subroutine section of "Perl
Cookbook" by Tom Christiansen & N. Torkington.

Below is the code I don't understand:

First in the subroutine sort_by_column

    sub sort_by_column {
        my $m   = shift;
        my $col = shift;

        return unless ref($m) && @$m && $col;

        my $colidx = find_column_index $m, $col;
        return unless defined $colidx;

        @{$m}[1..$#$m] = sort { $a->[$colidx] <=> $b->[$colidx] }
                              @{$m}[1..$#$m];
    }

    sort_by_column \@array, 'L3';

I don't understand the shift operator and how it moves \@array (a reference to
an array) and 'L3' into $m and $col.  I know the input to a subroutine are the
elements of @_ but what does shift mean? 

The statement return unless ref($m) && @$m && $col; tests to see that the
reference $m and value $col exist but what's @$m mean? An array whose pointer
reference starts at $m?

Also I'm not sure what the expression  @{$m}[1..$#$m] means.  obviously a
pointer $m to an array but  [1..$#$m]? .

Next I don't understand some of the code in the subroutine find_column_index:

    sub find_column_index {
        my $a = shift;
        my $col = shift;

        my $header = $a->[0];
        my $colidx = 0;
        for (@$header) {
            last if $_ eq $col;
            ++$colidx;
        }

        $colidx >= @$header ? () : $colidx;
    }

I take it that "my $header = $a->[0];" means store the pointer reference of the
0'th element into $header?  "for (@$header)" means for each element of the input
array do the below?  I didn't know "last" would end the loop after the last
statement if the "if" statement was true.  Neat.  I take it that when you say
"for(@$header)" each element of the array is stored into $_ one by one in the
for loop?

Last what does $colidx >= @$header ? () : $colidx; mean?  If the array element
number of 'L3' is greater then or equal to ...then I get lost.

Thanks for your help, I'm learning a lot!

Dennis



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

Date: Sun, 29 Jun 2003 21:47:44 -0000
From: gbacon@hiwaay.net (Greg Bacon)
Subject: Re: How do you sort a 2D array with column headers?
Message-Id: <vfunk060dd9b30@corp.supernews.com>

In article <q4iufvkdmm9etdlqbdbliidf7u6prdhs0l@4ax.com>,
     <Dennis@NoSpam.com> wrote:

: [...]
:
: First in the subroutine sort_by_column
: 
:     sub sort_by_column {
:         my $m   = shift;
:         my $col = shift;
: 
:         return unless ref($m) && @$m && $col;
: 
:         my $colidx = find_column_index $m, $col;
:         return unless defined $colidx;
: 
:         @{$m}[1..$#$m] = sort { $a->[$colidx] <=> $b->[$colidx] }
:                               @{$m}[1..$#$m];
:     }
: 
:     sort_by_column \@array, 'L3';
: 
: I don't understand the shift operator and how it moves \@array (a
: reference to an array) and 'L3' into $m and $col. I know the input to
: a subroutine are the elements of @_ but what does shift mean?

From the perlfunc documentation on the shift operator:

    Shifts the first value of the array off and returns it,
    shortening the array by 1 and moving everything down.  If
    there are no elements in the array, returns the undefined
    value.  If ARRAY is omitted, shifts the "@_" array within
    the lexical scope of subroutines . . .

The shifts are plucking off the subroutine's arguments.  To see shift
in action, consider the following:

    [16:15] ant% cat try
    #! /usr/local/bin/perl

    $" = "][";  # separator for interpolating arrays

    @a = ('apples', 'oranges', 'bananas');
    print "[@a]\n";

    $first = shift @a;
    print "\$first = [$first], \@a = [@a]\n";
    [16:15] ant% ./try
    [apples][oranges][bananas]
    $first = [apples], @a = [oranges][bananas]

: The statement return unless ref($m) && @$m && $col; tests to see that
: the reference $m and value $col exist but what's @$m mean? An array
: whose pointer reference starts at $m?

Yes, but your terminology could stand polishing.  (If I seem picky, I'm
only trying to help you learn.)  In Perl parlance, we'd say that we're
making sure -- albeit indirectly -- that $m is an array reference, that
$m's thingy (Perl's pedestrian way of saying 'referent', i.e., the array
to which $m refers) has at least one element, and that we have a column
label to look for.  See the perlref manpage.

We might have written the following

    return unless ref($m) && @$m && $col;

to be more chatty as

    unless ($m && ref($m) eq 'ARRAY') {
        warn "'$m' is not an array reference";
        return;
    }

    unless (@$m > 0) {
        warn "no rows!";
        return;
    }

    if (!defined($col) || $col eq '') {
        warn "no column label!";
        return;
    }

I wrote the check the way I did because sort_by_column operates
in-place, so, at worst, I'd just leave the data alone.  One line was
also a little more appealing than twelve. :-)

There are also lots of hairy philosophical arguments surrounding this
issue such as "defensive programming is bad style because it hides
bugs", but let's not get into all that.

: Also I'm not sure what the expression  @{$m}[1..$#$m] means. 
: obviously a pointer $m to an array but  [1..$#$m]? .

Remember that Perl doesn't have pointers but references.

Perl's .. operator can produce ranges, e.g.,

    % perl -le 'print 0..9'
    0123456789

Recall from the perldata manpage that $#ARRAY gives the index of the
last element of @ARRAY.  For example

    % perl -le '@a = (1..10); print $#a'
    9

(I might be setting a bad example.  mjd, rightly IMHO, says using
$#ARRAY is a red flag[*].  The usage is correct in this case, but
do what I say, not what I do. :-)

[*] http://groups.google.com/groups?selm=3bd70c54.b10%24141%40news.op.net

The perlref manpage shows how to dereference arrays, and $#$m yields the
index of the last element in $m's thingy.  @{$m}[...] takes a slice of
$m's thingy, i.e., a sublist -- see the perldata manpage.

Don't get bogged down in the low-level details.  Think about what we're
trying to do: we want to leave the first row alone (the header) and
sort everything else, i.e., all the rows from index 1 up to the last
index in $m's thingy.  We're operating in-place, so we put the rows back
where we got them:

    @{$m}[1..$#$m] = sort { $a->[$colidx] <=> $b->[$colidx] }
                          @{$m}[1..$#$m];

: Next I don't understand some of the code in the subroutine
: find_column_index:
: 
:     sub find_column_index {
:         my $a = shift;
:         my $col = shift;
: 
:         my $header = $a->[0];
:         my $colidx = 0;
:         for (@$header) {
:             last if $_ eq $col;
:             ++$colidx;
:         }
: 
:         $colidx >= @$header ? () : $colidx;
:     }
: 
: I take it that "my $header = $a->[0];" means store the pointer
: reference of the 'th element into $header?

Yes, we're storing a copy of a reference to the array of column headers.
I used a separate variable to show the code's intent.

:                                            "for (@$header)" means for
: each element of the input array do the below? I didn't know "last"
: would end the loop after the last statement if the "if" statement was
: true. Neat.

Yes.  Perl's last operator is like break in C but cooler.

:             I take it that when you say "for(@$header)" each element
: of the array is stored into $_ one by one in the for loop?

Yes.  See the perlsyn manpage.

: Last what does $colidx >= @$header ? () : $colidx; mean?  If the array
: element number of 'L3' is greater then or equal to ...then I get lost.

That's the ternary operator as in C, sometimes called an "inline if".
See the perlsyn manpage.

That code is checking whether we found a match.  If the condition is
true (no match), then $colidx will be at least as large as the number of
elements in @$header, and we return () or nothing.  Otherwise (what's
after the colon), we send back the desired header's index.

Hope this helps,
Greg
-- 
When I was a boy of fourteen, my father was so ignorant that I could hardly
stand to have the old man around.  But when I got to be twenty-one, I was
astonished at how much he'd learned in seven years.
    -- Mark Twain


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

Date: Sun, 29 Jun 2003 17:53:41 GMT
From: Bernt Levinsson <levin.spambox@telia.com>
Subject: How to create a file
Message-Id: <2r9ufv84uqeieotvfqtah3mo2c40r6cauo@4ax.com>

This I've learned:
open(OUTFILE, ">output.txt");

But, if the file doesn't exists, how can get the file handle to write
to a new file?





http://w1.321.telia.com/~u32102551/


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

Date: Sun, 29 Jun 2003 18:02:50 GMT
From: Michael Budash <mbudash@sonic.net>
Subject: Re: How to create a file
Message-Id: <mbudash-2A00DD.11024929062003@typhoon.sonic.net>

In article <2r9ufv84uqeieotvfqtah3mo2c40r6cauo@4ax.com>,
 Bernt Levinsson <levin.spambox@telia.com> wrote:

> This I've learned:
> open(OUTFILE, ">output.txt");
> 
> But, if the file doesn't exists, how can get the file handle to write
> to a new file?

but it will!

RTFM:

perldoc -f open

-- 
Michael Budash


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

Date: Sun, 29 Jun 2003 13:52:02 -0500
From: Tony Curtis <tony_curtis32@yahoo.com>
Subject: Re: How to create a file
Message-Id: <878yrkaf8t.fsf@limey.hpcc.uh.edu>

>> On Sun, 29 Jun 2003 17:53:41 GMT,
>> Bernt Levinsson <levin.spambox@telia.com> said:

> This I've learned: open(OUTFILE, ">output.txt");

> But, if the file doesn't exists, how can get the file
> handle to write to a new file?

As MD pointed out, this *does* create a new file.

(Modulo suitable permissions of course)

Is this a "stealth" CGI question by an chance?

hth
t


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

Date: Sun, 29 Jun 2003 19:11:45 GMT
From: tiltonj@erols.com (Jay Tilton)
Subject: Re: How to create a file
Message-Id: <3eff385a.672869611@news.erols.com>

Bernt Levinsson <levin.spambox@telia.com> wrote:

: This I've learned:
: open(OUTFILE, ">output.txt");
: 
: But, if the file doesn't exists, how can get the file handle to write
: to a new file?

That capability is built into the ">" mode.  If it fails, Perl can
tell you the reason.

    open(OUTFILE, ">output.txt")
      or die "Cannot open 'output.txt' for write: $!";

Always check the return from open() for success.



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

Date: Sun, 29 Jun 2003 18:41:34 +0000 (UTC)
From: mjd@plover.com (Mark Jason Dominus)
Subject: Re: Module for sorting (while either reading from or writing to) a FH?
Message-Id: <bdnbsu$44n$1@plover.com>

In article <ej0rfvg3vdevforo7hbdb0s9k36k6be3t4@4ax.com>,
Michele Dondi  <bik.mido@tiscalinet.it> wrote:
>Please forgive me for the wording, but I couldn't express myself
>better. 

Other folks answered the technical end of your question.  I'm just
posting to say that I thought the wording was fine, and that your
question was perfectly clear.


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

Date: Sun, 29 Jun 2003 11:49:53 -0400
From: Eric Amick <eric-amick@comcast.net>
Subject: Re: Not following "if"
Message-Id: <qd2ufvsdrqtf4h8lmmei9i61rc6vtf9h5b@4ax.com>

On Sat, 28 Jun 2003 19:05:40 -0500, "Eric J. Roode"
<REMOVEsdnCAPS@comcast.net> wrote:

>Autovivification only happens when you use a nonexistent hash or array 
>element as a reference.  Simply testing whether it's true or not will not 
>cause it to spring into existence.
>
>But yes, it appears that the exists operator is what the OP needs.

Fair enough, but I'm now puzzled about why the OP's original code
doesn't work.  I suppose it must have to do with the value stored in the
hash.

-- 
Eric Amick
Columbia, MD


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

Date: Sun, 29 Jun 2003 11:59:55 -0400
From: Eric Amick <eric-amick@comcast.net>
Subject: Re: Not following "if"
Message-Id: <jn2ufvs50vq65b0u9en46kcmk1dd2dmg7n@4ax.com>

On Sat, 28 Jun 2003 16:25:02 +0200, Stefan Glimne <Snygg@gmx.net> wrote:

>Hello 2 u all,
>
>I have a really interesting problem that I get when I program my 
>html-pages with perl.
>The problem is that the perl-program doesn't follow the if-statement.
>
>1. I get info from a standard text-file database
>2. I store an hash like , $imdblink{$imdbid} = $value , from the
>    database
>3. Then I have a new number $imdbid_new that I want to check if it's in
>    the $imdblink-hash like ,
>    if ($imdblink{$imdbid_new}) {
>      "if it exist then this should happen"
>    } else {
>      "if it doesn't exist then this should happen"
>    }
[snip]
>Here is the example that does not work:
>
>##############################################
>#
># Load Films in FilmDataBase
>#
>$file = "db\\filmdatabase_comp.txt";
>open (INDATA, "$home_dir$file") or die "Can't open $home_dir$file: $!\n";
>while ($line = <INDATA>) {
>   chop $line;

chomp is a better choice.

>   ($key,$value) = split(" = ", $line);
>   $key2 = $filmid . '_' . $key;
>   $filmdatabase{$key2} = $value;
>   if ($key eq "imdblink") {
>     ($key,$imdbid) = split('\?', $line);
>     $imdblink{$imdbid} = $filmid;

Where does $filmid get a value?  If it's uninitialized or 0, that
explains your whole problem--the later if test will always be false,
even if the hash entry exists.  Using exists as we've already suggested
is definitely better than testing the value, but it appears you're
storing the wrong value anyway.

>   }
>}
>close INDATA;

-- 
Eric Amick
Columbia, MD


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

Date: Sun, 29 Jun 2003 19:22:04 GMT
From: ed <coo_t2-NO-LIKE-SPAM@yahoo.com>
Subject: objects vs sub routines in loop
Message-Id: <1feufvc8kch2f5k9h2jpm8ec31m7k50qrl@4ax.com>

Hi all.  I need to create a script that is always going to be running.
So I guess pretty much everything is going to be taking place inside
of 
one main loop.

If I use objects that are lexically scoped within that loop, it means
that 
new objects have to be created at the beginning of every iteration. 

Would using objects be much slower than just calling sub routines?  

If the answer to that is yes.  I wonder if one solution(as a way to
still use OOP)
would be to extend my classes and create a "clear()" method or
something similar 
that would basically set my object back to an uninitialized state. 
Then I reinitialize it at the top of the loop and use it as if it were
a new 
object.

Example:

my $obj = new Obj;
while (!$done)
{   
    $obj->initialize('param1', 'param2');

    $obj->doSomething();
    $obj->doSomethingElse();

    $obj->clear();
}

As opposed to:

while (!$done)
{   
    my $obj = new Obj('param1', 'param2');

    $obj->doSomething();
    $obj->doSomethingElse();
}

-----
Note: In a real situation the parameters to the objects will change
with 
every interation.  I just wanted to keep the examples simple.

----------

Would using the first example speed things up substantially?
Would it still be substantially slower than if I were just calling sub
routines 
instead of creating objects?

Is object creation quick enough in perl that I should not even worry
about it?

tia,
--ed



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

Date: Sun, 29 Jun 2003 19:44:43 GMT
From: Bob Walton <bwalton@rochester.rr.com>
Subject: Re: objects vs sub routines in loop
Message-Id: <3EFF4186.4020304@rochester.rr.com>

ed wrote:

> Hi all.  I need to create a script that is always going to be running.
> So I guess pretty much everything is going to be taking place inside
> of 
> one main loop.
> 
> If I use objects that are lexically scoped within that loop, it means
> that 
> new objects have to be created at the beginning of every iteration. 
> 
> Would using objects be much slower than just calling sub routines?  
> 
> If the answer to that is yes.  I wonder if one solution(as a way to
> still use OOP)
> would be to extend my classes and create a "clear()" method or
> something similar 
> that would basically set my object back to an uninitialized state. 
> Then I reinitialize it at the top of the loop and use it as if it were
> a new 
> object.
> 
> Example:
> 
> my $obj = new Obj;
> while (!$done)
> {   
>     $obj->initialize('param1', 'param2');
> 
>     $obj->doSomething();
>     $obj->doSomethingElse();
> 
>     $obj->clear();
> }
> 
> As opposed to:
> 
> while (!$done)
> {   
>     my $obj = new Obj('param1', 'param2');
> 
>     $obj->doSomething();
>     $obj->doSomethingElse();
> }
> 
> -----
> Note: In a real situation the parameters to the objects will change
> with 
> every interation.  I just wanted to keep the examples simple.
> 
> ----------
> 
> Would using the first example speed things up substantially?
> Would it still be substantially slower than if I were just calling sub
> routines 
> instead of creating objects?
> 
> Is object creation quick enough in perl that I should not even worry
> about it?
> 
 ...
> --ed

Why don't you

     use Benchmark;

and find out the answers to your speed questions on your own objects? 
In my opinion, if you are really really concerned about speed, you 
should probably code in C and forget OO altogether.  It will probably be 
the method calls that slow things down the most, regardless of the OO 
language you code in.  But if your methods themselves do significant 
work, the overhead of the method calls could well be inconsequential.

It seems like you are putting too much emphasis on speed -- by the time 
you complete your project, Moore's law will have made your speed 
problems go away anyhow.

-- 
Bob Walton



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

Date: Sun, 29 Jun 2003 20:44:06 +0200
From: "Alan J. Flavell" <flavell@mail.cern.ch>
Subject: Re: Perl 5.6 and Perl 5.8
Message-Id: <Pine.LNX.4.53.0306291946580.960@lxplus072.cern.ch>

On Sun, Jun 29, Joe Smith inscribed on the eternal scroll:

> There are a lot of things that fail with RedHat-8, straight out of the
> box.

Really?  I honestly don't recall having the problems that you are
describing.  I'm certainly not having them now.

> For instance, the 'man' command.  Instead of hyphens or double
> hyphens, it produces en-dash and em-dash, which do not have
> displayable glyphs in the default font.

This is the font in the (gnome) terminal window, is it? What is your
"default font"?  Mine seems to be Lucida Typewriter. I don't see the
problems you are describing.  Maybe I had changed it from the
installation default without really thinking - I'm not sure.  But
choosing other plausible monospace fonts, I still don't see the
problems you're describing.

> I found that adding this to my .login file helps:
>
>   if ($?LANG) then
>     if ($LANG == en_US.UTF-8) setenv LANG en_US # RedHat-8.0 KDE

Well, my LANG setting is en_GB.UTF-8 - it seems to work well for me.

> Perl-5.8 is sensitive to LANG being set to any UTF setting.

Indeed it is, as part of the move towards Unicode. It's true enough
that the move had a few knock-on effects, but it's the way things are
going: I think I'd recommend coming to terms with it as far as
possible, and only resorting to the backward move as a temporary
workaround while sorting things out properly:

> Try using a non-UTF setting before running your perl programs.

However, see
http://groups.google.com/groups?selm=bcftmm%24k88%241%40news.service.uci.edu

It appears that this specific Perl dependence on LANG will go away
again in 5.8.1.


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

Date: 29 Jun 2003 15:52:15 GMT
From: "A. Sinan Unur" <asu1@c-o-r-n-e-l-l.edu>
Subject: Re: Perl keeps me from throwing up while programming java
Message-Id: <Xns93A978C25B63Dasu1cornelledu@132.236.56.8>

rook_5150@yahoo.com (Bryan Castillo) wrote in 
news:1bff1830.0306290415.59148497@posting.google.com:

> Subject: Perl keeps me from throwing up while programming java
> From: rook_5150@yahoo.com (Bryan Castillo)
> Newsgroups: comp.lang.perl.misc
 ...
> 
>       $type .= " []" if ($array)

FYI, you are missing a semicolon at the end of this line.

Very cute, by the way.

Sinan.

-- 
A. Sinan Unur
asu1@c-o-r-n-e-l-l.edu
Remove dashes for address
Spam bait: mailto:uce@ftc.gov


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

Date: 29 Jun 2003 10:44:10 -0700
From: tivolinewbie@canada.com (Kenjis Kaan)
Subject: Re: perl\site\lib\auto\...  (DLLs, LIB, EXP etc)  to another location under your dev directory?
Message-Id: <6a8ba9f8.0306290944.5c6bbd6e@posting.google.com>

"Randy Kobes" <randy@theoryx5.uwinnipeg.ca> wrote in message news:<P2DLa.20131$I7.30848@news1.mts.net>...
> "Kenjis Kaan" <tivolinewbie@canada.com> wrote in message
>  news:6a8ba9f8.0306282245.3bb9474a@posting.google.com...
> > Would it be possible to move support files under
> > perl\site\lib\auto\...  (DLLs, LIB, EXP etc)  to another location
> > under your dev directory?
> [ ... ]
> If your users are running ActivePerl, you can create a ppm package
> (http://aspn.activestate.com/ASPN/docs/ActivePerl/faq/ActivePerl-faq2.html)
> which users can install with the ppm utility.

> Alternatively, after
> building the package, you could distribute the blib/ directory,
> which users can then include as, eg, 'perl -Mblib ...'.
> 
> best regards,
> randy kobes

Thanks for you reply.  How would you do this second alternative, ie
distribute the blib/ directory.  I guess when you say blib/ you mean
/perl/site/lib
I am in fact using ActivePerl 5.6.x


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

Date: Mon, 30 Jun 2003 05:33:30 +1000
From: "Sisyphus" <kalinabears@hdc.com.au>
Subject: Re: perl\site\lib\auto\...  (DLLs, LIB, EXP etc)  to another location under your dev directory?
Message-Id: <3eff4040$0$22145@echo-01.iinet.net.au>


"Kenjis Kaan" <tivolinewbie@canada.com> wrote in message
news:6a8ba9f8.0306290944.5c6bbd6e@posting.google.com...
> "Randy Kobes" <randy@theoryx5.uwinnipeg.ca> wrote in message
news:<P2DLa.20131$I7.30848@news1.mts.net>...
> > "Kenjis Kaan" <tivolinewbie@canada.com> wrote in message
> >  news:6a8ba9f8.0306282245.3bb9474a@posting.google.com...
> > > Would it be possible to move support files under
> > > perl\site\lib\auto\...  (DLLs, LIB, EXP etc)  to another location
> > > under your dev directory?
> > [ ... ]
> > If your users are running ActivePerl, you can create a ppm package
> >
(http://aspn.activestate.com/ASPN/docs/ActivePerl/faq/ActivePerl-faq2.html)
> > which users can install with the ppm utility.
>
> > Alternatively, after
> > building the package, you could distribute the blib/ directory,
> > which users can then include as, eg, 'perl -Mblib ...'.
> >
> > best regards,
> > randy kobes
>
> Thanks for you reply.  How would you do this second alternative, ie
> distribute the blib/ directory.  I guess when you say blib/ you mean
> /perl/site/lib
> I am in fact using ActivePerl 5.6.x

No, the 'blib' is created when you build a module from source.

for(@INC) {print $_, "\n"}

If you run that you'll normally find that there are 3 @INC folders - your
'/perl/lib/' folder, your '/perl/site/lib/' folder, and '.', which is the
current working directory.

If you're script uses a module called Bogus::Rubbish, then perl will look
for Rubbish.pm in the '$INC[0]/Bogus/' folder, then the '$INC[1]/Bogus/'
folder, and lastly the '$INC[2]/Bogus/' folder (ie './Bogus/').

It will look for Rubbish.dll in the
'$INC[0]/auto/Bogus/Rubbish/' folder, then the
'$INC[1]/auto/Bogus/Rubbish/' folder, and lastly in the
'$INC[2]/auto/Bogus/Rubbish/' folder.

So you would need to ensure that Rubbish.pm and Rubbish.dll are installed in
one of those locations on the user's PC.

Alternatively you could insist that the user place Rubbish.pm in
'C:/some_folder/Bogus/' and Rubbish.dll in
'C:/some_folder/auto/Bogus/Rubbish/' - and include in the script that they
are running:
use lib 'C:/some_folder';

(see perldoc lib.)

Hth.

Cheers,
Rob






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

Date: Sun, 29 Jun 2003 15:28:47 -0500
From: "Randy Kobes" <randy@theoryx5.uwinnipeg.ca>
Subject: Re: perl\site\lib\auto\...  (DLLs, LIB, EXP etc)  to another location under your dev directory?
Message-Id: <YZHLa.20647$I7.31747@news1.mts.net>

"Kenjis Kaan" <tivolinewbie@canada.com> wrote in message
news:6a8ba9f8.0306290944.5c6bbd6e@posting.google.com...
> "Randy Kobes" <randy@theoryx5.uwinnipeg.ca> wrote in message
news:<P2DLa.20131$I7.30848@news1.mts.net>...
> > "Kenjis Kaan" <tivolinewbie@canada.com> wrote in message
> >  news:6a8ba9f8.0306282245.3bb9474a@posting.google.com...
> > > Would it be possible to move support files under
> > > perl\site\lib\auto\...  (DLLs, LIB, EXP etc)  to another location
> > > under your dev directory?
> > [ ... ]
> > Alternatively, after
> > building the package, you could distribute the blib/ directory,
> > which users can then include as, eg, 'perl -Mblib ...'.
>
> Thanks for you reply.  How would you do this second alternative, ie
> distribute the blib/ directory.  I guess when you say blib/ you mean
> /perl/site/lib
> I am in fact using ActivePerl 5.6.x

As Rob mentioned, the blib directory is created within
the package's source directory upon building. This isn't
meant to be a permanent solution, but in principle, what
you could do is transfer the entire blib directory to some other
machine (which runs the same Perl version as the original),
and then run your script as
    perl -Mblib your_script
or
    perl -Mblib=dir your_script
depending on where you put the blib directory. This adjusts
@INC so as to include the appropriate directories under blib.
See 'perldoc blib' for more details.

best regards,
randy





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

Date: Sun, 29 Jun 2003 18:39:16 +0000 (UTC)
From: mjd@plover.com (Mark Jason Dominus)
Subject: Re: URL checking
Message-Id: <bdnbok$42n$1@plover.com>

In article <6522b540.0306281641.4bbf5b23@posting.google.com>,
Mandy <mandy100@ihug.com.au> wrote:
>Hi.
>I can't seem to find any examples that will help me learn how to check
>2 things using a perl script.
>
>1. Does a given page exist on a remote site
>e.g.  If i want to check that my homepage's pictures.html page exists.

I usually use the LWP::Simple module for that.  First install the
module by running the command:

        perl -MCPAN -e 'install LWP::Simple'


Once you have LWP::Simple, you can use it to check for a page this
way:

        use LWP::Simple;

        if (head($url)) {
          # it seems to exist 
        } else {
          # not
        }

>2. Does a page contain a url that I specify
>e.g. does my pictures.html page contain a link to my diary.html page

Similarly, you can use LWP::Simple to fetch the page's content, and
then search through it looking for the link.  Try

        use LWP::Simple;
        use HTML::LinkExtor;  # "Link Extractor"

        my $content = get($url);
        if (defined $content) {
          my $found = 0;
          HTML::LinkExtor->new(sub { my $tag, %links = @_;
                                     for (values %links) {
                                       $found = 1 if $_ eq "diary.html";
                                     }         
                                   }, $url)
                         ->parse($content);
          if ($found) { 
            # found it
          } else {
            # didn't find it
          }
        }



Good luck.



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

Date: 29 Jun 2003 15:47:34 GMT
From: "A. Sinan Unur" <asu1@c-o-r-n-e-l-l.edu>
Subject: Re: Yet another "undefined reference to `_WinMain@16'" in cygwin
Message-Id: <Xns93A977F70DDAAasu1cornelledu@132.236.56.8>

dejanews@email.com (Sam Denton) wrote in
news:3c863a7a.0306290538.58310144@posting.google.com: 

> "A. Sinan Unur" <asu1@c-o-r-n-e-l-l.edu> wrote in message
> news:<Xns93A8676006B3Dasu1cornelledu@132.236.56.8>... 
>> dejanews@email.com (Sam Denton) wrote in
>> news:3c863a7a.0306272123.2b827030@posting.google.com: 

>> I am only asking this because I do not see a `shared' flag anywhere,
>> and it looks like, from the line
>> 
>> > LD_RUN_PATH="/usr/local/lib" g++  -s -L/usr/local/lib Plotter.o
>> 
>> you are stripping symbols. Again, I am no expert on cygwin, but those
>> look like problem spots to me. Have you tried asking this question on
>> the cygwin mailing list?
>> 
>> Sinan.
> 
> Ah, this did the trick!
> 
 ...
> 
> Adding the '-shared' flag works!  I did not have to remove the '-s'
> flag, and I was able to remove the dummy 'main()' as well.
> 
> Thank you for your assistance.

Glad it worked out. You are welcome.

Sinan.
-- 
A. Sinan Unur
asu1@c-o-r-n-e-l-l.edu
Remove dashes for address
Spam bait: mailto:uce@ftc.gov


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

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


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