[7329] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 954 Volume: 8

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sun Aug 31 17:07:11 1997

Date: Sun, 31 Aug 97 14:00:28 -0700
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, 31 Aug 1997     Volume: 8 Number: 954

Today's topics:
     Re: A module to my cgi-bin dir <rootbeer@teleport.com>
     Re: cgi ( disk space available ) ---> html <rootbeer@teleport.com>
     Re: changing dir of parent shell (Andrew M. Langmead)
     Re: changing dir of parent shell <godzilla@futuris.net>
     Re: duplicate problems.. (Andrew M. Langmead)
     Re: Filtering CR & CRLF from text input <nospam@domain.com>
     Re: FTP with perl (Paul Buder)
     getting time accuracy in miliseconds (Michael Q. Le)
     Re: getting time accuracy in miliseconds <rootbeer@teleport.com>
     Re: Is there a perl IDE? (stephen benson)
     Re: my scoping, 5.002 vs 5.004 (Andrew M. Langmead)
     Re: my scoping, 5.002 vs 5.004 (Eric Arnold)
     Pattern matching problem with \n (Ha_Ha_X)
     Re: perl and XEmacs (Terje Bless)
     Perl field validating... <marauder@morepower.com>
     Re: Perl field validating... <rael@zx80.dnai.com>
     Perl Web Search required <jerryp.usenet@SPAMconnected.demon.co.uk>
     Re: Perl Web Search required (Jim Michael)
     Re: Questions about passing by reference. (dave)
     Re: Reading a data file <rootbeer@teleport.com>
     stand-alone perle apps? (Mark E. Crane)
     Re: struct in perl <fawcett@nynexst.com.spam-me-not>
     Trouble with DBM files (webmaster@vmirror.com)
     Use with if statements (J. Paul Reed)
     Re: Use with if statements <fawcett@nynexst.com.spam-me-not>
     Re: Use with if statements <rootbeer@teleport.com>
     Re: Use with if statements (Eric Arnold)
     Re: using unix commands for missing libwww module <rael@zx80.dnai.com>
     Version of leafnode in Perl? <bruce@cenderis.demon.co.uk>
     Digest Administrivia (Last modified: 8 Mar 97) (Perl-Users-Digest Admin)

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

Date: Sun, 31 Aug 1997 09:55:42 -0700
From: Tom Phoenix <rootbeer@teleport.com>
To: Aitor <dmedia@vzc.servicom.es>
Subject: Re: A module to my cgi-bin dir
Message-Id: <Pine.GSO.3.96.970831094954.15641W-100000@julie.teleport.com>

On Sun, 31 Aug 1997, Aitor wrote:

> How may I upload a module (CGI.pm & libwww) to my cgi-bin directory?
> 
> I've got a mac. Upload to a unix server.

You'll need to find out from your webmaster how to do this at your site,
but it usually involves an FTP client such as Fetch for the Mac. Be sure
to use Text mode for text files (which scripts and modules are), so that
they will be properly converted from Mac text to Unix text.

Of course, the usual way to get those files onto your Unix machine is to
use that machine to get their source distributions from CPAN; that's done
with standard Unix utilities such as ftp and tar. In fact, if CGI.pm is
not available already, you should complain to your webmaster - it's
standard with Perl 5.004, which you should be running. 

So the best solution to your problem may be to ask your webmaster to
install those modules for you. That's the way I like to do it. :-) 

Good luck!

-- 
Tom Phoenix           http://www.teleport.com/~rootbeer/
rootbeer@teleport.com  PGP   Skribu al mi per Esperanto!
Randal Schwartz Case:  http://www.rahul.net/jeffrey/ovs/



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

Date: Sun, 31 Aug 1997 09:36:41 -0700
From: Tom Phoenix <rootbeer@teleport.com>
To: "David J. Thomas" <thomasdj@wam.umd.edu>
Subject: Re: cgi ( disk space available ) ---> html
Message-Id: <Pine.GSO.3.96.970831093201.15641T-100000@julie.teleport.com>

On Sat, 30 Aug 1997, David J. Thomas wrote:

> I have a cgi generated webpage that shows various stats. I would like to
> show how much disk space I have available as well.

You'll need to find out your system's method to determine the available
disk space; it's different on different machines. You might be able to use
a module from CPAN if you're trying to determine your quota, though. 

    http://www.perl.com/CPAN/

Hope this helps!

-- 
Tom Phoenix           http://www.teleport.com/~rootbeer/
rootbeer@teleport.com  PGP   Skribu al mi per Esperanto!
Randal Schwartz Case:  http://www.rahul.net/jeffrey/ovs/



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

