[19323] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 1518 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Aug 14 09:05:42 2001

Date: Tue, 14 Aug 2001 06:05:13 -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: <997794313-v10-i1518@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Tue, 14 Aug 2001     Volume: 10 Number: 1518

Today's topics:
    Re: Accessing a widget when defined local to a sub <bkennedy99@Home.com>
    Re: Accessing a widget when defined local to a sub <bkennedy99@Home.com>
    Re: Can read, but can't write <samneric@tigerriverOMIT-THIS.com>
    Re: case sensitive <tinamue@zedat.fu-berlin.de>
    Re: CGI.pm broken? (Re: weird problem with Gecko) (Helgi Briem)
    Re: Comma's at end of list can break program?? (Logan Shaw)
    Re: Connecting to a remote MS SQL server (DimitriM)
        cygwin date dtschurr@hotmail.com
    Re: cygwin date <bart.lateur@skynet.be>
        FAQ: Why can't I just open(FH, ">file.lock")? <faq@denver.pm.org>
    Re: Flock: Just to be sure ! (Anno Siegel)
    Re: get rid of these leading zeros in Perl <dtweed@acm.org>
        Length of strings and arrays <nilsbertling@web.de>
    Re: Length of strings and arrays <wyzelli@yahoo.com>
        module File::Find and parameters (Chris van der Geer)
    Re: module File::Find and parameters <krahnj@acm.org>
    Re: module File::Find and parameters <bart.lateur@skynet.be>
        Passing parameters to subroutines <glenn@surveystar.com>
    Re: Passing parameters to subroutines (Rafael Garcia-Suarez)
    Re: perldoc is like Greek to a beginner?? <bart.lateur@skynet.be>
        Possible perl/DOS bug? <nospam.jonni@ifm.liu.se>
    Re: regex with ascii code - chr(0) ? <bart.lateur@skynet.be>
    Re: SQLServer HowTo <bart.lateur@skynet.be>
    Re: Stateful CGI <skpurcell@hotmail.com>
        Test coverage without Devel:Coverage <Rui.Nogueira@de.bosch.com>
    Re: TK:Date and Access database problem <Pcmann1@btinternet.com>
    Re: Uh Oh: URL Encode <bart.lateur@skynet.be>
    Re: Uh Oh: URL Encode <bart.lateur@skynet.be>
    Re: Uh Oh: URL Encode <flavell@mail.cern.ch>
    Re: Uh Oh: URL Encode <Tassilo.Parseval@post.rwth-aachen.de>
    Re: Uh Oh: URL Encode <bart.lateur@skynet.be>
        Win32::GUI <philippe.perrin@sxb.bsf.alcatel.fr>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Tue, 14 Aug 2001 12:44:29 GMT
From: "Ben Kennedy" <bkennedy99@Home.com>
Subject: Re: Accessing a widget when defined local to a sub
Message-Id: <N29e7.102778$EP6.26236163@news1.rdc2.pa.home.com>


"Peter Mann" <Pcmann1@btinternet.com> wrote in message
news:9l8tmv$ckh$1@uranium.btinternet.com...
>
> Dear all,
> Thanks for the advice, but the code you suggested still doesn't allow me
to
> access the combo1 from outside the 'donotebook' subroutine. For instance,
> upon pressing the button which calls 'comboInsert', the element still isnt
> inserted into the combo box!
> The code you provided only works within donotebook!
> Or im I missing some obvious point?

You can do two things:

1) Declare $combo1 with my outside your subroutine to that it is i score
everywhere
2) Declare $combo1 within the subroutine, and return it from the subroutine
that creates it

The third option I suggested earlier was to create a closure in the
subroutine that does stuff to $combo1, thus keeping $combo1 indirectly
around,  but perhaps you should stick to 1 or 2

--Ben Kennedy





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

Date: Tue, 14 Aug 2001 12:55:44 GMT
From: "Ben Kennedy" <bkennedy99@Home.com>
Subject: Re: Accessing a widget when defined local to a sub
Message-Id: <kd9e7.102786$EP6.26243291@news1.rdc2.pa.home.com>


"gnari" <gnarinn@hotmail.com> wrote in message
news:997728875.752654464449733.gnarinn@hotmail.com...

> closures can be nice, but IMHO, not really relevant in your example.
> you still have to store the closure in a global, so why not just have
> the $combo object in a global. and what if you want 2 combo widgets?

In general, closres in Tk can make life a lot easier, as specific
functionality can be nicely encapsulated.  Often I do this to feed data into
a display widget.  If the widget has to do several things to make sure the
display is up to date (such as updating labels or activating buttions) it
makes sense to return a sub that does all the updating for a chunk of data,
rather than a mess of widgets and expect the calling code to know how data
affects them.  Another nice side effect is that all your code for dealing
with that widget is together, which helps readibility.  You could always
return a hash containing the buttons and labels and then pass that to a
named sub that updates the display, but then you may as all go all-out OO
with composite widgets.  I'm not sure what the OP wanted, but closures were
probably overkill - he needs some more fundamental help with scoping issues

--Ben Kennedy




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

Date: Tue, 14 Aug 2001 08:40:06 -0400
From: Samneric <samneric@tigerriverOMIT-THIS.com>
Subject: Re: Can read, but can't write
Message-Id: <MPG.15e2e62d98687e3e989681@news.usit.net>

