[9206] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 2801 Volume: 8

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sat Jun 6 15:07:37 1998

Date: Sat, 6 Jun 98 12:00:32 -0700
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Sat, 6 Jun 1998     Volume: 8 Number: 2801

Today's topics:
    Re: -d ? 3 : 7 is ambiguous, how comes? (Larry Rosler)
        A Question about Quotes <signal@shreve.net>
    Re: A Question about Quotes (Ronald J Kimball)
        about pipe command in win32 <oldpig@nease.net>
        DBD::Oracle: finish doesn't free resources (Todd Hivnor)
    Re: delete slice in list <jhi@alpha.hut.fi>
    Re: Determining JPEG and GIF dimension sizes in PERL (Snowhare)
    Re: Displaying "my" vars in debugger (Ronald J Kimball)
    Re: Foreach Efficiency (Ronald J Kimball)
        I cant to setup Perl 5 00404 <vog@magmk.chel.su>
    Re: I'm having problems: (Chris Reynolds)
    Re: I'm having problems: (Ronald J Kimball)
        IP to DNS <stathy@jaske.com>
        IP to DNS <stathy@jaske.com>
        lines of text, inserting spaces plener@ibm.net
    Re: lines of text, inserting spaces (Ronald J Kimball)
    Re: Looking for upload.pl (Bob Trieger)
        newbie problem opening pipe sweth@my-dejanews.com
        Problem with re-iterating if loops... fastmethod@mindless.com
    Re: Problem with re-iterating if loops... (Michael J Gebis)
    Re: Problem with re-iterating if loops... <tchrist@mox.perl.com>
    Re: Problem with re-iterating if loops... (Jonathan Stowe)
        Recursive directory movement (Jason Weber)
    Re: Recursive directory movement <tchrist@mox.perl.com>
        rounding down a decimal  to 2 points without OOP?? <steph@hotkey.net.au>
    Re: rounding down a decimal  to 2 points without OOP?? (Bob Trieger)
    Re: rounding down a decimal  to 2 points without OOP?? <tchrist@mox.perl.com>
    Re: script for DBF file? (John D Groenveld)
    Re: striphtml program (Bbirthisel)
    Re: thumbnails (Snowhare)
    Re: thumbnails <tchrist@mox.perl.com>
    Re: Tutor? <ngouah@erols.com>
    Re: Where is WIN32::API? (Bbirthisel)
    Re: Why is there no "in" operator in Perl? (Snowhare)
        Yes, 'No it's not' is not it (was: Yes, I think it is ( (Andre L.)
    Re: Yes, 'No it's not' is not it (was: Yes, I think it  (Bob Trieger)
        Digest Administrivia (Last modified: 8 Mar 97) (Perl-Users-Digest Admin)

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

Date: Sat, 6 Jun 1998 09:34:39 -0700
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: -d ? 3 : 7 is ambiguous, how comes?
Message-Id: <MPG.fe30f77e1637f66989680@nntp.hpl.hp.com>

[This followup was posted to comp.lang.perl.misc and a copy was sent to 
the cited author.]

In article <6lbhb2$j3p$1@csnews.cs.colorado.edu>, tchrist@mox.perl.com 
says...
>  [courtesy cc of this posting sent to cited author via email]
> 
> In comp.lang.perl.misc, 
>     lr@hpl.hp.com (Larry Rosler) writes:
> :perl -ew 'print "hi\n"'
> 
> That's wrong.  Please try it.

