[22877] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 5098 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Jun 9 14:06:12 2003

Date: Mon, 9 Jun 2003 11:05:10 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Mon, 9 Jun 2003     Volume: 10 Number: 5098

Today's topics:
        Array Shift Question <blnukem@hotmail.com>
    Re: Array Shift Question <erutiurf@web.de>
    Re: Array Shift Question <erutiurf@web.de>
    Re: Array Shift Question <nobody@dev.null>
    Re: bareword complaints in if statement (hymie!)
        DHCP response (Gareth Glaccum)
    Re: exclude a word using regexp (Tad McClellan)
    Re: Formatting and encoding of words (slash)
    Re: Help with XML::Simple <mrt@thomaszone.com>
        How to I arrange for a socket connection to time out? (John Brock)
    Re: newbie: will a big array hurt performance? <ndronen@io.frii.com>
    Re: newbie: will a big array hurt performance? <nobull@mail.com>
        Perl CGI and Downloading Files - How? 10ghz@radiate.com
    Re: Perl CGI and Downloading Files - How? <erutiurf@web.de>
    Re: Perl exam - fair or not? (Tramm Hudson)
    Re: Perl exam - fair or not? <nobull@mail.com>
    Re: Perl exam - fair or not? <drew4jones@yahoo.ca>
        SDBM Utility <jmcada@hotmail.com>
    Re: SDBM Utility <glex_nospam@qwest.net>
        Search & Evaluate an array (Almir)
    Re: Search & Evaluate an array <glex_nospam@qwest.net>
    Re: Sorting IP's <glex_nospam@qwest.net>
    Re: Unbuffered output from another program? (Gareth Glaccum)
    Re: upload file without cgi.pm <jurgenex@hotmail.com>
    Re: upload file without cgi.pm <nobody@dev.null>
    Re: upload file without cgi.pm <ghostnr1@telia.com>
    Re: upload file without cgi.pm <simon.andrews@bbsrc.ac.uk>
    Re: upload file without cgi.pm news@roaima.freeserve.co.uk
    Re: upload file without cgi.pm <drumspoorly@reachone.net>
    Re: upload file without cgi.pm <ghostnr1@telia.com>
        Win32::OLE and Sorts <psion.is.fubar@thebroonclan.com>
    Re: Win32::OLE and Sorts <psion.is.fubar@thebroonclan.com>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Mon, 09 Jun 2003 17:30:38 GMT
From: "Blnukem" <blnukem@hotmail.com>
Subject: Array Shift Question
Message-Id: <2v3Fa.5162$ly.2348042@news4.srv.hcvlny.cv.net>

Hi All

@array qw(one two three);
shift @array;
print $_;   #Returns nothing

print @array;   #Returns "two three"

where does the "one" value go?

Thanx Blnukem




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

Date: Mon, 09 Jun 2003 19:40:02 +0200
From: Richard Voss <erutiurf@web.de>
Subject: Re: Array Shift Question
Message-Id: <bc2h28$so5$01$1@news.t-online.com>

Blnukem wrote:
> Hi All
> 
> @array qw(one two three);

that's a syntax error already

> shift @array;

ok.
perldoc -f shift

> print $_;   #Returns nothing

This should give you a warning. See `perldoc perlvar` and `perldoc warnings`, 
please.

> print @array;   #Returns "two three"

No, because @array was never properly initialized. This should

> where does the "one" value go?

It's probably never been there, according to the code you posted.

> Thanx Blnukem

What sort of drugs did your parents take when they named you like that? I 
suspect you had a hard childhood.

-- 
sub{use strict;local$@=sub{select($,,$,,$,,pop)};unshift@_,(45)x 24,split q=8==>
55.52.56.49.49.55.56.49.49.53;do{print map(chr,@_[0..(@_/2-1)]),"\r";$@->(1/6)=>
push@_=>shift}for@_,++$|}->(map{$_+=$_%2?-1:1}map ord,split//,'u!`onuids!Qdsm!'.
'i`bjds') #my email-address is reversed!      <http://fruiture.de>



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

Date: Mon, 09 Jun 2003 19:44:58 +0200
From: Richard Voss <erutiurf@web.de>
Subject: Re: Array Shift Question
Message-Id: <bc2hbg$so5$01$3@news.t-online.com>

Richard Voss wrote:
> Blnukem wrote:
>> print @array;   #Returns "two three"
> 
> No, because @array was never properly initialized. This should

give you a warning as well.

> [...]

sorry, i was disturbed right when i wrote that and left off then.


-- 
sub{use strict;local$@=sub{select($,,$,,$,,pop)};unshift@_,(45)x 24,split q=8==>
55.52.56.49.49.55.56.49.49.53;do{print map(chr,@_[0..(@_/2-1)]),"\r";$@->(1/6)=>
push@_=>shift}for@_,++$|}->(map{$_+=$_%2?-1:1}map ord,split//,'u!`onuids!Qdsm!'.
'i`bjds') #my email-address is reversed!      <http://fruiture.de>



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

Date: Mon, 09 Jun 2003 17:59:22 GMT
From: Andras Malatinszky <nobody@dev.null>
Subject: Re: Array Shift Question
Message-Id: <3EE4CAB2.80500@dev.null>



Blnukem wrote:

> Hi All
> 
> @array qw(one two three);
> shift @array;
> print $_;   #Returns nothing
> 
> print @array;   #Returns "two three"
> 
> where does the "one" value go?
> 
> Thanx Blnukem


There is this place where Elvis, Osama, Saddam and all those half-pairs 
of socks you lost in the laundry all hang out. That's where the "one" 
value is.

If you want to capture the value returned by shift in $_, you have to 
explicitely do it:

$_=shift @array




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

Date: Mon, 09 Jun 2003 17:19:01 -0000
From: hymie@lactose.smart.net (hymie!)
Subject: Re: bareword complaints in if statement
Message-Id: <ve9gc52fk6uu18@corp.supernews.com>

In our last episode, the evil Dr. Lacto had captured our hero,
  xyzzy@billgates.com, who said:

>this generates the bareword error
>        if( ( $testNum >= 100 ) && ( $testNum <= l200 ) ) {
                                                  ^
Is that a One or an L ?

hymie!          http://www.smart.net/~hymowitz          hymie@lactose.smart.net
===============================================================================


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

Date: 9 Jun 2003 09:19:08 -0700
From: verycoldpenguin@hotmail.com (Gareth Glaccum)
Subject: DHCP response
Message-Id: <991491a9.0306090819.54b446c6@posting.google.com>

I am trying to send some DHCP responses to a computer, can anyone
suggest a GOOD module to use with perl?
RawIP is refusing to send the packet correctly, and I am finding the
lack of documentation for it very irritating.
Gareth


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

Date: Mon, 9 Jun 2003 08:19:03 -0500
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: exclude a word using regexp
Message-Id: <slrnbe92a7.h3i.tadmc@magna.augustmail.com>

paaro <paaro@hockeymail.com> wrote:

> I have a following problem: I read a HTML file into a variable, 


You should use a module that understand HTML for processing HTML.


> then I want to find all links (<a ....>...</a>) and check whether they
> have an attribute "target". If they don't, then I want to add
> target="_blank".


> Any ideas of how to exclude particular word?


A regex approach is bound to be sub-optimal compared to a module
that does a Real Parse, but here is a fragile regex "solution":

   s{(<a.*?>)}
   {
     my $a = $1;
     unless ( $a =~/\btarget\s*=/ )
        { substr($a, -1, 0) = ' target="_blank"' }
     $a;
   }ige;


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


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

Date: 9 Jun 2003 06:19:36 -0700
From: satishi@gwu.edu (slash)
Subject: Re: Formatting and encoding of words
Message-Id: <30fe9f1e.0306090519.4eea51a4@posting.google.com>

Hello,
Thanks for your help! 
So, I guess for sorting, I would have to come up with my own method.
Hopefully that won't be too hard.
As far as encoding goes, can I build some sort of a wrapper
application in C/C++/Java where encoding can be addressed for faster
speed. The need for speed arises from the fact that we will be
processing a very very large (over a million) collection of documents.
Any suggestions on optimization or sorting? 

Thanks,
Satish


"Tassilo v. Parseval" <tassilo.parseval@rwth-aachen.de> wrote in message news:<bc1hce$935$1@nets3.rz.RWTH-Aachen.DE>...
> Also sprach slash:
> 
> > I apologize for the simplicity of this question in advance as I am new
> > to Perl.
> > I have a table of words generated dynamically from Text::Table CPAN
> > module. I am trying to select certain columns.
> > Here is my code:
> > 
> > use CPAN;
> > use Text::Table;
> 
> Heh, I like this. Even though Text::Table is a module from the CPAN (and
> you are thus using the CPAN somewhat) you don't have to use the CPAN
> module. This module is for accessing the CPAN repository
> programmatically. Just 'use Text::Table;'.
> 
> > 
> >         my @words = qw( Use this form to post your message...);
> > 
> >         my $n_cols = 3;
> >         my $col = { align => 'left'}; 
> >         my $tb = Text::Table->new( ( $col) x $n_cols);
> > 
> >         my @stack = ( '*' ) x $n_cols;
> >         for my $word ( @words ) {
> >             shift @stack;
> >             push @stack, $word;
> >             $tb->add( @stack);
> >         }
> > 
> >         print $tb;
> > 
> > How do I select the columns? Let's say, if the columns had titles and
> > they were following (but they do not have column titles currently): a,
> > b, c
> > 
> > and I wanted the following output:
> > 
> > b, a          b, c
> 
> The select() method takes columns and returns a new table consisting
> only of those columns. Between those columns you can sprinkle in
> directives how to format the whole thing. For your problem, you can
> write this:
> 
>     my $t1 = $tb->select(1, 0, {  is_sep => 1,
>                                   body   => "\t"  },
>                          1, 2);
>     print $t1;
>     __END__
>     *    *          *    Use
>     Use  *          Use  this
>     this Use        this form
>     form this       form to
>     to   form       to   post
>     post to         post your
>     your post       your message...
>     
> 
> > I tried using the select() method from the module specification but I
> > guess I wasn't using it correctly. For whatever column i chose,
> > my $sub = select ($b, $a, $b, $c), the output would be always be 4
> > copies of column a. Can someone please help me?
> 
> You give column-numbers to select them. First column has index 0. I
> guess $a .. $c were strings and thus converted into the number 0.
> 
> > Secondly, can I also sort table columns? I didn't see this in the
> > specification. For instance, if I wanted to sort column a and column c
> > based on their "value", i.e., whatever their memory encoding
> > representation value is. 
> 
> I haven't found anything like that either. Anno, some work for you. :-)
> 
> > Which brings me to the next point...How is a Perl string stored in
> > memory? Can I write a script so that words are encoded in binary? If I
> > do that then the string comparisons will be faster, right? So, can I
> > encode them in base64 or any base I want? I guess, all I would have to
> > do is generate a lookup key or table of the alphabet. Any suggestions
> > would be greatly appreciated.
> 
> Strings aren't stored much differently than in C. The variable that
> holds them (a scalar which in the sourcecode is referred to as 'SV*')
> has some administrative overhead when you look at the internals but
> eventually it is just a 'char*' pointer.
> 
> Encoding your strings wont change anything about it and you wont gain
> speed advantages from it. Consider: Perl was initially designed to work
> with text so it can do that very fast. Don't yet worry about those
> optimizations. You should start to worry once your programs run too
> slowly...but I doubt that encoding your strings is the right angle to
> look at it.
> 
> Tassilo


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

Date: Mon, 9 Jun 2003 10:06:11 -0400
From: "Mark Thomas" <mrt@thomaszone.com>
Subject: Re: Help with XML::Simple
Message-Id: <bc248j$or1$1@blsnews.bls.gov>

"Graham Smith" <grehom@ntlworld.com> wrote in message
news:98eb7f13.0306070627.6523aa45@posting.google.com...
> Much as I like nested arrays and hashes of references to same I'd be
> tempted to argue that XML::Simple isn't all that simple - contrast it
> with:
>
> [XML::Twig example]
>
> added to this the caveats regarding XML::Simple and I think XML::Twig
> would be a much better solution.

Agreed. But I'll go another step further and say that and XPath
implementation (like in XML::XPath or XML::LibXML) is even easier.

  use XML::XPath;
  use XML::XPath::XMLParser;

  my $xp = XML::XPath->new(filename => 'doc.xml');
  my @developers = findnodes('/phonebook/developers/person');
  print "ID: " . $_->findvalue('@id') . ", Phone: " . $_->findvalue('phone')
 . "\n" foreach @developers;

A big advantage of using XPath is that the paths can be stored as variables
or externalized. If the XML document changes, you only change a string, not
programming logic as would be required in a DOM-style interface (including
XML::Twig).

My $0.02

-- 
Mark Thomas
mrt@thomaszone.com





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

Date: 9 Jun 2003 11:29:05 -0400
From: jbrock@panix.com (John Brock)
Subject: How to I arrange for a socket connection to time out?
Message-Id: <bc2941$g8c$1@panix2.panix.com>

I am using Perl to write a client module which communicates with
a server through a socket connection.  I want the client to time
out the socket connection if the server does not respond within,
let's say, 60 seconds, and I am trying to figure out the correct
and idiomatic Perl way to do this.  (I also want this to be portable,
since the client needs to run on both Unix and Windows NT).

At first I thought I could use the timeout() method of IO::Socket,
but after investigating the code I realized that this timeout
applied only to connect() and accept().  (I.e., only to the creation
of the socket connection, not during its use).

After further investigation I came across IO::Select, and I thought
I had found the answer.  I would create an IO::Select object and
add my single IO::Socket object to the list of file handles.  Then
prior to every read I would perform a can_read(60) on the IO::Select
object.  Under normal circumstances -- since the client should
never be blocking -- this would return instantly, and I would then
proceed to read from the socket.  If the server was slow then
eventually I would get an empty list from the IO::Select object,
and I would know that there had been a timeout.

Unfortunately it didn't work.  Actually it would work once or twice
and then hang on the can_read() call, long before the server was
done sending.  I did some more investigating, and I noticed this
ominous sentence in my Programming Perl book:

	One should probably not attempt to mix buffered I/O (like
	read or <HANDLE>) with select, except as permitted by POSIX,
	and even then only on truly POSIX systems.  Use sysread
	instead.

Well, I am definitely using read() and the angle bracket operator
to read from the socket.  So, is that my problem, or might it be
something else?  I can try to use sysread() instead of read(), but
what do I use to replace <HANDLE> (or actually the getline() method
of IO::Handle), which reads until it hits an end-of-line character?
Do I have to go into a loop and read one character at a time using
sysread until I hit "\n"?  That doesn't look very efficient!  And
should I even be using IO::Select at all?  Maybe I've missed a
better way to do what I'm trying to do.

So to get back to my question, what is the proper way to code a
client in Perl so that it will time out a socket connection if the
server does not respond quickly enough?
-- 
John Brock
jbrock@panix.com



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

Date: 09 Jun 2003 15:12:09 GMT
From: Nicholas Dronen <ndronen@io.frii.com>
Subject: Re: newbie: will a big array hurt performance?
Message-Id: <3ee4a3c9$0$206$75868355@news.frii.net>

Steve Grazzini <grazz@pobox.com> wrote:
SG> Nicholas Dronen <ndronen@io.frii.com> wrote:
>> 
>> If you want to do *some* read-ahead, then something like 
>> this might work.  I don't know if it has any pitfalls.  

SG> At least one :-)

