[7239] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 864 Volume: 8

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Aug 14 00:08:02 1997

Date: Wed, 13 Aug 97 21:00:24 -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           Wed, 13 Aug 1997     Volume: 8 Number: 864

Today's topics:
     Re: ??  perl5  ?? problem installing (Mike Stok)
     Amending A database [help] (Ranson)
     Re: associative array question (Tad McClellan)
     Re: complex argument passing (Mike Stok)
     Re: dbmopen  key and value (help, sort of urgent) (Tim  Smith)
     Re: getting variables <burleigh@hackberry.chem.niu.edu>
     Re: global string searches (Greg Bacon)
     Had trouble comparing 2 files using File::Compare bz7347275@ntu.edu.sg
     Re: HELP NEEDED <burleigh@hackberry.chem.niu.edu>
     Re: Insecure dependency in glob (Greg Bacon)
     Re: Is it possible to use HTPASSWD within Perl? <pwiseman@mindspring.com>
     Re: jumping to a URL <pwiseman@mindspring.com>
     Name of NT Port that also runs in Win32s (win 3.1)? (Richard Puckett)
     Need help accessing tty modem devices within perl!!! <nreit00@mail.gpbx.net>
     Re: Need help! (Greg Bacon)
     Re: Newbie Question re: <SELECT> menu & search results <burleigh@hackberry.chem.niu.edu>
     Re: Novice scratches head <stuartc@ind.tansu.com.au>
     Re: Random Number question (Greg Bacon)
     Re: random numbers (Greg Bacon)
     Re: Script testing (Ranson)
     Re: Seeking object enlightenment (Greg Bacon)
     Someone Want a Challenge? (Ranson)
     Re: sorting... (Greg Bacon)
     Re: Traverse ~~ Heres a question for you! (Greg Bacon)
     Variable substitution into a regexp <stefano.bonacina@st.com>
     Digest Administrivia (Last modified: 8 Mar 97) (Perl-Users-Digest Admin)

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

Date: 14 Aug 1997 02:24:16 GMT
From: mike@stok.co.uk (Mike Stok)
Subject: Re: ??  perl5  ?? problem installing
Message-Id: <5stq8g$j92@news-central.tiac.net>

