[13967] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 1377 Volume: 9

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sun Nov 14 18:10:32 1999

Date: Sun, 14 Nov 1999 15:10:16 -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: <942621016-v9-i1377@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Sun, 14 Nov 1999     Volume: 9 Number: 1377

Today's topics:
    Re: regular expression riddle (Brett W. McCoy)
    Re: regular expression riddle (Brett W. McCoy)
    Re: regular expression riddle (Bart Lateur)
    Re: regular expression riddle (Martien Verbruggen)
    Re: Removing occurrences of a string from another strin <D.Bayne@NmaOssSeyP.aAc.Mnz>
    Re: return height and width of jpeg, gif accessed via u (Martien Verbruggen)
    Re: Search & Replace Question... (Craig Berry)
    Re: Show me a better way! <jeff@vpservices.com>
    Re: sort lists together <lr@hpl.hp.com>
    Re: sort lists together (Brett W. McCoy)
    Re: sort lists together <uri@sysarch.com>
    Re: sort lists together <lr@hpl.hp.com>
    Re: sort lists together <uri@sysarch.com>
        SSI & CGI  ( beginner) <eddie3@nassau.cv.net>
    Re: SSI & CGI  ( beginner) (Brett W. McCoy)
    Re: Style Sheets crash netscape (Martien Verbruggen)
        Sys::Syslog setlogsock <jvahn@short.circuit.com>
    Re: System Command (Brett W. McCoy)
    Re: Too much Perl? (Brett W. McCoy)
    Re: Trying to use a variable as an operator <lr@hpl.hp.com>
    Re: Trying to use a variable as an operator (Brett W. McCoy)
    Re: Weekday in perl (Martien Verbruggen)
    Re: Which Search engine script? (Mike Thompson)
    Re: Why Doesn't This Work on ICOM? <uri@sysarch.com>
    Re: Win32::ODBC use of uninitialized value warnings (Brett W. McCoy)
    Re: Win32::ODBC use of uninitialized value warnings <nmorison@ozemail.com.au>
        Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)

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

Date: Sun, 14 Nov 1999 17:22:49 GMT
From: bmccoy@news.lan2wan.com (Brett W. McCoy)
Subject: Re: regular expression riddle
Message-Id: <slrn82tsds.l5i.bmccoy@dragosani.lan2wan.com>

On Sat, 13 Nov 1999 20:30:14 +0200, Re'em Bar <reembar@netvision.net.il> wrote:
>
>I want to change any word so it begins with CAPS
>the little rabbit => The Little Rabbit
>hope it's not in the FAQ too...

'Fraid it is, dude.  Look up ucfirst in your perl documentation.

>also, excuse my ignorance, but is there a way to pass more then one
>array to a subroutine, not into the @_?

Not sure what you mean.  Can you be more specific?

-- 
Brett W. McCoy           
                                        http://www.lan2wan.com/~bmccoy/
-----------------------------------------------------------------------
Tomorrow, you can be anywhere.


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

Date: Sun, 14 Nov 1999 17:27:05 GMT
From: bmccoy@news.lan2wan.com (Brett W. McCoy)
Subject: Re: regular expression riddle
Message-Id: <slrn82tsls.l5i.bmccoy@dragosani.lan2wan.com>

On Sun, 14 Nov 1999 17:22:49 GMT, Brett W. McCoy <bmccoy@news.lan2wan.com>
wrote:

>>I want to change any word so it begins with CAPS
>>the little rabbit => The Little Rabbit
>>hope it's not in the FAQ too...
>
>'Fraid it is, dude.  Look up ucfirst in your perl documentation.

Oops, I take that back.  That only works on words.  Use this regular
expression:

 s/(\w+)/\u\L$1/g

-- 
Brett W. McCoy           
                                        http://www.lan2wan.com/~bmccoy/
-----------------------------------------------------------------------
Neutrinos are into physicists.


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

Date: Sun, 14 Nov 1999 20:49:08 GMT
From: bart.lateur@skynet.be (Bart Lateur)
Subject: Re: regular expression riddle
Message-Id: <382f1fb3.758843@news.skynet.be>

Brett W. McCoy wrote:

>>Look up ucfirst in your perl documentation.
>
>Oops, I take that back.  That only works on words.  Use this regular
>expression:
>
> s/(\w+)/\u\L$1/g

	s/(\w+)/ucfirst $1/ge;
or
	s/(\w+)/ucfirst lc $1/ge;

if there's any risk of unwanted characters (inside words) being
uppercase.

-- 
	Bart.


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

Date: Sun, 14 Nov 1999 22:45:54 GMT
From: mgjv@comdyn.com.au (Martien Verbruggen)
Subject: Re: regular expression riddle
Message-Id: <CYGX3.86$zg7.2135@nsw.nnrp.telstra.net>

