[19063] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 1258 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Jul 6 18:06:07 2001

Date: Fri, 6 Jul 2001 15:05:20 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <994457120-v10-i1258@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Fri, 6 Jul 2001     Volume: 10 Number: 1258

Today's topics:
        Can someone translate this Perl into common English *gr <miscellaneousemail@yahoo.com>
    Re: Can someone translate this Perl into common English (Eric Bohlman)
    Re: Can someone translate this Perl into common English <scollyer@dont.spam.me.netspinner.co.uk>
    Re: Can someone translate this Perl into common English <miscellaneousemail@yahoo.com>
        chmod 755, 777 <dmitriv_rus@hotmail.com>
    Re: chmod 755, 777 <rsherman@ce.gatech.edu>
    Re: Chmod and File::Find (BUCK NAKED1)
    Re: Correct way to open a .jpg image and save? (Craig Berry)
        DB_File saves records with huge amount of white space i <miscellaneousemail@yahoo.com>
        environment variable in cgi (hao tran)
    Re: environment variable in cgi <hillr@ugs.com>
    Re: environment variable in cgi <flavell@mail.cern.ch>
    Re: Error - Undefined subroutine &Win32::Process::Creat <news@simonflack.com>
        FAQ: Which version of Perl should I use? <faq@denver.pm.org>
        Flags to use with DB_File tie call?? <miscellaneousemail@yahoo.com>
    Re: Gtk or Tk or ? <newspost@coppit.org>
    Re: Gtk or Tk or ? <pne-news-20010706@newton.digitalspace.net>
        handling a file with a perl script (Ka-Hing Cheung)
    Re: how do you move a created file (Dave Hoover)
    Re: how to read multipart/form-data (Dave Hoover)
        I know this must be in the manpages... number formattin (Konstantinos Agouros)
    Re: I know this must be in the manpages... number forma <pne-news-20010706@newton.digitalspace.net>
    Re: I know this must be in the manpages... number forma <mjcarman@home.com>
        MySQL,DBI doesn't like my 'LIKE' query (Miriam Raphael-Roberts)
    Re: Parsing an html document for the title (don't flame (Craig Berry)
        Perl & C(++) comparison (Sasa Janiska)
    Re: Perl & C(++) comparison <newspost@coppit.org>
        Perl & C(++) (Sasa Janiska)
        Perl & C(++) (Sasa Janiska)
    Re: Perl 6:   ->   vs  . (David H. Adler)
        Perl Power Tools or Cygwin? <newspost@coppit.org>
    Re: Perl Power Tools or Cygwin? <lmoran@wtsg.com>
        Simple scripts... <dmitriv_rus@hotmail.com>
    Re: Simple scripts... <lmoran@wtsg.com>
    Re: Simple scripts... <dmitriv_rus@hotmail.com>
        store session data in mySQL? <bing-du@tamu.edu>
        Stumped on Text extraction\REGEX problem <vautourNO@SPAMunb.ca>
    Re: test <shino_korah@yahoo.com>
        Upload probs <mail@nexo.de>
    Re: Upload probs <mail@nexo.de>
        Using a hash passed by reference inside a function?? <miscellaneousemail@yahoo.com>
    Re: Using a hash passed by reference inside a function? <vze2r2j8@verizon.net>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Fri, 06 Jul 2001 19:32:01 GMT
From: Carlos C. Gonzalez <miscellaneousemail@yahoo.com>
Subject: Can someone translate this Perl into common English *grin*??
Message-Id: <MPG.15afbfc9bba26152989683@news.edmonton.telusplanet.net>

Hi everyone,

What does the following mean?  It's from the DB_File module documentation 
and it prints out the values contained in the %h hash.  I am 
not sure I understand the use of the double variables in the while 
expression, the each statement referring to the %h hash, and the string 
expression being printed.  

The $k and $v scalars are not used until this loop is reached.  

while (($k, $v) = each %h)
  { print "$k -> $v\n" }

I am guessing that the above means something like this.  Take each of the 
values in the %h hash, store the index value in the $k scalar, the value 
associated with the index key value in the $v scalar and then for each 
key/value pair in %h print the key (stored in $k) and the value (stored 
in $v.  

Whew!

Is that what it means?

Thanks.
-- 
Carlos 
www.internetsuccess.ca


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

Date: 6 Jul 2001 19:41:33 GMT
From: ebohlman@omsdev.com (Eric Bohlman)
Subject: Re: Can someone translate this Perl into common English *grin*??
Message-Id: <9i549d$62b$3@bob.news.rcn.net>

Carlos C. Gonzalez <miscellaneousemail@yahoo.com> wrote:
> What does the following mean?  It's from the DB_File module documentation 
> and it prints out the values contained in the %h hash.  I am 
> not sure I understand the use of the double variables in the while 
> expression, the each statement referring to the %h hash, and the string 
> expression being printed.  

> The $k and $v scalars are not used until this loop is reached.  

> while (($k, $v) = each %h)
>   { print "$k -> $v\n" }

> I am guessing that the above means something like this.  Take each of the 
> values in the %h hash, store the index value in the $k scalar, the value 
> associated with the index key value in the $v scalar and then for each 
> key/value pair in %h print the key (stored in $k) and the value (stored 
> in $v.  

> Whew!

> Is that what it means?

Yep.  Take a look at the description of each() in the perlfunc manual.



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

Date: Fri, 6 Jul 2001 22:18:12 +0100
From: "Stephen Collyer" <scollyer@dont.spam.me.netspinner.co.uk>
Subject: Re: Can someone translate this Perl into common English *grin*??
Message-Id: <994453742.20684.0.nnrp-14.9e98901a@news.demon.co.uk>


Carlos C. Gonzalez <miscellaneousemail@yahoo.com> wrote in message
news:MPG.15afbfc9bba26152989683@news.edmonton.telusplanet.net...

> while (($k, $v) = each %h)
>   { print "$k -> $v\n" }
>
> I am guessing that the above means something like this.  Take each of the
> values in the %h hash, store the index value in the $k scalar, the value
> associated with the index key value in the $v scalar and then for each
> key/value pair in %h print the key (stored in $k) and the value (stored
> in $v.

That's precisely what it means. However, more can be said about *why*
the loop works.

The important point to be aware of is that the test of the while loop
is executed in scalar context. So whatever you put in between the
brackets in while (...) finds itself in scalar context. Here, we have
an assignment to a list: ($k, $v) = each %h. Perl arranges things
so that 1) an assignment can be used as an expression i.e. it can
return a value and 2) that when used in scalar context, a list
assignment returns the number of items available for assignment.

Now the question is, what *does* each return in the expression:
($k, $v) = each %h ? Well, each is assigning to a list, and this
means that it is evaluated in list context, not the scalar context
seen by the whole expression. And in list context, each steps
through its hash and returns key/value pairs, until there are no
more to return. So each returns a 2 element list repeatedly,
until the hash is exhausted, then a null list. The numbers of items
available for assignment thus goes ..., 2, 2, 2, 2, 0.

But 2 evaluates to true, by Perl's rules of truth, and 0 evaluates
to false. So the while test expression will evaluate to true and
execute the body of the while until there are no more key value
pairs to fetch from the hash.

That's a long explanation. The thing to understand is that there
are two levels of context working above. Firstly, the *whole*
assignment expression is evaluated in scalar context, because
the while test wants a boolean value, and that's a scalar.
Secondly, the each function is evaluated in list context, by virtue
of the assignment to a list. And the combination of both levels
of context is what makes the loop work.

Whew.

Steve Collyer





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

Date: Fri, 06 Jul 2001 21:31:23 GMT
From: Carlos C. Gonzalez <miscellaneousemail@yahoo.com>
Subject: Re: Can someone translate this Perl into common English *grin*??
Message-Id: <MPG.15afdbd679710f34989688@news.edmonton.telusplanet.net>

In article <994453742.20684.0.nnrp-14.9e98901a@news.demon.co.uk>, 
scollyer@dont.spam.me.netspinner.co.uk says...

Thanks Stephen.

You know to this day I still don't know how people on these forums have 
the time to write such thorough answers. 

-- 
Carlos 
www.internetsuccess.ca


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

Date: Fri, 06 Jul 2001 20:24:43 GMT
From: "Tro" <dmitriv_rus@hotmail.com>
Subject: chmod 755, 777
Message-Id: <f8p17.111340$Mf5.30415810@news3.rdc1.on.home.com>

What are they? What are chmod's are anyway....thanks for the help!




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

Date: Fri, 06 Jul 2001 17:23:24 +0500
From: Robert Sherman <rsherman@ce.gatech.edu>
Subject: Re: chmod 755, 777
Message-Id: <3B45ADBC.33F87DD4@ce.gatech.edu>

Tro wrote:

> What are they? What are chmod's are anyway....thanks for the help!

perldoc -f chmod

and

man chmod (if you're on *nix)



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

Date: Fri, 6 Jul 2001 12:54:33 -0500 (CDT)
From: dennis100@webtv.net (BUCK NAKED1)
Subject: Re: Chmod and File::Find
Message-Id: <2058-3B45FB59-47@storefull-247.iap.bryant.webtv.net>

Thanks again Tad for helping me clean up the code.  --Dennis



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

Date: Fri, 06 Jul 2001 21:31:47 -0000
From: cberry@cinenet.net (Craig Berry)
Subject: Re: Correct way to open a .jpg image and save?
Message-Id: <tkcbi31enauib0@corp.supernews.com>

Matt L. (mlaw@talk21.comNOSPAM) wrote:
: I'd been led to believe that binmode was for non-unix like systems such as
: Windows?

binmode was motivated by systems which use multicharacter line terminators
(and character EOF markers), but it's always safe and recommended to use
it on any system in the interests of clarity and portability.  See
'perldoc -f binmode' for a very thorough discussion.

: The script in question takes input from Windows-based browsers and
: saves the image files to Unix/Linux.
: However, using this syntax:
: 
: $file = param('file');
: open (SAVE, ">../images/$file") || die $!;
:    binmode(SAVE);
:    while (<$file>) {

$file is a string, which has not been associated with a file handle (at
least in the code you've shown us).

-- 
   |   Craig Berry - http://www.cinenet.net/~cberry/
 --*--  "Magick is the art and science of causing change in conformity
   |   with Will."  - Aleister Crowley


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

Date: Fri, 06 Jul 2001 21:35:44 GMT
From: Carlos C. Gonzalez <miscellaneousemail@yahoo.com>
Subject: DB_File saves records with huge amount of white space in file??
Message-Id: <MPG.15afdcf7fb877a7e989689@news.edmonton.telusplanet.net>

Hi everyone,

I am starting to use DB_File and have noticed that the data I save to a 
file through this module is saved with a huge amount of white space 
between each record.  

Does anyone know if this means that DB_File produces huge database files 
as a result?

Thanks

-- 
Carlos 
www.internetsuccess.ca


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

Date: 6 Jul 2001 12:07:22 -0700
From: hao7@yahoo.com (hao tran)
Subject: environment variable in cgi
Message-Id: <3913d5b4.0107061107.1181df64@posting.google.com>

Hi all,
I try to get the simple enviroment variable by $HOME = $ENV{HOME}; 
but the problem is it is not displayed on the browser like netscape. 
(using print "Content-type:text/html\n\n")

Please help.  Thanks.


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

Date: Fri, 06 Jul 2001 12:28:44 -0700
From: Ron Hill <hillr@ugs.com>
Subject: Re: environment variable in cgi
Message-Id: <3B46116C.377FC6@ugs.com>

hao tran wrote:

> Hi all,
> I try to get the simple enviroment variable by $HOME = $ENV{HOME};
> but the problem is it is not displayed on the browser like netscape.
> (using print "Content-type:text/html\n\n")
>

#!/usr:/bin/perl
print "Content-type: text/html\n\n";
Here it is<BR>";
while ( ($k,$v) = each %ENV)  {
print "$k => $v<br>\n";
}
Hope this helps

Ron



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

Date: Fri, 6 Jul 2001 22:10:33 +0200
From: "Alan J. Flavell" <flavell@mail.cern.ch>
Subject: Re: environment variable in cgi
Message-Id: <Pine.LNX.4.30.0107062159410.5035-100000@lxplus003.cern.ch>

On Jul 6, Ron Hill rearranged some electrons to say

> hao tran wrote:
>
> > I try to get the simple enviroment variable by $HOME = $ENV{HOME};
> > but the problem is it is not displayed on the browser like netscape.
> > (using print "Content-type:text/html\n\n")

> #!/usr:/bin/perl
> print "Content-type: text/html\n\n";
> Here it is<BR>";
> while ( ($k,$v) = each %ENV)  {
> print "$k => $v<br>\n";
> }

What drivel is this?

> Hope this helps

nah, there's almost nothing right in it.  I haven't time to list all
the ways; a brief perusal of this very group would reveal the local
culture regarding warnings, strict and so forth, and checking that
code actually runs before pasting it into an answer.

I'd be using CGI.pm, so it would be easy to apply its escapeHTML()
to turn any string into proper HTML form before printing it.

There are of course lighter-weight ways of doing that, if CGI.pm
wasn't being used anyway.

Perhaps a clearer question, with some concrete details of the actual
difficulty that the questioner is encountering, would have been
useful in targetting an answer at the real problem.




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

Date: Fri, 6 Jul 2001 20:41:07 +0100
From: "Simon Flack" <news@simonflack.com>
Subject: Re: Error - Undefined subroutine &Win32::Process::Create
Message-Id: <9i54ne$guf3v$1@ID-83895.news.dfncis.de>

> I am calling a perl script from another perl script and i get the
> following error any suggestions as to how to solve it would be great.
>

[...snip...]

> #!e:\perl\bin\perl -w
>
> Win32::Process::Create($ProcessObj,
> "D:\\Progra~1\\Apache~1\\Apache\\cgi-bin\\some_exe.exe", "s", 0,
> NORMAL_PRIORITY_CLASS, ".")|| die ErrorReport();

you need to add "use Win32::Process;" to your script.

That the Win32::Process::Create function is part of the Win32::Process
module that you aren't loading, so perl doesn't know what to do.

Regards
Simon



"minutiae" <minutiae@usa.net> wrote in message
news:3B45673A.76B033D5@usa.net...
>
> I am calling a perl script from another perl script and i get the
> following error any suggestions as to how to solve it would be great.
>
> Thanks
>
>
> Undefined subroutine &Win32::Process::Create called at D:\Program
> Files\Apache Group\Apache\cgi-bin\test2.pl line 3.
>
> Orig.pl
> #!e:\perl\bin\perl -w
>
> Win32::Process::Create($ProcessObj,
> "D:\\Progra~1\\Apache~1\\Apache\\cgi-bin\\test.pl", "s", 0,
> DETACHED_PROCESS, ".")|| die ErrorReport();
>
> Test.pl
>
> #!e:\perl\bin\perl -w
>
> Win32::Process::Create($ProcessObj,
> "D:\\Progra~1\\Apache~1\\Apache\\cgi-bin\\some_exe.exe", "s", 0,
> NORMAL_PRIORITY_CLASS, ".")|| die ErrorReport();
>
>
> I call test.pl from orig.pl and i get the error :
> Undefined subroutine &Win32::Process::Create called at D:\Program
> Files\Apache Group\Apache\cgi-bin\test2.pl line 3.
>
> However if i call only test.pl it executes perfectly fine without any
> errors. In fact if i change the orig.pl to call an executable instead of
> test.pl it runs fine. So i am completely lost.
>
> Any thoughts would be much appreciated.
>
> Thanks.
>




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

Date: Fri, 06 Jul 2001 18:17:00 GMT
From: PerlFAQ Server <faq@denver.pm.org>
Subject: FAQ: Which version of Perl should I use?
Message-Id: <wgn17.24$T3.170735616@news.frii.net>

This message is one of several periodic postings to comp.lang.perl.misc
intended to make it easier for perl programmers to find answers to
common questions. The core of this message represents an excerpt
from the documentation provided with every Standard Distribution of
Perl.

+
  Which version of Perl should I use?

    You should definitely use version 5. Version 4 is old, limited, and no
    longer maintained; its last patch (4.036) was in 1992, long ago and far
    away. Sure, it's stable, but so is anything that's dead; in fact, perl4
    had been called a dead, flea-bitten camel carcass. The most recent
    production release is 5.6 (although 5.005_03 is still supported). The
    most cutting-edge development release is 5.7. Further references to the
    Perl language in this document refer to the production release unless
    otherwise specified. There may be one or more official bug fixes by the
    time you read this, and also perhaps some experimental versions on the
    way to the next release. All releases prior to 5.004 were subject to
    buffer overruns, a grave security issue.

- 

Documents such as this have been called "Answers to Frequently
Asked Questions" or FAQ for short.  They represent an important
part of the Usenet tradition.  They serve to reduce the volume of
redundant traffic on a news group by providing quality answers to
questions that keep coming up.

If you are some how irritated by seeing these postings you are free
to ignore them or add the sender to your killfile.  If you find
errors or other problems with these postings please send corrections
or comments to the posting email address or to the maintainers as
directed in the perlfaq manual page.

Answers to questions about LOTS of stuff, mostly not related to
Perl, can be found by pointing your news client to

    news:news.answers

or to the many thousands of other useful Usenet news groups.

Note that the FAQ text posted by this server may have been modified
from that distributed in the stable Perl release.  It may have been
edited to reflect the additions, changes and corrections provided
by respondents, reviewers, and critics to previous postings of
these FAQ. Complete text of these FAQ are available on request.

The perlfaq manual page contains the following copyright notice.

  AUTHOR AND COPYRIGHT

    Copyright (c) 1997-1999 Tom Christiansen and Nathan
    Torkington.  All rights reserved.

This posting is provided in the hope that it will be useful but
does not represent a commitment or contract of any kind on the part
of the contributers, authors or their agents.

                                                           01.03
-- 
    This space intentionally left blank


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

Date: Fri, 06 Jul 2001 20:04:52 GMT
From: Carlos C. Gonzalez <miscellaneousemail@yahoo.com>
Subject: Flags to use with DB_File tie call??
Message-Id: <MPG.15afc7896b19495a989684@news.edmonton.telusplanet.net>

Hi everyone,

I have just started using the DB_File Perl module and have some questions 
about it. 

Under this module one would normally "open" a file (tiying it to a hash) 
by using the following type of call.

tie %h, "DB_File", $file, O_RDWR|O_CREAT, 0640, $DB_HASH 
    or die "Cannot open $file: $!\n";

I have looked in the DB_File documentation, the Berkely DB documentation, 
and in www.perl.com and have not yet found any listing of the values that 
can be passed into the 4rth parameter (which above is O_RDWR|O_CREAT).  
Does anyone know where I can get the various values for this paramenter.  
They are flags of some sort designating how a file will be processed.  I 
know that much. 

Thanks

-- 
Carlos 
www.internetsuccess.ca


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

Date: Fri, 6 Jul 2001 16:24:26 -0400
From: David Coppit <newspost@coppit.org>
To: bowman <bowman@montana.com>
Subject: Re: Gtk or Tk or ?
Message-Id: <Pine.SUN.4.33.0107061616080.10750-100000@mamba.cs.Virginia.EDU>

[posted & mailed]

Thanks for the reply. To summarize:

- Tk: oldest, most portable, well documented, "ugly" widgets, probably
  already compiled on platform
- Gtk: "pretty" widgets, rapid development, probably need to compile
- Qt: "pretty" widgets, rapid development, looks a little better on
  Windows, probably need to compile

Questions:
- How is portability of Gtk and Qt with respect to Windows, Linux,
  SunOS, AIX, BSD/OS, FreeBSD, HP-UX, IRIX, and DEC OSF1?
- Are there licensing issues with Qt? (I think I remember you have to
  pay $$ to use it in a commercial package.)
- Any technical benefit of Qt over Gtk?

Thanks!
David



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

Date: Fri, 06 Jul 2001 23:00:43 +0200
From: Philip Newton <pne-news-20010706@newton.digitalspace.net>
Subject: Re: Gtk or Tk or ?
Message-Id: <2a9cktks781vs5btec6bes2rbaf07qj9n6@4ax.com>

On Tue, 3 Jul 2001 21:41:38 -0600, "bowman" <bowman@montana.com> wrote:

> Tk is a little more portable if you are going across a number of platforms.
> If you are staying with Linux, anything but the barest install will at least
> have the gtk and qt libs. Both of these are available on Windows, Qt being a
> little more polished.

While Gtk is available for Windows, the Perl-Gtk bindings apparently are
not. (At least that was the case at the time of last year's
yapc::Europe; things may have changed since then.)

Cheers,
Philip
-- 
Philip Newton <nospam.newton@gmx.li>
That really is my address; no need to remove anything to reply.
If you're not part of the solution, you're part of the precipitate.


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

Date: 6 Jul 2001 11:48:15 -0700
From: javabsp@yahoo.com (Ka-Hing Cheung)
Subject: handling a file with a perl script
Message-Id: <89f6b330.0107061048.7e6000d8@posting.google.com>

how to hadle a requested file with a certain extension with a perl
script?
I do not have access to the httpd.conf, so is there a way to do it in
 .htaccess?
if so, do I need to put it in every directory?
I know I can do something like this:

<Files ~ (\.htm)>
SetHandler perl-script
PerlHandler ???
</Files>

What should I put instead of ??? to make it work?
also, what will the server pass to my script so that I know which file
has been requested?

What if the file being requested doesnot exist? will the server know
this and not invoking my script?

Thanks a lot


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

Date: 6 Jul 2001 11:50:59 -0700
From: redsquirreldesign@yahoo.com (Dave Hoover)
Subject: Re: how do you move a created file
Message-Id: <812589bb.0107061050.3953402a@posting.google.com>

Mike wrote:
>  I'm using a cgi/perl script that creates a file called
> mega.htm and puts that file in my cgi-bin area. When I
> try to look at that file by typing the url in my browser,
> it gives me a 403 permissions error. 
[snip]
> here is the variable:
> $config{'megalist'} = '/usr/www/users/nuspirit/cgi-bin/';
[snip]

Rather than putting the file in your cgi-bin, where the web server is
probably trying to execute it (rather than just parse the HTML), put
it somewhere beneath your docroot where all the other HTML files are.

HTH

--
Dave Hoover
"Twice blessed is help unlooked for." --Tolkien
http://www.redsquirreldesign.com/dave


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

Date: 6 Jul 2001 11:38:31 -0700
From: redsquirreldesign@yahoo.com (Dave Hoover)
Subject: Re: how to read multipart/form-data
Message-Id: <812589bb.0107061038.480c77a6@posting.google.com>

Enrico Ng wrote:
> How do I read multipart/form-data?

Here is a snippet of code from my Soapbox.pm that uploads a file from
the client to the server.

----------------
sub uploadFile {
	my $s = shift;
        if ($s->{param}{file} ne "") {
		my $path;
		for ($s->{config}{doc_root}, $s->{config}{article_dir}, $s->{name})
{
			die "illegal characters in config file" if m|[^a-zA-Z0-9_/\.\-]|;
			/^(.*)$/;
			$path .= $1;
		}
		my $file = $q->param("file");
		open(OUTFILE, ">$path") 
			or die "unable to open $s->{config}{article_dir}$s->{name}";
		while (my $bytesread = read($file, my $buffer, 1024)) {
			print OUTFILE $buffer;
		}
		close(OUTFILE);
        } elsif ($s->{param}{type} =~ /cr/i) {
		print "Error: no file selected.";
	}
}
---------------

To see the rest of Soapbox.pm, go here:
http://redsquirreldesign.com/soapbox/Soapbox.pm.txt

To get more info about Soapbox, go here:
http://www.redsquirreldesign.com/soapbox

HTH

--
Dave Hoover
"Twice blessed is help unlooked for." --Tolkien
http://www.redsquirreldesign.com/dave


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

Date: 6 Jul 2001 22:07:54 +0200
From: elwood@news.agouros.de (Konstantinos Agouros)
Subject: I know this must be in the manpages... number formatting
Message-Id: <elwood.994448736@news.agouros.de>

I might be blind, but what I am looking for is some way to print larger integer
numbers with digits (german way) like
1000000000 gets printed to 1.000.000.000 or with ,'s depending on the locale.
I played around with printf but couldn't find the trick...

Konstantin
-- 
Dipl-Inf. Konstantin Agouros aka Elwood Blues. Internet: elwood@agouros.de
Otkerstr. 28, 81547 Muenchen, Germany. Tel +49 89 69370185
----------------------------------------------------------------------------
"Captain, this ship will not sustain the forming of the cosmos." B'Elana Torres


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

Date: Fri, 06 Jul 2001 23:00:44 +0200
From: Philip Newton <pne-news-20010706@newton.digitalspace.net>
Subject: Re: I know this must be in the manpages... number formatting
Message-Id: <3d9cktcpar1egloschp7n0phsb08k41dt0@4ax.com>

On 6 Jul 2001 22:07:54 +0200, elwood@news.agouros.de (Konstantinos
Agouros) wrote:

> I might be blind, but what I am looking for is some way to print larger integer
> numbers with digits (german way) like
> 1000000000 gets printed to 1.000.000.000 or with ,'s depending on the locale.

Well, the basic idea is in `perldoc -q "commas added"`. Switching the
decimal point/thousands comma to decimal comma/thousands point is as
easy as tr/,./.,/ after wards.

The "hard" bit is probably to determine the correct locale decimal
separator and thousands separator. Perhaps you can pull something out of
localeconv? ...hold on... yup, have a look in `perldoc POSIX` under
localeconv; the elements 'decimal_point' and 'thousands_sep' (or, for
money, 'mon_decimal_point' and 'mon_thousands_sep') look promising. Also
have a look at 'grouping' and 'mon_grouping' in case the locale wants
you to group by fours (or something else) rather than threes.

This assumes, of course, that your system's locale support is up to
scratch :)

Cheers,
Philip
-- 
Philip Newton <nospam.newton@gmx.li>
That really is my address; no need to remove anything to reply.
If you're not part of the solution, you're part of the precipitate.


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

Date: Fri, 06 Jul 2001 16:19:06 -0500
From: Michael Carman <mjcarman@home.com>
Subject: Re: I know this must be in the manpages... number formatting
Message-Id: <3B462B4A.F13B9FC@home.com>

Konstantinos Agouros wrote:
> 
> I might be blind, but what I am looking for is some way to print
> larger integer numbers with digits (german way)
> [...]
> I played around with printf but couldn't find the trick...

It's not a printf() option. Look at perlfaq5 "How can I output my
numbers with commas added?" and adapt it to use dots instead of commas.
Or, use it as is and whack it with tr/.,/,./ afterwards.

-mjc


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

Date: 6 Jul 2001 11:28:52 -0700
From: miriamraphael@yahoo.com (Miriam Raphael-Roberts)
Subject: MySQL,DBI doesn't like my 'LIKE' query
Message-Id: <748729f5.0107061028.6dec5e95@posting.google.com>

This is my first time ever posting to a newsgroup. I hope you'll all
 be able to help me.
I'm trying to create a small search engine for my site that queries 
the database. My program can execute and retrieve results for almost
 every SQL statement, It doesn't let me do queries though with the
'LIKE' command. The user enters the keyword and I search the database
(on the description column) to look for the keyword. I printed the
query and then pasted it into the MySQL command line interface and it
worked properly. Something is going on from the time I send the query
until Mysql
executes it. Anyone every have this problem? The version of Mysql 
is 3.22.23, I don't think it has anything to do with the version 
though because as I said, I pasted in the query and Mysql interpreted 
it correctly. I've written some code below which is basically
what my program is doing (I edited out the irrelvant parts). Instead 
of 'perl' I really have $keyword in my program, etc.
My email is miriamraphael@yahoo.com. I really need help to figure this
out.
Thanks!

#!/usr/local/bin/perl

my $query .= "select id from users where description like \'%perl%\' ;
";
my(@row) = ();
my(@select) = ();
my($dbh,$sth,$rv,$sql);

$dbh = &ConnectToDB;
$sth = $dbh->prepare($query) or die "Cant prepare $statement:
$rv = $sth->execute or  die $sth->errstr();

my($i) = 0;

        while(@row = $sth->fetchrow_array)
        {
                for ($j=0; $j < @row; $j++)
                { $select[$i+$j] = $row[$j]; }
                $i = $i + $j + 1;
                }

$rc = $sth->finish;

$dbh->disconnect || "failed to disconnect: $dbh->errstr()\n";
print @select;


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

Date: Fri, 06 Jul 2001 21:43:25 -0000
From: cberry@cinenet.net (Craig Berry)
Subject: Re: Parsing an html document for the title (don't flame, I have searched around)
Message-Id: <tkcc7t98ph3256@corp.supernews.com>

dave (usted@cyberspace.org) wrote:
: Flame away if you like, but:
: 
: while (<LINKS>) {
:    my $url = $_;

Why not just do

  while (my $url = <LINKS>) {

:    next if $_ =~ /^$/;

$_ is the default left operand of =~, so you could simplify this to

  next if /^$/;

I would prefer this, though:

  chomp $url;
  next unless length $url;

That removes the newline, which you probably don't want, and then loops if
this leaves a zero-length string.

:    my $page = get($url);
:    my $title = get_title($page);

Don't be afraid to nest function calls:

  my $title = get_title(get($url));

:    print "<h3>$title </h3>";
:    print "<a href=\"$url\">$url</a>\n <br><br>";

Prettier way to do it:

  print <<STUFF;
<h3>$title</h3>
<a href="$url">$url</a>
<br><br>
STUFF

  But I'd 'use CGI qw(:all)' and then do this:

  print h3($title),
        a({ href => $url }, $url),
        br, br;

All a matter of style & taste.

: }
: 
: sub get_title {
:    my $text = shift;
:    use HTML::HeadParser;
:    my $p = HTML::HeadParser->new;
:    $p->parse($text);
:    my $title = $p->header("Title");
:    return $title;


In general, I prefer to collect all modules used by a source file at
the top.  They all get included at compile time anyway, and it makes it 
easier to see depenendencies when you're maintaining the code later.

You could eliminate the $text and $p lexicals and just do this:

  return HTML::HeadParser->new->parse(shift)->header('Title');

: }
: 
: After only getting the title correctly out in 9/10 cases, I tried to
: use the HeadParser module, but not 4/10 current links return nothing! 
: Any ideas?  I don't want to have to roll my own regular expression to
: do this..

No clue on this part of your question.

-- 
   |   Craig Berry - http://www.cinenet.net/~cberry/
 --*--  "Magick is the art and science of causing change in conformity
   |   with Will."  - Aleister Crowley


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

Date: Fri, 6 Jul 2001 21:56:43 +0200
From: ggd@gaura.nitai.hr (Sasa Janiska)
Subject: Perl & C(++) comparison
Message-Id: <slrn9kc5vr.292.ggd@gaura.nitai.hr>

Hi!

I've just started to learn Perl, primarily to use it for CGI scripts, but I am 
thinking how much is Perl capable (using Perl compiler) in writing stand-alone 
applications  that are usually developed in C(++)?

Sincerely,
Sasa



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

Date: Fri, 6 Jul 2001 16:49:28 -0400
From: David Coppit <newspost@coppit.org>
Subject: Re: Perl & C(++) comparison
Message-Id: <Pine.SUN.4.33.0107061642180.10750-100000@mamba.cs.Virginia.EDU>

On Fri, 6 Jul 2001, Sasa Janiska wrote:

> I've just started to learn Perl, primarily to use it for CGI
> scripts, but I am thinking how much is Perl capable (using Perl
> compiler) in writing stand-alone applications  that are usually
> developed in C(++)?

Do a search on "compiler comp.lang.perl.misc" on
http://groups.google.com/, and you'll see that "compilation" usually
doesn't mean compilation like you're thinking.

Having said that, you really have two questions: (1) Is Perl a capable
programming language for non-script applications, and (2) Can Perl
programs be made into stand-alone programs.

Yes, and yes. I like Perl because I don't have to deal with storage
management headaches, and because I'm more interested in getting the
right result than getting a wrong result really quickly. Plus Perl is
"higher-level" than C or C++. I find that I'm actually making progress
toward a solution in Perl when I would still be programming
infrastructure classes in C++. However, since Perl is fairly flexible
(e.g. auto-coercion of types, dynamic dispatching of methods, etc.),
you need to employ more restraint when developing large, long-lived
systems. This is all IMHO, of course. :)

As far as (2), the perl2exe program works fairly well, and perlcc has
come a long way (although I haven't looked at it lately). There was
also some noise of Perl eventually supporting the packaging up of
modules so that all you need is the Perl interpreter and the package
to run an application.

David



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

Date: Fri, 6 Jul 2001 21:33:59 +0200
From: ggd@gaura.nitai.hr (Sasa Janiska)
Subject: Perl & C(++)
Message-Id: <slrn9kc4l7.1ek.ggd@gaura.nitai.hr>

Hi!

I've just started to learn Perl, primarily to use it for CGI scripts, but I am 
thinking how much is Perl capable (using Perl compiler) in writing stand-alone 
applications  that are usually developed in C(++)?

Sincerely,
Sasa



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

Date: Fri, 6 Jul 2001 21:53:53 +0200
From: ggd@gaura.nitai.hr (Sasa Janiska)
Subject: Perl & C(++)
Message-Id: <slrn9kc5qh.265.ggd@gaura.nitai.hr>

Hi!

I've just started to learn Perl, primarily to use it for CGI scripts, but I am 
thinking how much is Perl capable (using Perl compiler) in writing & 
producing stand-alone applications  that are usually developed in C(++)?

Sincerely,
Sasa



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

Date: 6 Jul 2001 20:20:05 GMT
From: dha@panix.com (David H. Adler)
Subject: Re: Perl 6:   ->   vs  .
Message-Id: <slrn9kc7bl.ja7.dha@panix2.panix.com>

In article <f002cdd6.0107031303.64e4f6bf@posting.google.com>, Michael G
Schwern wrote:
  
> 1)  Perl 6 breaks compatibility with Perl 5. 
> 2)  You will NOT have to rewrite all your Perl 5 code (though we hope
> you eventually will).

To clarify, that's that we hope you eventually rewrite all your Perl 5
code, not that we hope you will *have* to... :-)

dha

-- 
David H. Adler - <dha@panix.com> - http://www.panix.com/~dha/
tastes filling! less great!       - ignatz in #perl


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

Date: Fri, 6 Jul 2001 16:36:53 -0400
From: David Coppit <newspost@coppit.org>
Subject: Perl Power Tools or Cygwin?
Message-Id: <Pine.SUN.4.33.0107061634420.10750-100000@mamba.cs.Virginia.EDU>

So I'm thinking of adding some Unix-style tools to my Windows arsenal.
Cygwin seems like an obvious choice, but then there's the Perl Power
Tools project: http://language.perl.com/ppt/, which seems to have
implementations for a lot of stuff already...

Anyone using PPT exclusively? Any comments/advice? (Obviously you
don't get bash, which may be enough to make me want Cygwin. :)

David



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

Date: Fri, 06 Jul 2001 16:56:57 -0400
From: Lou Moran <lmoran@wtsg.com>
Subject: Re: Perl Power Tools or Cygwin?
Message-Id: <ed9cktctno6cg917sqlgr94t672339cjtg@4ax.com>

On Fri, 6 Jul 2001 16:36:53 -0400, David Coppit <newspost@coppit.org>
wrote wonderful things about sparkplugs:

>So I'm thinking of adding some Unix-style tools to my Windows arsenal.
>Cygwin seems like an obvious choice, but then there's the Perl Power
>Tools project: http://language.perl.com/ppt/, which seems to have
>implementations for a lot of stuff already...
>
>Anyone using PPT exclusively? Any comments/advice? (Obviously you
>don't get bash, which may be enough to make me want Cygwin. :)

Cygwin has made my Windows life bearable.  I haven't tried PPT
(probably becasue I was afraid it was a PowerPoint Presentation) but I
can say without reservation I love Cygwin (which I actually got for
the C compiler.) 

>
>David



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

Date: Fri, 06 Jul 2001 18:09:49 GMT
From: "Tro" <dmitriv_rus@hotmail.com>
Subject: Simple scripts...
Message-Id: <N9n17.110538$Mf5.30272817@news3.rdc1.on.home.com>

hi,
i've just started learning Perl and i'm in need to see some simple scripts
written by other people...I have a book on Perl but there aren't enough
examples there....if no one has any scripts then, could someone tell me if
there are any sites on the net that maybe have some...

Thanks in advance,
~Tro




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

Date: Fri, 06 Jul 2001 15:52:29 -0400
From: Lou Moran <lmoran@wtsg.com>
Subject: Re: Simple scripts...
Message-Id: <ek0ckt8pdqf81ttvrrahu2pphv27svg5v9@4ax.com>

On Fri, 06 Jul 2001 18:09:49 GMT, "Tro" <dmitriv_rus@hotmail.com>
wrote wonderful things about sparkplugs:

>hi,
>i've just started learning Perl and i'm in need to see some simple scripts
>written by other people...I have a book on Perl but there aren't enough
>examples there....if no one has any scripts then, could someone tell me if
>there are any sites on the net that maybe have some...

You get what you pay for...

www.freeperl.com

I would recommend (if you're familiar with programming) getting a copy
of the Perl Cookbook

>
>Thanks in advance,
>~Tro
>



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

Date: Fri, 06 Jul 2001 20:24:42 GMT
From: "Tro" <dmitriv_rus@hotmail.com>
Subject: Re: Simple scripts...
Message-Id: <e8p17.111339$Mf5.30415910@news3.rdc1.on.home.com>

thanks!




"Lou Moran" <lmoran@wtsg.com> wrote in message
news:ek0ckt8pdqf81ttvrrahu2pphv27svg5v9@4ax.com...
> On Fri, 06 Jul 2001 18:09:49 GMT, "Tro" <dmitriv_rus@hotmail.com>
> wrote wonderful things about sparkplugs:
>
> >hi,
> >i've just started learning Perl and i'm in need to see some simple
scripts
> >written by other people...I have a book on Perl but there aren't enough
> >examples there....if no one has any scripts then, could someone tell me
if
> >there are any sites on the net that maybe have some...
>
> You get what you pay for...
>
> www.freeperl.com
>
> I would recommend (if you're familiar with programming) getting a copy
> of the Perl Cookbook
>
> >
> >Thanks in advance,
> >~Tro
> >
>




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

Date: Fri, 06 Jul 2001 14:04:59 -0500
From: Bing Du <bing-du@tamu.edu>
Subject: store session data in mySQL?
Message-Id: <3B460BDB.3F6C139@tamu.edu>

Hi,

Our current Perl (version 5.005_03 built for irix-64) code writes
session data in the SDBM format on the hard disk.  We are trying to make
the code filesystem independant.  So it would be better to store session
data in mySQL database.  Since this Perl code is used by users to
deliver e-mails which always involves attachments handling, my question
is how I should get attachment stored in mySQL?  Is there any sample
script that I can study?

Any suggestions and pointers would be appreciated.

Bing



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

Date: Fri, 06 Jul 2001 17:00:59 -0300
From: Gil Vautour <vautourNO@SPAMunb.ca>
Subject: Stumped on Text extraction\REGEX problem
Message-Id: <3B4618FB.D0FFFEC5@SPAMunb.ca>

Hello,

Here goes...  I have one large text file that contains blocks of text
which I would like to extract and output to their own files.  Each block
of text starts with the same pattern of characters and ends with the
same pattern of characters. Each block also has a unique pattern of
characters (a word, and I have a list of all the possible words) in the
first line that I want to use to identify the block and also use as the
name of the file I eventually want to output for each block.
Simplified:

START blah blah UNIQUENAME1 blah blah
blah blah
blah blah
END blah blah
blah blah
START blah blah UNIQUENAME2 blah blah
blah blah
blah blah
END
 ...
etc.

What I can't get my head around is how to read in the file to a While
loop so that I can find each START and output it, and everything after
it, up to and including END to a new file called UNIQUENAME for each
block.  Any suggestions would be a great help.

Thanks,




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

Date: Fri, 6 Jul 2001 14:08:06 -0700
From: "terminalsplash" <shino_korah@yahoo.com>
Subject: Re: test
Message-Id: <9i59bn$r2r@news.or.intel.com>

It worked!:)
"Guillem Colomer" <guillem@burns.upc.es> wrote in message
news:7dlmm4oijr.fsf@burns.upc.es...
> test




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

Date: Fri, 6 Jul 2001 22:57:53 +0200
From: "Emil Horowitz" <mail@nexo.de>
Subject: Upload probs
Message-Id: <9i58oj$gkthn$1@ID-78897.news.dfncis.de>

Hi,

close to desperation, here is my call for help: In one of my scripts I have
an upload routine to give the user the possibility to upload a picture. This
should be quite simple, but it does not work. The file name arrives all
right on the server, but not the file itself. After uploading, the file size
is 0.

The server is UNIX, the source file comes from a Windows PC with Windows
path-syntax. I use this code:


my $sourceFile = 'c:\img\mypic.gif';
my $targetFile = '../img/tarpic.gif';
open (OUTFILE, ">$targetFile");
print "$targetFile<br>";
 while (my $bytesread = read($quellDatei, my $buffer, 1024))
  print OUTFILE $buffer;
 }
chmod (0404, "$targetFile");
close (OUTFILE);

This should work, should it not? Please help!

Thanks!
Emil





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

Date: Fri, 6 Jul 2001 23:01:25 +0200
From: "Emil Horowitz" <mail@nexo.de>
Subject: Re: Upload probs
Message-Id: <9i58va$g967q$1@ID-78897.news.dfncis.de>

Hi,

just found a mistake in my above posting:

"$quellDatei" should be "$sourceFile", I just missed to translate it.

Emil





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

Date: Fri, 06 Jul 2001 21:01:29 GMT
From: Carlos C. Gonzalez <miscellaneousemail@yahoo.com>
Subject: Using a hash passed by reference inside a function??
Message-Id: <MPG.15afd4838cbee8d989687@news.edmonton.telusplanet.net>

Hi ya'll,

How can I use a hash passed by reference (in order to prevent it being 
flattened into a scalar) inside a subroutine?

Say that I have a hash called %h

Say that I pass that hash by a call to a function called contents like 
so:

print contents(\%h);

How do I get the function as listed below to print out the hash passed by 
reference??

sub contents
{
  my $hash = @_;
  while (($k, $v) = each $hash)
  { 
    print "$k -> $v\n"
  }
}

Perl tells me that I the argument to each must be a hash and not a 
private variable. 

Thanks

-- 
Carlos 
www.internetsuccess.ca


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

Date: Fri, 06 Jul 2001 22:03:36 GMT
From: "Kurt Stephens" <vze2r2j8@verizon.net>
Subject: Re: Using a hash passed by reference inside a function??
Message-Id: <YAq17.737$4M3.134459@typhoon1.gnilink.net>

"Carlos C. Gonzalez" <miscellaneousemail@yahoo.com> wrote in message
news:MPG.15afd4838cbee8d989687@news.edmonton.telusplanet.net...
> Hi ya'll,
>
> How can I use a hash passed by reference (in order to prevent it being
> flattened into a scalar) inside a subroutine?

The arguments to a non-prototyped function are evaluated in list context, so
the hash would be passed a a list of key/value pairs, not 'flattened' into a
scalar.  Still, it's a good idea to use a reference to avoid the overhead of
copying the hash.

>
> Say that I have a hash called %h
>
> Say that I pass that hash by a call to a function called contents like
> so:
>
> print contents(\%h);

Do you really want to print the return value of contents()?  Since you have
your print statements in the sub below, you don't need to print here.

> How do I get the function as listed below to print out the hash passed by
> reference??
>
> sub contents
> {
>   my $hash = @_;

Problem #1 - Assigning @_ to $hash evaluates the parameter list in scalar
context, returning the value 1 for the single hash reference passed from
contents(\%h).  Use either

    my ($hash) = @_;

to assign @_ to the list ($hash) or else use

    my $hash = shift;

to retrieve the first element from @_ and assign it to $hash.

>   while (($k, $v) = each $hash)

Problem #2 - You need to dereference $hash as %$hash.

>   {
>     print "$k -> $v\n"
>   }
> }
>

The code below should work:

use strict;
use warnings;

my %h = ( one => 'I', two => 'II', three => 'III' );

print_contents(\%h);

sub print_contents {
    my ($hash) = @_;
    while (my ($k, $v) = each %$hash) {
        print "$k -> $v\n"
    }
}


HTH,

Kurt Stephens





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

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


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