Date: Sun, 31 Aug 1997 14:08:59 GMT
From: aml@world.std.com (Andrew M. Langmead)
Subject: Re: changing dir of parent shell
Message-Id: <EFs7B0.A9v@world.std.com>

[a copy of this article as e-mailed to the cited author.]
Les Schaffer <godzilla@futuris.net> writes:

>tadmc@flash.net (Tad McClellan) writes:

>> I guess you missed it when you checked the Perl FAQ before posting to
>> the Perl newsgroup.

>i guess you havent read that part of the FAQ yourself, or you'd know
>how little info there is there.

>so fella, do you have a better answer? i figured out one way to solve
>the problem after getting a helpful hint from another poster.

Les, if you going to try defend _NOT_ reading the FAQ, keep me and
what I post out of it. My article gave the exact same information that
the FAQ, that it wasn't something that could be done without
cooperative help between the parent and the child process.

On the other hand, I can see how someone can miss a section of the
FAQ, or think that their question can't be a frequently asked one. So
on simple answers, I'll often put an answer, or the rough outline of
the answer along with the pointer to the FAQ. (If the explaination is
a little more complex, then I don't want to waste my time re-writing
the explanation that Tom Christiansen has already wrote. His answer is
probably better written and since the FAQ has been around longer than
an answer that I post, it has a better chance of being accurate.)

If you had read the FAQ, and it didn't help you, at least your
question would have been different, a little more
knowledgable. Something along the lines of "How do I get a perl script
to communicate with bash to tell bash which directory to change to
once the script exits."

-- 
Andrew Langmead


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

Date: 31 Aug 1997 16:00:01 -0400
From: Les Schaffer <godzilla@futuris.net>
Subject: Re: changing dir of parent shell
Message-Id: <m2iuwmxgvy.fsf@futuris.net>

Russ Allbery <rra@stanford.edu> writes:

> The FAQ *does* give a reference to the comp.unix.questions FAQ, and in
> fact question 2.8 of that FAQ is:

yes, that answer is more detailed. its also SUBSTANTIALLY what i
posted in my originally query; viz, i had already been sourcing a bash
script. In fact, after some prompting from elsewhere, i wrapped a call
to my perl script in a source'd bash script -- which seems ugly.

BTW, for the benefit of the silent majority, the comp.unix.questions
FAQ points to:

ftp://ftp.wg.omron.co.jp/pub/unix-faq/docs/script-vs-env

which has EVERYTHING you need IF YOU ARE SATISFIED WITH SHELL SCRIPTS
being a part of the solution.

anyway, now that i needed to rewrite the bulk of that original script
in perl, my question stands unanswered by the FAQs:

can i get my perl script to change the directory of the parent (bash)
shell, THAT DOES NOT INCLUDE SOURCING A BASH SHELL SCRIPT (WRAPPER)?
 -- u.c. added for improved clarity.

* If you have SOLVED this problem, please let me know. 
    - i get the feeling now maybe no-one has. is it WORTH solving?

* If there is a way to modify bash and/or perl so that the parent
* environment CAN be influenced by a child process at certain times, let
* me know. 
    - requires IPC stuff? for example, xemacs can send a URL to
    - netscape. (yes, i know they are not parent and child, but they ARE
    - processes)

* Is there another working environment besides the shell where parent
* and child processes are more easily in communication? 
    - (x)emacs shell environment with some lisp coding?

* If it cant be solved: ie, the answer is no (only 2 bytes required),
* "just say no".
    - \116\117

* If you are interested in being FAQ police, write me privately (or
* publicy if you prefer) and i will share my views on FAQ/USENET
* politics with YOU.



later

les schaffer


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

Date: Sun, 31 Aug 1997 18:53:33 GMT
From: aml@world.std.com (Andrew M. Langmead)
Subject: Re: duplicate problems..
Message-Id: <EFsKH9.3Du@world.std.com>

Zaheed Haque <zaheed.haque@ein.ericsson.se> writes:

>As you can see the third item here in some places are duplicates..
>I am trying to clean the list in the following logic.. 

Hashes are great data structures to use to weed out duplicates. You
put items that need to be unique as the key, and you'll only get one,
no matter how many times its been re-assigned.

In a very simplistic way, something like this:

while(<>) {
  ($name, $number) = (split /\|/)[2,4];
  print unless $seen{"$name$number"}++;  
}

But unfortunately, this will fail when two different $name and $number
patterns will concatinate into the same key. (Like if one record had
"Type1", and a value of "234", and another had "Type", and "1234".)
Older perl's got around this with "multi-dimensional array emulation",
which turned an expression like "$seen{$name,$number}" into
 "$seen{join($; ,$name, $number)}" where the value of the "$;"
variable is an unprintable control character you are very unlikely to
come accross when reading and manipulating text files.