On Sat, 13 Nov 1999 20:30:14 +0200,
	Re'em Bar <reembar@netvision.net.il> wrote:
> 
> I want to change any word so it begins with CAPS
> the little rabbit => The Little Rabbit
> hope it's not in the FAQ too...
> 
> also, excuse my ignorance, but is there a way to pass more then one
> array to a subroutine, not into the @_?

I have seen quite a few questions from you of late, and many of them
have been answered by pointing you to the documentation. I think the
time has now come to give you a lesson on how to use the
documentation, so you can stop asking us questions like these, and you
can start finding out the answers yourself.

Perl comes with a large, large amount of documentation, which is most
easily (and crossplatform) accessible with perldoc. In the following,
'#' is the shell prompt:

# perldoc perl
# perldoc perldoc
# perldoc perldata
# perldoc -f open
# perldoc -q keyword

Your question:

# perldoc -q capital
=head1 Found in /usr/local/lib/perl5/5.00502/pod/perlfaq4.pod

=head2 How do I capitalize all the words on one line?

To make the first letter of each word upper case:
[snipped, to encourage you to try it for yourself]

You should consider the following documentation mandatory reading:

# perldoc perl
# perldoc perlsyn
# perldoc perldata
# perldoc perlop
# perldoc perlsub
[And this one contains the answer to your second question under 'Pass
by Reference']
# perldoc perlref
# perldoc perlfunc
[at least browse through it]
# perldoc perlre
[if you want to do regular expressions]

# perldoc perl
will give you an (almost) complete list of documentation

# perldoc perlfaq

Do yourself a favour, and spend some time reading the documentation,
and/or buy a good book about Perl. You can find references to good
books on www.perl.com.

Martien
-- 
Martien Verbruggen              | 
Interactive Media Division      | 
Commercial Dynamics Pty. Ltd.   | What's another word for Thesaurus?
NSW, Australia                  | 


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

Date: Mon, 15 Nov 1999 09:01:22 +1300
From: "Duncan Bayne" <D.Bayne@NmaOssSeyP.aAc.Mnz>
Subject: Re: Removing occurrences of a string from another string
Message-Id: <jyEX3.2073$5W2.45796@news.clear.net.nz>

: That's utterly amazing. What's next, someone reading a book about
: Java, and "missing" how to do OO?

Thanks to all who responded for the information.  I must admit that, as
Abigail stated, I was pretty stupid to miss s/// in the manpages.  Being
used to languages like C / C++, with all text manipulation utilities in
functions, it never ocurred to me that I should be looking for an operator,
not a function.  Therefore, I didn't look for an operator :-(

With this in mind, I found everything I needed to know within minutes.  Once
again, thanks.

Cya,
Duncan Bayne

-----
GCS/d++@s+:+@a--c++ULP+>+++L++>++++EW++N++@o?K?wOM-V?PS+@PE++Y+PGP-t+5X+@R+!
tvb+DI++++D+G--e>++h---@r++x+ - http://www.geekcode.com

This message is personal, and in no way related to the affairs of Massey
University, or to my employment by Massey University.




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

Date: Sun, 14 Nov 1999 22:15:25 GMT
From: mgjv@comdyn.com.au (Martien Verbruggen)
Subject: Re: return height and width of jpeg, gif accessed via url
Message-Id: <1wGX3.66$zg7.2135@nsw.nnrp.telstra.net>

On Sun, 14 Nov 1999 14:37:41 GMT,
	Kragen Sitaker <kragen@dnaco.net> wrote:
> In article <slrn82s5o2.jb7.mgjv@wobbie.heliotrope.home>,
> Martien Verbruggen <mgjv@comdyn.com.au> wrote:
> >iAnd I agree here. But the OP said there were valid reasons not to use
> >modules that don't come with the Perl distribution. While I doubt that
> >very much, as expressed in my previous post, a way the deluded can get
> >around using modules at all is by putting the module code in their
> >scripts. Of course, they are then _still_ usign the module. They just
> >got rid of some of the benefits as you pointed out. And that was what I
> >really meant with my question :).
> >
> >I don't know why people don't seem to get that using a module is no
> >different from writing your own code (apart from the points you made,
> >and one or two others), and keep insisting on this 'no other modules
> >than the standard ones' crap.
> 
> Well, code you have written yourself is theoretically code you
> understand, and it's probably smaller and more specialized than the
> code from the module.  There are sometimes good arguments against
> reusing code.

I agree. But indeed, it requires some very good reasons. Valid reasons
I can think of:

- The module is big. Really big. I only need 5% of the
  functionality