In article <c5d7d22b.0108111030.7580a715@posting.google.com>, 
brianwharris@hotmail.com says...
> I'm trying to write to an html file in htdocs with my perl script
> that's in cgi-bin. Using Unix with Apache.

There's always the possibility that your script >IS< creating the file, but 
that you are telling it to create/write the file in one location and then you 
look for the resulting file in another location.

> $file2 = "/htdocs/favlinks.html";
> open (INFILE, ">$file2") || die("favlinks.html does not exist: $!");

Here you tell it to open the file in the directory "/htdocs" (located off of 
the root directory). But the path (on some systems that use "htdocs" for 
webpages) from "cgi-bin" to "htdocs" is "../htdocs" - NOT -> "/htdocs".

Add after the open() statement:

if (-e $file2) { print "$file2 exists\n"; }
else { print "$file2 doesn't exist\n"; }

That should tell you something that you might want to know :)



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

Date: 14 Aug 2001 11:58:40 GMT
From: Tina Mueller <tinamue@zedat.fu-berlin.de>
Subject: Re: case sensitive
Message-Id: <9lb3pg$8f33m$4@fu-berlin.de>

Tad McClellan <tadmc@augustmail.com> wrote:
> jtjohnston <jtjohnston@courrier.usherb.ca> wrote:

>>I want to find out if the user inputted, from html, the correct answer,
>>but using case insensitive. 
>>    foreach $i (0..$#MyArray)
>>    {
>>       if (/$MyArray[$i]/i  eq  /$user_input/i)  #obviously not correct

> You should let perl walk through the array for you. You seldom
> need explicit indexing to walk an array in Perl:

>    foreach my $element ( @MyArray ) {
>       if ( lc($element) eq lc($user_input) ) {
>       }
>    }

well, then i let perl walk through it:

my $lc_user_input = lc($user_input);
if (grep {$lc_user_input eq lc($_)} @MyArray)

or:
if (grep {/^$user_input$/i} @MyArray)
(which is not so efficient, of course but nicer =)

regards,
tina
-- 
http://www.tinita.de \  enter__| |__the___ _ _ ___
tina's moviedatabase  \     / _` / _ \/ _ \ '_(_-< of
search & add comments  \    \ _,_\ __/\ __/_| /__/ perception
---   Warning: content of homepage hopelessly out-dated   ---


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

Date: Tue, 14 Aug 2001 10:26:35 GMT
From: helgi@NOSPAMdecode.is (Helgi Briem)
Subject: Re: CGI.pm broken? (Re: weird problem with Gecko)
Message-Id: <3b78fc9c.1907795995@news.isholf.is>

On Mon, 13 Aug 2001 12:15:40 +0100, nick@fenris.webthing.com
(Nick Kew) wrote:

>In article <3B77A3AF.6879D855@poczta.onet.pl>, one of infinite monkeys
>	at the keyboard of Sonia Walter <sonia_walter@poczta.onet.pl> hath written:
> 
>[ added c.l.p.m crosspost ]
>
>> That was the problem, thanks. I got the issue now. The pages are 
>> generated with help of CGI.pm module.
>
>I don't use CGI.pm's HTML-generating facilities.  But from this post and
>various others I've seen, I wonder if it's rather clue-challenged in places?

No, it is not, but its users definitely are.

Regards,
Helgi Briem



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

Date: 12 Aug 2001 23:34:21 -0500
From: logan@cs.utexas.edu (Logan Shaw)
Subject: Re: Comma's at end of list can break program??
Message-Id: <9l7lcd$jfq$1@charity.cs.utexas.edu>

In article <x7r8uglirx.fsf@home.sysarch.com>,
Uri Guttman  <uri@sysarch.com> wrote:
>>>>>> "CCG" == Carlos C Gonzalez <miscellaneousemail@yahoo.com> writes:
>  CCG> "Put commas at the end of lists to so your program won't break if
>  CCG> someone inserts another item at the end of the list."
>
>very simple concept. here is a list of quoted strings:
>
>	@list = ( 
>		'first string',
>		'another one',
>		'last but not least'
>	) ;
>
>now you are editing this and need to put another string at the end of
>the list so you insert the line:
>
>		'added line to end'
>
>and your program now breaks because the code below has illegal syntax.

And then you ask yourself, "Why did I become a programmer, when
apparently I'm not smart enough to edit a text file and keep in mind a
few simple syntactic rules?"  Or at least I would, because if "you must
make sure the thing you added at the end has a comma before it" is too
hard a rule to remember and follow, how are you *ever* going to get
along with the zillions of other rules that are way, way more complex
than that (and which have worse consequences)?

In other words, I've never seen the point in adding the comma.  It just
seems to make the code more cluttered, and not only that, but when I
see code with the comma after the last item, I sometimes wonder if
maybe someone has accidentally deleted the last item of the list.

On the other hand, I put semicolons after all statements (even those at
the end of a block or file), so maybe I am a hypocrite.  :-)

  - Logan
-- 
"Our grandkids love that we get Roadrunner and digital cable."
(Advertisement for Time Warner cable TV and internet access, July 2001)


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

Date: 14 Aug 2001 04:32:46 -0700
From: Dimitri.Maesfranckx@MERANT.COM (DimitriM)
Subject: Re: Connecting to a remote MS SQL server
Message-Id: <7237a36f.0108140332.6436904@posting.google.com>

Jim,

Take a look at http://www.cpan.org/modules/00modlist.long.html#7)DatabaseInterfac
to get the proper module.
Now besised the module you will also need an ODBC driver that connects
to SQLServer. You might want to have a look at the Merant DataDirect
drivers.
Free evals (Connect SQLServer ODBC and SequeLink ODBC) are available
at www.merant.com/datadirect.

Cheers,
Dimitri

Jim Turner <jimt+nospam@netins.net> wrote in message news:<3B72AE45.F5BB48B0@netins.net>...
> Hi,
> 
>     I'm a bit confused on what I should be doing
> to accomplish this.  I'm very new to database
> interaction using perl.
> 
>     The server I am trying to connect to is a
> generic install of MS SQL (v6.0 I believe, but
> I may be wrong there) on a NT server in a remote
> office.  What I will be connecting from is a
> Digital UNIX 4.0e server.  Perl version installed
> is 5.6.0.
> 
>     From what I've read, I need to have either
> MSSQL::BDlib, DBD::ODBC, or DBD::Sybase.  But I
> assume I need some sort of SQL DB libraries to
> link against.  Then there is some discussion of
> perl DBI, but none of these has a clear desciption
> of what is needed for installation and in what
> order.
> 
>     Also, it appears as if a lot of these are
> meant for connections in which the DB is on the
> same machine as the perl script.  This is not
> my case, obviously.
> 
>     If anyone has some pointers to documentation,
> books, or suggestions on things that have worked,
> I would be in your debt.
> 
>     Thanks.
> 
> __
> Jim Turner
> Systems Administration
> netINS, Inc.


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

Date: 13 Aug 2001 14:18:18 GMT
From: dtschurr@hotmail.com
Subject: cygwin date
Message-Id: <9l8nja$cin$1@news.netmar.com>


Hi there,
Sorry, this question is more about cygwin, but I don't know where to post it:
I'm using Perl under cygwin and have the following problem:
using localtime, the time displayed is always two hours before my system time
seen on the windows clock. (The same occurs in bash shell with date command).
It seems that GMT time is displayed instead of my local time.

Any suggestions? Thanks,

Daniel




 -----  Posted via NewsOne.Net: Free (anonymous) Usenet News via the Web  -----
  http://newsone.net/ -- Free reading and anonymous posting to 60,000+ groups
   NewsOne.Net prohibits users from posting spam.  If this or other posts
made through NewsOne.Net violate posting guidelines, email abuse@newsone.net


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

Date: Tue, 14 Aug 2001 11:49:14 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: cygwin date
Message-Id: <a54intcuhlu6jaf8p28reoej3jg4grf3qc@4ax.com>

dtschurr@hotmail.com wrote:

>Sorry, this question is more about cygwin, but I don't know where to post it:
>I'm using Perl under cygwin and have the following problem:
>using localtime, the time displayed is always two hours before my system time
>seen on the windows clock. (The same occurs in bash shell with date command).
>It seems that GMT time is displayed instead of my local time.
>
>Any suggestions? Thanks,

Time zone. I think you haven't set it, althrough I wouldn't really know
*where* to set it. I gather that gmtime() and localtime() return the
same value?

Perhaps you need to set a TZ environment variable, oh, to "CEST" I would
think. I'm really *really* just guessing.

-- 
	Bart.


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

Date: Tue, 14 Aug 2001 12:17:02 GMT
From: PerlFAQ Server <faq@denver.pm.org>
Subject: FAQ: Why can't I just open(FH, ">file.lock")?
Message-Id: <2F8e7.91$V3.170971648@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.

+
  Why can't I just open(FH, ">file.lock")?

    A common bit of code NOT TO USE is this:

        sleep(3) while -e "file.lock";      # PLEASE DO NOT USE
        open(LCK, "> file.lock");           # THIS BROKEN CODE

    This is a classic race condition: you take two steps to do something
    which must be done in one. That's why computer hardware provides an
    atomic test-and-set instruction. In theory, this "ought" to work:

        sysopen(FH, "file.lock", O_WRONLY|O_EXCL|O_CREAT)
                    or die "can't open  file.lock: $!":

    except that lamentably, file creation (and deletion) is not atomic over
    NFS, so this won't work (at least, not every time) over the net. Various
    schemes involving link() have been suggested, but these tend to involve
    busy-wait, which is also subdesirable.

- 

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.

                                                           05.18
-- 
    This space intentionally left blank


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

Date: 14 Aug 2001 12:49:01 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Flock: Just to be sure !
Message-Id: <9lb6nt$8oj$1@mamenchi.zrz.TU-Berlin.DE>

According to Mariman Center <Mariman@mariman.net>:
> 
> We  have  some  problems  in  a  script on a domain with high traffic,
> 
> Please correct me if I make mistakes here:
> 
> 
> When I want the users to only READ in a file:
> 
> open (FILE, "$file");

I'll suppose that you left out "or die ..." for this discussion only,
but it will be there in the real code.

> flock (FILE,1);

Instead of "1" you should use the constant LOCK_SH from the Ioctl
module.  Similar comments apply below.

> #operations
> close (FILE)
> 
> So, multiple users can access the file in reading, right ?
> 
> 
> When I want one user to WRITE in a file
> open (FILE, ">>$file"); # or open (FILE, ">$file");

The first option is fine when you actually want to append data.  The
other one 

    open (FILE, ">$file");

will truncate the file, no matter how many readers it currently has.
That is because locking is not mandatory (in most cases), so the
open() will succeed even with outstanding locks.  The cautious way
of opening a file in this situation is

    open( FILE, "+>$file);

This will open for read/write, retaining the contents.  Then, after
your

> flock (FILE,2);

succeeds, you can start with the

> #operations

which would probably include a seek() to the beginning and a
truncate() to clear the file before re-writing it.

> close (FILE)
> 
> So, NO other user may write in this file til it isn't closed, right ?
> 
> 
> Now,  what  happens if a file is flock (FILE,1) and that somebody else
> tries to write into it, doing a flock (FILE,2) ? In other words, the 2
> operations above, together by different users ?

The second flock() waits until it can be served.  Except...

But, please, this is all covered in the documentation.  man flock
and perldoc -f flock should give you all the information you are
asking here.

> Last, is it requested to write a flock (FILE,8), before closing it ?

No, it is even discouraged.  Close the file as soon as you're done
with it, then every lock you hold on this file will be released.
Explicit unlock is rarely desirable.

Anno


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

Date: Tue, 14 Aug 2001 12:40:38 GMT
From: Dave Tweed <dtweed@acm.org>
Subject: Re: get rid of these leading zeros in Perl
Message-Id: <3B791B28.7C5627B6@acm.org>

David Combs wrote:
> Philippe PERRIN  <philippe.perrin@sxb.bsf.alcatel.fr> wrote:
> >$id1 = "00061";
> >print "$id1\n";    # will display 00061
> >
> >$id1 =~ s/^0*//g;
> >print "$id1\n";    # will display 61
> >
> 
> Is that /g really needed, and if so, why?

Also, beware the case $id1 = "00000"

-- Dave Tweed


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

Date: Tue, 14 Aug 2001 13:28:39 +0200
From: Nils Bertling <nilsbertling@web.de>
Subject: Length of strings and arrays
Message-Id: <3B790B67.58E49A9B@web.de>

Infact I do have some problems concerning a program, which doesn't
run at the moment. One reason might be the length of the implemented
strings or arrays. Are there any limitation in length or elements?
It would be very kind if anybody can help me solving this problem.



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

Date: Tue, 14 Aug 2001 21:48:37 +0930
From: "Wyzelli" <wyzelli@yahoo.com>
Subject: Re: Length of strings and arrays
Message-Id: <Vo8e7.42$1T.130258@wa.nnrp.telstra.net>

"Nils Bertling" <nilsbertling@web.de> wrote in message
news:3B790B67.58E49A9B@web.de...
> Infact I do have some problems concerning a program, which doesn't
> run at the moment. One reason might be the length of the implemented
> strings or arrays. Are there any limitation in length or elements?
> It would be very kind if anybody can help me solving this problem.

Only available memory.  Show us some code so we can be of more assistance.

Wyzelli
--
#Modified from the original by Jim Menard
for(reverse(1..100)){$s=($_==1)? '':'s';print"$_ bottle$s of beer on the
wall,\n";
print"$_ bottle$s of beer,\nTake one down, pass it around,\n";
$_--;$s=($_==1)?'':'s';print"$_ bottle$s of beer on the
wall\n\n";}print'*burp*';




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

Date: 14 Aug 2001 04:10:42 -0700
From: floorvdgeer@hotmail.com (Chris van der Geer)
Subject: module File::Find and parameters
Message-Id: <f4bd591c.0108140310.ec40a43@posting.google.com>

I have made the following script that opens all files in directory
'/', reads inode-information and puts it into a hash that has been
tied to a .dbm-file on the filesystem.

<BEGIN SCRIPT>
#!/usr/bin/perl

use File::Find;

sub wanted {
        my $file=$File::Find::name;
	my $fileinfo = join(' ', stat $File::Find::name);
        $hash{$file}=$fileinfo;
}

dbmopen(%hash, '/tmp/outputfile', 0644) || die "Cannot create file:
$!";
find \&wanted, "/";
dbmclose(%hash);
<END SCRIPT>

For so far it works OK.
But now I want to use 'use strict' and declare my hash %hash local.
That won't succeed.

I have tried to call sub-routine 'wanted' with parameters (reference
to a local declared hash) but sub-routine 'wanted' doesn't accept
parameters.
I have tried to tie the hash, put 1 entry into the hash and untie the
hash in subroutine 'wanted', but the program gets very very slow.

Does anyone have an idea to solve this problem?

Chris vd Geer


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

Date: Tue, 14 Aug 2001 11:41:54 GMT
From: "John W. Krahn" <krahnj@acm.org>
Subject: Re: module File::Find and parameters
Message-Id: <3B790F25.852D8A5A@acm.org>

Chris van der Geer wrote:
> 
> I have made the following script that opens all files in directory
> '/', reads inode-information and puts it into a hash that has been
> tied to a .dbm-file on the filesystem.
> 
> <BEGIN SCRIPT>
> #!/usr/bin/perl
> 
> use File::Find;
> 
> sub wanted {
>         my $file=$File::Find::name;
>         my $fileinfo = join(' ', stat $File::Find::name);
>         $hash{$file}=$fileinfo;
> }
> 
> dbmopen(%hash, '/tmp/outputfile', 0644) || die "Cannot create file:
> $!";
> find \&wanted, "/";
> dbmclose(%hash);
> <END SCRIPT>
> 
> For so far it works OK.
> But now I want to use 'use strict' and declare my hash %hash local.
> That won't succeed.
> 
> I have tried to call sub-routine 'wanted' with parameters (reference
> to a local declared hash) but sub-routine 'wanted' doesn't accept
> parameters.
> I have tried to tie the hash, put 1 entry into the hash and untie the
> hash in subroutine 'wanted', but the program gets very very slow.
> 
> Does anyone have an idea to solve this problem?


#!/usr/bin/perl -w
use strict;
use File::Find;
use DB_File;

my %hash;
tie %hash, 'DB_File', '/tmp/outputfile' or die "Cannot open
'/tmp/outputfile': $!";
find( sub { $hash{$File::Find::name} = "@{[stat()]}" }, '/' );
untie %hash;

__END__


John
-- 
use Perl;
program
fulfillment


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

Date: Tue, 14 Aug 2001 11:51:59 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: module File::Find and parameters
Message-Id: <r74intce01jqrm7km5ase1g0vjfls8apg3@4ax.com>

Chris van der Geer wrote:

>But now I want to use 'use strict' and declare my hash %hash local.
>That won't succeed.

Put 

	my %hash;

at the front of your script. You *want* a "global" variable. If that
doesn't work, use a 

	use vars '%hash';

or

	our %hash;	# 5.6 or later

instead.

-- 
	Bart.


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

Date: Tue, 14 Aug 2001 08:54:00 -0400
From: Glenn <glenn@surveystar.com>
Subject: Passing parameters to subroutines
Message-Id: <3B791F68.6928D662@surveystar.com>

I'm  confused about how passing parameters works in Perl 5.  Here's my
test program...

    &SUB1(21);  #call first subroutine with some value

    sub SUB1 {
    my $passed1=$_[0];
    print "<br>passed1 is: $passed1 ";
    &SUB2;  #call 2nd subroutine with no passed value
    }

    sub SUB2 {
    my $passed2=$_[0];                         # should be NULL if
nothing passed to SUB2, right?
    print "<br>passed2 is: $passed2 ";
    }

 ...my output is...
    passed1 is: 21
    passed2 is: 21

Why does $passed2 get the value of $passed1?  This happens unless I call
SUB2 with an empty parameter list like &SUB2();

Any light to be shed on this?
Thanks!



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

Date: 14 Aug 2001 12:59:07 GMT
From: rgarciasuarez@free.fr (Rafael Garcia-Suarez)
Subject: Re: Passing parameters to subroutines
Message-Id: <slrn9ni8ev.ppb.rgarciasuarez@rafael.kazibao.net>

Glenn wrote in comp.lang.perl.misc:
} I'm  confused about how passing parameters works in Perl 5.  Here's my
} test program...
} 
}     &SUB1(21);  #call first subroutine with some value
} 
}     sub SUB1 {
}     my $passed1=$_[0];
}     print "<br>passed1 is: $passed1 ";
}     &SUB2;  #call 2nd subroutine with no passed value
}     }
} 
}     sub SUB2 {
}     my $passed2=$_[0];                         # should be NULL if
} nothing passed to SUB2, right?
}     print "<br>passed2 is: $passed2 ";
}     }
} 
} ...my output is...
}     passed1 is: 21
}     passed2 is: 21
} 
} Why does $passed2 get the value of $passed1?  This happens unless I call
} SUB2 with an empty parameter list like &SUB2();

