[17376] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 4798 Volume: 9

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Nov 2 18:15:42 2000

Date: Thu, 2 Nov 2000 15:15:21 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <973206921-v9-i4798@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Thu, 2 Nov 2000     Volume: 9 Number: 4798

Today's topics:
    Re: Pattern Matching /isg (Frank Lettau)
    Re: Pattern Matching /isg (Tad McClellan)
    Re: Perl Question <james@NOSPAM.demon.co.uk>
    Re: Perl Question <james@NOSPAM.demon.co.uk>
    Re: Perl Question <ren.maddox@tivoli.com>
        Postprocessing output to a file <bart.lateur@skynet.be>
    Re: Postprocessing output to a file <ren.maddox@tivoli.com>
        Print to shared printer queue in ActivePerl hiroshiishii@my-deja.com
        Question about "use strict;" zabor@my-deja.com
    Re: Question about "use strict;" (Tad McClellan)
    Re: regular expression <bart.lateur@skynet.be>
    Re: regular expression <ren.maddox@tivoli.com>
    Re: running UNIX utilities in perl <gellyfish@gellyfish.com>
    Re: SMS - text messaging (Richard J. Rauenzahn)
    Re: SMS - text messaging <gellyfish@gellyfish.com>
        String manipulation?? <cedarstorm@hotmail.com>
    Re: String manipulation?? <jeffp@crusoe.net>
    Re: Unix authentication with an /etc/shadow file <gellyfish@gellyfish.com>
    Re: Want to process all files less than 24 hours old (Jerome O'Neil)
    Re: Want to process all files less than 24 hours old (Tad McClellan)
    Re: Want to process all files less than 24 hours old <mark-lists@webstylists.com>
    Re: Want to process all files less than 24 hours old (Tad McClellan)
    Re: Want to process all files less than 24 hours old <mark-lists@webstylists.com>
    Re: Want to process all files less than 24 hours old (Tom Christiansen)
    Re: Want to process all files less than 24 hours old (Jerome O'Neil)
        Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)

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

Date: 2 Nov 2000 19:24:09 GMT
From: killing_fountains@gmx.de (Frank Lettau)
Subject: Re: Pattern Matching /isg
Message-Id: <8FE0CE7B4killingfountainsgmxd@137.226.144.7>

bluearchtop@my-deja.com wrote in comp.lang.perl.misc:

>Can someone help me with this one. Let's say I have the following:
>$str=<<_EOF_;
><LOOP>
>something...
></LOOP>
>
>blah
>
><LOOP>
>something
></LOOP>
>...
>_EOF_
>
>I want to pull out what is in between the <LOOP> </LOOP> blocks:
>
>$str=~s/<LOOP>(.+)<\/LOOP>/&myfunc($1)/is  works fine if there is just
>one loop block, but it is being greedy if multiple Loop blocks. I just
>want it to hit the first ending loop tag. I've tried .? and /isg and
>that didn't work.

Try .+?

cheers,
    	Frank


-- 
Frank Lettau <killing_fountains@gmx.de>
"Sometimes truth is stranger than fiction"
                   - Brett Gurewitz
                   


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

Date: Thu, 2 Nov 2000 13:59:44 -0500
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: Pattern Matching /isg
Message-Id: <slrn903ed0.f7u.tadmc@magna.metronet.com>

On Thu, 02 Nov 2000 18:51:29 GMT, bluearchtop@my-deja.com 
   <bluearchtop@my-deja.com> wrote:

>Can someone help me with this one. 


An answer is already on your hard drive!


>I want to pull out what is in between the <LOOP> </LOOP> blocks:
                               ^^^^^^^
                               ^^^^^^^

   perldoc -q between

   "How can I pull out lines between two patterns that are
    themselves on different lines?"


>$str=~s/<LOOP>(.+)<\/LOOP>/&myfunc($1)/is  works fine 


It does? Really?

Then what you want to do is replace "<LOOP>" with the eight 
characters '&myfunc(' and replace "</LOOP>" with ')'  ?

That seems a strange thing to "want"   :-)

Or did you leave an option off of the end of your pattern match there?


>if there is just
>one loop block, but it is being greedy if multiple Loop blocks. 


Make it non-greedy then.


> I just
>want it to hit the first ending loop tag. I've tried .? and /isg and
>that didn't work.


Of course not. Because that is not how you make it non-greedy.

   perldoc perlre

the first use of "greedy" there tells how to make patterns non-greedy.

In case you also don't know what a "quantifier" is, the "+" in
your pattern above is a quantifier.


-- 
    Tad McClellan                          SGML consulting
    tadmc@metronet.com                     Perl programming
    Fort Worth, Texas


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