Of course I tried it.  But on a version of perl before 5.004. :-(
 
:LR>                             And you would probably be wise to type 
:LR>'perl -ew' instead of 'perl -e' in any case.
:
:Only if you really wanted to execute the script 'w'.    Try 'perl -we'
:instead.
:
:Mike Guy 

Neither my tests on 5.004_03 nor those of Xuming Wang on 5.004_02 show 
that behavior -- it simply does nothing.  Is this Yet Another Version 
Problem, in 5.004_04 perhaps?  I don't have one  at hand (yet) to check 
it myself.

-- 
Larry Rosler
Hewlett-Packard Laboratories
lr@hpl.hp.com


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

Date: Sat, 6 Jun 1998 12:44:13 -0500
From: Brian <signal@shreve.net>
Subject: A Question about Quotes
Message-Id: <Pine.LNX.3.96.980606124212.2310A-100000@mercury.shreve.net>

I am using the Msql module to do some database stuff and have run into a
problem I can't figure out using quotes:

Here is what I am doing:



$statment="INSERT INTO $table VALUES ('$realname','$username')";
$sth = $dbh->query($statment);


The problem is, what if the users real name is "Larry O'Keefe", it screws
up because of the ' in Larrys name it gives parse errors.

How does one normally fix something like this?

Brian

/-------------------------- signal@shreve.net -----------------------------\
| Brian Feeny                | USR TC Hubs | ShreveNet Inc. (318)222-2638  |
| Network Administrator      | Perl, Linux | Web hosting, online stores,   |
| ShreveNet Inc.             |  USR Pilot  | Dial-Up 14.4-56k, ISDN & LANs |
| 89 CRX DX w/MPFI, lots of  |-=*:Quake:*=-| http://www.shreve.net/        |
| mods/Homepage coming soon  |LordSignal/SN| Quake server: 208.206.76.47   |
\-------------------------- 318-222-2638 x109 -----------------------------/




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

Date: Sat, 6 Jun 1998 14:39:21 -0400
From: rjk@coos.dartmouth.edu (Ronald J Kimball)
Subject: Re: A Question about Quotes
Message-Id: <1da7he0.1crtwf21sajk3cN@bay1-167.quincy.ziplink.net>

Brian <signal@shreve.net> wrote:

> $statment="INSERT INTO $table VALUES ('$realname','$username')";
> $sth = $dbh->query($statment);
> 
> The problem is, what if the users real name is "Larry O'Keefe", it screws
> up because of the ' in Larrys name it gives parse errors.
> 
> How does one normally fix something like this?

I don't know how one normally fixes something like this from an SQL
point-of-view, but I know how you could fix it for Perl:

$statment="INSERT INTO $table VALUES ('\Q$realname\E','\Q$username\E')";

\Q, for quotemeta, puts a backslash before each non-word character.

-- 
 _ / '  _      /         - aka -         rjk@coos.dartmouth.edu
( /)//)//)(//)/(     Ronald J Kimball      chipmunk@m-net.arbornet.org
    /                                  http://www.ziplink.net/~rjk/
        "It's funny 'cause it's true ... and vice versa."


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

Date: Sun, 07 Jun 1998 00:37:36 +0900
From: "Steeven.Lee" <oldpig@nease.net>
Subject: about pipe command in win32
Message-Id: <35796240.7136@nease.net>

I debug perl on win95 with perl.exe, and I found pipe command worked
well on unix system, but never worked under win32. Here is it:
open (MAIL, "|$mail_program");
Also some other pipe command wouldn't work either. :(
I tried Dos-pipe command, it seems no problem.
anyone know what's wrong? how to made it run under dos?

rem:  I've installed a command-line-winmail. worked well under dos.


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

Date: 6 Jun 1998 14:32:47 -0400
From: hivnor@shore.net (Todd Hivnor)
Subject: DBD::Oracle: finish doesn't free resources
Message-Id: <6lc20f$nks@shell2.shore.net>

 I'm using perl 5.004_04 with DBI 0.93, DBD:Oracle 0.48, 
and Oracle 7.3 on Solaris 2.5. 

  It seems that that the finish method doesn't actually 
free any resources. Specifically, if I repeatedly prepare, 
execute, and finish a statement handle, I get an 
"ORA-01000: maximum open cursors exceeded (DBD: oopen error)" 
error. 

  Here is a sample script which demonstrates the error.
It should crash if you have more tables in your schema than
available Oracle cursors. (At least, it crashes on my 
system.)

------------------------------------
#!/usr/bin/perl

# $dbh = connect to your Oracle database ..

# Grab all the table names in this schema. 
# My database has over 50 tables.

$sth_tables = $dbh -> prepare (qq{
   select table_name
     from user_tables
 order by table_name
});

$sth_tables -> execute;      

$n = 0;
while (($table) = $sth_tables->fetchrow_array) {
    $n++;
    print "Preparing $table ($n)\n";

    $sth = $dbh -> prepare ("select * from $table")
        || die $DBI::errstr;

    $sth -> execute;
    $sth -> finish;
}

$sth_tables -> finish;   
------------------------------------

  I can work around the problem by frequently 
disconnecting and reconnecting to the database, 
but that's a nasty solution. 

  I've also noticed that I can prepare a statement, 
execute it, finish it, and then execute it again.
My understanding is that once I finish a statement, 
I have to prepare it again. 

  Any clues?

Todd Hivnor
<hivnor at shore dot net>



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

Date: 06 Jun 1998 20:06:52 +0300
From: Jarkko Hietaniemi <jhi@alpha.hut.fi>
Subject: Re: delete slice in list
Message-Id: <oeera12a28j.fsf@alpha.hut.fi>


perldoc -f splice

-- 
$jhi++; # http://www.iki.fi/~jhi/
        # There is this special biologist word we use for 'stable'.
        # It is 'dead'. -- Jack Cohen


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

Date: 6 Jun 1998 11:13:53 -0600
From: snowhare@xmission.xmission.com (Snowhare)
Subject: Re: Determining JPEG and GIF dimension sizes in PERL
Message-Id: <6lbtch$ps4$1@xmission.xmission.com>



Nothing above this line is part of the signed message.

In article <6l78l1$es4@news-central.tiac.net>,
The Needham's <needcrew@tiac.net> wrote:
>Hi,
>
>I am trying to figure out if there is a way to determine the height and
>width of a given image from within perl.  I will be using only JPG and GIF
>images if this helps.

These code fragments (which I adapted from code in wwwimagesize) are what
I use. My mods to the jpegsize code keep it from blowing up (which could
happen in wwwimagesize) on corrupt images and process the images as whole
entities rather than streams. Both routines return null if they can't
parse the image. You could probably get them to run under Perl4 by
replacing all occurances of 'my' with 'local', if needed.

(Before someone goes pointing out that you get the same functionality and
more from the CPAN module - I needed _standalone_ code for one of my free
utilities).

sub gifsize {
        my($GIF) = @_;
                
        my ($type,$a,$b,$c,$d,$s,$width,$height);
        
        $type=substr($GIF,0,6);
        if(!($type =~ m/GIF8[7,9]a/) || (length($s=substr($GIF, 6, 4))!=4) ){
                return;
        }
        ($a,$b,$c,$d)=unpack("C"x4,$s);
        $width= $b<<8|$a;
        $height= $d<<8|$c;
        return ($width,$height);
 }

sub jpegsize {
        
  my($JPEG) = @_;
    
  my($count) = 2;
  my($length)= length($JPEG); 
  my($ch)    = "";
  my ($c1,$c2,$a,$b,$c,$d,$width,$height);
     
  while (($ch ne "\xda") && ($count<$length)) {
    # Find next marker (JPEG markers begin with 0xFF)
    while (($ch ne "\xff") && ($count < $length)) {
        $ch=substr($JPEG,$count,1);
        $count++;
    }
    # JPEG markers can be padded with unlimited 0xFF's
    while (($ch eq "\xff") && ($count<$length)) {
        $ch=substr($JPEG,$count,1);
        $count++;
    }
    # Now, $ch contains the value of the marker.
    if ((ord($ch) >= 0xC0) && (ord($ch) <= 0xC3)) {
        $count+=3;
        ($a,$b,$c,$d)=unpack("C"x4,substr($JPEG,$count,4));
        $width=$c<<8|$d;
        $height=$a<<8|$b;
        return($width,$height);
    } else { 
      # We **MUST** skip variables, since FF's within variable names are
      # NOT valid JPEG markers
        ($c1,$c2)= unpack("C"x2,substr($JPEG,$count,2));
        $count += $c1<<8|$c2;
    }
  }
 }
         

Benjamin Franz


Version: 2.6.2

iQCVAwUBNXl4lejpikN3V52xAQFNHgP+LW0T8dvNja5pSfOtXgaJshPvzZooQxxY
xhuabzYj85G4CZhLF9uMgHsXe7Z6Tk5L9TAAgXSye5vLG38sj0X8KB2n6Pc8vDv1
jasnI7oTDkwSI1ODqOXGxxpI7zS/CeBcekzKe1HHIcvr7H4ojJNCyFc6VC3yBbLT
4KtZpRKGc3M=
=UE0Y
-----END PGP SIGNATURE-----


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

Date: Sat, 6 Jun 1998 14:21:25 -0400
From: rjk@coos.dartmouth.edu (Ronald J Kimball)
Subject: Re: Displaying "my" vars in debugger
Message-Id: <1da6iwb.oqxpoq1ejuwzkN@bay1-167.quincy.ziplink.net>

Paul Thilking <paulth@ix.netcom.com> wrote:

> In this simple program, if you place a breakpoint at the first print
> statement, and then
> type "X local_var", you see the value of local_var.
> 
> If you type "X my_var", you see nada. What am I doing wrong?

You are failing to understand the effect of my and the use of the
debugger commands.

X [vars]        Same as "V currentpackage [vars]".

V [pkg [vars]]  List some (default all) variables in package (default
                current). Use ~pattern and !pattern for positive and
                negative regexps.

Note that X and V are used to list variables *in a package*.

my expr

This operator declares one or more private variables...
 ...The variable name may not be package qualified, because package
variables are all global, and private variables are not related to any
package...

Note that my variables are not in any package.

Hence, you cannot use X or V to display the values of my variables.  Use
x instead.

-- 
 _ / '  _      /         - aka -         rjk@coos.dartmouth.edu
( /)//)//)(//)/(     Ronald J Kimball      chipmunk@m-net.arbornet.org
    /                                  http://www.ziplink.net/~rjk/
        "It's funny 'cause it's true ... and vice versa."


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

Date: Sat, 6 Jun 1998 14:21:27 -0400
From: rjk@coos.dartmouth.edu (Ronald J Kimball)
Subject: Re: Foreach Efficiency
Message-Id: <1da6j6k.s1a7cs1hhf61oN@bay1-167.quincy.ziplink.net>

Peter A Fein <p-fein@uchicago.edu> wrote:

> > > Well, because I have finals in a few days and I need to get this
> > > working yesterday.  Although I'd like to mess around & benchmark parts
> > > of my code at some point, that point is not now.  
> > 
> > In that case, why are you bothering with usenet at all?
> > [...]
> 
> Posting takes a few seconds tops.  Compared to d/l'd, installing,
> reading the docs, altering my code, running it, restoring my code &
> then debugging the bugs I just introduced by doing this. ;)
> Whatever.  Look, it works, thanks for the pointer to Benchmark.