>>      # Grab two lines after root's.  This too is arbitrary.
>>      @d[0,1] = <$f>, <$f>;

SG> That's list context, so the first readline() slurps the rest
SG> of the file.

I think you're mistaken.  See the perldata man page.

       Entire arrays (and slices of arrays and hashes) are
       denoted by '@', which works much like the word "these" or
       "those" does in English, in that it indicates multiple
       values are expected.

           @days               # ($days[0], $days[1],... $days[n])
           @days[3,4,5]        # same as ($days[3],$days[4],$days[5])
           @days{'a','c'}      # same as ($days{'a'},$days{'c'})

Doesn't that explain why I get the following results when running
almost the same code as the code I posted?

	$ bin/readahead
	d[0]: daemon:x:1:1:daemon:/usr/sbin:/bin/sh
	d[1]: bin:x:2:2:bin:/bin:/bin/sh

And I just know my passwd file's more than 3 lines.

Regards,

Nicholas

-- 
"Meanings are another story."  http://www.ifas.org/wa/glossolalia.html


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

Date: 09 Jun 2003 18:23:03 +0100
From: Brian McCauley <nobull@mail.com>
Subject: Re: newbie: will a big array hurt performance?
Message-Id: <u9el23jhc8.fsf@wcl-l.bham.ac.uk>

Nicholas Dronen <ndronen@io.frii.com> writes:

> Steve Grazzini <grazz@pobox.com> wrote:
> SG> Nicholas Dronen <ndronen@io.frii.com> wrote:
> >> 
> >> If you want to do *some* read-ahead, then something like 
> >> this might work.  I don't know if it has any pitfalls.  
> 
> SG> At least one :-)
> 
> >>      # Grab two lines after root's.  This too is arbitrary.
> >>      @d[0,1] = <$f>, <$f>;
> 
> SG> That's list context, so the first readline() slurps the rest
> SG> of the file.
> 
> I think you're mistaken.

I think he is not.

      @d[0,1] = <$f>, <$f>;

Does exactly the same as 

      @d[0,1] = <$f>;

I think you meant:

      @d[0,1] = ( scalar(<$f>), scalar(<$f>));

>  See the perldata man page.
  [ snip explaination of slice syntax ]

What does that have to do with it?  Perl has only list an scalar
assignment.
 