Date: Thu, 2 Nov 2000 20:26:49 +0000
From: James Taylor <james@NOSPAM.demon.co.uk>
Subject: Re: Perl Question
Message-Id: <ant022049209fNdQ@oakseed.demon.co.uk>

In article <fk530t867ldfg4mhtcq85gcc2qgcen0t83@4ax.com>, Bart Lateur
<URL:mailto:bart.lateur@skynet.be> wrote:
> 
> Oh, to come back to your original question: I know nothing of Perl+Java,

Errr, I think you have me confused with the original poster.
You don't think I would choose such a silly subject line do you?

-- 
James Taylor <james (at) oakseed demon co uk>
PGP key available ID: 3FBE1BF9
Fingerprint: F19D803624ED6FE8 370045159F66FD02



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

Date: Thu, 2 Nov 2000 20:33:19 +0000
From: James Taylor <james@NOSPAM.demon.co.uk>
Subject: Re: Perl Question
Message-Id: <ant022019354fNdQ@oakseed.demon.co.uk>

In article <m3bsvy4avo.fsf@dhcp11-177.support.tivoli.com>, Ren Maddox
<URL:mailto:ren.maddox@tivoli.com> wrote:
>
> In article <ant0212086d2fNdQ@oakseed.demon.co.uk> James Taylor wrote:
> >
> > I was thinking of writing a Perl prog to use the message
> > references stored in the news spool indexes to track a thread back to
> > its root and display the articles in date order say. When following
> > the thread back, should I just stack *all* the references of the
> > article, find the articles referred to and stack *all* their references
> > recursively, or is there a more intelligent way of doing this?
> 
> My newsreader, gnus, has two commands that I use for this.  One pulls
> up the parent article of the current article and the other pulls up
> all articles in the current thread.  Obviously, in both cases the
> articles must still be available to be displayed.

Hmmm, I think you misunderstood my question which was to do with what
algorithm a program I want to write would use to track a thread backwards.
Sorry, perhaps I shouldn't be high-jacking this thread to ask programming
questions, especially when so many people have scored this thread down
based on the original poster's poor choice of subject line. Oh well... :-)

-- 
James Taylor <james (at) oakseed demon co uk>
PGP key available ID: 3FBE1BF9
Fingerprint: F19D803624ED6FE8 370045159F66FD02



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

Date: 02 Nov 2000 14:39:51 -0600
From: Ren Maddox <ren.maddox@tivoli.com>
Subject: Re: Perl Question
Message-Id: <m38zr22jmw.fsf@dhcp11-177.support.tivoli.com>

James Taylor <james@NOSPAM.demon.co.uk> writes:

> In article <m3bsvy4avo.fsf@dhcp11-177.support.tivoli.com>, Ren Maddox
> <URL:mailto:ren.maddox@tivoli.com> wrote:
> >
> > In article <ant0212086d2fNdQ@oakseed.demon.co.uk> James Taylor wrote:
> > >
> > > I was thinking of writing a Perl prog to use the message
> > > references stored in the news spool indexes to track a thread back to
> > > its root and display the articles in date order say. When following
> > > the thread back, should I just stack *all* the references of the
> > > article, find the articles referred to and stack *all* their references
> > > recursively, or is there a more intelligent way of doing this?
> > 
> > My newsreader, gnus, has two commands that I use for this.  One pulls
> > up the parent article of the current article and the other pulls up
> > all articles in the current thread.  Obviously, in both cases the
> > articles must still be available to be displayed.
> 
> Hmmm, I think you misunderstood my question which was to do with what
> algorithm a program I want to write would use to track a thread backwards.
> Sorry, perhaps I shouldn't be high-jacking this thread to ask programming
> questions, especially when so many people have scored this thread down
> based on the original poster's poor choice of subject line. Oh well... :-)

Actually, I wasn't really trying to answer your question -- and I
should have made that clear.  I was just making a (barely) related
comment.  My thought process was something along the lines of, "Is
what he wants to do something like this?"

As for how... I don't think there's anything wrong with your proposal
-- assuming you are checking for duplicates along the way.

-- 
Ren Maddox
ren@tivoli.com


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

Date: Thu, 02 Nov 2000 19:38:14 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Postprocessing output to a file
Message-Id: <e9f30t846uc8tvgu0ire4v72iq4b5ti81s@4ax.com>

In a script udner Windows, I need to "print" Windows text to a file, but
the resulting file should contain Macintosh text. So there should be an
intermediate step, converting Windows text to Mac text on the fly. I'm
not having trouble doing the actual conversion, so for this example,
let's suppose that whatever you print, it should come out all caps. Now,
how would you do that?