This behavior is described at the very beggining of the perlsub manpage
(in the synopsis). You should have written &SUB2() instead.

-- 
Rafael Garcia-Suarez / http://rgarciasuarez.free.fr/


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

Date: Tue, 14 Aug 2001 10:38:27 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: perldoc is like Greek to a beginner??
Message-Id: <kgvhntcd5tfdo6uv238tl83t7a84lnahdc@4ax.com>

Pete Sohi wrote:

>Can someone recommend other APIs, documentation, references guides,
>links, user-groups, tutorials that might be better pitched for those
>still on the learning curve?.....

There's a "learning perl" website and some mailing lists.

	<http://learn.perl.org/>


In the standard documentation, look for the files with "tut" in their
name (for OO, see "oot"). You can get an overview in "perldoc perl", or
on the web in <http://www.perldoc.com/perl5.6/pod/perl.html>.

-- 
	Bart.


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

Date: Tue, 14 Aug 2001 14:19:29 +0200
From: "Jonas Nilsson" <nospam.jonni@ifm.liu.se>
Subject: Possible perl/DOS bug?
Message-Id: <9lb4ou$6tm$1@newsy.ifm.liu.se>

Try out this code changing $mydir to a dir in your dir structure.

use strict;
my $mydir='D:/Slask/testdir/';
mkdir($mydir."testdir1../");
mkdir($mydir."testdir2..\\");
mkdir($mydir."testdir3");
opendir(DIR,$mydir);
for (readdir DIR) {
 printf "%-20s %-20s\n",$_,(-d $mydir.$_?"A dir":"Not a dir");
};