Perl 5 gave even a more accurate solution by allowing true
multi-dimensional arrays,

$seen{$name}{$number}++;

But before you learn about multidimensional array, you need at least a
tenuous grasp of the perl concept of "references", which a lot of
people don't consider a novice concept.
-- 
Andrew Langmead


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

Date: Sun, 31 Aug 1997 09:55:31 -0400
From: John Nolan <nospam@domain.com>
Subject: Re: Filtering CR & CRLF from text input
Message-Id: <340977D3.13B7@domain.com>

Bart Lateur wrote:
> "Carey Barnett" <cbarnett@idirect.com> wrote:
> >I'm new to Perl, but isn't this the 'chomp()' function EXACTLY!
> 
> You didn't understand the question quite right. Chomp remove the CRLF
> from the END of a line.
> 
> The problem was how to remove CRLF's from WITHIN a text field, with
> multiline text, where the user used the return key to preformat his
> text. The question was how to turn this back into one single line.


I pasted some code here to do what you asked.  

You're a newbie, I forgive you, but this was really elementary.
You definitely need to buy a Perl book.  
Look up "regular expressions," and start reading.  :) 


#--------------------------------------------------------
# You can use split and chomp if you want.  This is less obvious. 

$text = "This is line one. \n This is line two, \nand this is line 3.
\n";

@text = split /\n/, $text;  # creates an array, where each newline 
                            # in the original string is the last char 
                            # in a member of the array

chomp(@text);               # This munges the array, chopping the 
                            # newline from the end of each member
                            # of the array. 

print @text;                # Print the array. 


#--------------------------------------------------------
# You can also use a very simple regex.  

$othertext = "This is line one. \n This is line two, \nand this is line
3. \n";

$othertext =~ s/\n//g;      # This strips out all CRLF's.  Peanuts. 

print $othertext;

#--------------------------------------------------------

--
## John Nolan
## jpn acm org


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

Date: 31 Aug 1997 10:45:27 -0700
From: paulb@linda.teleport.com (Paul Buder)
Subject: Re: FTP with perl
Message-Id: <5ucajn$qvc$1@linda.teleport.com>

In <5u3sks$qeq$1@solaris.cc.vt.edu> mweber@vt.edu (Matt Weber) writes:

>Is there an easy perl script or module for FTPing something?  It needs to be 
>able to run on its own....log itslef in....transfer files and close the socket.  
>The running on its own part will be done with crontabs.  Any suggestions?

As others have pointed out there is Net::FTP.  But if you don't want
to get that a quick hack is like

system("ftp -i -n somewhere.com <<EOD
user yourname yourpassword
cd /somewhere
get something
quit
EOD
");


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

Date: 31 Aug 1997 16:00:59 GMT
From: lem@ece.ucdavis.edu (Michael Q. Le)
Subject: getting time accuracy in miliseconds
Message-Id: <5uc4fr$pl1$1@mark.ucdavis.edu>

Hello,

Is there a way to measure elapsed time in miliseconds? I am
trying to measure the time between sending and receiving
a packet from a server and want the delay.  It's basically
a "ping" function. Is there a way to do this?  The functions
in perl seem to only have resolution in seconds.

Thanks for any help,

-- 
--------------------------------------------------------------------
 Michael Q. Le                      Office: (916) 752-6347
 Solid State Circuits Research Lab  Fax:    (916) 752-8428
 Dept. of Electrical Engineering    University of California, Davis

 Powered by Debian GNU/Linux
   http://junior.ece.ucdavis.edu    lem@junior.ece.ucdavis.edu
--------------------------------------------------------------------


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

Date: Sun, 31 Aug 1997 10:08:17 -0700
From: Tom Phoenix <rootbeer@teleport.com>
To: "Michael Q. Le" <lem@ece.ucdavis.edu>
Subject: Re: getting time accuracy in miliseconds
Message-Id: <Pine.GSO.3.96.970831100732.15641X-100000@julie.teleport.com>

On 31 Aug 1997, Michael Q. Le wrote:

> Is there a way to measure elapsed time in miliseconds? 

    http://www.perl.com/CPAN/doc/FAQs/FAQ/html/perlfaq8/
          How_can_I_measure_time_under_a_s.html

Hope this helps!

-- 
Tom Phoenix           http://www.teleport.com/~rootbeer/
rootbeer@teleport.com  PGP   Skribu al mi per Esperanto!
Randal Schwartz Case:  http://www.rahul.net/jeffrey/ovs/



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

Date: Sun, 31 Aug 1997 19:00:22 GMT
From: stephenb@scribendum.win-uk.net (stephen benson)
Subject: Re: Is there a perl IDE?
Message-Id: <3409be45.40915433@nntp.ibmpcug.co.uk>

  What emacs for Win32 are you using (and where can I get it); it's a
while  since I used one, and I know there's quite a few. I remeber
liking Pearl's  WinEmacs, but that was a while ago.
  



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

Date: Sun, 31 Aug 1997 14:38:58 GMT
From: aml@world.std.com (Andrew M. Langmead)
Subject: Re: my scoping, 5.002 vs 5.004
Message-Id: <EFs8oy.J2u@world.std.com>

colink@latticesemi.com (Colin Kuskie) writes:

>Running this under 5.002 produces no warnings of any kind.  However, 5.004_03
>says:
>"my" variable $var masks earlier declaration in same scope at try line 9.

>Here's my quandry:
>1)using use strict is a good thing