Here's what I did (note that I use "printf" because it DOESN'T append $\
at the end of what it prints):

	tie *OUT, File::Out::Filter, 'c:/my documents/allcaps.txt',
	  sub { uc shift };
	$, = ', '; $\ = "!\n";
	select OUT;
	print qw'Hello world';  # should come out as "HELLO, WORLD!\n"

	package File::Out::Filter;
	use FileHandle;
	use Carp;

	sub TIEHANDLE {
	    my($class, $file, $func) = @_;
	    $file =~ s/^>?/>/;
	    my $fh = new FileHandle $file
	      or croak "Cannot open file: $!";
	    return bless { FH => $fh, FUNC => $func || sub { shift } };
	}

	sub PRINT {
	    my $self = shift;
	    printf {$self->{FH}} '%s', $self->{FUNC}->(join($,, @_).$\);
	}

-- 
	Bart.


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

Date: 02 Nov 2000 14:01:17 -0600
From: Ren Maddox <ren.maddox@tivoli.com>
Subject: Re: Postprocessing output to a file
Message-Id: <m3lmv22lf6.fsf@dhcp11-177.support.tivoli.com>

Bart Lateur <bart.lateur@skynet.be> writes:

> In a script udner Windows, I need to "print" Windows text to a file, but
> the resulting file should contain Macintosh text. So there should be an
> intermediate step, converting Windows text to Mac text on the fly. I'm
> not having trouble doing the actual conversion, so for this example,
> let's suppose that whatever you print, it should come out all caps. Now,
> how would you do that?

Are you actually having a problem with it or just presenting your
solution?

> Here's what I did (note that I use "printf" because it DOESN'T append $\
> at the end of what it prints):

I notice that you still use "\n", which is still going to put in the
OS-specific line ending unless you binmode() the filehandle, which you
don't seem to do.

[Code omitted]

-- 
Ren Maddox
ren@tivoli.com


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

Date: Thu, 02 Nov 2000 22:45:43 GMT
From: hiroshiishii@my-deja.com
Subject: Print to shared printer queue in ActivePerl
Message-Id: <8tsqqk$v49$1@nnrp1.deja.com>

Hi there:

I use ActivePerl from Win98.  I have Novell printer server and queue.

open(PRINTER,'>lpt1:') work for my local printer.  Now I want to print
to a shared network printer's queue, \\svr\printer_Q.abc.xyz.

Hoever, open(PRINTER,'>\\svr\printer_Q.abc.xyz') or open
(PRINTER,'>//svr/printer_Q.abc.xyz') doesn't work.

Can someone show me a working example?

T.I.A.

-Hiroshi





Sent via Deja.com http://www.deja.com/
Before you buy.


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

Date: Thu, 02 Nov 2000 21:14:21 GMT
From: zabor@my-deja.com
Subject: Question about "use strict;"
Message-Id: <8tslf4$q21$1@nnrp1.deja.com>

When I "use strict;" I understand how to use the "my()" way of defining
the variables. But do not understand how to define a global variable. I
have seen the example "$X::foo = 1;", can I use
this "$X::foo,foo2,foo3", how do I define multiple global variables?


Sent via Deja.com http://www.deja.com/
Before you buy.


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

Date: Thu, 2 Nov 2000 16:31:15 -0500
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: Question about "use strict;"
Message-Id: <slrn903n93.fus.tadmc@magna.metronet.com>

On Thu, 02 Nov 2000 21:14:21 GMT, zabor@my-deja.com <zabor@my-deja.com> wrote:

>When I "use strict;" I understand how to use the "my()" way of defining
>the variables. But do not understand how to define a global variable. 


You are misusing terminology there. Where you say "define" you
surely must mean "declare" instead.

you _define_ variables by assigning something to them:

   my($var1, $var2) = split;

or

   ($var1, $var2) = split;

Those *both* define variables. Only the first _declares_ variables though.

The first also happens to define the variables, but you can
declare with out defining:

   my($var1, $var2);



Perl does not have truly global variables.

If your program is all in one file, then you _already know_
how to declare a global variable! You use my() outside of
any block. Then the variable will be visible to your
entire program (ie. global).

If your program is in multiple files, then lexical (my)
variables won't get the job done. For that you need
dynamic variables instead. Perl FAQ part 7 has helpful
info about the 2 types of variables in Perl:

   "What's the difference between dynamic and lexical (static) scoping?  
    Between local() and my()?"

>I
>have seen the example "$X::foo = 1;", 


That is not a variable declaration.

That is simply using the variable named $foo in the package
named X.


>can I use
>this "$X::foo,foo2,foo3", 


No.


>how do I define multiple global variables?


with our() or "use vars".

   perldoc -f our

   perldoc vars