>        Entire arrays (and slices of arrays and hashes) are
>        denoted by '@', which works much like the word "these" or
>        "those" does in English, in that it indicates multiple
>        values are expected.
> 
>            @days               # ($days[0], $days[1],... $days[n])
>            @days[3,4,5]        # same as ($days[3],$days[4],$days[5])
>            @days{'a','c'}      # same as ($days{'a'},$days{'c'})
> 
> Doesn't that explain why I get the following results when running
> almost the same code as the code I posted?
> 
> 	$ bin/readahead
> 	d[0]: daemon:x:1:1:daemon:/usr/sbin:/bin/sh
> 	d[1]: bin:x:2:2:bin:/bin:/bin/sh

Er yes.  It does.

You slurp the whole file file into memory and store the first two
lines in the first two elements of @d, discarding the rest.

> And I just know my passwd file's more than 3 lines.

Yes, so?

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


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

Date: Mon, 09 Jun 2003 17:42:47 GMT
From: 10ghz@radiate.com
Subject: Perl CGI and Downloading Files - How?
Message-Id: <teh9evo6ke95uqce1cc1mrrupfc2bvtogi@4ax.com>



OK, I have a small Perl script that runs on my server.
It is supposed to show zip files for download.
But, I don't want the User to know where those zip  files are located on the
sevrer. Can that be done? 





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

Date: Mon, 09 Jun 2003 19:42:37 +0200
From: Richard Voss <erutiurf@web.de>
Subject: Re: Perl CGI and Downloading Files - How?
Message-Id: <bc2h72$so5$01$2@news.t-online.com>

10ghz@radiate.com wrote:
> 
> OK, I have a small Perl script that runs on my server.
> It is supposed to show zip files for download.
> But, I don't want the User to know where those zip  files are located on the
> sevrer. Can that be done? 

They can't find out. HTTP doesn't know files, it only knows resources.

-- 
sub{use strict;local$@=sub{select($,,$,,$,,pop)};unshift@_,(45)x 24,split q=8==>
55.52.56.49.49.55.56.49.49.53;do{print map(chr,@_[0..(@_/2-1)]),"\r";$@->(1/6)=>
push@_=>shift}for@_,++$|}->(map{$_+=$_%2?-1:1}map ord,split//,'u!`onuids!Qdsm!'.
'i`bjds') #my email-address is reversed!      <http://fruiture.de>



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

Date: Mon, 9 Jun 2003 14:04:10 +0000 (UTC)
From: hudson@swcp.com (Tramm Hudson)
Subject: Re: Perl exam - fair or not?
Message-Id: <bc244q$8k8$1@iruka.swcp.com>

Brian McCauley  <nobull@mail.com> wrote:
> hudson@swcp.com (Tramm Hudson) writes:
> > And neither 'local' nor 'my' are functions.  They are keywords that
> > modify the storage class of variables.
>
> No, 'my' is a storage class modifier, 'local' is not.

While I agree that 'local' does not change the storage class of the
variables (they still go into the package namespace), and that it does
have a runtime effect as well, I believe it is roughly equivilant to
C's "auto" storage class modifier.  Obviously, 'local' does have other
semantics that 'auto' does not, but as storage class modifiers they
both request the default storage class of the language (package
namespace or on the stack, respectively).

> You may or may
> not wish to consider local() to be a function depending on how you
> define that.  I, however, choose to consider 'local' to be a function.

It does have runtime effects and that could make it seem like a
function.  I'm willing to concede that it does act like a function
and that calling it one is within reason.

You could even implement your own 'local' function that maintains
a stack of older values and overloads the destructor so that it can
pop the old value once the current one goes out of scope.

> [...]

Trammell
-- 
  -----|----- hudson@osresearch.net                   W 240-283-1700