Reslult:
 .                    A dir
 ..                   A dir
testdir1.            Not a dir
testdir2.            Not a dir
testdir3             A dir

Remove the dirs with:
my $mydir='D:/Slask/testdir/';
rmdir($mydir."testdir1../");
rmdir($mydir."testdir2../");

Perl canīt find the dirs which was created. Niether can you remove them with
explorer.

How about it?

This was tried on:
This is perl, v5.6.1 built for MSWin32-x86-multi-thread
(with 1 registered patch, see perl -V for more detail)

Copyright 1987-2001, Larry Wall

Binary build 628 provided by ActiveState Tool Corp.
http://www.ActiveState.com
Built 15:41:05 Jul  4 2001
--
/jN




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

Date: Tue, 14 Aug 2001 10:44:32 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: regex with ascii code - chr(0) ?
Message-Id: <970int0foev492n2rkbc267mtpoclg30gh@4ax.com>

YMK wrote:

>^@ is a single character (as in vi), when I read it (i.e. substr), that
>give chr(0)!

You mean "\c@"? Or "\000". Yes, both work in regexes (without the
quotes).

-- 
	Bart.


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

Date: Tue, 14 Aug 2001 11:16:26 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: SQLServer HowTo
Message-Id: <h22int4bun8f1jrcv0hlmi2h1djutajibi@4ax.com>