-- 
    Tad McClellan                          SGML consulting
    tadmc@metronet.com                     Perl programming
    Fort Worth, Texas


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

Date: Thu, 02 Nov 2000 19:12:08 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: regular expression
Message-Id: <i2f30t8dbu6kthmf1g8j6qdcpn7pmi3gk3@4ax.com>

Ren Maddox wrote:

>> 	$_ = 'string\with\a\backslash\'oops!';
>
>How does this demonstrate your assertion?  AFAIK, the only useful
>doubling of a backslash in a single-quoted string is when you want the
>string to end with a backslash:
>
>   $_ = 'only\the\last\'one\needs\to\be\doubled\\';

The supposition is that I want the string to be:

	string\with\a\backslash\'oops!

Don't tell me you don't need to double the backslash.

-- 
	Bart.


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

Date: 02 Nov 2000 13:30:03 -0600
From: Ren Maddox <ren.maddox@tivoli.com>
Subject: Re: regular expression
Message-Id: <m3puke2mv8.fsf@dhcp11-177.support.tivoli.com>

Bart Lateur <bart.lateur@skynet.be> writes:

> Ren Maddox wrote:
> 
> >> 	$_ = 'string\with\a\backslash\'oops!';
> >
> >How does this demonstrate your assertion?  AFAIK, the only useful
> >doubling of a backslash in a single-quoted string is when you want the
> >string to end with a backslash:
> >
> >   $_ = 'only\the\last\'one\needs\to\be\doubled\\';
> 
> The supposition is that I want the string to be:
> 
> 	string\with\a\backslash\'oops!
> 
> Don't tell me you don't need to double the backslash.

Actually, doubling that backslash will not work -- it won't even
compile.  You'll need to triple it.  If you only double it, then the '
is not going to be escaped.

Doubling the slashes "all the time" is the type of cargo-cultist
mentality that leads to exactly this type of mistake.  It is better to
clearly understand when and why a double backslash is needed, which
I've already described.

-- 
Ren Maddox
ren@tivoli.com


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

Date: 2 Nov 2000 07:11:57 -0000
From: Jonathan Stowe <gellyfish@gellyfish.com>
Subject: Re: running UNIX utilities in perl
Message-Id: <8tr43t$7el$1@orpheus.gellyfish.com>

On Wed, 01 Nov 2000 17:14:22 GMT Chris Fedde wrote:
> In article <slrn900477.a5b.tadmc@magna.metronet.com>,
> Tad McClellan <tadmc@metronet.com> wrote:
>>On Wed, 01 Nov 2000 06:02:28 GMT, Chris Fedde 
>>   <cfedde@fedde.littleton.co.us> wrote:
>>>In article <39FFADDE.905A38E1@student.murdoch.edu.au>,
>>>Ryan Fraser  <r.fraser@student.murdoch.edu.au> wrote:
>>>>How do I run a "make" for the "C" compiler command in a perl CGI script.
>>>>
>>>>Fraser
>>>>
>>>
>>>Who was it that was recently asking about morally questionable
>>>questions in this news group?
>>
>>
>>What is morally questionable in his question?
>>
>>
> 
> Nothing, really.  That's just a technique that was exploited (in a slightly
> different context) by the Morris worm.  But consider the implications of a
> url like the following:
> 
>     http://fedde.littleton.co.us/runme&cmd=rm&arg=rm&arg=-r&arg=*
> 

well sure if you have a program 'runme':

use CGI qw(:standard);

my @args = map { param($_) } param();

print header,start_html,'Good bye Cruel World!',end_html;

system @args;



Oh and you need to change the first ampersand in your URL into a '?'

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


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

Date: 2 Nov 2000 19:45:11 GMT
From: nospam@hairball.cup.hp.com (Richard J. Rauenzahn)
Subject: Re: SMS - text messaging
Message-Id: <973194310.271820@hpvablab.cup.hp.com>

Chris Kantarjiev <cak@putzl.com> writes:
>Steve wrote:
>> 
>> Richard J. Rauenzahn wrote:
>> >
>> <snip>
>> >
>> > I wish many posters on clpm would try to write clearer questions.
>> 
>> Sorry I thought it was clear ;-) - I want visitors to my site to be
>> able to send text messages (sms) from my site to a mobile phone
>> of their choice. They type a text message into an input box - then
>> type the phone number and then press send and it's sent to the phone.

It was clearer than most, but it wasn't clear [to me at least] whether
you wanted to build a website to do this or use existing websites to do
this.

Rich