*>=====[]L\   hudson@rotomotion.com                   M 505-463-1896
'     -'-`-   http://www.swcp.com/~hudson/                    KC5RNF



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

Date: 09 Jun 2003 18:10:25 +0100
From: Brian McCauley <nobull@mail.com>
Subject: Re: Perl exam - fair or not?
Message-Id: <u9isrfjhxa.fsf@wcl-l.bham.ac.uk>

hudson@swcp.com (Tramm Hudson) writes:

> Brian McCauley  <nobull@mail.com> wrote:
> > hudson@swcp.com (Tramm Hudson) writes:
> > > And neither 'local' nor 'my' are functions.  They are keywords that
> > > modify the storage class of variables.
> >
> > No, 'my' is a storage class modifier, 'local' is not.
> 
> While I agree that 'local' does not change the storage class of the
> variables (they still go into the package namespace), and that it does
> have a runtime effect as well,

I am aware that the meaning of the phrase "as well" is a little
different in American from it is in English.

In English the above sentence implies you think local() has some
semantics other than at runtime.  If this is the case then what do you
think they are?

> I believe it is roughly equivilant to C's "auto" storage class
> modifier.

My C is a bit rusty by IIRC C's auto is, on the contrary, analagous to
Perl's my().

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


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

Date: Mon, 09 Jun 2003 17:54:56 GMT
From: Drew Jones <drew4jones@yahoo.ca>
Subject: Re: Perl exam - fair or not?
Message-Id: <dae11fd1a8c85cf7f3cbadc0e6c606f7@free.teranews.com>

On Sun, 8 Jun 2003 22:54:21 +0000 (UTC), hudson@swcp.com (Tramm
Hudson) wrote:

>Tad McClellan <tadmc@augustmail.com> wrote:
>> anon <> wrote:
>> > [...]
>> > 28. Which are valid methods of turning on call-by-value? 
>> >  (a) Using the local function. 
>> >  (b) Using the my function. 
>> >  (c) Using the values function. 
>> >  (d) Using the & symbol to call the subroutine. 
>>
>> There is no correct answer for that question either.
>>
>> call-by-value is *impossible* in Perl, so you cannot "turn it on",
>> though you _can_ get the _effect_ of call-by-value by making a copy
>> and operating only on the copy.
>
>And neither 'local' nor 'my' are functions.  

But that is irrelevent in a multi choice exam.  The answers will
always include many statements that are incorrect (by definition).
Good "answers" on a multi choice exam will often include bogus terms.
In fact bogus answers are almost a kind of give away to help the
"honest but not briliant" students to get some marks.  A student that
has done their homework will be familiar enough with the topic to get
the right answer by weeding out the impossible answers even if they
aren't sure of the correct answer.  A student who didn't do their
homework will not have a clue because all the answers look reasonable.


> I can't imagine a serious
>teacher of C asking students if "using the static function" is a valid
>method of creating a private variable that holds its value between
>function calls.  

I beg to differ - you would ask that on a multi choice test.  The
point of the question would be to check whether the student is
familiar with static variables, or has simply recognized the word
"static" from last night's cramming session.



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

Date: Mon, 09 Jun 2003 16:38:00 GMT
From: "Josh McAdams" <jmcada@hotmail.com>
Subject: SDBM Utility
Message-Id: <IJ2Fa.2303$6E6.795318374@newssvr12.news.prodigy.com>

I'm looking for a command line utility to read/edit an SDBM database created
by Perl.  Does anyone know where I can find such a program?

Thanks,
Josh McAdams




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

Date: Mon, 09 Jun 2003 12:06:58 -0500
From: "J. Gleixner" <glex_nospam@qwest.net>
Subject: Re: SDBM Utility
Message-Id: <N83Fa.27$6W4.36633@news.uswest.net>

Josh McAdams wrote:
> I'm looking for a command line utility to read/edit an SDBM database created
> by Perl.  Does anyone know where I can find such a program?


You can create your own using various modules. Look on CPAN, for example:

http://search.cpan.org/search?query=sdbm&mode=all

Or you simply enter "perl sdbm" in google and you'll find documents and 
example code.


p.s. it doesn't matter that it was "created by Perl".



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

Date: 9 Jun 2003 08:55:25 -0700
From: almir_7@yahoo.com (Almir)
Subject: Search & Evaluate an array
Message-Id: <72ddae16.0306090755.55ac68a9@posting.google.com>

Hello all,

I'm stuck on writing a simple little program that reads in data from a
ODBC database and gets two counts out. The frist half of the program
is done where it counts all the distinct patron barcodes from the
database table. And the second half is to count all the 20 minute
sessions in the table of patron barcodes. The problem: I read in the
$barcode, $mdate, $mtime as string values.

$db->Sql("SELECT plog.Barcode, plog.Auth_Date, plog.Auth_Time FROM
plog WHERE(((plog.Auth_Date) Between #3/1/2003# And #3/31/2003#) AND
((plog.Key)=[key]))"); #distinct users for the month
while ($db->FetchRow())
    {
        ($barcode, $mdate, $mtime) = $db->Data();   #read in data by
row
        
     ...
}

I change the format of the strings:

$adate = $1 if $mdate =~ /((\d\d\d\d)-(\d\d)-(\d\d)/:  #2003-06-09
$atime = $1 if $mtime =~ /(\d\d : \d\d : \d\d)/:       #09:32:47

Now, i want to look at the three values and evaluate them:

If the barcode is in the array @patrons check the $adate, where
barcode is different i have to check the current combination against
that last occurance, and thus messure the time difference (if over
20minutes then store the combination if not then don't count it). If
the $barcode is found in the array @patrons then i check if the $adate
is different. If it is diffrent then store that combination of
$barcode, $adate, and $atime into array @patrons. If the $adate is the
same (last occurance = current combination) then check the $atime
diffrence (here i'm looking for time difference of 20minutes** only
for the same barcodes).

here is the sample data being read in:
$barcode               $mdate            $mtime

29094003734449  3/1/2003 (0:00:00) <- garbage (12/30/1899) <- garbage
9:39:32
29094003734449    3/1/2003 0:00:00   12/30/1899 10:43:52
29094003734449    3/1/2003 0:00:00   12/30/1899 10:44:40
29094003734449    3/1/2003 0:00:00   12/30/1899 12:06:01
29094003734449    3/1/2003 0:00:00   12/30/1899 12:50:58
29094003734449    3/1/2003 0:00:00   12/30/1899 14:06:45
29094003734449    3/1/2003 0:00:00   12/30/1899 15:21:34
29094003734449    3/1/2003 0:00:00   12/30/1899 16:48:13
29094003734449    3/1/2003 0:00:00   12/30/1899 20:56:23
29094003734449    3/1/2003 0:00:00   12/30/1899 21:42:12
29094004103578    3/1/2003 0:00:00   12/30/1899 22:35:21
29094003734449    3/2/2003 0:00:00   12/30/1899 10:57:41
29094003734449    3/2/2003 0:00:00   12/30/1899 16:07:04
29094003774320    3/2/2003 0:00:00   12/30/1899 16:25:42
29094004214532    3/2/2003 0:00:00   12/30/1899 16:56:03
29094003734449    3/2/2003 0:00:00   12/30/1899 17:34:20
29094003734449    3/2/2003 0:00:00   12/30/1899 19:08:50
29094003734449    3/2/2003 0:00:00   12/30/1899 20:55:17
29094003734449    3/2/2003 0:00:00   12/30/1899 20:55:34
29094003552189    3/2/2003 0:00:00   12/30/1899 23:06:39
29094003734449    3/3/2003 0:00:00   12/30/1899 0:57:37 
29094003734449    3/3/2003 0:00:00   12/30/1899 2:30:31 
29094003734449    3/3/2003 0:00:00   12/30/1899 2:33:00 
29094003734449    3/3/2003 0:00:00   12/30/1899 2:33:54 
29094003688686    3/3/2003 0:00:00   12/30/1899 8:32:48 
29094003688686    3/3/2003 0:00:00   12/30/1899 8:32:50 
29094004071312    3/3/2003 0:00:00   12/30/1899 9:30:26 
29094004071312    3/3/2003 0:00:00   12/30/1899 9:48:24 
29094003734449    3/3/2003 0:00:00   12/30/1899 9:58:13


I'm looking for 20 minute intervals within the unique patron records.

ACTUAL CODE:

#!perl
use Win32::ODBC;


$DSN = "IIIL"; #database name

if (!($db = new Win32::ODBC($DSN)))
    {
    print "connect to database failed.</br>"; #database connection
    print "Error:".win32::ODBC::Error()."<br>\n";
    exit;
    }


$db->Sql("SELECT DISTINCT plog.Barcode FROM plog
WHERE(((plog.Auth_Date) Between #3/1/2003# And #3/31/2003#) AND
((plog.Key)=[key]))"); #distinct users for the month

while ($db->FetchRow())
{
        ($barcode) = $db->Data();
        #print "$barcode\n"; #prints all the distinct barcodes
        $patrons+=1;
}

print "Number of Distinct Users: $patrons\n";  #prints the number

$i=0;
$db->Sql("SELECT plog.Barcode, plog.Auth_Date, plog.Auth_Time FROM
plog WHERE(((plog.Auth_Date) Between #3/1/2003# And #3/31/2003#) AND
((plog.Key)=[key]))"); #distinct users for the month
if ($db->FetchRow())
{
    ($barcode, $mdate, $mtime) = $db->Data();
           
    $code[$i] = $barcode;
    $dates[$i] = $1 if $mdate =~ /((\d\d\d\d)-(\d\d)-(\d\d))/;
    $times[$i] = $1 if $mtime =~ /(\d\d:\d\d:\d\d)/;
       
}

@bfound = 0;
@dfound = 0;
@tfound = 0;
$i=1;
$db->Sql("SELECT plog.Barcode, plog.Auth_Date, plog.Auth_Time FROM
plog WHERE(((plog.Auth_Date) Between #3/1/2003# And #3/31/2003#) AND
((plog.Key)=[key]))"); #distinct users for the month
while ($db->FetchRow())
    {
        ($barcode, $mdate, $mtime) = $db->Data();   #read in data by
row
        
        $adate = $1 if $mdate =~ /((\d\d\d\d)-(\d\d)-(\d\d))/;
        $atime = $1 if $mtime =~ /(\d\d:\d\d:\d\d)/;
        
        @patron = ($barcode, $adate, $atime);
        print "@patron\n";
        
        
        if (@bfound = grep /$barcode/, @code)   #check if there is the
previous barcode occurance
        {
            if (@dfound = grep /$adate/, @dates)    #check if there is
the previous date occurance
            {
                    if ($tfound = grep /$atime/, @times)    #check if
there is a previous time occurance
                    {
                        
                    }
                    else
                    {
                        ($hour, $min, $sec) = ($times[$tfound] =~
m/(\d+):(\d+):(\d+)/);
                        $checkoff = ((($hour * 60)*60) + ($min * 60) +
$sec);          #convert the time in seconds
                        
                        ($ahour, $amin, $asec) = ($atime =~
m/(\d+):(\d+):(\d+)/);
                        $inseconds = ((($ahour * 60)*60) + ($amin *
60) + $asec);        #convert the time in seconds
                        
                        if ($inseconds != $checkoff)  #check if the
time is equal
                        {
                            if ($inseconds >= $checkoff + 1200) 
#check if the time is bigger
                            {
                                $i+=1;
                                $code[$i] = $barcode;
                                $dates[$i] = $adate;
                                $times[$i] = $atime;
                                $number+=1;
                            }
                        }
                        else
                        {
                            $i+=1;
                        }
                    }
                
            }
            else
            {
                $i+=1;
                $code[$i] = $barcode;
                $dates[$i] = $adate;
                $times[$i] = $atime;
                $number+=1;
            }
        }
        else
        {
           $i+=1;
           $code[$i] = $barcode;
           $dates[$i] = $adate;
           $times[$i] = $atime;
           $number+=1; 
        }
}
print "Number of Sessions: $number\n"


ANY HELP OR SUGESTIONS WOULD BE GREATLY APPRECIATED.....


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

Date: Mon, 09 Jun 2003 11:22:44 -0500
From: "J. Gleixner" <glex_nospam@qwest.net>
Subject: Re: Search & Evaluate an array
Message-Id: <jv2Fa.21$6W4.32726@news.uswest.net>

Almir wrote:
> Hello all,
> 
> I'm stuck on writing a simple little program that reads in data from a
> ODBC database and gets two counts out. The frist half of the program
> is done where it counts all the distinct patron barcodes from the
> database table. And the second half is to count all the 20 minute
> sessions in the table of patron barcodes. The problem: I read in the
> $barcode, $mdate, $mtime as string values.
[...]
> ANY HELP OR SUGESTIONS WOULD BE GREATLY APPRECIATED.....

Any your perl question is????

Looks like you may like to get some SQL help.  A cursory look at your 
SQL...

For the first one learn how to use count().

For the second, no idea why you're doing that query since you do the 
same query again.

For the third, have the database return the number of seconds 
unix_timestamp(), if you're using MySQL, and use distinct(). Use a hash 
instead of grep'ing through an array.

You could probably benefit from having a timestamp field, instead of 
separate fields in your database.  Furthermore, it's likely you can do 
this whole script using only a few lines of SQL using: count(), 
distinct(), various date/time commands, order, and group by.  That'd be 
much faster than going through each record, parsing, grep'ing, 
comparing, and counting based on date & time.



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

Date: Mon, 09 Jun 2003 11:55:38 -0500
From: "J. Gleixner" <glex_nospam@qwest.net>
Subject: Re: Sorting IP's
Message-Id: <8_2Fa.24$6W4.35529@news.uswest.net>

derek / nul wrote:
> Can someone point me to any information about sorting IP addresses.

use Net::Netmask

Almost any issue regarding IP addresses can benefit from methods in that 
module.

http://search.cpan.org/author/MUIR/Net-Netmask-1.9004/Netmask.pod



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

Date: 9 Jun 2003 09:14:14 -0700
From: verycoldpenguin@hotmail.com (Gareth Glaccum)
Subject: Re: Unbuffered output from another program?
Message-Id: <991491a9.0306090814.408699af@posting.google.com>

verycoldpenguin@hotmail.com (Gareth Glaccum) wrote in message news:<991491a9.0306090219.49ba4606@posting.google.com>...
> I need to open a program from within a perl script, and then read the
> output of that program occasionally. Not a problem usually,
> 
> open(FH,"prog |")||die("Stupid proggy: $!");
> $t=<FH>;
> 
> assuming that FH does not over buffer.
> 
> However, I now need to make this nicer, so that other items can occur
> at all times.
> Therefore, I need to read the input from the program, if it exists,
> and not pause until it exists, and do stuff with the input. And, if
> the input is not there I will continue to do stuff with the OLD input.
> Does this make sense? 
> It is like a forked program, but the data from one part of the fork
> must be made available to the other part, without the other part
> needing to pause until the data exists.
> Thanks for any help
> Would prefer not to start up sockets though if easily avoidable.
> Gareth.

Thanks for not answering, here is my solution, not all there, but enough to see:

#################################################
use IO::Pipe;
$RE=new IO::Pipe;
$pid=fork();
if($pid){

$RE->reader();
$RE->blocking(0);
$line=0;
while(1){
while(<$RE>){
}
$n++;
}
}else{
$RE->writer();
$RE->autoflush(1);
open("blocking program |");
while(<FH>){
$RE->print($_);
}
}
}


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

Date: Mon, 09 Jun 2003 13:16:47 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: upload file without cgi.pm
Message-Id: <3N%Ea.72124$Pb.20915@nwrddc01.gnilink.net>

GhostNr1 wrote:
> I don't know where the other post get but I try again.
> I need to upload a file without useing cgi.pm or cgi-lib. Don't ask
> why. [...]

Ok, I won't. CGI.pm would have been the wrong tool anyway.
If you want to FTP a file then it's better to use Net::FTP instead.

jue




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

Date: Mon, 09 Jun 2003 13:57:34 GMT
From: Andras Malatinszky <nobody@dev.null>
Subject: Re: upload file without cgi.pm
Message-Id: <3EE49204.3000603@dev.null>



Jürgen Exner wrote:

> GhostNr1 wrote:
> 
>>I don't know where the other post get but I try again.
>>I need to upload a file without useing cgi.pm or cgi-lib. Don't ask
>>why. [...]
>>
> 
> Ok, I won't. CGI.pm would have been the wrong tool anyway.
> If you want to FTP a file then it's better to use Net::FTP instead.
> 
> jue
> 


Well, no, if you read the OP's posting carefully, you'll see that he is 
looking for an HTTP file upload -- for which CGI.pm is a very good tool 
in my experience.

Why he is averse to using CGI.pm is a mystery that apparently will not 
get revealed, but I doubt he will get more help than he got two weeks ago.




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

Date: Mon, 09 Jun 2003 14:32:19 GMT
From: "GhostNr1" <ghostnr1@telia.com>
Subject: Re: upload file without cgi.pm
Message-Id: <TT0Fa.14343$dP1.27526@newsc.telia.net>

Well it was mutch that peaple didn't understood and yes it is a HTTP file
upload I should have.
There must be someone that have done this.
There are very mutch post about it but very few solution. But there must be
someone that have done it I think.


---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.488 / Virus Database: 287 - Release Date: 6/5/2003




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

Date: Mon, 09 Jun 2003 16:21:59 +0100
From: Simon Andrews <simon.andrews@bbsrc.ac.uk>
Subject: Re: upload file without cgi.pm
Message-Id: <3EE4A617.9040108@bbsrc.ac.uk>


GhostNr1 wrote:
> Well it was mutch that peaple didn't understood and yes it is a HTTP file
> upload I should have.
> There must be someone that have done this.
> There are very mutch post about it but very few solution. But there must be
> someone that have done it I think.

Of course there is.  Lincoln Stein made a very nice job of handling file 
uploads.

Not wishing to sound obvious, but if you have some dire (and almost 
certainly irrational) fear of using CGI.pm, there's still nothing to 
stop you looking at the code it uses to handle file uploads.  You aren't 
going to get a better answer of how to do it than the answer in the 
standard module.

Having had a quick glance at the CGI.pm source there is a sub called 
"read_multipart" which should prove enlightening.

Heck, you can ever read it on the web if you like!

http://search.cpan.org/src/LDS/CGI.pm-2.94/CGI.pm

With any luck you'll see what it takes to do the job reliably and 
securely, then maybe decide that there are better ways of spending your 
time than doing all of this over again!

Hope this helps

Simon.



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

Date: Mon, 9 Jun 2003 16:24:39 +0100
From: news@roaima.freeserve.co.uk
Subject: Re: upload file without cgi.pm
Message-Id: <neler-i7f.ln1@moldev.cmagroup.co.uk>

GhostNr1 <ghostnr1@telia.com> wrote:
> Well it was mutch that peaple didn't understood and yes it is a HTTP file
> upload I should have.

Perhaps you should explain why you really don't want to use CGI.pm. (And
ensure you've read the FAQ entry, "How do I keep my own module/library
directory?")

Chris
-- 
@s=split(//,"Je,\nhn ersloak rcet thuarP");$k=$l=@s;for(;$k;$k--){$i=($i+1)%$l
until$s[$i];$c=$s[$i];print$c;undef$s[$i];$i=($i+(ord$c))%$l}


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

Date: Mon, 09 Jun 2003 08:57:10 -0700
From: Steve May <drumspoorly@reachone.net>
Subject: Re: upload file without cgi.pm
Message-Id: <ve9b50j4urh515@corp.supernews.com>

Simon Andrews wrote:
> 
> GhostNr1 wrote:
> 
>> Well it was mutch that peaple didn't understood and yes it is a HTTP file
>> upload I should have.
>> There must be someone that have done this.
>> There are very mutch post about it but very few solution. But there 
>> must be
>> someone that have done it I think.
> 
> 
> Of course there is.  Lincoln Stein made a very nice job of handling file 
> uploads.
> 
> Not wishing to sound obvious, but if you have some dire (and almost 
> certainly irrational) fear of using CGI.pm, there's still nothing to 
> stop you looking at the code it uses to handle file uploads.  You aren't 
> going to get a better answer of how to do it than the answer in the 
> standard module.
> 

Well, there is one case where CGI.pm simply won't do and that is when
you want to embed instructions into a multiple file upload form so
that your script will perform actions *between* uploading files from
the same form page.

Unless CGI.pm has changed of course. :-)

True, it's pretty rare to really need the above, but I've run
across it with customers who insisted on a specific GUI and left
me with little choice.

Actually it is not that tough to write a file upload routine if
the OP would just read the docs and then run the obvious tests.

Then again, if someone needs example code beyond what is in CGI.pm, then
they probably don't know enough about the subject to mess with it and
should stick with CGI.

s.



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

Date: Mon, 09 Jun 2003 16:24:11 GMT
From: "GhostNr1" <ghostnr1@telia.com>
Subject: Re: upload file without cgi.pm
Message-Id: <Lw2Fa.14359$dP1.27513@newsc.telia.net>

Well it is not me that should run this and what I have seen there have been
some problem when you switch from one computer to another. If I should run
it on this computer then I can use it. Maby this isn't the best excuse. Then
I whant to learn how it works. Line by line. It is the only why to learn
something. If you allways use other works and don't understand what they
have done then there can be problem.
Maby I'm a morran that don't use cgi.pm but that's me.



---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.488 / Virus Database: 287 - Release Date: 6/5/2003




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

Date: Mon, 9 Jun 2003 17:29:53 +0100
From: "SymbianPSION Hater" <psion.is.fubar@thebroonclan.com>
Subject: Win32::OLE and Sorts
Message-Id: <bc2dff$sng$1@news6.svr.pol.co.uk>

can anyone shed some light on this

Excel macro is

    Range("A6:AE100").Select
    Selection.Sort Key1:=Range("A6"), Order1:=xlDescending,
Key2:=Range("C6") _
        , Order2:=xlDescending, Key3:=Range("D6"), Order3:=xlDescending,
Header _
        :=xlNo, OrderCustom:=1, MatchCase:=False,
Orientation:=xlTopToBottom, _
        DataOption1:=xlSortNormal, DataOption2:=xlSortNormal, DataOption3:=
_
        xlSortNormal

perl translation im using is

    $SortOrd1 = $sheet->Range("A6:A6");
    $SortOrd2 = $sheet->Range("C6:C6");
    $SortOrd3 = $sheet->Range("D6:D6");
    $SheetSort = $sheet->Range("$Range");
    $SheetSort->Sort ({
       Key1     => $SortOrd1});
       Order1    => xll->{xlDescending},
       Key2     => $SortOrd2,
       Order2    => xll->{xlDescending},
       Key3     => $SortOrd3,
       Order3    => xll->{xlAscending},
       Header    => xll->{xlNo},
       OrderCustom => 1,
       MatchCase  => False,
       Orientation => xll->{xlTopToBottom},
       DataOption1 => xll->{xlSortNormal},
       DataOption2 => xll->{xlSortNormal},
       DataOption3 => xll->{xlSortNormal}});         # set sorts

$sheet can be assumed to be ok - sorks fine everywhere else.

WHAT AM I DOING WRONG?

Ken




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

Date: Mon, 9 Jun 2003 17:45:53 +0100
From: "SymbianPSION Hater" <psion.is.fubar@thebroonclan.com>
Subject: Re: Win32::OLE and Sorts
Message-Id: <bc2dk3$j59$1@news8.svr.pol.co.uk>

Sorry
typo on my part in perl code key1 =>...  - ignore ");"

"SymbianPSION Hater" <psion.is.fubar@thebroonclan.com> wrote in message
news:bc2dff$sng$1@news6.svr.pol.co.uk...
> can anyone shed some light on this
>
> Excel macro is
>
>     Range("A6:AE100").Select
>     Selection.Sort Key1:=Range("A6"), Order1:=xlDescending,
> Key2:=Range("C6") _
>         , Order2:=xlDescending, Key3:=Range("D6"), Order3:=xlDescending,
> Header _
>         :=xlNo, OrderCustom:=1, MatchCase:=False,
> Orientation:=xlTopToBottom, _
>         DataOption1:=xlSortNormal, DataOption2:=xlSortNormal,
DataOption3:=
> _
>         xlSortNormal
>
> perl translation im using is
>
>     $SortOrd1 = $sheet->Range("A6:A6");
>     $SortOrd2 = $sheet->Range("C6:C6");
>     $SortOrd3 = $sheet->Range("D6:D6");
>     $SheetSort = $sheet->Range("$Range");
>     $SheetSort->Sort ({
>        Key1     => $SortOrd1});
>        Order1    => xll->{xlDescending},
>        Key2     => $SortOrd2,
>        Order2    => xll->{xlDescending},
>        Key3     => $SortOrd3,
>        Order3    => xll->{xlAscending},
>        Header    => xll->{xlNo},
>        OrderCustom => 1,
>        MatchCase  => False,
>        Orientation => xll->{xlTopToBottom},
>        DataOption1 => xll->{xlSortNormal},
>        DataOption2 => xll->{xlSortNormal},
>        DataOption3 => xll->{xlSortNormal}});         # set sorts
>
> $sheet can be assumed to be ok - sorks fine everywhere else.
>
> WHAT AM I DOING WRONG?
>
> Ken
>
>




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

Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 6 Apr 01)
Message-Id: <null>


Administrivia:

The Perl-Users Digest is a retransmission of the USENET newsgroup
comp.lang.perl.misc.  For subscription or unsubscription requests, send
the single line:

	subscribe perl-users
or:
	unsubscribe perl-users

to almanac@ruby.oce.orst.edu.  

To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.

To request back copies (available for a week or so), send your request
to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
where x is the volume number and y is the issue number.

For other requests pertaining to the digest, send mail to
perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
sending perl questions to the -request address, I don't have time to
answer them even if I did know the answer.


------------------------------
End of Perl-Users Digest V10 Issue 5098
***************************************


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