In other words, you're foisting off all the work onto us.  Thank you so
much.

-- 
 _ / '  _      /         - aka -         rjk@coos.dartmouth.edu
( /)//)//)(//)/(     Ronald J Kimball      chipmunk@m-net.arbornet.org
    /                                  http://www.ziplink.net/~rjk/
        "It's funny 'cause it's true ... and vice versa."


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

Date: Sat, 06 Jun 1998 23:45:24 +0000
From: "Qepcei Vsj`mnb" <vog@magmk.chel.su>
Subject: I cant to setup Perl 5 00404
Message-Id: <3579D492.77473E6A@alanland.ru>

    Hi!

 Somebody!!!

 Why when I starting perl5.00404 on FreeBSD 3.0 (SNAP 0426) I see:

  --->>>  ld.so failed: Can't find shared library "libnet.so.0.92"

 8-( What is it.

 Sergey
 alan@mmk.ru





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

Date: Sat, 06 Jun 1998 05:07:50 GMT
From: cmreynolds@hotmail.com (Chris Reynolds)
Subject: Re: I'm having problems:
Message-Id: <3578cdc5.83822913@news.sprint.ca>

On Fri, 05 Jun 1998 17:44:43 GMT, John Porter <jdporter@min.net>
wrote:


>
>Where did you get this crap?
>Whoever wrote it is a perl4-head -- I haven't seen that many 

>
>John Porter

Ok, so I am guessing that there is a big difference between Perl 4 and
5.  See, I am very very new at this stuff and trying to learn it and
make sense out of this unsual language.  I wanted to makea script for
sorting directories and knowing what is where and how much is where a
little easier .... 

I do really appreciate all the help.



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

Date: Sat, 6 Jun 1998 14:21:28 -0400
From: rjk@coos.dartmouth.edu (Ronald J Kimball)
Subject: Re: I'm having problems:
Message-Id: <1da6jfo.fn0hx11cy4ssrN@bay1-167.quincy.ziplink.net>

David Barr <dafydd@jps.net> wrote:

> Either I read something wrong, or it should be

And the something you read wrong would be the Perl documentation.

> ( @ARGV == 2 and -d $ARGV[1] ) or die "Usage: $1 directory\n";
> 
> right?   Isn't $ARGV[0] the name of the perl script itself?

Wrong.  From perlvar:

@ARGV

The array containing the command-line arguments intended for the script.
Note that $#ARGV is generally the number of arguments minus one,
***since $ARGV[0] is the first argument, not the command name.***  See
$0 for the command name.  [my emph]


It doesn't get much more obvious than that, does it?

-- 
 _ / '  _      /         - aka -         rjk@coos.dartmouth.edu
( /)//)//)(//)/(     Ronald J Kimball      chipmunk@m-net.arbornet.org
    /                                  http://www.ziplink.net/~rjk/
        "It's funny 'cause it's true ... and vice versa."


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

Date: Sat, 06 Jun 1998 13:42:02 -0500
From: Stathy Touloumis <stathy@jaske.com>
Subject: IP to DNS
Message-Id: <35798D7A.F0886382@jaske.com>

Hi,
        I currently have my httpd log files logging the
visiting
clients ip address.  Some of my clients would like these to be
the domain names for there use.  I would not like this to be
done on the server end (slow down) but would instead like to
write a script which parses the information (ip addresses) and
converts them to domain names.  I am stuck on that part.  Am
currently trying to use the function gethostbyaddr() but am
unable to determine how to convert the ip addresses into a
format that gethostbyaddr() can use.

Any suggestions?

stathy@jaske.com


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

Date: Sat, 06 Jun 1998 13:52:44 -0500
From: Stathy Touloumis <stathy@jaske.com>
Subject: IP to DNS
Message-Id: <35798FFC.24D8869E@jaske.com>

Hi,
        I currently have my httpd log files logging the
visiting
clients ip address.  Some of my clients would like these to be
the domain names for there use.  I would not like this to be
done on the server end (slow down) but would instead like to
write a script which parses the information (ip addresses) and
converts them to domain names.  I am stuck on that part.  Am
currently trying to use the function gethostbyaddr() but am
unable to determine how to convert the ip addresses into a
format that gethostbyaddr() can use.

Any suggestions?


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

Date: Sat, 06 Jun 1998 14:05:50 -0700
From: plener@ibm.net
Subject: lines of text, inserting spaces
Message-Id: <3579AF2E.54FDB9E7@ibm.net>

newbie needs some help on inserting spaces in lines of continuous
text--fi;e is 250 megs of text data and each line is erminated by a
carrage return
data looks like this 112121821745647263562393434941947 ......cr
i need to insert spacea at certain positions
so data looks like this
1212 1218 45678 7677767 121212..
please note that the above data is just examples
i need to insert the space to act as a deliminater for a statistical
data file
can you help?
i have looked in the books and kind of got some idea on how to do it
but really need a little basic help
could you  please also email me your answer?
plener@ibm.net



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

Date: Sat, 6 Jun 1998 14:39:22 -0400
From: rjk@coos.dartmouth.edu (Ronald J Kimball)
Subject: Re: lines of text, inserting spaces
Message-Id: <1da7hji.kmfcuaf2flsN@bay1-167.quincy.ziplink.net>

<plener@ibm.net> wrote:

> data looks like this 112121821745647263562393434941947 ......cr
> i need to insert spacea at certain positions
> so data looks like this
> 1212 1218 45678 7677767 121212..
> please note that the above data is just examples

How do you determine where to insert the spaces?  Do you have a set of
column positions or something?

@cols = (4, 8, 13, 20, ...)

while (<>) {
  foreach $col (reverse @cols) {
    substr($_, $col, 0) = ' ';
  }
  print;
}

-- 
 _ / '  _      /         - aka -         rjk@coos.dartmouth.edu
( /)//)//)(//)/(     Ronald J Kimball      chipmunk@m-net.arbornet.org
    /                                  http://www.ziplink.net/~rjk/
        "It's funny 'cause it's true ... and vice versa."


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

Date: Sat, 06 Jun 1998 16:52:39 GMT
From: sowmaster@juicepigs.com (Bob Trieger)
Subject: Re: Looking for upload.pl
Message-Id: <6lbs7l$b2j$1@ligarius.ultra.net>

[ posted and mailed ]

Jim Fritz <jimfritz@softhouse.com> wrote:
-> I am looking for a perl script to allow users to upload small text files
-> from their browsers.  I have seen mention of a script called upload.pl;
-> but I am sure there are many more out there.  However I haven't as of
-> yet been able to find any.  If anyone could point me in the right
-> direction I would really appreciate it.

Where have you looked?

I searched altavista for "upload.pl" and it returned 171 matches in a matter 
of seconds. hotbot returned 71 matches even faster.

I searched www.perl.com for "upload" and it returned with the script you are 
seeking in no time.

Why did you post here hoping that within a day or 2 somebody would reply? 
Those other methods are a lot faster and reliable.


Good luck,

Bob Trieger
sowmaster@juicepigs.com
" Cost a spammer some cash: Call 1-800-239-0341
    and hang up when the recording starts. "


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

Date: Sat, 06 Jun 1998 17:46:41 GMT
From: sweth@my-dejanews.com
Subject: newbie problem opening pipe
Message-Id: <6lbva1$mq4$1@nnrp1.dejanews.com>

I have a bunch of shell-script-based cgi pages that I'm trying to convert to
perl, to which I am very new.  One of the pages keeps exiting with a syntax
error on line 26 (below, along w/ line 27) that I can't figure out.  I'm
trying to mail the output of a subroutine using mailx; the line in question
is copied straight from the camel book's section on anonymous pipes, with a
different filehandle name and a different command after the pipe (obviously).
 what am i missing here?

26: open MAILER, "| /usr/bin/mailx -s 'SMTP Registration Submitted' $NOTIFY"
27:    or die "$REGFAIL" ;

-----== Posted via Deja News, The Leader in Internet Discussion ==-----
http://www.dejanews.com/   Now offering spam-free web-based newsreading


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

Date: Sat, 06 Jun 1998 15:51:58 GMT
From: fastmethod@mindless.com
Subject: Problem with re-iterating if loops...
Message-Id: <6lboiu$eta$1@nnrp1.dejanews.com>

Hey perl people,

I'm calling this subroutine from within a foreach loop to determine the
type of search that is being performed (I'm getting the search types
from a parsed GET string, and iterating through the list of search types
in the foreach loop.  The problem is that I have to put the if statements
in the following order, because if I find - for example, that the search
type is 'title', the next time I call &find_search_type, it doesn't make
it past the point where it matched.  Consequently I am forced to put the
if statements in an order where I am sure they will match last to first.

Is there a way I can put the if statements in any order?  This would make
my job alot less complicated.

Here is my code:

sub find_search_type
	{
	if ($query_type eq "title"){ $search_type = 2; }
	if ($query_type eq "artist"){ $search_type = 3; }
	if ($query_type eq "medium"){ $search_type = 6; }
	if ($query_type eq "comment"){ $search_type = 9; }
	if ($query_type eq "category"){ $search_type = 10; }
	}

Any help would be most appeciated, if you could mail me at:

fastmethod@mindless.com

You guys know the deal.

-Mr. Method

-----== Posted via Deja News, The Leader in Internet Discussion ==-----
http://www.dejanews.com/   Now offering spam-free web-based newsreading


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

Date: 6 Jun 1998 17:37:38 GMT
From: gebis@albrecht.ecn.purdue.edu (Michael J Gebis)
Subject: Re: Problem with re-iterating if loops...
Message-Id: <6lbup2$3iq@mozo.cc.purdue.edu>

fastmethod@mindless.com writes:

}Here is my code:
}sub find_search_type
}	{
}	if ($query_type eq "title"){ $search_type = 2; }
}	if ($query_type eq "artist"){ $search_type = 3; }
}	if ($query_type eq "medium"){ $search_type = 6; }
}	if ($query_type eq "comment"){ $search_type = 9; }
}	if ($query_type eq "category"){ $search_type = 10; }
}	}