-- 
Rich Rauenzahn ----------+xrrauenza@cup.hp.comx+ Hewlett-Packard Company
Technical Consultant     | I speak for me,     |   19055 Pruneridge Ave. 
Development Alliances Lab|            *not* HP |                MS 46TU2
ESPD / E-Serv. Partner Division +--------------+---- Cupertino, CA 95014


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

Date: 2 Nov 2000 07:19:07 -0000
From: Jonathan Stowe <gellyfish@gellyfish.com>
Subject: Re: SMS - text messaging
Message-Id: <8tr4hb$7f4$1@orpheus.gellyfish.com>

On Wed, 01 Nov 2000 14:25:02 +0000 Steve wrote:
> Hi all,
> 
> Can anybody recommend a script that allows a user to
> send text messages from a website to a mobile phone.
> 

In the first instance you will to search for 'smsclient' - this is not
a perl program though and if you have difficulty with it you will want
to find a more apropriate newsgroup.

Once you have smsclient installed and working it is trivial to wrap it in
a Perl program to work with the CGI.

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


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

Date: Thu, 2 Nov 2000 21:58:35 +0100
From: "Murx Cedarstorm" <cedarstorm@hotmail.com>
Subject: String manipulation??
Message-Id: <iFkM5.29861$tL4.369883@zonnet-reader-1>

I made a subroutine.pl library in where i read data from a file into an
array. the name of this array is passed on to the subroutine like this:

the subroutine in subroutines.pl:

    open(readFile, $_[0]) || die;
    $_[1] = <readFile>;
    close(readFile);

and it's called like this:

    &_read("template.dat",@template);

but somehow it does not work...yes i set the "require = subroutines.pl"
stuff, other subs do work...the problem is in the name of the array,
@template...

any help would be realy appreciated.
thnx





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

Date: Thu, 2 Nov 2000 17:15:17 -0500
From: Jeff Pinyan <jeffp@crusoe.net>
Subject: Re: String manipulation??
Message-Id: <Pine.GSO.4.21.0011021711440.25313-100000@crusoe.crusoe.net>

[posted & mailed]

On Nov 2, Murx Cedarstorm said:

>    open(readFile, $_[0]) || die;
>    $_[1] = <readFile>;
>    close(readFile);
>
>and it's called like this:
>
>    &_read("template.dat",@template);
>
>but somehow it does not work...yes i set the "require = subroutines.pl"
>stuff, other subs do work...the problem is in the name of the array,
>@template...

The problem is that you are trying to populate an array in a way that will
not work.  My guess is @template is empty, and you are trying to fill it
with the lines in the file.  You COULD do it like this:

  sub _read {
    open FILE, "< $_[0]" or die "can't read $_[0]: $!";
    @{ $_[1] } = <FILE>;
    close FILE;
  }

  _read("foo.bar", \@array);

Notice I pass the array by reference.  You can not assign to the ARRAY
itself by passing it to a function -- the most you could hope to do is
assign to any elements that currently exist in it, which is not what you
want.

You might want to do something like:

  sub _read {
    open FILE, "< $_[0]" or die "can't read $_[0]: $!";
    my $contents = [ <FILE> ];
    close FILE;
    return $contents;
  }

  $array_ref = _read("foo.bar");
  # or
  @array = @{ _read("foo.bar") };

But this is NOT the type of thing a function should be used for (in my
opinion) since it will require copying a (potentially big) list of lines
back and forth.

-- 
Jeff "japhy" Pinyan     japhy@pobox.com     http://www.pobox.com/~japhy/
PerlMonth - An Online Perl Magazine            http://www.perlmonth.com/
The Perl Archive - Articles, Forums, etc.    http://www.perlarchive.com/
CPAN - #1 Perl Resource  (my id:  PINYAN)        http://search.cpan.org/





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

Date: 2 Nov 2000 07:25:14 -0000
From: Jonathan Stowe <gellyfish@gellyfish.com>
Subject: Re: Unix authentication with an /etc/shadow file
Message-Id: <8tr4sq$7fq$1@orpheus.gellyfish.com>

On Wed, 1 Nov 2000 13:28:24 -0500 Che Gonzalez wrote:
> WIthout using the Authen module is there any way to authenticate a user in
> BSD | Linux that uses a /etc/shadow file.  Also, no greping or reading
> /etc/shadow.  Any alternatives?
> 

There are no alternatives to reading the file, how else would you determine
the contents?  You might not explicitly do so but something must.

Check the perlfunc entrys for the getpw* functions.

I have this horrible feeling that you are figuring to use this in a web
type application - if that is the case then I would suggest that you think
again very carefully.  You might not care much if someone is able to guess
the pasword for your website but if that is also a login pasword for your
system then you might come to rue a bad decision.

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


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