Yes it it.

>2)that says I need to use my

No, it doesn't. It says that variables must be either:

1. Lexically local scoped via my().

2. A fully qualified global, that is $A::Foo::Bar::var.

3. Marked as exempt from "use strict" by the "use vars" directive,
like "use vars qw/$var/;".

>3)my causes different scoping than unmy'ed variables

As designed.

>I can also think of 3 or 4 different solutions to this problem, (the easiest is
>not to declare different packages in the same file).  But why doesn't package
>define a new lexical scope?

Because package directives define the default symbol table that a
(global) variable is put into, and variables declare via my() aren't
put into the symbol table.

Package variables (and their runtime manipulation by the local()
function) and my() lexically scoped variables affect variables in
different ways.  Package variables are affected by the current
package, and by when they are accessed at runtime. my() variables are
affected by the block scopes that the compiler processes at compile
time. (with the largest scope being the file, not the package.) Their
purposes rarely conflict.
-- 
Andrew Langmead


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

Date: 31 Aug 97 20:11:51 GMT
From: eric.arnold@sun.com (Eric Arnold)
Subject: Re: my scoping, 5.002 vs 5.004
Message-Id: <ERIC.97Aug31201151@m-e-ir1.sun.com>


Geez, somebody should change the "pod" page (and FAQ) to make this
point stand out better (it's buried in the middle of a paragraph, and
the full implications aren't immediately apparent).  It really causes
severe consternation until you understand it (especially since we
encountered it prior to "use vars ...").

-Eric


In article <EFs8oy.J2u@world.std.com>
	aml@world.std.com (Andrew M. Langmead) writes:
  >colink@latticesemi.com (Colin Kuskie) writes:
  >
  >>Running this under 5.002 produces no warnings of any kind.  However, 5.004_03
  >>says:
  >>"my" variable $var masks earlier declaration in same scope at try line 9.
  >
  >>Here's my quandry:
  >>1)using use strict is a good thing
  >
  >Yes it it.
  >
  >>2)that says I need to use my
  >
  >No, it doesn't. It says that variables must be either:
  >
  >1. Lexically local scoped via my().
  >
  >2. A fully qualified global, that is $A::Foo::Bar::var.
  >
  >3. Marked as exempt from "use strict" by the "use vars" directive,
  >like "use vars qw/$var/;".
  >
  >>3)my causes different scoping than unmy'ed variables
  >
  >As designed.
  >
  >>I can also think of 3 or 4 different solutions to this problem, (the easiest is
  >>not to declare different packages in the same file).  But why doesn't package
  >>define a new lexical scope?
  >
  >Because package directives define the default symbol table that a
  >(global) variable is put into, and variables declare via my() aren't
  >put into the symbol table.
  >
  >Package variables (and their runtime manipulation by the local()
  >function) and my() lexically scoped variables affect variables in
  >different ways.  Package variables are affected by the current
  >package, and by when they are accessed at runtime. my() variables are
  >affected by the block scopes that the compiler processes at compile
  >time. (with the largest scope being the file, not the package.) Their
  >purposes rarely conflict.
  >-- 
  >Andrew Langmead


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

Date: Sun, 31 Aug 1997 17:12:26 GMT
From: spam-yourself@127.0.0.1 (Ha_Ha_X)
Subject: Pattern matching problem with \n
Message-Id: <3409a313.6314342@netnews.nyu.edu>

I'm writing a script that takes a series of strings, scans them for
'\n', '\t', and '\\\\' (two backslashes), and replaces each of them
with physical newlines, tab characters, and backslashes respectively.
In other words, I'm trying to read strings in and process C-style
escape sequences in those strings.

The natural way to solve this would be with pattern matching, using
something like this:

    $somestring =~ s/\n/"\n"/g ;   # replace '\n' with newline
    $somestring =~ s/\t/<tab>/g ;  # replace '\t' with tab
    $somestring =~ s/\\/\/g ;      # replace double backslash with
                                   # single backslash