Didn't anybody ever tell you globals are bad?  I'm confused by your
question, but I suspect that if you coded up this routine like this:

sub find_s_t
{
	my($query_type)=@_;
	if($query_type eq "title"} { return 2;}
	# your other if statements here
	return 0;  # or some other more meaningful "no query type" value
}

 ...you would have not needed to ask the question.   Also, if you continue
to think of them as "if _loops_" you may have to be called in for
re-education at one of the many government centers.  They are not
loops in any conventional sense of the word.

Of course, you really should be using a hash, so that you
could just do this:

print $search_type{'title'}; #Prints 2

I'll leave the details of doing this up to you, but it's easy, so
don't be a slacker.  This is about the most straigtforward way to use
a hash.  Go look it up.  Now!

}You guys know the deal.

Indeed we do.

-- 
Mike Gebis  gebis@ecn.purdue.edu  mgebis@eternal.net


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

Date: 6 Jun 1998 18:24:42 GMT
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: Problem with re-iterating if loops...
Message-Id: <6lc1ha$9ie$3@csnews.cs.colorado.edu>

 [courtesy cc of this posting sent to cited author via email]

In comp.lang.perl.misc, fastmethod@mindless.com writes:
:sub find_search_type
:       {
:       if ($query_type eq "title"){ $search_type = 2; }
:       if ($query_type eq "artist"){ $search_type = 3; }
:       if ($query_type eq "medium"){ $search_type = 6; }
:       if ($query_type eq "comment"){ $search_type = 9; }
:       if ($query_type eq "category"){ $search_type = 10; }
:       }