Date: Thu, 02 Nov 2000 19:06:55 GMT
From: jerome@activeindexing.com (Jerome O'Neil)
Subject: Re: Want to process all files less than 24 hours old
Message-Id: <jXiM5.911$3T.147942@news.uswest.net>

Mark Thompson <mark-lists@webstylists.com> elucidates:

> I've learned so much to expect that I can find everything on the web
> and get examples on Usenet that I didn't even realize all the
> documentation I could get with the perldoc command on my local
> machine.

Now, Grasshopper, you're journey truley begins...

-- 
"Civilization rests on two things: the discovery that fermentation 
produces alcohol, and the voluntary ability to inhibit defecation.  
And I put it to you, where would this splendid civilization be without 
both?" --Robertson Davies "The Rebel Angels" 


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

Date: Thu, 2 Nov 2000 14:06:15 -0500
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: Want to process all files less than 24 hours old
Message-Id: <slrn903ep7.f7u.tadmc@magna.metronet.com>

On Thu, 02 Nov 2000 11:03:21 -0800, Mark Thompson 
   <mark-lists@webstylists.com> wrote:

>Anyway, for anyone who wants a code sample (it's kindof ugly), here is
>what I've done.  Feel free to comment on it if you're bored :)


OK ...


>#!/usr/local/bin/perl5


No -w   +   No "use strict"   =   Tad won't be areadin' it

Fix that and try again  :-)


[ snip unread code ]


-- 
    Tad McClellan                          SGML consulting
    tadmc@metronet.com                     Perl programming
    Fort Worth, Texas


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

Date: Thu, 02 Nov 2000 12:36:02 -0800
From: Mark Thompson <mark-lists@webstylists.com>
Subject: Re: Want to process all files less than 24 hours old
Message-Id: <aqj30tkpc28jfh15onem2ufm2nj98qujco@4ax.com>

On Thu, 2 Nov 2000 14:06:15 -0500, tadmc@metronet.com (Tad McClellan)
wrote:

>On Thu, 02 Nov 2000 11:03:21 -0800, Mark Thompson 
>   <mark-lists@webstylists.com> wrote:
>
>>Anyway, for anyone who wants a code sample (it's kindof ugly), here is
>>what I've done.  Feel free to comment on it if you're bored :)
>
>>#!/usr/local/bin/perl5
>
>
>No -w   +   No "use strict"   =   Tad won't be areadin' it
>
>Fix that and try again  :-)

ok ok ok :)  Just me being lazy!  Wasn't all that hard to do!

#!/usr/local/bin/perl5 -w

use strict;
use File::Find;

my $logfiledir = '/u/logs/companyname;
my $databasefile = '/u/companyname/data/download_req.txt';

my %log;
my %data;


readdatabasefile();
find(\&wanted, $logfiledir);
outputreport();

sub readdatabasefile
{
    open(DBFILE, $databasefile);
    while(<DBFILE>)
    {
        my $dataitem;
        my $rest;
        
        chomp;
        ($dataitem, $rest) = split(/\t/, $_, 2);   
        $data{$dataitem} = $_;
        
    }
    close (DBFILE);
}
    

sub wanted 
{ 
    if (-f && (-C ($_) < 1) && /\.d$/)
    {

        open(LOGFILE, $File::Find::name);
        while(<LOGFILE>)
        {
            my @logitem;
            my $time;
            my $cookie;
            my $file;
            my @cookies;
            my $count;

            
            chomp;
            @logitem = split(/\t/, $_, 4); 
            $time = $logitem[0];
            $cookie = $logitem[1];
            $file = $logitem[2];
            @cookies = split(/;/, $cookie);
            @cookies = trim(@cookies);
            $count = 1;
            if ($file =~ /pdf$/i)
            {
	        while ($count <= @cookies) 
	        {
	            $cookies[$count - 1] =~ /ManualDownloadCode=(.+)/;
	            if ($1)
	            {     
	                my $manualcode;
	                $manualcode = $1;
	                $log{$manualcode}{$file} = 1;
	            }  
	            $count++;
	        }
	    }
        }
        close(LOGFILE);
    }
}

sub outputreport()
{


    my $user;
    foreach $user ( keys %log ) 
    {

        my @dataarray;
        my $i;
        my $filedl;
       
        @dataarray = split("\t",$data{$user});
        for ($i = 1; $i <= @dataarray; $i++)
        {
            if (length($dataarray[$i - 1 ]))
            {
                print "$dataarray[$i - 1]\n"
            }
        }
    
    
        print "Files Downloaded:\n";
        for $filedl ( keys %{ $log{$user} } ) 
        {
            print "  $filedl\n";
        }
        print "\n";
    }
}