where <tab> is a physical tab character. Of course, the backslash has
special meanings in pattern matching strings, and that's my problem. I
can't come up with a substitution that does what I want it to.

My current workaround is to use colons instead of backslashes, i.e.--

    $somestring =~ s/:n/\n/g ;
    $somestring =~ s/:t/\t/g ;
    $somestring =~ s/::/:/g ;

But I don't want to do this, especially since this is a port of a C
program and I want to be able to use the old data files. Can anyone
come up with a solution for this problem?

Thanks in advance...

~k.lee


h a - h a - x_/ \_/ \_/ \_   Webfoot, New Ink: 
                / \_/ \_/ \_ http://www.nyu.edu/pubs/new.ink
kql6708@is.nyu.edu  \_/ \_/ \_     Visit the Radiohead Mailing List FAQ:
http://members.aol.com/hahax/ \_   http://members.aol.com/hahax/rhfaq/


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

Date: Sun, 31 Aug 1997 15:23:35 +0200
From: link@tss.no (Terje Bless)
Subject: Re: perl and XEmacs
Message-Id: <link-3108971523350001@news.uit.no>

In article <uowyb5jl52i.fsf@tremere.ecte.uswc.uswest.com>,
    rjray@uswest.com (Randy J. Ray) wrote:

>Are regex's hard to read? Yes.
>Does Perl improve this?   No.