- The module's interface is inconvenient. I need access to bits of the
  module that are undocumented, and therefore not guaranteed to work
  in the next release. I'll send a patch to the author, and implement
  my own version
- The module does not do all the things I want. I either use the
  module, and insert a sub into it at runtime (also sending a patch to
  the author), or inherit and add my own code. If I expect that code
  to be implemented, I will wrap it so it doesn't overwrite module
  code.
- The module is broken.

And finally:
- I know better how to do it than the module author

This last one, of course, is very, very rare. In fact, it's never
happened to me, and its reverse is of course the main argument for
most people to use modules. The author probably, most likely knew
better what she or he was doing than you, or at least already has made
(and corrected) all the mistakes that you are going to make.

Martien

-- 
Martien Verbruggen              | 
Interactive Media Division      | Failure is not an option. It comes
Commercial Dynamics Pty. Ltd.   | bundled with your Microsoft product.
NSW, Australia                  | 


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

Date: Sun, 14 Nov 1999 19:03:29 GMT
From: cberry@cinenet.net (Craig Berry)
Subject: Re: Search & Replace Question...
Message-Id: <s2u1s1nvhsq91@corp.supernews.com>

Kazz (kazz@ashernet.net) wrote:
: Say I have a tag to replace that I know begins with "<body" and I want
: to replace everything to the ">" end of that tag. Actually, I want to
: prepend a scalar to it but want to make sure what I'm adding isn't
: added until the end of the tag... what's the best way?
: $line =~ s/<body .. >/<body .. >$morestuff/gi;   ??

  $line =~ s/(<body.*?>)/$1$morestuff/gi;

Do you really want /g?  Is there going to be more than one body tag?

Also, beware of running this over HTML you didn't write (or inspect).
Doing HTML mods without parsing is not guaranteed to work in all cases.

-- 
   |   Craig Berry - cberry@cinenet.net
 --*--  http://www.cinenet.net/users/cberry/home.html
   |   "They do not preach that their God will rouse them
      a little before the nuts work loose." - Kipling


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

Date: 14 Nov 1999 19:21:34 GMT
From: Jeff Zucker <jeff@vpservices.com>
To: Jody Fedor <JFedor@datacom-css.com>
Subject: Re: Show me a better way!
Message-Id: <382F0B74.9EB7D2B0@vpservices.com>

[posted and mailed]

Jody Fedor wrote:
> 
> Jeff Zucker wrote in message <382DCE76.C684F558@vpservices.com>...
> >
> >I'd lose the ifs and use hashes and ors.
> >
> >my $state = $cookies{state} || $in{fstate} || '';
> 
> if $in{fstate} is null or "" and $cookies{state} = "OH" would $state="OH"?
> What if both where "OH" if there were three comparisons or 4 if there
> were multiple "OH"'s would $state="OH"? (Assuming of course one contained
> OH)
> 
> such as:
> 
> my $state = $cookies{state} || $in{fstate} || $in{state} || $input{st} || ''

Well, the best way for you to find out, is to put a bunch of different
values in those variables and try it out. :-)

My understanding is that $state takes the value of the first non-empty
variable reading from left to right, then ignores everything else.  It
becomes '' if and only if all the other variables are empty.

This construct is based on simple truth values.  It evaluates the first
variable on the left (in this case, $cookies{state}) and if it is true
(i.e. $cookies{$state} is some value other than 0 or '' or undefined)
then the construct sets $state equal to $cookies{$state} and is done. 
But if the first variable on the left is false (e.g. $cookies{state} is
undefined or '' or 0), then it moves on to the next variable and does
the same test.  And so on for as many variables as you care to put in. 
This means that the order you put the variables in is very important. 
The way your example is written, it would always take the cookie value
if there was a cookie value so even if the user set a different value in
$input, it would be ignored unless there was no $cookie.  If, instead,
you wanted it to use $input first and only consult $cookie if there was
no $input, then you'd have to reverse the order of those variables in
the construct.

This construct is very handy for many tasks, especially if you are
running with -w (which you should be) since it means you will never get
an uninitialized variable warning -- even if the variable ends up being
empty, it is initialized.

-- 
Jeff


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

Date: Sun, 14 Nov 1999 09:38:19 -0800
From: Larry Rosler <lr@hpl.hp.com>
Subject: Re: sort lists together
Message-Id: <MPG.1298936a4b906ca598a1fa@nntp.hpl.hp.com>

In article <slrn82tjli.rs3.abigail@alexandra.delanet.com> on 14 Nov 1999 
08:57:46 -0600, Abigail <abigail@delanet.com> says...

 ...

> You can speed up the sorting using one of GRP tricks, but that's besides
> the point here.

I didn't think any 'tricks' were needed when I posted the identical 
code.  :-)