sub trim {
    my @out = @_;
    for (@out) {
        s/^\s+//;
        s/\s+$//;
    }
    return wantarray ? @out : $out[0];
}



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

Date: Thu, 2 Nov 2000 15:36:08 -0500
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: Want to process all files less than 24 hours old
Message-Id: <slrn903k1n.fon.tadmc@magna.metronet.com>

On Thu, 02 Nov 2000 12:36:02 -0800, Mark Thompson 
   <mark-lists@webstylists.com> wrote:
>On Thu, 2 Nov 2000 14:06:15 -0500, tadmc@metronet.com (Tad McClellan)
>wrote:
>
>>On Thu, 02 Nov 2000 11:03:21 -0800, Mark Thompson 
>>   <mark-lists@webstylists.com> wrote:
>>
>>>Anyway, for anyone who wants a code sample (it's kindof ugly), here is
>>>what I've done.  Feel free to comment on it if you're bored :)
>>
>>>#!/usr/local/bin/perl5
>>
>>
>>No -w   +   No "use strict"   =   Tad won't be areadin' it
>>
>>Fix that and try again  :-)
>
>ok ok ok :)  Just me being lazy!  
              ^^^^^^^^^^^^^^^^^^^

You may think you were being lazy, but you weren't.

Lazy Perl programmers always use both of those.

A lazy person would want a machine to find common mistakes _for_ them.

-w and strictures cause the machine to find common mistakes for you.

I like having a machine do my work for me  :-)



>Wasn't all that hard to do!


And you can get all of that machine-help cheaply, so there is
no excuse for not using them. Hence my immediate and total
disregard for a program once I determine that they are missing.

Spending brain cycles in lieu of CPU cycles is foolishness.

Somebody else can spend their time on foolishness, but
not _this_ fool. 


>#!/usr/local/bin/perl5 -w
>
>use strict;
>use File::Find;
>
>my $logfiledir = '/u/logs/companyname;


Oh Geez!

Now you have hit yet another "stop reading here" indicator.

When I see code that won't compile, I stop reading.

I wonder what else besides the missing quote is different
from the real code?

The code that you see and the code that I see are not the same
(assuming that the code you see can be compiled at least).

Waste of time if we are going to refer to different source code...



[ snip code of unknown origin :-) ]


Third time's the charm? ...


-- 
    Tad McClellan                          SGML consulting
    tadmc@metronet.com                     Perl programming
    Fort Worth, Texas


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

Date: Thu, 02 Nov 2000 14:34:15 -0800
From: Mark Thompson <mark-lists@webstylists.com>
Subject: Re: Want to process all files less than 24 hours old
Message-Id: <kkq30tc0vvk07letc0t6l1562tv9nvs1uf@4ax.com>

On Thu, 2 Nov 2000 15:36:08 -0500, tadmc@metronet.com (Tad McClellan)
wrote:


>>>
>>>No -w   +   No "use strict"   =   Tad won't be areadin' it
>>>
>>>Fix that and try again  :-)
>>
>>ok ok ok :)  Just me being lazy!  
>              ^^^^^^^^^^^^^^^^^^^
>
>You may think you were being lazy, but you weren't.
>
>Lazy Perl programmers always use both of those.
>
>A lazy person would want a machine to find common mistakes _for_ them.
>
>-w and strictures cause the machine to find common mistakes for you.
>
>I like having a machine do my work for me  :-)
>
>
>
>>Wasn't all that hard to do!
>
>
>And you can get all of that machine-help cheaply, so there is
>no excuse for not using them. Hence my immediate and total
>disregard for a program once I determine that they are missing.
>
>Spending brain cycles in lieu of CPU cycles is foolishness.
>
>Somebody else can spend their time on foolishness, but
>not _this_ fool. 
>
>
>>#!/usr/local/bin/perl5 -w
>>
>>use strict;
>>use File::Find;
>>
>>my $logfiledir = '/u/logs/companyname;
>
>
>Oh Geez!
>
>Now you have hit yet another "stop reading here" indicator.
>
>When I see code that won't compile, I stop reading.
>
>I wonder what else besides the missing quote is different
>from the real code?
>
>The code that you see and the code that I see are not the same
>(assuming that the code you see can be compiled at least).
>
>Waste of time if we are going to refer to different source code...
>
>
>
>[ snip code of unknown origin :-) ]
>
>
>Third time's the charm? ...

Sorry, I changed the real company name's directory with "companyname"
and must've lopped off the end quote.  Only two lines changed are the
lines with the filenames.