In article <5srgac$t9j@internal.sa.gov.au>,
Andrew Galdes <galdes.andrew@pi.sa.gov.au> wrote:
>G'day,
>I am another one of those people having trouble with perl5. i am got a
>version for DOS (16bit) but it didn't work at all. i would like to
>know if there are any woking versions of PERL5 out there (preferably
>for 16bit PC. WIN95 would also be nice. Couls anyone send me a ZIP of
>perl which might be what i want? Thanks for your time.

Do any of the ports under http://www.perl.com/CPAN/ports/win95/ look
reasonable to you?  Tom's machien should get you to a "nearby" CPAN
mirror.

Hope this helps,

Mike



-- 
mike@stok.co.uk                    |           The "`Stok' disclaimers" apply.
http://www.stok.co.uk/~mike/       |   PGP fingerprint FE 56 4D 7D 42 1A 4A 9C
http://www.tiac.net/users/stok/    |                   65 F3 3F 1D 27 22 B7 41
stok@psa.pencom.com                |      Pencom Systems Administration (work)


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

Date: 14 Aug 1997 00:27:39 GMT
From: ranson@infoave.net (Ranson)
Subject: Amending A database [help]
Message-Id: <5stjdr$gjt@news1.infoave.net>


Greetings,   

	I have a challenge that I have no idea how to do.  I am 
writing a shoping cart program for a gem dealer and have to 
amend the data every time someone orders a stone or stones.
So that the quantity available is always correct to the user.
The fields [7] are comma delinated, and the last field is the quantity.

Some tips on doing this would be greatly appricated. A sample of the 
data is below.

If anyone wants to look at the program it is at:
http://www.corpsite.com/jgcom/home.htm

20600:African Amethyst:6mm Rd:20600.jpg:2.75:each:50



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

Date: Wed, 13 Aug 1997 20:19:32 -0500
From: tadmc@flash.net (Tad McClellan)
Subject: Re: associative array question
Message-Id: <4fmts5.qec.ln@localhost>

Jon Marshall (xkn14@dial.pipex.com) wrote:

: i am looping through a number of projects one at a time. i am adding up
: the total size of the files in each project while at the same time adding
: up
: the size of groups of similar files within the project. all this is fine -
: i end
: up with an associative array with the type of file being the key to the
: size.

: ie. 

: @filetypes = qw( 3dv cd 3dh );

: foreach $project ( @projects ) {
:     @files = `find /disk/seisworks/*/$project -type f -ls`;
:     for ( @files ) {
:          ($size,$name) = (split)[6,10];   
:          foreach $type ( @filetypes ) {
:              if ( $name =~ /$type$/ ) { 
:                  $count{$type} += $size;
:              }
:          }
:          $totalsize += $size;
:     }


      printf "%20s %12d ", $project, $totalsize; # this is going to end up
      foreach (@filetypes) {                     # up being a pretty darn
         printf "%16s %12d ", $_, $count{$_};    # long line...
      }
      print "\n";


: }
: the problem comes in printing - is there an easy way to print the project
: name, the total, and the sizes of the files on the same line in a nice
: format-


--
    Tad McClellan                          SGML Consulting
    tadmc@flash.net                        Perl programming
    Fort Worth, Texas


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

Date: 14 Aug 1997 02:29:23 GMT
From: mike@stok.co.uk (Mike Stok)
Subject: Re: complex argument passing
Message-Id: <5stqi3$jhk@news-central.tiac.net>

In article <bkhiltonEEuuMC.EEM@netcom.com>,
Brand and Karina Hilton <bkhilton@netcom.com> wrote:
>In article <5spo1l$dcn@news-central.tiac.net>,
>Mike Stok <mike@stok.co.uk> wrote:
>>
>>Probably the easiest thing to do for some arbitrary function in C is to
>>write an extension using either XS or swig where the extension language
>>helps you pass parameters between perl and a C and return values back. 
>
>Ok, I give up.  What's swig?

swig(1)     Simplified Wrapper and Interface Generator    swig(1)

NAME
       swig  -  produce  scripting  language wrapper code from an
       interface specification file

SYNOPSIS
       swig [ options ] file.i

DESCRIPTION
       swig generates wrapper  code  needed  to  integrate  C/C++
       functions  and variables with Tcl, Perl, Python, and Guile
       and produces documentation.  Consult the SWIG user  manual
       for more details.

[...]

RESOURCES
       SWIG   documentation   and   updates   are   available  at
       http://www.cs.utah.edu/~beazley/SWIG

Hope this helps,

Mike

-- 
mike@stok.co.uk                    |           The "`Stok' disclaimers" apply.
http://www.stok.co.uk/~mike/       |   PGP fingerprint FE 56 4D 7D 42 1A 4A 9C
http://www.tiac.net/users/stok/    |                   65 F3 3F 1D 27 22 B7 41
stok@psa.pencom.com                |      Pencom Systems Administration (work)


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

Date: 13 Aug 1997 18:53:01 -0700
From: trs@azstarnet.com (Tim  Smith)
Subject: Re: dbmopen  key and value (help, sort of urgent)
Message-Id: <5stodt$piu@web.azstarnet.com>

In article <01bca817$2a0b5070$6e6fa1cd@www>,
Ryan <rmcguigan@ramresearch.com> wrote:
>Right now I'm using dbmopen to store data, is there anyway to have
>something more than $key and $value, such as multiple records?  If not
>possible, I would have to emulate it somehow, any suggestions.  

What kind of data are you storing?  Could something as simple as
using a delimiter, like "\t", to separate different fields in each
record work?  Like this:

# assume that %DB is tied to your database file
# and $key has your key value and @fields have your fields

$DB{$key} = join "\t", @fields;

# later on...

@fields = split /\t/, $DB{$key};


Enjoy,

Tim



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

Date: Wed, 13 Aug 1997 22:00:08 -0500
From: Darin Burleigh <burleigh@hackberry.chem.niu.edu>
Subject: Re: getting variables
Message-Id: <33F274B8.3E6B@hackberry.chem.niu.edu>

Rick Bauman wrote:
> 
> I have RTFM's and faq's and camel, 

 YAY.

>but I still can't figure this one
> out . . . maybe someone out there can help.

it would help if you told us which part you're having trouble with.
otherwise, it would seem as if you want somebody else to do 
all your work for you?

I would do something like:

open(IN blahblahblah ...;

while( <IN> ) {
   if ( /^\S+/ ) {  # assuming no space before name...
      ($name, $line1 ) = split;   # -- assuming split on whitespace

        # test name, line1
       }
    else {
       $n++;
       # -- test line 'n'
       }
    }



> 
> I need to read in a flatfile text database that looks similar to this
> 
> somename            somerandomtext
>                              secondlineoftext
>                              thirdline of text
> 
> somename            some random text
>                              second line of text
>                              thirdline of text
>                              fourthlineof text
> 
> the records may be of different lengths, and there are about 1200
> records
> 
> I need to search for a string and. . .
> 
> if it is not present return a value of "0"
> 
> if it shows up in the "somename" field return a value of "1"
> 
> if it shows up on the first line of the record, but not in the
> "somename" portion return a value of "2"
> 
> if it shows up in any other line of text, in any record  return a value of "3"
> 
> if it shows up more than once in any record return a value of "4"
> 
> and if it shows up in more than one record return a value of "5"
> 
> and in all cases return the "somename" of the record in which it was
> found . . . . does anybody have an idea where I can find some good
> info on how to do this?
> 
> thanks
> 
> Rick
> rick@internetx.net

-- 
==========================================================
 - darin
burleigh@hackberry.chem.niu.edu
\\//\\//.\\//\\//.\\//\\//. http://hackberry.chem.niu.edu/HOME/dcb/
 '2 kinds of green, look out!' - dieter rot


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

Date: 14 Aug 1997 02:58:39 GMT
From: gbacon@cs.uah.edu (Greg Bacon)
To: Mwolak@wesleyan.edu
Subject: Re: global string searches
Message-Id: <5sts8v$de9$7@info.uah.edu>

[Posted and mailed]

In article <33F1A7DA.80A96115@wesleyan.edu>,
	Matt Wolak <Mwolak@wesleyan.edu> writes:
: I am currently writing a program that extracts info from pdb (a chemical
: format) files. Is it 'legal' to search in the same string you are doing
: a global search on ie:
: 
: while($str =~ /whatever(.{3})/g){
:     $temp = $1;
:     if($str =~ /somethingelse $temp/){      #Not really what I'm tring
:         print("yes")
:     }
: }
: 
: or does this mess up the global searches pointer?

Beware: failed /g searches reset the scalar's pos.  If you don't want
this behavior, use the cool new /c modifier to m//, as in this example
from the perlop(1) manpage:

    # using m//gc with \G
    $_ = "ppooqppqq";
    while ($i++ < 2) {
        print "1: '";
        print $1 while /(o)/gc; print "', pos=", pos, "\n";
        print "2: '";
        print $1 if /\G(q)/gc;  print "', pos=", pos, "\n";
        print "3: '";
        print $1 while /(p)/gc; print "', pos=", pos, "\n";
    }

Do it without /c, and note the difference.

Hope this helps,
Greg
-- 
open(G,"|gzip -dc");$_=<<EOF;s/[0-9a-f]+/print G pack("h*",$&)/eg
f1b88000b620f22320303fa2d2e21584ccbcf29c84d2258084
d2ac158c84c4ece4d22d1000118a8d5491000000
EOF


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

Date: Thu, 14 Aug 1997 11:24:05 -0800
From: bz7347275@ntu.edu.sg
Subject: Had trouble comparing 2 files using File::Compare
Message-Id: <33F35B54.5F0ED3A2@iris.eee.ntu.ac.sg>

Hi,

    I was trying to compare 2 files which are actually the same but i
found out
    that 1 file actually contains an "eof" and 1 doesn't.

    How can i take away the eof from the file?

    use File::Compare;

    if (compare("file1","file2") == 0) {
        print "identical";
    }

Thks.
Benny
bz7347275@ntu.edu.sg



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

Date: Wed, 13 Aug 1997 22:27:34 -0500
From: Darin Burleigh <burleigh@hackberry.chem.niu.edu>
Subject: Re: HELP NEEDED
Message-Id: <33F27B26.4CDC@hackberry.chem.niu.edu>

David Torre wrote:
> 
> L'ASSOCIATION MONDIALE DES ENTREPRENEURS (WORLD WIDE ENTREPRENEURS
> ASSOCIATION) would like to borrow assets such as Treasury Bills,
> stocks, bonds, etc., as enhancements for our financial statement.
> 
> The assets would not be traded, sold, pledged, or in any way
> encumbered.
> 
> If you could help us, please send an e-mail to "amde@citenet.net" with
> some details.  Also include a phone number and time you could be
> reached if you don't mind.
> 
> Thank you,
> 
> L'ASSOCIATION MONDIALE DES ENTREPRENEURS


I  think you want the International::Fraud module.
HTH.

-- 
==========================================================
 - darin
burleigh@hackberry.chem.niu.edu
\\//\\//.\\//\\//.\\//\\//. http://hackberry.chem.niu.edu/HOME/dcb/
 '2 kinds of green, look out!' - dieter rot


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

Date: 14 Aug 1997 02:34:22 GMT
From: gbacon@cs.uah.edu (Greg Bacon)
To: Wilter Borba <wborba@bse.com.uy>
Subject: Re: Insecure dependency in glob
Message-Id: <5stqre$de9$3@info.uah.edu>

[Posted and mailed]

In article <871483122.7356@dejanews.com>,
	Wilter Borba <wborba@bse.com.uy> writes:
:  # untaint file_spec
:  $file_spec =~ /^(\w*)$/;         # <<< line 94
:  $untainted = $1;
:  @all_files = glob($untainted);   # <<< line 96
: 
: I tried others expressions in line 94, but always get an error:
: "Insecure dependency in glob while running setuid at /dev/fd/3 line 96."

Globbing is a bad idea if security is an objective.  It's probably best
to roll your own.

    opendir DIR, '/home/httpd/pages' or die "Failed opendir: $!\n";
    @html_files = grep { /\.html$/ } readdir DIR;
    closedir DIR;

You get the added benefit of not being bitten by files named something
like "/tmp/foo\n/etc/passwd".

Hope this helps,
Greg
-- 
open(G,"|gzip -dc");$_=<<EOF;s/[0-9a-f]+/print G pack("h*",$&)/eg
f1b88000b620f22320303fa2d2e21584ccbcf29c84d2258084
d2ac158c84c4ece4d22d1000118a8d5491000000
EOF


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

Date: Wed, 13 Aug 1997 22:41:22 -0400
From: Patrick Wiseman <pwiseman@mindspring.com>
Subject: Re: Is it possible to use HTPASSWD within Perl?
Message-Id: <33F27052.728D4AC1@mindspring.com>

TIM ARMBRUSTER wrote:
> 
> I am trying to generate user names and passwords for per-directory access
> within a Perl script

I've used the following subroutine -- your form cgi script obviously
must provide the variables.  $HTPASSWD is the path to htpasswd,
$AUTH_DIR the directory in which .htpasswd rssides.

sub htpasswd {
        open(PASSWD,"|$HTPASSWD $AUTH_DIR/.htpasswd $in{username}
>/dev/null 2>&1") or return(0); # one line
        print PASSWD "$in{passwd1}\n";
        print PASSWD "$in{passwd1}\n";
        close PASSWD;
} # end htpasswd


Patrick


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

Date: Wed, 13 Aug 1997 22:47:32 -0400
From: Patrick Wiseman <pwiseman@mindspring.com>
Subject: Re: jumping to a URL
Message-Id: <33F271C4.F5D5AC37@mindspring.com>

Sam Mingolelli wrote:

> When the program gets into a specific subroutine I would like to
> instruct the browser to jump to a designated URL.  Anyone have any ideas
> as to how to do this?

print "Location:$URL\n\n";

where $URL is the FULL URL to which you wish to jump.

Patrick


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

Date: 14 Aug 1997 02:28:34 GMT
From: smedit@access5.digex.net (Richard Puckett)
Subject: Name of NT Port that also runs in Win32s (win 3.1)?
Message-Id: <5stqgi$2la$1@news2.digex.net>

Does anyone know the name of a putative PERL 4.X port for Windows NT that
is also supported in the Win32s environment? Supposedly it runs in Windows
3.1 with the standard Windows GUI.  I was assured that such a port is
available, but I have not been able to find it. 

(Note: I have tried perl32.zip, bperl4x.zip and bigperl; it's not any of
these.)


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

Date: 14 Aug 1997 03:24:51 GMT
From: "Nick Reitman" <nreit00@mail.gpbx.net>
Subject: Need help accessing tty modem devices within perl!!!
Message-Id: <01bca860$f4fbca00$6dab9cce@Pnreit00>

Is there anyway to use the open command to open a connection to a modem. I
need to write a program that send some characters to the modem like
at&b0
atz
at&b1
when I try a command like
open (MODEM, ">/dev/ttyA00");
the program stops.
If anyone can help I would really apprreciate it!


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

Date: 14 Aug 1997 02:37:53 GMT
From: gbacon@cs.uah.edu (Greg Bacon)
Subject: Re: Need help!
Message-Id: <5str21$de9$4@info.uah.edu>

In article <slrn5v3vmf.2sk.sami@d246a.mtalo.ton.tut.fi>,
	sami@d246a.mtalo.ton.tut.fi (Sami Sandqvist) writes:
: Have you considered that the users should only be able to read their
: own mailboxes? In that case, check out $ENV{MAIL} and $ENV{LOGNAME}
: etc. You may find something useful if the users have a default shell
: on your ISP.

If the permissions on their mailbox aren't sufficiently private, what's
to stop someone from invoking a Useful Use of Cat? :-)

Greg
-- 
open(G,"|gzip -dc");$_=<<EOF;s/[0-9a-f]+/print G pack("h*",$&)/eg
f1b88000b620f22320303fa2d2e21584ccbcf29c84d2258084
d2ac158c84c4ece4d22d1000118a8d5491000000
EOF


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

Date: Wed, 13 Aug 1997 22:14:25 -0500
From: Darin Burleigh <burleigh@hackberry.chem.niu.edu>
Subject: Re: Newbie Question re: <SELECT> menu & search results
Message-Id: <33F27811.986@hackberry.chem.niu.edu>

Jo Ann wrote:
> 
> Hi!  I'm trying to edit Selena Sol's database manager for a record store.
> So far, so good, but I've implemented a Select Menu to help narrow
> down search results, and now I am having trouble getting accurate search
> results.

hmmm, sounds like a question for either the author, or 
for the CGI newsgroup.

HTH.

> If you select "ALL" from the select menu, it *will* display *all* of the
> records.
> If you select one of the categories, it will show all records within that
> category.
> In this sense, the select menu works just fine. Granted, I don't know what value

==========================================================
 - darin
burleigh@hackberry.chem.niu.edu
\\//\\//.\\//\\//.\\//\\//. http://hackberry.chem.niu.edu/HOME/dcb/
 '2 kinds of green, look out!' - dieter rot


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

Date: 14 Aug 1997 12:59:33 +1000
From: Stuart Cooper <stuartc@ind.tansu.com.au>
Subject: Re: Novice scratches head
Message-Id: <yeo90y5cvvu.fsf@kudu.ind.tansu.com.au>

mccurdy@rohan.sdsu.edu (Mike McCurdy) writes:

> My understanding was that perl would treat these variables as integers 
> when used like this. Given that $x's value is not equal to 100000, why is 
> $x being printed? TIA ... 
> 
> 
> #!/usr/local/bin/perl
> $x = system "/usr/bin/sar -r 1 | tail -1 | cut  -c26-32";
> if ($x == 100000) {
>         print $x;   
> }
> 
  $x isn't being printed. You're seeing the output of the command you're 
systeming. What you should do is this:

$x=`/usr/bin/sar -r 1 | tail -1 | cut  -c26-32`;
if ($x == 100000) {
	print "Wow: $x";
}

* The `` backquotes gobbles the output into the variable $x
* system " " still sends the output to the screen/stdout and returns the exit 
  status into $x; *not* the value returned by sar -r

Cheers,

Stuart Cooper
stuartc@ind.tansu.com.au


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

Date: 14 Aug 1997 03:08:19 GMT
From: gbacon@cs.uah.edu (Greg Bacon)
To: temp.ed.vanderbush@bentley.com
Subject: Re: Random Number question
Message-Id: <5stsr3$de9$8@info.uah.edu>

[Posted and mailed]

In article <33F1B4F6.7AD7@bentley.com>,
	Ed Vander Bush <temp.ed.vanderbush@bentley.com> writes:
: I am tring to choose a random 20 digit number and make sure that is
: already hasn't been used (he lit of used ones is in a file. I can chhose
: a random number rand 99999999999999999999  but that will give my numbers
: other than 20 digits. How can I make sure it hasn't been used. Thanks.


    ## read random numbers from file into %random

    {
        $rand = join '', map { int rand 10 } 1 .. 20;
 
        redo if exists $random{$rand};
        $random{$rand}++;
    }

Once you're out of that naked block, $rand will contain a random
20-digit number that hasn't yet been used.

Hope this helps,
Greg
-- 
open(G,"|gzip -dc");$_=<<EOF;s/[0-9a-f]+/print G pack("h*",$&)/eg
f1b88000b620f22320303fa2d2e21584ccbcf29c84d2258084
d2ac158c84c4ece4d22d1000118a8d5491000000
EOF


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

Date: 14 Aug 1997 02:46:37 GMT
From: gbacon@cs.uah.edu (Greg Bacon)
To: david1@earthlink.net
Subject: Re: random numbers
Message-Id: <5strid$de9$5@info.uah.edu>

[Posted and mailed]

In article <5ssmo1$lm4@chile.earthlink.net>,
	david1@earthlink.net (David Cheitel) writes:
: I am familiar with the rand function but I need to generate 15 random numbers 
: from a range of 1 to 30 that are unique from each other. The rand function 
: does not guarantee this.

If you want unique AND random (neither implies the other):

    do { $random{int(rand 30) + 1}++ } until scalar(keys %random) == 15;

Perl tip: When you think uniq(ue)?, you should immediately think hash.

: Please reply to david1@earthlink.net

Why should you get a free private consultation? :-)