> I would use a list of structured thingybobs [1], be it hashrefs, arrayrefs,
> or objects.
> 
> [1] I first said "structured objects", but "object" already has a meaning
>     as being a reference blessed into a package. Anyone has a good term?

"Structured entities" does it for me.

-- 
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com


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

Date: Sun, 14 Nov 1999 17:39:21 GMT
From: bmccoy@news.lan2wan.com (Brett W. McCoy)
Subject: Re: sort lists together
Message-Id: <slrn82ttcs.l5i.bmccoy@dragosani.lan2wan.com>

On 14 Nov 1999 08:57:46 -0600, Abigail <abigail@delanet.com> wrote:

>[1] I first said "structured objects", but "object" already has a meaning
>    as being a reference blessed into a package. Anyone has a good term?

I don't know... 'thingybob' sounds pretty specific and unambiguous to me.

-- 
Brett W. McCoy           
                                        http://www.lan2wan.com/~bmccoy/
-----------------------------------------------------------------------
Why do we have two eyes?  To watch 3-D movies with.


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

Date: 14 Nov 1999 12:51:55 -0500
From: Uri Guttman <uri@sysarch.com>
Subject: Re: sort lists together
Message-Id: <x7d7tdx8p0.fsf@home.sysarch.com>

>>>>> "A" == Abigail  <abigail@delanet.com> writes:

  A>     my @indx        = sort  {$age [$a] <=> $age [$b]} 0 .. $#age;
  A>     my @sorted_age  = @age  [@indx];
  A>     my @sorted_name = @name [@indx];

also you should label that (and larry should too) as an index sort. it
is where you actually sort indexes of your data so you can use the
sorted resulted to order multiple sets or order a set that can't be
sorted directly (such as array or hash refs in the GRP sort).

  A> I would use a list of structured thingybobs [1], be it hashrefs,
  A> arrayrefs, or objects.

  A> [1] I first said "structured objects", but "object" already has a
  A> meaning as being a reference blessed into a package. Anyone has a
  A> good term?

structures. good, all purpose container word. IMO perl structures
generally include array and hash refs and most objects.

uri

-- 
Uri Guttman  ---------  uri@sysarch.com  ----------  http://www.sysarch.com
SYStems ARCHitecture, Software Engineering, Perl, Internet, UNIX Consulting
The Perl Books Page  -----------  http://www.sysarch.com/cgi-bin/perl_books
The Best Search Engine on the Net  ----------  http://www.northernlight.com


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

Date: Sun, 14 Nov 1999 12:08:00 -0800
From: Larry Rosler <lr@hpl.hp.com>
Subject: Re: sort lists together
Message-Id: <MPG.1298b67c5e01a8ea98a1fd@nntp.hpl.hp.com>

In article <x7d7tdx8p0.fsf@home.sysarch.com> on 14 Nov 1999 12:51:55 -
0500, Uri Guttman <uri@sysarch.com> says...
> >>>>> "A" == Abigail  <abigail@delanet.com> writes:
> 
>   A>     my @indx        = sort  {$age [$a] <=> $age [$b]} 0 .. $#age;
>   A>     my @sorted_age  = @age  [@indx];
>   A>     my @sorted_name = @name [@indx];
> 
> also you should label that (and larry should too) as an index sort.

Er, um, I did.  You must have seen my post of the code, or you wouldn't 
have mentioned me.  But this was there too:

LR> That is good advice, applicable if you are willing and able to 
LR> manipulate two-level data structures.  Nevertheless, there is a
LR> simple solution to the problem as posed -- the index sort.
LR> ...

-- 
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com


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

Date: 14 Nov 1999 17:20:46 -0500
From: Uri Guttman <uri@sysarch.com>
Subject: Re: sort lists together
Message-Id: <x73du8yatd.fsf@home.sysarch.com>

>>>>> "LR" == Larry Rosler <lr@hpl.hp.com> writes:

  LR> In article <x7d7tdx8p0.fsf@home.sysarch.com> on 14 Nov 1999 12:51:55 -
  LR> 0500, Uri Guttman <uri@sysarch.com> says...

  >> also you should label that (and larry should too) as an index sort.

  LR> Er, um, I did.  You must have seen my post of the code, or you wouldn't 
  LR> have mentioned me.  But this was there too:

  LR> That is good advice, applicable if you are willing and able to 
  LR> manipulate two-level data structures.  Nevertheless, there is a
  LR> simple solution to the problem as posed -- the index sort.

musta missed it. good boy! :-)

uri

-- 
Uri Guttman  ---------  uri@sysarch.com  ----------  http://www.sysarch.com
SYStems ARCHitecture, Software Engineering, Perl, Internet, UNIX Consulting
The Perl Books Page  -----------  http://www.sysarch.com/cgi-bin/perl_books
The Best Search Engine on the Net  ----------  http://www.northernlight.com


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