Your braces are misdented, but anyway.

    sub find_search_type {
        for ($query_type) {
            return  /^title$/       &&  2       ||
                    /^artist$/      &&  3       ||
                    /^medium$/      &&  6       ||
                    /^comment$/     &&  9       ||
                    /^categegory$/  && 10;
	} 
    } 

    # maybe you don't need the anchors?

    sub find_search_type {
        for (lc $query_type) {
            return  /title/       &&  2       ||
                    /artist/      &&  3       ||
                    /medium/      &&  6       ||
                    /comment/     &&  9       ||
                    /categegory/  && 10;
	} 
    } 

Or 

    BEGIN {
        my %query2search = (
            title       =>  2,
            artist      =>  3,
            medium      =>  6,
            comment     =>  9,
            categegory  => 10,
        );
        sub find_search_type {
            return $query2search{$query_type};
        } 
    } 

(These do both have the problem of returning undef in list context
rather than ().)

I wish I knew why people had such a hard time writing multibranch
conditionals ("case" or "switch" constructs).

--tom
-- 
"A momentary lapse of stupidity" -- Dean Roehrich


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

Date: Sat, 06 Jun 1998 18:33:52 GMT
From: Gellyfish@btinternet.com (Jonathan Stowe)
Subject: Re: Problem with re-iterating if loops...
Message-Id: <35797969.70849460@news.btinternet.com>

On Sat, 06 Jun 1998 15:51:58 GMT, fastmethod@mindless.com wrote :