Hope this helps,
Greg
-- 
open(G,"|gzip -dc");$_=<<EOF;s/[0-9a-f]+/print G pack("h*",$&)/eg
f1b88000b620f22320303fa2d2e21584ccbcf29c84d2258084
d2ac158c84c4ece4d22d1000118a8d5491000000
EOF


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

Date: 14 Aug 1997 01:07:21 GMT
From: ranson@infoave.net (Ranson)
Subject: Re: Script testing
Message-Id: <5stlo9$jvp@news1.infoave.net>

In article <33f1ad04.425243357@igate.hst.moc.com>
zawodny@hou.moc.com (Jeremy D. Zawodny) wrote:

> [cc'd automagically to original author]
> 
> On Wed, 13 Aug 1997 02:47:25 -0400, "Shane P. Miles"
> <yngwie@erols.com> wrote:
> 
>>    Where can I get a hold of a personal web server so I can try out my
>>scripts?  I've searched with very little luck.

O'Riley has a great server for win 95 or NT I use it on my machine at home.

Ranson
> 
> Uhm, that really depends what Operating System you're running. Both
> Microsoft and Netscape have products for Win32 based systems.
> 
> Linux & other Unix users could use Apache.
> 
> Check in the comp.infosystems.www.servers* groups and see what's out
> there...
> 
> Jeremy
> -- 
> Jeremy Zawodny
> Internet Technology Group
> Information Technology Services
> Marathon Oil Company, Findlay Ohio
> 
> http://www.marathon.com/
> 
> Unless explicitly stated, these are my opinions only--not those of my employer.





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

Date: 14 Aug 1997 02:29:19 GMT
From: gbacon@cs.uah.edu (Greg Bacon)
To: bart.mediamind@tornado.be (Bart Lateur)
Subject: Re: Seeking object enlightenment
Message-Id: <5stqhv$de9$2@info.uah.edu>

[Posted and mailed]

In article <33f58ba0.7079942@news.tornado.be>,
	bart.mediamind@tornado.be (Bart Lateur) writes:
: Which brings me to... modules, "use" etc.
: 
: I just cannot get a feel for it. Packages and "require" are easy. Can
: somebody please (pretty please) demistify pragma's,

Pragmata are, by nature, mystical.  Demystifyication requires a fairly
good knowledge of perl's guts.

: and explain exactly
: what's happening when a program encounters either "use" or "no"?
:
: A simple explanation (like Randal's explanation about "bless") might do
: wonders for people still clingling on to Perl4-isms... :-)

Such an explanation is in the perlfunc(1) manpage.  Search for
`use Module'.  If you have 5.004, you can invoke perldoc -f use.

Here's a simple example:

----

[21:24] oreo% cat Hello.pm 
package Hello;
 
require Exporter;
 
@ISA = qw( Exporter );
@EXPORT = qw( say_hello );
 
sub say_hello { print "Hello, world!\n" }
[21:25] oreo% cat try
#! /usr/bin/perl -w
 
use Hello;
 
say_hello;
[21:25] oreo% ./try
Hello, world!

----

Exporter (read about it with perldoc Exporter) is handy because it
has a default import method so you don't have to roll your own.  The
perlmod(1) manpage has lots of info on this sort of thing as well.
The documentation is your friend.  Read the documentation! :-)

Hope this helps,
Greg
-- 
open(G,"|gzip -dc");$_=<<EOF;s/[0-9a-f]+/print G pack("h*",$&)/eg
f1b88000b620f22320303fa2d2e21584ccbcf29c84d2258084
d2ac158c84c4ece4d22d1000118a8d5491000000
EOF


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

Date: 14 Aug 1997 00:58:19 GMT
From: ranson@infoave.net (Ranson)
Subject: Someone Want a Challenge?
Message-Id: <5stl7b$kvj@news1.infoave.net>


Hi all,    I have a counter statistic program that is driving me nuts!  The 
log file [ CountLogs/today.log ] keeps erasing itself, starting the count over. 
Sometimes once a day, sometimes 15 times a day, sometimes it runs
flawlessly for months.  BTW this is SSI. But will run stand alone.

I have tryed everything - obvously not - and nothing seems to make a
difference. I have 1000's of pages and ~100 or more use various counters 
and none ever screw up, except this one. This keeps the count for today,
grand total, and the counts for the previous 30 days.   I know it is not too 
kosher, but I felt it was necessary to post the whole script. 

If anyone figures this one out please email me. 

Thanks to all.

Ranson

                                               ### *** *** ###

#!/usr/bin/perl

# *by Ranson Johnson 
# *Last Modified: 01/08/97
# Counter script for page statistics

# This file: new_stat.cgi

# Associated Files:
# today.log
# new_total.log
# stats.cgi


# Enter the complete path for the stats.cgi
$stats_cgi = 'http://www.rlaj.com/cgi-rlaj/stats/stats.cgi';

# What is the name of the count log?
$count_log = 'statscount.log';

# Do you want the counter centered?  1 = yes   0 = no
$center = 1;

# Do you want the count to be displayed in a table?   1 = yes  0 = no
$table = 1;

# Text that appears before the count number
$before = "Total visitors to this page: ";

# Text that appears after the count number
$after = "";

# You can change the font color for the counter 000000 = Black
$font_color = "<FONT COLOR=\"000000\">";

# You can chang the font size of the counter text
$font_size = "<FONT SIZE=\"3\">";


# Enter the information you want on the bottom of the page
$bottom_of_page = "<CENTER>Copyright 1996/1997 all rights reserved</CENTER><P>";



                                               ### *** *** ###


$day_no = `date +"%e"`; 	# Day of month - 5
chop ($day_no);

$today = `date +"%j"`; 		# Day of year - 156
chop ($today);
$today =~ s/\n//;

$shortmonth = `date +"%b"`; 	# Abbreviated month name - Jan
chop ($shortmonth);

  # A loop for the file locking
$quit = 0;
while ($quit != 1) {
   # If lockfile exist, then someone is already writing to the file
   if (-e "/.filelock") {
      # We'll take a 1 seconds nap
      sleep(1);
   }
   else {
      # Now we're cooking ...
      # Create a lock file
      open(LOCK, ">/.filelock");
      close LOCK;


                           ### *** *** ###

# Open log and get count
               
	open LOG,"CountLogs/stats.log";    #$count_page.log";  
	@log_lines = <LOG>;
	close LOG;

	foreach $line (@log_lines){

# Add 1 to the log number for current hit
        	
        $next_number = $line +1; 
      }
     


# Open log and print new count

	open LOG,">CountLogs/stats.log";    #$count_page.log";    
        print LOG "$next_number";
	close LOG;


                           ### *** *** ###


open (TODAY, "CountLogs/today.log");
@lines = <TODAY>;
close (TODAY);
foreach $line (@lines)

  	 {

   	 #chop $line;
   	 ($logday, $loghit, $logtotal) = split(/:/,$line);
    
  	 }

$new_hit = $loghit + 1;

$GrandTotal = $logtotal + 1;

               ### *** Open log for output *** ###

if ($today == $logday) {

open (Today, ">CountLogs/today.log");

	print Today "$today:";
	print Today "$new_hit:";
	print Today "$GrandTotal\n";

close (today);

}

if ($today > $logday) {

open (Today, ">CountLogs/today.log");

	print Today "$today:";
	print Today "1:";
	print Today "$GrandTotal\n";

close (today);

}




                             ### *** *** ###

open (TOTALS, "new_total.log");
@LINES = <TOTALS>;
close (TOTALS);


open (TOTALS_LOG,">new_total.log"); 

if($today eq $logday){


        print TOTALS_LOG "<TR><TH><b>$shortmonth $day_no</b></TH>";
	print TOTALS_LOG "<TH><b>$new_hit</b></TH>";
	print TOTALS_LOG "<TH><b>$GrandTotal</b></TH></TR>\n";


foreach $line (@LINES[1..29]){
	print TOTALS_LOG "$line";

	}

 }

if ($today > $logday) {

        print TOTALS_LOG "<TR><TH><b>$shortmonth $day_no</b></TH>";
	print TOTALS_LOG "<TH><b>1</b></TH>";
	print TOTALS_LOG "<TH><b>$GrandTotal</b></TH></TR>\n";


foreach $line (@LINES[0..29]){
	print TOTALS_LOG "$line";

	}


} # End of if($today 
      

 close (TOTALS_LOG); 



                             ### *** *** ###

open (MAINLOG, ">>main.log");

print MAINLOG "$GrandTotal - $ENV{'HTTP_REFERER'}\n";

close (MAINLOG);




#################### DONE WRITING TO FILE


      # Unlock the file
      unlink("/.filelock"); 
    $quit = 1;
 }
}
     
### *** This section prints the page count and the bottom of the page
 

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




if ($center eq 1){
     print "<CENTER>";

   }else{
     print "</CENTER>\n";
    
   }

if ($table eq 1){
     print "<table border=3><tr><td colspan=2>\n";
   }

     print "$font_color\n";
     print "$before ";
     print "<B>$font_size $GrandTotal</FONT></B>\n";
     print " $after</FONT>\n";

if ($table eq 1){
     print "</td></tr>\n";
   }   

if ($table eq 1){
     print "<tr><td>\n";
   }

if ($table ne 1){
     print "<P>";
   }

if($today eq $logday){

     print "Visitors today: &nbsp; <B>$new_hit</B></td><th><A 
HREF=\"$stats_cgi\">Stats</A>\n";

}else{

          print "Visitors today: &nbsp; <B>$new_hit</B></td><th><A 
HREF=\"$stats_cgi\">Stats</A>\n";

}

if ($table eq 1){
     print "</th></tr>\n";
   }


if ($table eq 1){
     print "</td></tr></table>\n";
   }   

if ($center eq 1){
     print "</CENTER>";
   }
     
     print "<HR>$bottom_of_page</body></html>\n";





                           ### *** *** ###

exit;  




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

Date: 14 Aug 1997 02:54:04 GMT
From: gbacon@cs.uah.edu (Greg Bacon)
To: Pat Trainor <ptrainor@aura.title14STOPSPAM.com>
Subject: Re: sorting...
Message-Id: <5sts0c$de9$6@info.uah.edu>

[Posted and mailed]

In article <Pine.LNX.3.95.970813150221.21194E-100000@aura>,
	Pat Trainor <ptrainor@aura.title14STOPSPAM.com> writes:
: 
: 	if I output:
: 
: while (($key, $value) = each(%MAIN_CHOICES)) {
:         print "$key has a value of $value\n <br>";
: }
: 
: 	The output is unsorted.
: 
: 	What is the best way to sort the output by either key or value?

Seek enlightenment in the perlfaq4(1) manpage under "How do I sort a
hash (optionally by value instead of key)?"

If you don't have 5.004 yet, you can find the Perl FAQ at

    http://www.perl.com/perl/faq/

Hope this helps,
Greg
-- 
open(G,"|gzip -dc");$_=<<EOF;s/[0-9a-f]+/print G pack("h*",$&)/eg
f1b88000b620f22320303fa2d2e21584ccbcf29c84d2258084
d2ac158c84c4ece4d22d1000118a8d5491000000
EOF


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

Date: 14 Aug 1997 02:06:44 GMT
From: gbacon@cs.uah.edu (Greg Bacon)
To: chaotic@rli-net.net
Subject: Re: Traverse ~~ Heres a question for you!
Message-Id: <5stp7k$de9$1@info.uah.edu>

[Posted and mailed]

In article <33F1CD00.A158EE0C@webpromote.com>,
	James Rudny <jamesr@webpromote.com> writes:
: I was wondering if there is someone out there who wrote a Traverse
: program that will go though a web site grab all the URLs off the page
: and keep following thoes URLs until it is so deep.

Our good friend Randal Schwartz was kind enough to write not one but
*TWO* Web Techniques columns on just this subject.  Find Randal's
columns at

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

and then bookmark the page, because you'll find it to be an immensely
helpful resource when doing web programming in Perl.

Hope this helps,
Greg
-- 
open(G,"|gzip -dc");$_=<<EOF;s/[0-9a-f]+/print G pack("h*",$&)/eg
f1b88000b620f22320303fa2d2e21584ccbcf29c84d2258084
d2ac158c84c4ece4d22d1000118a8d5491000000
EOF


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

Date: Wed, 13 Aug 1997 10:04:47 +0200
From: stefano bonacina <stefano.bonacina@st.com>
Subject: Variable substitution into a regexp
Message-Id: <33F16A9F.2781E494@st.com>

Hello all
suppose I got the following script

 ...
foreach $field (@fields) {
	$rec =~ s|<$field>(.*?)</$field>||;
	print $1;
}
 ...

Actually the regexp doesn't work. How can I escape the $s?
Thanks in advance for your help
-- 
Stefano Bonacina                E-mail: stefano.bonacina@st.com
SGS-Thomson Microelectronics


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

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

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