Date: Sun, 14 Nov 1999 18:34:25 GMT
From: "Ed" <eddie3@nassau.cv.net>
Subject: SSI & CGI  ( beginner)
Message-Id: <RgDX3.7165$Hc.19901081@news.optonline.net>

Hi

I am trying to call an ssi from with in a cgi script footer, Is this
possible ?


<!--#exec cgi="/cgi-bin/counterlog.pl"-->

If this is the wrong group to post to also let me know which one is proper.

Thanks
Ed






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

Date: Sun, 14 Nov 1999 18:43:26 GMT
From: bmccoy@news.lan2wan.com (Brett W. McCoy)
Subject: Re: SSI & CGI  ( beginner)
Message-Id: <slrn82u152.l5i.bmccoy@dragosani.lan2wan.com>

On Sun, 14 Nov 1999 18:34:25 GMT, Ed <eddie3@nassau.cv.net> wrote:

>I am trying to call an ssi from with in a cgi script footer, Is this
>possible ?
>
><!--#exec cgi="/cgi-bin/counterlog.pl"-->

Did you try it to see?

>If this is the wrong group to post to also let me know which one is proper.

Actually, a newsgroup more suited to HTML and CGI development is probably
more suitable.

-- 
Brett W. McCoy           
                                        http://www.lan2wan.com/~bmccoy/
-----------------------------------------------------------------------
Pandora's Rule:
	Never open a box you didn't close.


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

Date: Sun, 14 Nov 1999 21:59:38 GMT
From: mgjv@comdyn.com.au (Martien Verbruggen)
Subject: Re: Style Sheets crash netscape
Message-Id: <ehGX3.61$zg7.2135@nsw.nnrp.telstra.net>

[Your newsreader seems to have a chronology problem. Your response to
my remarks actually arrived before my remarks. Please reset your
clock]
[If you quote a message, please at least remove the signature. You
should also remove anything that is not pertinent to the post]
[If you email as well as post, pleas esay so in the body of the
message. Most people read their email before Usenet, and itr prevents
them from responding in person when it really should be on the group]

On Sat, 13 Nov 1999 01:25:21 +0900,
	Mike Ryan <mryan@kc4.so-net.ne.jp> wrote:
> Martien Verbruggen wrote:
> 
> > On Fri, 12 Nov 1999 15:02:14 +0900,
> >         Mike Ryan <mryan@kc4.so-net.ne.jp> wrote:
> > > OK please IGNORE this, I am idiot :)
[snip of remarks pointing out that the question wasn't about Perl]

> Well Im sorry if I was the cause of eyeball strain while you were reading
> this BUT my initial question was about perl. I was having problems with
>  print $query->start_html(-title=>"Survey",
>      -meta=>{'keywords'=>'1,2,3,4,5'},
>      -style=>{-src=>'/style/style1.css'},
>      -bgcolor=>"#FF9933");

That does not make it a Perl question. In your own followup to your
own post, you pointed out that you had some error in your HTML. That's
what I pointed out to you. Perl has no power to make browsers crash.
Perl does not interface with browsers. Perl has no stylesheets. The
fact that you use Perl to print these things does not make it a perl
issue. Had you used C for this, would it have been a C issue?

No.

So, next time your browser does something you don't expect, inspect
the HTML that it is trying to render. Do not look at the perl code
until you have found which bit of the HTML is making the browser go
*kadunk*. Not unless you know that, is there any sense in going back
to your perl code.

> Oh what the hell why even  bother  try explaining myself....
> have fun !

There is absolutely no need to get defensive about this. You are not
the only one making the mistake of equating Perl with CGI, HTTP, HTML,
JavaScript and anything else that has anything to do with the Web.
Insted of getting defensive and pissed off, you should take this to
heart, and learn to separate the issues when programming using
interfaces. What exactly is the interface's responsibility, and what
the programming language's. Once you master that, you'll be a lot more
comfortable programming. If you get defensive, you don't get anywhere.

Learn, and move on.

Martien
-- 
Martien Verbruggen              | 
Interactive Media Division      | 
Commercial Dynamics Pty. Ltd.   | Curiouser and curiouser, said Alice.
NSW, Australia                  | 


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

Date: 14 Nov 1999 21:53:28 GMT
From: James Vahn <jvahn@short.circuit.com>
Subject: Sys::Syslog setlogsock
Message-Id: <80nb0o$vbs$1@gonzo.circuit.com>

The old method was   use Sys::Syslog;

The new method is    use Sys::Syslog qw(:DEFAULT setlogsock);
                     setlogsock 'unix';
    
How do we program perl to accomodate whichever method is
appropriate for whatever version?

Specifically, I need to run the same script on perl versions
5.003_07 and 5.004_05.

-- 


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

Date: Sun, 14 Nov 1999 17:44:10 GMT
From: bmccoy@news.lan2wan.com (Brett W. McCoy)
Subject: Re: System Command
Message-Id: <slrn82ttlt.l5i.bmccoy@dragosani.lan2wan.com>

On Sun, 14 Nov 1999 11:13:14 +0100, Kastro Vinic <kastrovinic@hotmail.com>
wrote:

>What is the ` doing.
>eg. $out = `dir`;
>is this like a system() command?

Not quite. Backticks take the *output* of the command (which does get
executed) and puts it into the string.  You can also put it into a list
context instead of scalar context.

-- 
Brett W. McCoy           
                                        http://www.lan2wan.com/~bmccoy/
-----------------------------------------------------------------------
Why do we have two eyes?  To watch 3-D movies with.


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

Date: Sun, 14 Nov 1999 17:50:11 GMT
From: bmccoy@news.lan2wan.com (Brett W. McCoy)
Subject: Re: Too much Perl?
Message-Id: <slrn82tu16.l5i.bmccoy@dragosani.lan2wan.com>

On Sat, 13 Nov 1999 20:21:40 GMT, Kragen Sitaker <kragen@dnaco.net> wrote:

>I write things in C sometimes, but mostly when the problem isn't any
>better suited to Perl than to C.

I do feel pangs of remose sometimes when I see the piles of C books
collecting dust on the floor, or remnants of old C programs that never got
finished, but then I recall the old question of why C programmers have
such flat foreheads...

-- 
Brett W. McCoy           
                                        http://www.lan2wan.com/~bmccoy/
-----------------------------------------------------------------------
Like the ski resort of girls looking for husbands and husbands looking
for girls, the situation is not as symmetrical as it might seem.
		-- Alan McKay


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

Date: Sun, 14 Nov 1999 09:40:30 -0800
From: Larry Rosler <lr@hpl.hp.com>
Subject: Re: Trying to use a variable as an operator
Message-Id: <MPG.129893ec91ac188798a1fb@nntp.hpl.hp.com>

[Rearranged with comment after that which is commented on.]

In article <kYrX3.3452$Xo.18732@news-server.bigpond.net.au> on Sun, 14 
Nov 1999 05:41:36 GMT, Douglas Garstang <dgarstan@nsw.bigpond.net.au> 
says...
+ Scott Lanning wrote in message ...
+ >jradford@my-deja.com writes:
+ >> I would like to be able to change the "$operator" variable
+ >> to other operators on the fly, and still have it work:
+ >>
+ >> $operator = 'eq';
+ >>
+ >> if("text" $operator "text") {
+ >>   do_something;
+ >> }
+ >
+ >You can use eval().
+ >
+ >#!/usr/local/bin/perl -w
+ >use strict;
+ >my @text = qw('foo' 'bar');
+ >my $op = 'eq';
+ >
+ >$_ = "$text[0] $op $text[0]";
+ >print "text1=$text[0], text2=$text[0]: ";
+ >if(eval){
+ >    print "matched\n";
+ >}else {
+ >    print "didn't match\n";
+ >}
+ >
+ >$_ = "$text[0] $op $text[1]";
+ >print "text1=$text[0], text2=$text[1]: ";
+ >if(eval){
+ >    print "matched\n";
+ >}else {
+ >    print "didn't match\n";
+ >}
+ >
+ >__END__
+ >
+ >
+ >Alternatively, you can make a command hash like
+ >
+ >#!/usr/local/bin/perl -w
+ >use strict;
+ >my @text = qw('foo' 'bar');
+ >my $op = 'eq';
+ >
+ >my %op = (
+ >    "eq" => \&is_equal,
+ >    etc...
+ >);
+ >
+ >print "1\n";
+ >print "matched\n" if $op{$op}->($text[0], $text[1]);
+ >print "2\n";
+ >print "matched\n" if $op{$op}->($text[0], $text[0]);
+ >
+ >sub is_equal {
+ >    return shift eq shift;
+ >}
+ >
+ >etc...

+ Now THAT is nifty....

The first approach (eval STRING) is *not* nifty.  It is quite slow.  It 
is also quite flexible, because the contents of the operator string 
don't have to be anticipated.  But this also makes it vulnerable to 
attack, if the operator string comes from an outside source.  Consider, 
for example,

    $operator = q{ eq 'foobar' || system('rm -fr /') || };

But surely you meant that the second approach (dispatch table) is nifty, 

which it is (with suitable error handling for the default case of an 
unanticipated operator string).  But we couldn't tell that because your 
observation was in the wrong place relative to what you quoted.

-- 
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com


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

Date: Sun, 14 Nov 1999 17:53:22 GMT
From: bmccoy@news.lan2wan.com (Brett W. McCoy)
Subject: Re: Trying to use a variable as an operator
Message-Id: <slrn82tu75.l5i.bmccoy@dragosani.lan2wan.com>

On Sun, 14 Nov 1999 02:44:49 GMT, jradford@my-deja.com
<jradford@my-deja.com> wrote:

>I am wondering how to make the following code
>work, I would like to be able to change the
>"$operator" variable to other operators on the
>fly, and still have it work:
>
>$operator = 'eq';
>
>if("text" $operator "text") {
>  do_something;
>}

You'd need to bundle your expression up into a string passed to eval.


-- 
Brett W. McCoy           
                                        http://www.lan2wan.com/~bmccoy/
-----------------------------------------------------------------------
All things are either sacred or profane.
The former to ecclesiasts bring gain;
The latter to the devil appertain.
-- Dumbo Omohundro


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

Date: Sun, 14 Nov 1999 22:24:10 GMT
From: mgjv@comdyn.com.au (Martien Verbruggen)
Subject: Re: Weekday in perl
Message-Id: <eEGX3.78$zg7.2135@nsw.nnrp.telstra.net>

On Fri, 12 Nov 1999 22:09:53 -0500,
	J. Moreno <planb@newsreaders.com> wrote:
> Martien Verbruggen <mgjv@wobbie.heliotrope.home> wrote:
> 
> >       Larry Rosler <lr@hpl.hp.com> wrote:
> > > GMT, Viscano <kc@disinfo.net> says...
> > > + Probably a faster way to do it..but...
> > 
> > [snip code]
> > 
> > > + That will give you the current day of the week in three letter form,
> > > + ie: Mon, Tue, Wed, etc....
> > 
> > > But in general, you have a problem with code bloat.  The last four lines
> > > of code in your subroutine (from '$date =' on) do nothing more than
> > > this:
> > > 
> > >             substr localtime $epoch_seconds, 0, 3
> > 
> > And the whole thing really doesn't do much more than
                                   ^^^    ^^^^^^^^^
> > 
> > use POSIX;
> > print strftime "%a", localtime;
> 
> Sure it does, specifically:

See the 'not much more' in my sentence?

> 
>    $epoch_seconds = timelocal(0, 0, 0, $d, $m, $y);

Then do something like this:

sub ThreeLetterWeekDay
{
	my $time = shift || time();
	strftime "%a", localtime($time);
}

Or make it fancier whichever way you like.

> can't be replaced with localtime, since it is supposed to be for a
> particular date (possibly adjustable) and not today (at least according
> to the original post).

localtime takes an argument.

Martien
-- 
Martien Verbruggen              | 
Interactive Media Division      | I'm just very selective about what I
Commercial Dynamics Pty. Ltd.   | accept as reality - Calvin
NSW, Australia                  | 


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

Date: Sun, 14 Nov 1999 22:33:01 GMT
From: mpthompson@home.net (Mike Thompson)
Subject: Re: Which Search engine script?
Message-Id: <382f255a.164629720@news.smateo1.sfba.home.com>

Hi Paul,

At Atomz.com we have just removed monthly search limits for both the
free and the paid search engine service.  If you have a site with less
than 500 pages you can use the exact same search engine as used at
www.oreilly.com and www.webmonkey.com for free.  Even if you have one
of the busiest sites on the web -- and we should all have such
problems :-).

Mike Thompson
VP/CTO Atomz.com

On Mon, 08 Nov 1999 07:54:22 GMT, webmaster@torontoshop.com (Paul
Alves) wrote:
>
>atomz.com looks cool... but when you get high traffic it doesnt look
>worth it at all...  time to install a custom cgi script...
>
>Other than that atomz.com looks like a real cool service.
>
>
>On Fri, 29 Oct 1999 07:30:07 GMT, mpthompson@home.net (Mike Thompson)
>wrote:
>
>>On Mon, 27 Sep 1999 14:19:24 +0800, "van Weelden" <cim@cim-net.com>
>>wrote:
>>>I have a homepage with information of different companies. Now I want to =
>>>install a search engine on this homepage, but which script is the best =
>>>and easy to use? It must be possible to search HTML pages with keywords. =
>>>But it must also be possible to look for a specific company name, =
>>>country, etc...
>>>If you know a good script, let me know.
>>
>>Give www.atomz.com a try. It is a free search engine service 
>>that is very easy to add to any web site.  It is the same search
>>service used by some very large high-capacity sites such as
>>www.oreilly.com, www.webmonkey.com, and many others, 
>>but the same exact search engine is available for free to 
>>smaller sites.
>>
>>Mike Thompson
>>
>



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

Date: 14 Nov 1999 12:55:06 -0500
From: Uri Guttman <uri@sysarch.com>
Subject: Re: Why Doesn't This Work on ICOM?
Message-Id: <x7aeohx8jp.fsf@home.sysarch.com>

>>>>> "A" == Abigail  <abigail@delanet.com> writes:

  A> Kendar (heron@hell.com) wrote on MMCCLXIV September MCMXCIII in
  A> ,, Script execution error
  A> ,, Unable to execute script due to a configuration problem.
  A> ,, Please notify the webmaster of this error.
  A> ,, exec() returned: 2: No such file or directo

  A> I can tell you that Perl never suggests notifying a webmaster.

looks like it might come from CGI::Carp which does send a notify the
webmaster message to the browser.

uri

-- 
Uri Guttman  ---------  uri@sysarch.com  ----------  http://www.sysarch.com
SYStems ARCHitecture, Software Engineering, Perl, Internet, UNIX Consulting
The Perl Books Page  -----------  http://www.sysarch.com/cgi-bin/perl_books
The Best Search Engine on the Net  ----------  http://www.northernlight.com


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

Date: Sun, 14 Nov 1999 18:00:27 GMT
From: bmccoy@news.lan2wan.com (Brett W. McCoy)
Subject: Re: Win32::ODBC use of uninitialized value warnings
Message-Id: <slrn82tuk9.l5i.bmccoy@dragosani.lan2wan.com>

On Sun, 14 Nov 1999 23:18:48 +1100, Neale Morison
<nmorison@ozemail.com.au> wrote:

>I am experimenting with Win32::ODBC. I am getting a lot of uninitialized
>value warnings when running with -w switch. My test script is very simple:
>--
>use Win32::ODBC;
>use strict;
>
>my $dsn = "TasklogD";
>my $data = new Win32::ODBC($dsn);
>
>if (!defined $data) { die "Couldn't connect to $dsn\n"};
>
>my @tables = $data->TableList('','','','');
>print join "\n", @tables;
>
>$data->Close();

What variables is Perl saying are uninitialized?

-- 
Brett W. McCoy           
                                        http://www.lan2wan.com/~bmccoy/
-----------------------------------------------------------------------
The real trouble with reality is that there's no background music.


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

Date: Mon, 15 Nov 1999 10:00:27 +1100
From: "Neale Morison" <nmorison@ozemail.com.au>
Subject: Re: Win32::ODBC use of uninitialized value warnings
Message-Id: <3VGX3.2518$MZ.19561@ozemail.com.au>

Brett W. McCoy <bmccoy@news.lan2wan.com> wrote in message
news:slrn82tuk9.l5i.bmccoy@dragosani.lan2wan.com...
> On Sun, 14 Nov 1999 23:18:48 +1100, Neale Morison
> <nmorison@ozemail.com.au> wrote:
> What variables is Perl saying are uninitialized?

Perl is complaining about uninitialised variables in the Win32::ODBC module
It gives me line numbers. Here are the lines from the Win32::ODBC module in
a little context:
I didn't find it very informative. The common element seems to be the
@Results array. Could this array contain uninitialised values?

#Use of uninitialized value at . . ./perl/site/lib/Win32/ODBC.pm line 261.
#Use of uninitialized value at . . ./perl/site/lib/Win32/ODBC.pm line 260.
sub GetData{
    my($self) = @_;
    my(@Results, $num);

    @Results = ODBCGetData($self->{'connection'});
    if (!(@Results = processError($self, @Results))){
        return undef;
    }
        ####
        #   This is a special case. Do not call processResults
        ####
    ClearError();
    foreach (@Results){
        s/ +$//; # HACK #### 261
        $self->{'data'}->{ ${$self->{'fnames'}}[$num] } = $_; #### 260
        $num++;        }
        #   return is a hack to interface with a assoc array.
    return wantarray? (1, 1): 1;
}

#Use of uninitialized value at . . ./perl/site/lib/Win32/ODBC.pm line 290.
sub Catalog{
    my ($self) = shift;
    my ($Qualifier, $Owner, $Name, $Type) = @_;
    my (@Results) = ODBCTableList($self->{'connection'}, $Qualifier, $Owner,
$Name, $Type);

        #   If there was an error return 0 else 1
     return (updateResults($self, @Results) != 1); ##### 290
}



>
> --
> Brett W. McCoy
>                                         http://www.lan2wan.com/~bmccoy/
> -----------------------------------------------------------------------
> The real trouble with reality is that there's no background music.




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

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


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