I do have a question that maybe you or someone else can answer, does
use strict or -w slow things down any?  Once I've tested the program
(as I've done), should I remove them knowing that I can put them back
if I need to make changes to the program?

#!/usr/local/bin/perl5 -w

use strict;
use File::Find;

my $logfiledir = '/u/logs/companyname';
my $databasefile = '/u/companyname/data/download_req.txt';

my %log;
my %data;


readdatabasefile();
find(\&wanted, $logfiledir);
outputreport();

sub readdatabasefile
{
    open(DBFILE, $databasefile);
    while(<DBFILE>)
    {
        my $dataitem;
        my $rest;
        
        chomp;
        ($dataitem, $rest) = split(/\t/, $_, 2);   
        $data{$dataitem} = $_;
        
    }
    close (DBFILE);
}
    

sub wanted 
{ 
    if (-f && (-C ($_) < 1) && /\.d$/)
    {

        open(LOGFILE, $File::Find::name);
        while(<LOGFILE>)
        {
            my @logitem;
            my $time;
            my $cookie;
            my $file;
            my @cookies;
            my $count;
            
            chomp;
            @logitem = split(/\t/, $_, 4); 
            $time = $logitem[0];
            $cookie = $logitem[1];
            $file = $logitem[2];
            @cookies = split(/;/, $cookie);
            @cookies = trim(@cookies);
            $count = 1;
            if ($file =~ /pdf$/i)
            {
	        while ($count <= @cookies) 
	        {
	            $cookies[$count - 1] =~ /ManualDownloadCode=(.+)/;
	            if ($1)
	            {     
	                my $manualcode;
	                $manualcode = $1;
	                $log{$manualcode}{$file} = 1;
	            }  
	            $count++;
	        }
	    }
        }
        close(LOGFILE);
    }
}

sub outputreport()
{
    my $user;
    foreach $user ( keys %log ) 
    {

        my @dataarray;
        my $i;
        my $filedl;
       
        @dataarray = split("\t",$data{$user});
        for ($i = 1; $i <= @dataarray; $i++)
        {
            if (length($dataarray[$i - 1 ]))
            {
                print "$dataarray[$i - 1]\n"
            }
        }
    
    
        print "Files Downloaded:\n";
        for $filedl ( keys %{ $log{$user} } ) 
        {
            print "  $filedl\n";
        }
        print "\n";
    }
}

sub trim {
    my @out = @_;
    for (@out) {
        s/^\s+//;
        s/\s+$//;
    }
    return wantarray ? @out : $out[0];
}



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

Date: 2 Nov 2000 15:51:58 -0700
From: tchrist@perl.com (Tom Christiansen)
Subject: Re: Want to process all files less than 24 hours old
Message-Id: <3a01f00e$1@cs.colorado.edu>

In article <dqd30tsss8m4onlt1r9698lso8ngtmi1ac@4ax.com>,
Mark Thompson  <mark-lists@webstylists.com> wrote:
>I've learned so much to expect that I can find everything on the web
>and get examples on Usenet that I didn't even realize all the
>documentation I could get with the perldoc command on my local
>machine.

That's the first step.  Another step, maybe not the very next one,
but another one, is when you that "perldoc" is superfluous to your
task, and highly sub-functional.  You will eventually wish to become
far more intimate with the Perl manpages than that silly craplet
can hope to provide.  Well, or else you'll install my rewrite. :-)

--tom


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

Date: Thu, 02 Nov 2000 22:52:03 GMT
From: jerome@activeindexing.com (Jerome O'Neil)
Subject: Re: Want to process all files less than 24 hours old
Message-Id: <nemM5.1546$3T.218641@news.uswest.net>

Mark Thompson <mark-lists@webstylists.com> elucidates:

> I do have a question that maybe you or someone else can answer, does
> use strict or -w slow things down any?  Once I've tested the program
> (as I've done), should I remove them knowing that I can put them back
> if I need to make changes to the program?

Not to any degree you would notice, even under heavy load.

What does get slowed down is your development time if you
don't use them.  You'll spend a lot of time looking for things
that perl would have told you, had you merely had warnings 
enabled.

Whether or not you keep them when you deploy will dependent on the
deployment environment.

-- 
"Civilization rests on two things: the discovery that fermentation 
produces alcohol, and the voluntary ability to inhibit defecation.  
And I put it to you, where would this splendid civilization be without 
both?" --Robertson Davies "The Rebel Angels" 


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

Date: 16 Sep 99 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 16 Sep 99)
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.  

| NOTE: The mail to news gateway, and thus the ability to submit articles
| through this service to the newsgroup, has been removed. I do not have
| time to individually vet each article to make sure that someone isn't
| abusing the service, and I no longer have any desire to waste my time
| dealing with the campus admins when some fool complains to them about an
| article that has come through the gateway instead of complaining
| to the source.

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 V9 Issue 4798
**************************************


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