Paul Fortescue wrote:

>I can program SQL/ODBC stuff in C. I am new but getting better at Perl. I
>need to access a SQLSERVER DB in Perl on Linux, I have a DB but I don't know
>what to do next.
>
>From reading the manual/newsgroups, it looks like I need some DBI module.
>
>Am I right? Can I get this from anywhere?

Modules (DBI and DBD::ODBC) from CPAN, or
<http://www.activestate.com/PPMpackages/> if for Windows.

For info, check out "<http://dbi.symbolstone.org>. In particular, check
out the "Connecting UNIX and Microsoft Access / SQLServer Tutorial"
link.

-- 
	Bart.


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

Date: Tue, 14 Aug 2001 07:26:42 -0500
From: "spurcell" <skpurcell@hotmail.com>
Subject: Re: Stateful CGI
Message-Id: <3b7919fb$0$4344@wodc7nh0.news.uu.net>

There are basically only two ways to do this: Cookies and URL-Rewriting.
Mod-Perl offers some internal SID capabilities. Cookies are not always
widely accepted as people do turn off their cookie capability.

As a side note, JSP does offer some wonderful automatic capabilities for
this .

Scott


"Sean Hamilton" <sh@planetquake.com> wrote in message
news:Zy3e7.56809$b_3.5259463@news0.telusplanet.net...
> Greetings,
>
> Firstly I apologise if this is the incorrect group... the only CGI and
Perl
> related groups I could find had very few posts, and seemed to be
abandoned.
>
> Anyhow.
>
> I was wondering what the best way of having a user authentication system
is.
> I was thinking one of the following:
>
> - Server keeps a list of session IDs, stating the client's IP address.
> Client supplies that ID with every request. Problem is that then if the
> client idles for a long time, the session times out, and the client has to
> re-authenticate, and then it becomes diffiult to know (from the client's
> perspective) whether or not the last request registered. NTMail does this,
> and it's extremely frustrating writing out a lengthy e-mail, hitting
submit,
> having to reauthenticate, and not knowing if that email went through --
> which it didn't.
>
> - Client sends login and password with every request. Has the advantage of
> having pages bookmarked, but if the system is accessed from a public
system,
> people can refer to the history, and bring up a session.
>
> - Cookies, etc, etc...
>
> Is there a universally accepted solution to this problem, or am I just
going
> to have to pick one of the above situations and live with the
consequences?
>
> sh
>
>




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

Date: Tue, 14 Aug 2001 14:22:25 +0200
From: "Rui Nogueira" <Rui.Nogueira@de.bosch.com>
Subject: Test coverage without Devel:Coverage
Message-Id: <9lb565$eg$3@proxy.fe.internet.bosch.com>

Hi to all,

I want to know the test coverage of my Perl-script (some thousands of code
lines).
I found the Devel::Coverage module. But as this tool is still in the alpha
phase I now want to make something own.
Does anybody of you know how I can do it without using the Devel::Coverage
module?
The point would be to know, when a certain sub routine of my script is
calling another routine or an "if", "foreach" or "while" command is reached
in my code.

Thanks for your help.

Rui




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

Date: Tue, 14 Aug 2001 12:07:39 +0100
From: "Peter Mann" <Pcmann1@btinternet.com>
Subject: Re: TK:Date and Access database problem
Message-Id: <9lb0o3$92r$1@uranium.btinternet.com>

Thanks, got it working now!

Thankyou!