>Hey perl people,
>
>I'm calling this subroutine from within a foreach loop to determine the
>type of search that is being performed (I'm getting the search types

<snip>

>
>sub find_search_type
>	{
>	if ($query_type eq "title"){ $search_type = 2; }
>	if ($query_type eq "artist"){ $search_type = 3; }
>	if ($query_type eq "medium"){ $search_type = 6; }
>	if ($query_type eq "comment"){ $search_type = 9; }
>	if ($query_type eq "category"){ $search_type = 10; }
>	}
>

You need hash, er *a* hash of course:

%query_lookup = {
                                "title"           => 2,
	                   "artist"         => 3,
                                 "medium"    => 6,
                                 "comment"  => 9,
                                 "category"  => 10
                               };
                     

sub find_search_type
  {
       my $query = shift;
       return $query_lookup{$query};
   }


You will have to change the callers of find_search_type to take an
explicit return rather than using what appears to be a global
variable.

>Any help would be most appeciated, if you could mail me at:
>
>fastmethod@mindless.com
>

Its free like this - otherwise you mail me and ask for the rates.

>You guys know the deal.
>

Hey, if you can get that shit cheaper than I can I want to know about
it.

>-Mr. Method
>

Nice one "Stanivlasky posts to c.l.p.m"  I can see the headlines now

>-----== Posted via Deja News, The Leader in Internet Discussion ==-----
>http://www.dejanews.com/   Now offering spam-free web-based newsreading

Thats no excuse you know.

/J\
Jonathan Stowe
Some of your questions answered:
<URL:http://www.btinternet.com/~gellyfish/resources/wwwfaq.htm>



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

Date: 4 Jun 1998 19:18:57 GMT
From: jweber@clive.central.sun.com (Jason Weber)
Subject: Recursive directory movement
Message-Id: <6l6rv1$i73$1@centralnews2.Central.Sun.COM>
Keywords: recursion

I would like to be able to use this to go through a whole directory
structure and report back the names of all of the  directories in that
file system. I have been unable to do this recursively. All that I have
gotten so far is a recursive search through the first dir in every dir.
I know that I am not close to being a good programmer but I would like to
make this work without having to pragerize someone elses material. I would
like to really know how to get this to work.

Thanks in advance


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


$count = 0;
$alldirs[$count] = `pwd`;
$where = `pwd`;
$x=0;
rip($where);


sub rip {

        chdir("@_");
        @raw = `ls -l`;
        shift(@raw);
        $z=0;
        $j=0;
        for ($i=0; $i<=$#raw; $i++) {
                $fc = substr($raw[$i],0,1);
                if ($fc ne "d") {
                        $j++;
                }
                elsif ($fc eq "d") {
                        $var = $raw[$i];
                        $var =~ s/ {2,10}/ /g;
                        @array = split(/ /, $var);
                        chop($array[8]);
                        $dirname[$z] = $array[8];
                        $z++;
                }
        }

        if ($j < $#raw) {

                for($x=0;$x<=$#dirname;$x++) {
                        $count++;
                        $where = `pwd`;
                        chop($where);
                        $alldirs[$count] = "$where" . "\/" . "$dirname[$x]";
                        print "$alldirs[$count]\n";
                        rip($alldirs[$count]);
                }
        }
}





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

Date: 6 Jun 1998 18:15:58 GMT
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: Recursive directory movement
Message-Id: <6lc10u$9ie$2@csnews.cs.colorado.edu>
Keywords: recursion

 [courtesy cc of this posting sent to cited author via email]

In comp.lang.perl.misc, jweber@clive.central.sun.com writes:
:I would like to be able to use this to go through a whole directory
:structure and report back the names of all of the  directories in that
:file system. 

Use File::Find.

--tom
-- 
    "I can only bend the rules so much before it starts looking like I'm breaking
    the rules." --Larry Wall


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

Date: Sun, 07 Jun 1998 03:17:04 +1000
From: Stephan Carydakis <steph@hotkey.net.au>
Subject: rounding down a decimal  to 2 points without OOP??
Message-Id: <3579798F.6D16@hotkey.net.au>

Hello All,

PROBLEM: can I round(to 2 decimal points) a scalar without
"use Math::BigFloat".Is there a simpler way in Perl do do this??

I can round up to the closest integer using sprintf, but this is not
what I need.

Could someone give me any info as to this?? Anything would help.

I'm running Perl5 for win32(95a :-[). I have been using Perl for CGI
development using a Netscape Fast Track Server.

I've have been trying to teach my self Perl since the start of the year
using the "legendary" book 'Programming Perl'(my brain is frying, but
I'm loving it :]). 

thanks in advance
_________________
Stephan Carydakis
mailto: steph@hotkey.net.au


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

Date: Sat, 06 Jun 1998 17:38:55 GMT
From: sowmaster@juicepigs.com (Bob Trieger)
Subject: Re: rounding down a decimal  to 2 points without OOP??
Message-Id: <6lbuud$bpd$1@ligarius.ultra.net>

[ posted and mailed ]

steph@hotkey.net.au wrote:
-> Hello All,
-> 
-> PROBLEM: can I round(to 2 decimal points) a scalar without
-> "use Math::BigFloat".Is there a simpler way in Perl do do this??
-> 
-> I can round up to the closest integer using sprintf, but this is not
-> what I need.

Perhaps I misunderstand this FAQ, but why doesn't
        sprintf "%.2f","$yournumber"; 
work for you?


Bob Trieger
sowmaster@juicepigs.com
" Cost a spammer some cash: Call 1-800-239-0341
    and hang up when the recording starts. "


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

Date: 6 Jun 1998 18:15:11 GMT
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: rounding down a decimal  to 2 points without OOP??
Message-Id: <6lc0vf$9ie$1@csnews.cs.colorado.edu>

 [courtesy cc of this posting sent to cited author via email]

In comp.lang.perl.misc, steph@hotkey.net.au writes:
:I can round up to the closest integer using sprintf, but this is not
:what I need.

What do you mean "round *up*"?  sprintf should work for you.

--tom
-- 
Besides, it's good to force C programmers to use the toolbox occasionally.  :-)
        --Larry Wall in <1991May31.181659.28817@jpl-devvax.jpl.nasa.gov>


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

Date: 6 Jun 1998 13:59:54 -0400
From: groenvel@cse.psu.edu (John D Groenveld)
Subject: Re: script for DBF file?
Message-Id: <6lc02q$am9$1@tholian.cse.psu.edu>

http://www.cpan.org/modules/00modlist.long.html#15)WorldWideWeb
http://www.cpan.org/modules/00modlist.long.html#7)DatabaseInter

John
groenveld@acm.org


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

Date: 06 Jun 1998 17:15:33 GMT
From: bbirthisel@aol.com (Bbirthisel)
Subject: Re: striphtml program
Message-Id: <1998060617153300.NAA21782@ladder01.news.aol.com>

Hi Jonathan:

>>I've been using this program successfully on a Solaris box with perl
>>5.003, but when I attempt to run it with either the Laszlo Molnar
>>djgpp port of perl 5.004 for Win16 or the GSAR port for Win32, I
>>get the following error:

<snip of regular expression error>

>This snippet contains a modified version of the regular expression in
>question that does work:
>
>#!perl 
>while(<>)
>{
>s/(?:<[^>'"]*|".*?"|'.*?')+>//gs;
>print;
>}
>
>>Does anybody have any idea what has changed between 5.002 (called for
>>in the program) and perl 5.004 to cause this error?  

Without looking up the entire original expression, I'm going to guess that it
provided for multi-line matches (the last "s" in your snippet). Since MS-DOS
like OSs use CRLF, that's a place to look.

-bill
Making computers work in Manufacturing for over 25 years (inquiries welcome)


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

Date: 6 Jun 1998 11:18:17 -0600
From: snowhare@xmission.xmission.com (Snowhare)
Subject: Re: thumbnails
Message-Id: <6lbtkp$q99$1@xmission.xmission.com>



Nothing above this line is part of the signed message.

In article <6l9jij$d3si$1@newssvr04-int.news.prodigy.com>,
Kelby Valenti <kelby@mplx.com> wrote:
>I'm looking for a program that will create thumbnails from a directory of
>images.  I would like this to be a cgi program.  If you can help me in my
>search I'd appreciate it.

Its not CGI, but should do the job.

<URL:http://www.nihongo.org/snowhare/utilities/htmlthumbnail/>

Benjamin Franz


Version: 2.6.2

iQCVAwUBNXl5e+jpikN3V52xAQFiJQQAhWJLH3kkbuqLB/+GF+EybqTcParnVMRe
UeZVBbDfyhEAu/LRR/4xNCSl/cXUJtXvMxa0oiJJbOGH4o7kLAvcuwCw5rZ3Nrwd
vLRewd/PEZH03jmF0VnIm1gofg3jnGXmbcgmInqbs9iuCGYh2raNtdSt6h7QrhlH
zZD/nmIuRMk=
=GGU5
-----END PGP SIGNATURE-----


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

Date: 6 Jun 1998 18:27:53 GMT
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: thumbnails
Message-Id: <6lc1n9$9ie$4@csnews.cs.colorado.edu>

 [courtesy cc of this posting sent to cited author via email]

In comp.lang.perl.misc, "Kelby Valenti" <kelby@mplx.com> writes:
:I'm looking for a program that will create thumbnails from a directory of
:images.  I would like this to be a cgi program.  If you can help me in my
:search I'd appreciate it.

Why did you post here?  Why didn't you post to comp.lang.c or something?
Or comp.lang.fortran?  How odd.

--tom
-- 
Build a system that even a fool can use, and only a fool will want to use it.


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

Date: Sat, 06 Jun 1998 12:59:28 -0400
From: Birgitt Funk <ngouah@erols.com>
Subject: Re: Tutor?
Message-Id: <35797570.2B87@erols.com>

Gary M. Greenberg wrote:
> 
> Linda,
> 
> You don't say a few things that may be helpful:
> 1. What book(s) you're using.
> 2. What other, if any, programming background you have.
> 3. What OS(es) you're familiar with.
> 4. How much time you've actually been able to spend learning.
> 
> I've been teaching myself Perl for a very short time (about a month).
> I started learning Perl about 18 months ago, but my work load was so
> heavy, I couldn't spend any time with it. Last month, I forced Perl
> to fit into my schedule; now, I spend a least 30 minutes a day with
> it--it isn't really enough, but I'm doing more and more with it.
> 
> I taught myself C using several books && usenet.
> It took me several years to become pretty good, but I've still got
> a lot to learn.
> I believe almost anyone can learn to program, if they really want to.
> One of the keys is structuring your learning process.

I like your answer.

But ... if you would analyze what you said, you
will see that someone who has *no* programming background and
has/had no job related exposure to system administration 
on any OS ... can hardly make it within a year, if you have
to squeeze it into your other daily duties.

Trying to do just what you suggested, structuring your 
learning process for someone who has had *zero* exposure,
I came up with:

1. work through one structured introductory programming
   book and/or classes using a language like let's say Pascal 
   (how about Fortran BTW?)
2. learn Unix system administration, unix utitlies, one editor
   in depth (vi/vim),learn the basics about the
   hardware your system is on and about networking/routing.
3. learn shell scripting, learn about different shells
4. learn to program in C
5. learn regular expressions
6. learn Perl
7. choose a goal or project, ask yourself why you want to
   learn it anyway.
8. search for all material needed to read through.
9. glance over everything and find out the proper order
   of learning things. If you don't want your house to
   fall upon you, start with the basement and foundation.
10.Realize that all you do is changing all the time and what
   you learned today might not be true anymore tomorrow.
11.Be prepared that once you started you have always to relearn
   to keep up with the changes.


IMHO nobody should make anyone believe that this 
is a matter of a one year learning process in your free time,
if you don't have job related exposure or tasks to go with it.

Wrong ?

Birgitt Funk


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

Date: 06 Jun 1998 16:56:03 GMT
From: bbirthisel@aol.com (Bbirthisel)
Subject: Re: Where is WIN32::API?
Message-Id: <1998060616560300.MAA15721@ladder03.news.aol.com>

Hi:

>I have seen mention of an interface to the Win32 API module called
>Win32::API  in this newsgroup, but I can't find it on CPAN. Can anyone
>tell me if this module still exists? And where can I find it?

## http://www.divinf.it/dada/perl

Aldo's site is undergoing substantial rebuilding. This is a temporary page
with links to his modules.

>Will it be possible to use this module to make use of Windows' GUI to
>interface to PERL?

It will take a LOT of work to get a Microsoft "look and feel". It's certainly
possible to pop up message and dialog boxes that already exist in a DLL,
but if you have to create you own DLLs you've lost some of the
reasons for using perl originally.

> I want to write a couple of scripts to manage flat
>file text databases using PERL, but, its a little user 'unfriendly'
>doing this from the command line.

You might want to look at the 5.004 port and TK.

-bill 
Making computers work in Manufacturing for over 25 years (inquiries welcome)


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

Date: 6 Jun 1998 11:44:08 -0600
From: snowhare@xmission.xmission.com (Snowhare)
Subject: Re: Why is there no "in" operator in Perl?
Message-Id: <6lbv58$t5r$1@xmission.xmission.com>



Nothing above this line is part of the signed message.

In article <6l926h$7of$2@client3.news.psi.net>,
Abigail <abigail@fnx.com> wrote:
>Michael J Gebis (gebis@albrecht.ecn.purdue.edu) wrote on MDCCXXXVIII
>September MCMXCIII in <URL: news:6l6v7k$m2q@mozo.cc.purdue.edu>:
>++ Andrew Johnson <ajohnson@gpu.srv.ualberta.ca> writes:
>++ 
>++ }note, though, that grep is not restricted to regular expressions
>++ }for testing, one can use an 'eq' test for improved performance:
>++ 
>++ If you care about performance, and your arrays are big, don't use a
>++ linear search.  Hash, baby, hash!  (Please see tcgrep's post on this
>++ for more copies of the word "HASH".)
>
>
>Even if you have huge arrays, if you're searching only once, there's
>no point in hashing, as building the hash table is linear too.

But searching it is not. It depends on the relative constants for building
the array *AND* linearly searching it vs. building the hash and finding an
entry. 

The question is which is larger:

K O(N) + S O(N) (for building and searching an array)

vs

M O(N) + T      (for building and finding an entry in a hash).

if (M < (K + S)) then, for large enough N, it will be faster to build the
hash _even for only one search_. 

Benjamin Franz


Version: 2.6.2

iQCVAwUBNXl/yujpikN3V52xAQE4MgP/fvfwP8fXew6tgL9neh/2bO1fOe1Hf9Ka
TQKoCMWdeB4JbZ6Dx4qejVUwcUTw/2o7+FJURT9AvGrn2+PAiN39OqjXsAi9RRzW
CUYI5e3IzVfXEzjlzLbrfHiHrYnpwfRieGYCTrnoGDvWrh+RSd6OpvSkeWh9A4ZN
r7QyPyk/O0k=
=Ub/i
-----END PGP SIGNATURE-----


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

Date: Sat, 06 Jun 1998 13:44:52 -0500
From: alecler@cam.org (Andre L.)
Subject: Yes, 'No it's not' is not it (was: Yes, I think it is (was Re: No, It's Not (was Re: Yes, it is)))
Message-Id: <alecler-0606981344520001@dialup-608.hip.cam.org>