I disagree. Perl's Regular Expression syntax is the most legible of all
implementations I've seen thus far (but I haven't by far seen `em all so
YMMV). The addition of embedded comments in 5.003 has once and for all
disspelled the myth that Perl code vaguely resembles line noise.


m{              # Start of the m(atch) operator.
    [Rr]andy            # upper or lower -case in case Randy gets sloppy

    \s                  # followed by a space

    ([Jj]\. )?          # possibly followed by middle initial, period and space

    [Rr]ay              # Deal with caseless last name
}x;              # End of m(atch) for R.J.'s name.

Compare: "[Rr]andy\s([Jj]\.\s)?[Rr]ay".

They are exactly the same regex, but the first is written for maintainer
efficiency and the second for programmer efficiency.

And then my favourite from perlop:

    # Delete C comments.
    $program =~ s(
                    /\*     # Match the opening delimiter.
                    .*?     # Match a minimal number of characters.
                    \*/     # Match the closing delimiter.
                 ){}gsx;

Which could be written as "s/\/\*.*?\*\///gs".


Just for the record, I'm of the opinion that:

        "You can write bad code in any language"

:-)

-- 
Party? Party, lord? Yes, lord. Right away, lord.
        - Beopunk Cyberwulf


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

Date: 31 Aug 1997 20:24:10 GMT
From: "Mike Cisar" <marauder@morepower.com>
Subject: Perl field validating...
Message-Id: <5ucjta$2jp@nr1.calgary.istar.net>

 Am doing some CGI work in PERL and have come to a point in the project
where the client wants to validate fields (ie.  is phone number in format
(xxx) yyy-zzzz, zipcode is xxxxx or xxxxx-yyyy, email addresses are
xxx@yyy.zzz , etc, etc, etc)

Before I go reinventing the wheel, does anyone have any libraries or can
give any hints/tips on accomplishing this task.

Thanks,
>>>>> Mike <<<<<





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

Date: 31 Aug 1997 13:55:47 -0700
From: Rael Dornfest <rael@zx80.dnai.com>
Subject: Re: Perl field validating...
Message-Id: <87oh6edqcs.fsf@zx80.dnai.com>


"Mike Cisar" <marauder@morepower.com> writes:

>  Am doing some CGI work in PERL and have come to a point in the project
> where the client wants to validate fields (ie.  is phone number in format
> (xxx) yyy-zzzz, zipcode is xxxxx or xxxxx-yyyy, email addresses are
> xxx@yyy.zzz , etc, etc, etc)
> 
> Before I go reinventing the wheel, does anyone have any libraries or can
> give any hints/tips on accomplishing this task.

Not exactly a perl-esque suggestion, but if can assume the use of
browsers supporting JavaScript, you might take a look at Netscape's
formchek.js library at:

http://developer.netscape.com/library/examples/javascript/formval/overview.html

Rael

---------------------------------------------------------------------------
/Rael Dornfest/                                     <title>Webmaven</title>
                              %company = (DNAI => 'Direct Network Access');
print <<ADDRESS;
2039 Shattuck Avenue, Suite 206                           To: rael@dnai.com
Berkeley, CA 94704                                 atdt 888 321 3624 (DNAI)
ADDRESS                           <a href="http://www.dnai.com">Website</a>


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

Date: Sun, 31 Aug 1997 16:30:58 +0100
From: Jerry Pank <jerryp.usenet@SPAMconnected.demon.co.uk>
Subject: Perl Web Search required
Message-Id: <4kmeOBAy4YC0Ew8$@connected.demon.co.uk>

To enhance my non-existent knowledge of sockets I am looking for an 
example of a perl program that will recursively search a remote URL for 
say *.html, list finds and give me the opportunity to download to my 
browser.  I have studied various examples in O'Reilly books but am still 
unsure of the methodology required to do all of the above.


Armed with a good example I am confident I can reverse engineer it and 
re-write it so it looks like road-kill!  

The only way to learn !

Any help gratefully received - this group provides me with an daily 
reading material!  Thanks everyone.
-- 
This post in every-way totally reflects the views of my employer...

I am he.

Jerry           jerryp dot usenet at connected dot demon dot co dot uk

Warning - Wash out the spam filter.


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

Date: Sun, 31 Aug 1997 18:53:52 GMT
From: genepool@netcom.com (Jim Michael)
Subject: Re: Perl Web Search required
Message-Id: <genepoolEFsKHs.F4H@netcom.com>

Jerry Pank (jerryp.usenet@SPAMconnected.demon.co.uk) wrote:
: To enhance my non-existent knowledge of sockets I am looking for an 
: example of a perl program that will recursively search a remote URL for 
: say *.html, list finds and give me the opportunity to download to my 

Do a web search for webcopy.

Cheers,

Jim


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

Date: Sun, 31 Aug 1997 12:58:59 GMT
From: over@the.net (dave)
Subject: Re: Questions about passing by reference.
Message-Id: <34096a39.504376@news.one.net>

Tom Phoenix <rootbeer@teleport.com> wrote:

>On Fri, 29 Aug 1997, Peter de Vroomen wrote:
>
>> In my program I try to pass array's and hash-tables by reference as much
>> as possible, because I presume passing a reference to a large array is
>> much faster than passing the array itself (passing them to a subroutine
>> that is..). 
>
>Yes, it is faster. Passing them to other things than subs is faster by
>reference as well! :-)
>
>> I want to create an array inside a function and then pass the reference
>> to the array to the caller. I don't want to create a global array, and
>> creating a 'my' array is one of the most stupid things I could do, 
>
>Why would that be stupid? That's acceptable Perl, to return a reference to
>a variable which is going out of scope. The variable will stay around,
>although you can no longer reference it by name (of course).
>
Tom,

Your explanations are very good.  Thanks.

Dave

|
| Please visit me at http://w3.one.net/~dlripber
|
| For reply by email, use:
| dlripber@one.net
|________


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

Date: Sun, 31 Aug 1997 09:40:47 -0700
From: Tom Phoenix <rootbeer@teleport.com>
To: John <jimison@vision.net.au>
Subject: Re: Reading a data file
Message-Id: <Pine.GSO.3.96.970831093730.15641U-100000@julie.teleport.com>

On 31 Aug 1997, John wrote:

> I was wondering, how do I read a data file?

I usually use the line input operator, which looks like <FOO>, and is
documented in the perlop(1) manpage in the section about IO operators. You
may also need the open function, documented in the perlfunc(1) manpage. 

> Say I have a file called: data.txt and it contains
> 
> 1101|Book of RA|24.95|IN
> 1102|Fnord Hunting|12.95|OUT
> 
> How could I read for example, 24.95 in the first line? Or
> 1102 in the second line?

You'll probably want to split your input with the split function,
documented in the perlfunc(1) manpage.

Hope this helps!

-- 
Tom Phoenix           http://www.teleport.com/~rootbeer/
rootbeer@teleport.com  PGP   Skribu al mi per Esperanto!
Randal Schwartz Case:  http://www.rahul.net/jeffrey/ovs/



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

Date: 31 Aug 1997 16:26:02 GMT
From: mecran01@homer.louisville.edu (Mark E. Crane)
Subject: stand-alone perle apps?
Message-Id: <5uc5uq$ml$1@hermes.louisville.edu>


I'm burning 400 images on a cd rom for use by faculty at our school.  The
end product will be running on windows 3.1.

Can someone tell me if it is possible to put a Perl-based crawler and
search engine on the cd-rom that will look through the images (actually,
the html that accompanies each image) and let users search for stuff by
topic/keyword?

How tough would this be to do?

Would I have to have some sort of standalone server burned on the disk
that would run cgi scripts?

thanks,




-- 
M. Crane
University of Louisville



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

Date: 31 Aug 1997 13:58:50 -0400
From: Tom Fawcett <fawcett@nynexst.com.spam-me-not>
Subject: Re: struct in perl
Message-Id: <8jwwl21bfp.fsf@nynexst.com.spam-me-not>

bill <bill@dml0.wcupa.edu> writes:
> okay, sorry if this is a stupid question, but how do i do a struct in 
> perl?  i don't want to use the pack/unpack stuff 'cause i don't want to 
> have to do that for each record i look at.  i just want to be able to 
> say...
> array_of_recs[i].first_name = "bill";

A naive translation would be:
$array_of_recs[$i]{'first_name'} = "bill";

There might be more intelligent ways of coding it, depending on what you're 
doing.  There is at least one struct package in the CPAN, also.

-Tom


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

Date: Sun, 31 Aug 1997 13:40:58 GMT
From: webmaster@vmirror.com (webmaster@vmirror.com)
Subject: Trouble with DBM files
Message-Id: <3409727e.2306040@news.digex.net>

I have some cripts that I've been usinf for well over a year that
store some stats in dbm files and later create html pages from the
stats.

All of a sudden I am getting this error message when perl tries to
open the dbm files:
No dbm on this machine at try.pl line 2.

Here's all there is in try.pl:
#! /bin/perl
dbmopen(%LINES,"./97_08_logdbm", 0666);
dbmclose(LINES);
exit;

In the past, it never had a problem opening, or if the file didn't
exist already irt would create it. 

My system (Sun) creates both a *.pag file and a *.dir file for each
dbm file.  In the above case, there are 97_08_logdbm.pag and
97_08_logdbm.dir.

The files definitely are there, it seems to be some sort of system
wide thing because I have about 12 scripts dealing with 12 different
dbm files that are all failing with the same error.

We're using Perl 5.003 and it hasn't been changed in months.

It is possible, though unlikely, that  someone changed something else
on this machine. 

Does anyone have any idea what would cause this?

Thanks for the help!

Spike Hernandez
webmaster@vmirror.com







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

Date: 31 Aug 1997 10:49:47 GMT
From: preed@psd.k12.co.us (J. Paul Reed)
Subject: Use with if statements
Message-Id: <5ubi8b$jsr$1@mercury.psd.k12.co.us>

Hey Perl people:

This is my code:

if ($var) {
require "lib.pl";
} else {
use Package;
}


Unfortunately, my script fails because it can't find Package.pm on this
particular system; of course, that was the whole point of putting this if
statement in there, so how do I make perl not barf over this and actually
use the if statement.

Could I use something like AutoLoader (or whatever it's called)?

TIA!

Later,
Paul

P.S. To the perl.com people: nice redesign!
   -------------------------------------------------------------------
   J. Paul Reed                 preed@psd.k12.co.us || paul@619pro.com
   Computer, you and I need to have a little talk...
                     --Chief Miles O'Brien, "Emissary," Star Trek: DS9
   Geek Code and various other frivolities at www.psd.k12.co.us/~preed


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

Date: 31 Aug 1997 09:40:24 -0400
From: Tom Fawcett <fawcett@nynexst.com.spam-me-not>
Subject: Re: Use with if statements
Message-Id: <8jen7ao4hj.fsf@nynexst.com.spam-me-not>

preed@psd.k12.co.us (J. Paul Reed) writes:
> This is my code:
> 
> if ($var) {
> require "lib.pl";
> } else {
> use Package;
> }
> 
> Unfortunately, my script fails because it can't find Package.pm on this
> particular system; of course, that was the whole point of putting this if
> statement in there, so how do I make perl not barf over this and actually
> use the if statement.

use is a compile-time statement, not run-time.
If you want it to run at run-time you'll have to do
eval("use Package");

-Tom


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

Date: Sun, 31 Aug 1997 09:48:28 -0700
From: Tom Phoenix <rootbeer@teleport.com>
To: "J. Paul Reed" <preed@psd.k12.co.us>
Subject: Re: Use with if statements
Message-Id: <Pine.GSO.3.96.970831094148.15641V-100000@julie.teleport.com>

On 31 Aug 1997, J. Paul Reed wrote:

> if ($var) {
> require "lib.pl";
> } else {
> use Package;
> }

[ Just a note to clarify a potentially confusing word: One 'use's a
module, not a package. ]

As you've found; that doesn't do what it looks like, since 'use' is a
compile-time directive. The solution is (probably) to wrap your code in a
BEGIN block, so that it will be done at compile time. Then change the
'use' to its equivalent require & import, something like this. 

    BEGIN {
	if ($var) {
	    require "lib.pl";
	} else {
	    require Module;
	    import Module;
	}
    }

You should probably check out the details on 'use' in the perlfunc(1)
manpage, to be sure of what this does and whether it suits your needs.

Hope this helps!

-- 
Tom Phoenix           http://www.teleport.com/~rootbeer/
rootbeer@teleport.com  PGP   Skribu al mi per Esperanto!
Randal Schwartz Case:  http://www.rahul.net/jeffrey/ovs/



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

Date: 31 Aug 97 19:35:24 GMT
From: eric.arnold@sun.com (Eric Arnold)
Subject: Re: Use with if statements
Message-Id: <ERIC.97Aug31193524@m-e-ir1.sun.com>


You might consider doing something like this:

  BEGIN {
    eval{ use whatever };
    if ( $@ )
    {
      eval{ require "lib.pl" };
      if ( $@ )
      {
	die "Just can't get no....";
      }
    }
  }

-Eric

In article <5ubi8b$jsr$1@mercury.psd.k12.co.us>
	preed@psd.k12.co.us (J. Paul Reed) writes:
  >Hey Perl people:
  >
  >This is my code:
  >
  >if ($var) {
  >require "lib.pl";
  >} else {
  >use Package;
  >}
  >
  >
  >Unfortunately, my script fails because it can't find Package.pm on this
  >particular system; of course, that was the whole point of putting this if
  >statement in there, so how do I make perl not barf over this and actually
  >use the if statement.
  >
  >Could I use something like AutoLoader (or whatever it's called)?
  >
  >TIA!
  >
  >Later,
  >Paul
  >
  >P.S. To the perl.com people: nice redesign!
  >   -------------------------------------------------------------------
  >   J. Paul Reed                 preed@psd.k12.co.us || paul@619pro.com
  >   Computer, you and I need to have a little talk...
  >                     --Chief Miles O'Brien, "Emissary," Star Trek: DS9
  >   Geek Code and various other frivolities at www.psd.k12.co.us/~preed


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

Date: 31 Aug 1997 13:23:32 -0700
From: Rael Dornfest <rael@zx80.dnai.com>
Subject: Re: using unix commands for missing libwww module
Message-Id: <87u3g6druj.fsf@zx80.dnai.com>


[posted & mailed]

bob@cafemedia.com (Bob Maillet) writes:

> I am trying to get the following snippet of code to work..  The server I
> am currently working on does not have the libwww module installed so I am
> using unix commands to read the data from a remote sight..then parse out
> that data.
> I still have to enter a newline command when the script is run and the
> data does not display..any ideas?

Bob,

You should grab a copy of the libwww module and make it in your
own filespace -- add the path to @INC and you're in business.

Rael

---------------------------------------------------------------------------
/Rael Dornfest/                                     <title>Webmaven</title>
                              %company = (DNAI => 'Direct Network Access');
print <<ADDRESS;
2039 Shattuck Avenue, Suite 206                           To: rael@dnai.com
Berkeley, CA 94704                                 atdt 888 321 3624 (DNAI)
ADDRESS                           <a href="http://www.dnai.com">Website</a>


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

Date: 31 Aug 1997 19:37:30 +0100
From: Bruce Stephens <bruce@cenderis.demon.co.uk>
Subject: Version of leafnode in Perl?
Message-Id: <m3g1rqurkl.fsf@cenderis.demon.co.uk>

Why do I want leafnode in Perl?

Well, just because I'd like to be able customize it more.  Once it's
got some headers, for some groups, I'd like to be able to throw away
articles that are crossposted too much, or those that came from
certain domains.  Or (since this is only me), for some groups I'd like
to say "download no more than 100 articles", or perhaps limit it on
volume "stop after receiving 100K" (possibly this would be easier
working by lines, depending on what NNTP can provide).  Generally, I'd
like it to be more flexible than the current configuration.  

I can understand why it's not like that now: it's designed not just
for individuals, but for very small sites.  Looking through the module
list, this looks not too hard to do, pretty much just stringing
existing modules together.  (I'd guess it would be quite sufficient to
replace "fetch", whilst leaving the other bits (like "leafnode"
itself) as they are.)

So it should be pretty easy: has anybody done this?  (I can also
understand why nobody in the US would be very interested, but some of
us have to pay for phone calls by the minute!)


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

Date: 8 Mar 97 21:33:47 GMT (Last modified)
From: Perl-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 8 Mar 97)
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.misc (and this Digest), send your
article to perl-users@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.

The Meta-FAQ, an article containing information about the FAQ, is
available by requesting "send perl-users meta-faq". The real FAQ, as it
appeared last in the newsgroup, can be retrieved with the request "send
perl-users FAQ". Due to their sizes, neither the Meta-FAQ nor the FAQ
are included in the digest.

The "mini-FAQ", which is an updated version of the Meta-FAQ, is
available by requesting "send perl-users mini-faq". It appears twice
weekly in the group, but is not distributed in the digest.

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 V8 Issue 954
*************************************

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