"Benjamin Goldberg" <goldbb2@earthlink.net> wrote in message
news:3B78C0AF.53A63F87@earthlink.net...
> Peter Mann wrote:
> >
> > Dear All,
> >
> > I am stuck on a problem relating to inserting a date into an Access
> > database. I am correctly retrieving the date from a TK::Date widget.
> > However, when constructing the SQL statement and inserting a record
> > into a database, a date of '30/12/1899' is always displayed. I suspect
> > this might be due to the widget returning a 'string' and i need to
> > insert a variable of type 'date' fromat within the record.
> >
> > Does anyone know if this is the correct reason and if so are there are
> > functions available to do this converison. Or am i completely wrong in
> > my assumptions?
> >
> > The code extract of the relevant section is:
> >
>
> --------------------------------------------------------------------------
---
> > my $start    = $startDate->get("%d/%m/%y");
> > my $complete = $endDate->get("%d/%m/%y");
> >
> > print $start;  # For debug purposes!  "THIS DISPLAYS THE CORRECT DATE"
> >
> > #construct SQL statement (BUT THIS DOESN'T)
> > $sqlstatement= "INSERT INTO tasks (taskName, start, complete) VALUES
> > ('Objective', '$start', $complete) ";
>
> What exact types are taskName, start, complete?  integer, varchar, what?
>
> Also, does it make any difference if you do:
> my $sth = $dbi->prepare( q[
> INSERT INTO tasks (taskName, start, complete)
> VALUES ( 'Objective', ?, ?)
> ] );
>
> $sth->execute( $start, $complete );
>
> # or
> $sth->bind_values( 1, $start, SQL_DATE ); # or whatever
> $sth->bind_values( 2, $complete, SQL_DATE ); # same here
> $sth->execute();
>
> If that fails, try to use Date::Parse or timelocal or strftime or
> whatever to turn it into the correct format.
>
> --
> The Swedish Chef has been assimilated. "Borg borg borg!"




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

Date: Tue, 14 Aug 2001 11:21:55 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: Uh Oh: URL Encode
Message-Id: <sb2intc14qubsntls3q5ha556qk1tfo1kd@4ax.com>

Tassilo von Parseval wrote:

>Bart Lateur wrote:

>> 	use URI::Escape;
>> 	print uri_escape('a=b&c=d');
>> -->
>> 	a=b&c=d
>> 
>> It DOES NOT escape the most dangerous characters "=" and "&". It's a
>> know bug, or feature, depending on what side you're on. Lincoln Stein
>> describes it in his book "Network Programming with Perl", in chapter 9.
>
>Well, rather a sort of unpleasant feature. But uri_escape takes a second 
>argument. It is a character-class which overrides the characters usually 
>escaped. So with that, one could force uri_escape to also escape & and =.

And that makes it alright then? Do you know the solution that Lincoln
Stein used in his book?

    The manual fix would be to replace "&" with "%26" and "=" with "%3D"
     in the search terms /before/ constructing the query string and
     passing it to uri_escape().

Lincoln Stein is a *very* experienced Perl programmer. The problem with
URI::Escape is that it invites to writing buggy code, or extremely ugly
patches, like this one.

-- 
	Bart.


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

Date: Tue, 14 Aug 2001 11:28:00 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: Uh Oh: URL Encode
Message-Id: <vi2ints0sj956e03qletgcf9ptagdsgo40@4ax.com>

brian d foy wrote:

>> It DOES NOT escape the most dangerous characters "=" and "&". It's a
>> know bug, or feature, depending on what side you're on.
>
>i think you want to say "it does not, by default, escape all
>of the special characters that matter to the CGI".  after all, 
>HTTP is only one scheme out of many. :)

The problem is that it doesn't do what people expect it to do. They
expect it to be safe if they do

	$query = "foo=" . uri_escape($foo) . "&bar=" . uri_escape($bar);

It is not.

The interface I would like, is more like this:

	$query = form_escape(foo => $foo, bar => $bar);

which *would* escape all of the names and the values, escape "&" and "="
in them as well, and combine it all into a proper
"name1=value1&name2=value2" string.

If you want to use it for something other than form data, just use one
parameter to the function, so

	$q = form_escape('a=b');

returns "a%3Db" (and not "a%3Db=").

-- 
	Bart.


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

Date: Tue, 14 Aug 2001 14:11:02 +0200
From: "Alan J. Flavell" <flavell@mail.cern.ch>
Subject: Re: Uh Oh: URL Encode
Message-Id: <Pine.LNX.4.30.0108141335480.32180-100000@lxplus023.cern.ch>

On Aug 14, Bart Lateur twiddled the eigenstates thus:

> Stein used in his book?
>
>     The manual fix would be to replace "&" with "%26" and "=" with "%3D"
>      in the search terms /before/ constructing the query string and
>      passing it to uri_escape().

As a design strategy, that's fundamentally broken.  Question for you:
how would you hope to include the character string "%26" (percent,
two, six) into your properly-encoded URI?

> Lincoln Stein is a *very* experienced Perl programmer.

Well, yes, and he's implemented a number of heuristic procedures that
usually get the right (or at least a safe) result when bludgeoned by
people who don't really know what they're doing.

But there _is_ a correct procedure: the latest state of play is
carefully documented in RFC2396 section 2.4.2, and any software that
handles URI strings needs to support at least the correct procedure,
no matter what additional heuristics it might offer for dealing with
people who are trying to apply incorrect procedures.