In article <19980606.034959.1K5.rnr.w164w_-_@locutus.ofB.ORG>, Russell
Schulz <Russell_Schulz@locutus.ofB.ORG> wrote:

> I wonder if the original `Yes it is' was misposted in response to the
> `Is perl case-sensitive' question.
> 
> in which case `No, It's Not' is wrong.


You are correct on both counts.

But I really posted this just to add another level of nesting to the
subject line. :-)

A.L.


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

Date: Sat, 06 Jun 1998 18:36:30 GMT
From: sowmaster@juicepigs.com (Bob Trieger)
Subject: Re: Yes, 'No it's not' is not it (was: Yes, I think it is (was Re: No, It's Not (was Re: Yes, it is)))
Message-Id: <6lc2aa$mnd$1@strato.ultra.net>

alecler@cam.org (Andre L.) wrote:
-> In article <19980606.034959.1K5.rnr.w164w_-_@locutus.ofB.ORG>, Russell
-> Schulz <Russell_Schulz@locutus.ofB.ORG> wrote:
-> 
-> > I wonder if the original `Yes it is' was misposted in response to the
-> > `Is perl case-sensitive' question.
-> > 
-> > in which case `No, It's Not' is wrong.
-> 
-> 
-> You are correct on both counts.
-> 
-> But I really posted this just to add another level of nesting to the
-> subject line. :-)

Now I know who to blame when my bandwidth bill goes up.

Bob Trieger
sowmaster@juicepigs.com
" Cost a spammer some cash: Call 1-800-239-0341
    and hang up when the recording starts. "


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

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


Administrivia:

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

	subscribe perl-users
or:
	unsubscribe perl-users

to almanac@ruby.oce.orst.edu.  

To submit articles to comp.lang.perl.misc (and this Digest), send your
article to perl-users@ruby.oce.orst.edu.

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

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

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

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

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


------------------------------
End of Perl-Users Digest V8 Issue 2801
**************************************

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