> The problem with
> URI::Escape is that it invites to writing buggy code, or extremely ugly
> patches, like this one.

It sounds like it, indeed.  Confession: I haven't studied its
behaviour in full detail - I'm commenting chiefly on the basis of what
I've read in this thread, rather than on any microscopic study of the
module's code.

As the RFC says:  "Implementers should be careful not to
   escape or unescape the same string more than once"

But escaping them less than once is also wrong!  The escaped
representation of the unescaped string %26 is %2526 , and anything
else is wrong.

(Don't confuse this with HTML's requirement to represent & as &amp;
in HREF or SRC parameters.  The two procedures are fundamentally
different, and whenever they do anything meaningful they are not
interchangeable.)

cheers



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

Date: Tue, 14 Aug 2001 14:30:07 +0200
From: Tassilo von Parseval <Tassilo.Parseval@post.rwth-aachen.de>
Subject: Re: Uh Oh: URL Encode
Message-Id: <3B7919CF.60600@post.rwth-aachen.de>

Bart Lateur wrote:

> Tassilo von Parseval wrote:

[...]

>>Well, rather a sort of unpleasant feature. But uri_escape takes a second 
>>argument. It is a character-class which overrides the characters usually 
>>escaped. So with that, one could force uri_escape to also escape & and =.
>>
> 
> And that makes it alright then? Do you know the solution that Lincoln
> Stein used in his book?
> 
>     The manual fix would be to replace "&" with "%26" and "=" with "%3D"
>      in the search terms /before/ constructing the query string and
>      passing it to uri_escape().

So then, how would you have written uri_escape?

Take the following string:
"?arg1=Q&A=A&Q&arg2=val"

How should a module guess the grouping? It could be:

arg1 = Q
A = A&Q
arg2 = val

but, likewise:

arg1 = Q&A=A&Q
arg2 = val

Sure, that is an unlikely example but it shows that the whole query 
string can't just be correctly escaped in one step. One has to do that 
argument-wise.

> Lincoln Stein is a *very* experienced Perl programmer. The problem with
> URI::Escape is that it invites to writing buggy code, or extremely ugly
> patches, like this one.

I know about L. Stein's experience. Yet, he hasn't come up with a more 
intelligent and globally valid solution than doing it manually.

Tassilo


-- 
$a=[(74,116)];$b=[($a->[1]-1,$a->[1]++,0x20)];$c=[(97,110)];$d=[($c->
[1]+1,$b->[1],"her")];for(@{[$a,$b,$c,$d]}){for(@{$_}){$_=~/\d+/?print
(chr($_)):print;}}$c=sub{$l=shift;[(0x20+$l-1,0x50,0x65,0x73-0x01,108
),(0x20,0x68,0x61,)]};print(map{chr($_)}@{($c->(1))});$h={a=>33*3,b=>
10**2+7,c=>"1"."0"."1",d=>0162};@h=sort(keys(%$h));for(@h){print(chr(
ord(chr($h->{$_}))))};



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

Date: Tue, 14 Aug 2001 12:38:11 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: Uh Oh: URL Encode
Message-Id: <7u6intgu9bp17j2t2bpvqj06db3203f69v@4ax.com>

Tassilo von Parseval wrote:

>So then, how would you have written uri_escape?
>
>Take the following string:
>"?arg1=Q&A=A&Q&arg2=val"
>
>How should a module guess the grouping?

It shouldn't guess. It shouldn't HAVE to guess. See my post in another
subtread:

	$query = form_escape( arg1 => 'Q&A=A&Q', arg2 => 'val');

-- 
	Bart.


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

Date: Tue, 14 Aug 2001 14:01:10 +0200
From: Philippe PERRIN <philippe.perrin@sxb.bsf.alcatel.fr>
Subject: Win32::GUI
Message-Id: <3B791306.4F6CF974@sxb.bsf.alcatel.fr>

Hi

I'm using ActivePerl with Windows2000, and I'd like to know how to use
GUI functions from The Win32 API...
I installed Win32::GUI package with PPM. For instance, I can easily call
the Win32::GUI::MessageBox() function, but I can't figure out how to
call more complex functions, such as Win32::GUI::CreateWindowEx().
I know all these functions quite well (through C++ programming), but
could anyone tell me where I can find detailed reference for this
package (syntax, examples...) ?

Thanks !

-- 
PhP

($r1,$r2,$r3,$r4)=("19|20","0|1","28|29","5|24");($r5,$r6)=("9|10|15|16|$r1|$r2","9|10|$r3");%h=("1|",$r6,"1=","[1-5]|2[0-4]","1/","0|19","1\\","6|25","2|","0|6|19|25|$r6","2/","1|20","2\\",$r4,"3|","$r2|6|$r1|25|$r6","3/",$r4,"4|","$r2|$r1|$r6","4=","2|3|4|11|12|13|14|21|22|23","4/",$r4,"4\\",15,"5|","$r2|9|15|$r1|20|$r3","5/",10,"6|",$r5,"7|",$r5,"7/",$r3);for($l=1;$l<8;$l++){b:for($i=0;$i<30;$i++){c:foreach(keys
%h){next c if(!(/^$l(.*)$/));$a=$1;if($i=~/^($h{$_})$/){print $a;next
b;}}print " ";}print "\n";}


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

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


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