[19626] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 1821 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Sep 26 09:11:34 2001

Date: Wed, 26 Sep 2001 06:10:15 -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: <1001509814-v10-i1821@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Wed, 26 Sep 2001     Volume: 10 Number: 1821

Today's topics:
    Re: Pattern Matching (Ian Boreham)
    Re: Peek and Poke on Perl? <gamtci1@mpinet.net>
    Re: Peek and Poke on Perl? <gamtci1@mpinet.net>
    Re: Problems with $ character <jocke30_gbg@hotmail.com>
    Re: Processing page between two other pages. <iltzu@sci.invalid>
    Re: Regular Expression Problem <iltzu@sci.invalid>
        Security of letting user specify regex in CGI script? (Jay McGavren)
    Re: Security of letting user specify regex in CGI scrip (Randal L. Schwartz)
    Re: Setting max. values (cpu/ram usage) for mod_perl sc <nospaming@gmx.net>
    Re: Setting max. values (cpu/ram usage) for mod_perl sc <ilya@martynov.org>
    Re: Setting max. values (cpu/ram usage) for mod_perl sc <nospaming@gmx.net>
    Re: Setting max. values (cpu/ram usage) for mod_perl sc <ilya@martynov.org>
    Re: The joys of segmentation faults <iltzu@sci.invalid>
    Re: This has got to be a bug <iltzu@sci.invalid>
        Use of 'our' in older perl versions <leapius@hotmail.com>
    Re: Use of 'our' in older perl versions <ilya@martynov.org>
    Re: Use of 'our' in older perl versions (Rafael Garcia-Suarez)
    Re: Use of 'our' in older perl versions <bart.lateur@skynet.be>
    Re: Using URLs as hash keys <iltzu@sci.invalid>
    Re: What good is the hyphen for named parameters? (Rafael Garcia-Suarez)
    Re: What good is the hyphen for named parameters? <iltzu@sci.invalid>
    Re: What good is the hyphen for named parameters? <bart.lateur@skynet.be>
    Re: XL saveas doesn't work (excel) <bart.lateur@skynet.be>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: 26 Sep 2001 00:27:20 -0700
From: ianb@ot.com.au (Ian Boreham)
Subject: Re: Pattern Matching
Message-Id: <f02c4576.0109252327.39d2c3e5@posting.google.com>

Andrew Cady <please@no.spam> wrote in message news:<871yku7m17.fsf@homer.cghm>...
> phookie <phookie@xmission.com> writes:
> 
> > How would one match/sub a string which begins with a "<" with zero
> > or more"<", ">" alphanumerics, quotes, equal signs, period, commas,
> > semi-colons, underscores, forward "/" and back "\" slashes, white
> > space, etc and ends with a ">" character.  This does not appear to
> > work
> > 
> >    $mystring =~ s/^<[A-Z a-z 0-9 "=.,;_/\\\s].+>$/my_new_string/;

In addition to comments already made:

phookie: You haven't included "<" and ">" in the character class.
"A-Z", "a-z", "0-9" and "_" can all be replaced with "\w". The "/"
needs to be escaped or you need to use different delimiters for s///.

Bear in mind also that ^ and $ mean the start and end of the
string/line. Your string cannot include additional text before or
after the <...> and still match. There doesn't seem to be a lot of
point in using substitution if you can only ever match the whole
string or not.


> The ".+" matches one or more instance of any character (except \n),
> which kind of defeats the purpose of your character class (currently
> you only require that character class for the first character on the
> line).  Also \s doesn't work in a character class, you have to use

\s does work in a character class, as do \w, \W, \S, \d etc.

> [:space:], which is almost the same.  You want:
> 
> /^<[ [:space:] [:alnum:] "=.,;_/\\ ]+>/
> 
> Although I have to ask, are you sure those are the only characters you
> want to include?  A negated character class may be more appropriate.
> If you want to match everything except the closing >, that's very
> easy:
> 
> /^<[^>]+>/

phookie did mention allowing "<" and ">" explicitly, but this is
starting to look rather like a case of HTML/SGML/XML tag-matching,
which would be better handled by a module, and not (yet again) by a
necessarily incomplete regex.

Still, following the statement of requirements as given, you could
try:


#!/usr/bin/perl -w

my $mystring = "<hello123 _<there>.,;\"'=/\\>";
print "Matched\n" if $mystring =~ m%^<[<>\w\s'"=,.;/\\]*>$%;


Of course, the "etc" would still need to be taken into account.

Regards,


Ian


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

Date: Wed, 26 Sep 2001 11:59:55 GMT
From: Gary <gamtci1@mpinet.net>
Subject: Re: Peek and Poke on Perl?
Message-Id: <3BB1C305.39AB@mpinet.net>

I built the board, so it's not supported by any OS. However, I built 
it to reside at one of the segment addresses A,B,C,D or E. 

Currently, under DOS, I use an out instruction to the board's 
IO port to set the memory address, and then use peek and poke 
to get at the memory.

I appreciate all the reponses and comments. It is, however, as 
I feared: I have to write this module myself for use under 
Linux and NT.  I'm wondering now which newsgroup would be 
appropriate to ask if a "peek/poke/inport/outport" driver is
available for Linux and/or NT (even if it's a sample).


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

Date: Wed, 26 Sep 2001 12:06:19 GMT
From: Gary <gamtci1@mpinet.net>
Subject: Re: Peek and Poke on Perl?
Message-Id: <3BB1C485.5465@mpinet.net>

Why would this be a "surefire" way to get it to crash?  In order
for the OS to communicate with the monitor card (A000 thru B000),
the hard drive (often in C000), many ethernet boards (C000 or D000
or E000), and even the BIOS (F000), it would have to have mapped 
addresses within these spaces and it must use them constantly.


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

Date: Wed, 26 Sep 2001 12:29:24 +0200
From: "JJ" <jocke30_gbg@hotmail.com>
Subject: Re: Problems with $ character
Message-Id: <9osamq$e6a$1@vg170.it.volvo.se>

"Benjamin Goldberg" <goldbb2@earthlink.net> wrote in message
news:3BAE53E8.EFE10411@earthlink.net...
> JJ wrote:
> >
> > Hi,
> >
> > Problem 1.
> > Step 1.1: I have a perl script that collects table names from a Oracle
> > database.
> > Step 1.2: In that script it then execute another perl script with the
> > table as argument, that extracts the table (data and structure).
> >
> > The table name from step 1.1 can contain the character '$' such as
> > 'MLOG$_WI_PISECTIONUS'. When executing the second script it says:
> > "Table MLOG does not exist"
> >
> > Earlier when I executed those scripts on Linux it worked with the fix
> > in the first script:
> > $replace='\$';
> > while(@row = $sth->fetchrow_array())
> > {
> >   $tmp = $row[0];
> >   # fix the '$' in the table name if it exist
> >   $tmp =~ s/\$/$replace/g; ## <<<== The fix <<<<
> >   push @tables, $tmp;
> > }
> >
> > # For each table, dump the data
> > foreach $table ( @tables )
> > {
> >   $outfile = "$dataDir$table$dumpFileExtension";
> >   print "Dumping table $table for schema $dbSchema\n";
> >   $command = "./oracledump_to_mySQL.pl --add-drop-table -u $dbSchema
> > -p $password $database $table >> $outfile";
> >   system($command);
> > }
>
> Eww.  Why do it like this?  Surely dropping the table from within your
> script would be better than calling an external program to do it...
>
> my $dbh2 = DBI->connect( $dbSchema, '', $password, {RaiseError=>1} );
> my $droptable = $dbi2->prepare(q[DROP TABLE ?]); # or whatever.
> while( my ($tablename) = $sth->fetchrow_array ) {
> $droptable->execute( $tablename );
> }

NO. The snipplet:
foreach $table ( @tables )
{
  $outfile = "$dataDir$table$dumpFileExtension";
  print "Dumping table $table for schema $dbSchema\n";
  $command = "./oracledump_to_mySQL.pl --add-drop-table -u $dbSchema -p
$password $database $table >> $outfile";
  system($command);
}

Exports the Oracle database to mySQL files (one file/table and each file
containing DROP CREATE and N * INSERT). I'm surley _NOT_ want to drop my
data source since this a way to move data and structure from Oracle to
mySQL.


>
> > Now when have moved it to Solaris this doesn't work.
> > Why?
>
> Probably a different shell.  You would be better off not calling any
> external commands, and doing it all in one script.
> >
> > Problem 2:
> > I also need to execute a system command '. $SOEORA_SETUP dtim1t' but
> > here is the '$' character again and it doesn't work.
>
> There's probably two problems.  The first is likely that you're using ""
> to quote the command [it should be '' instead].  The second problem you
> will see, once you fix the first, is that you're calling a shell script
> whose purpose is to change the shell environment.  system() creates a
> new shell, runs the $SEORA_SETUP program within that shell, and then the
> shell exits.
>
> > How can I solve this and execute it in my Perl script?
>
> foreach( qx'. $SOEORA_SETUP dtim1t 1>&2; /bin/env' ) {
> chomp;
> (my ($key, $val) = split /=/, $_, 2) == 2 or next;
> $ENV{$key} = $val if !defined $ENV{$key};
> }
>
> Or:
> foreach( qx". $ENV{SOEORA_SETUP} dtim1t 1>&2; /bin/env" ) {
> etc.  In this version, just about any delimiter, not just "", may be
> used.  So it could be qx// or qx[] etc..  In this case, the variable
> interpolation will end up being done by perl, not by the shell.

I did a UNIX script that make environment and then execute the Perl-script.
It's working fine.

// Jocke




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

Date: 26 Sep 2001 11:08:43 GMT
From: Ilmari Karonen <iltzu@sci.invalid>
Subject: Re: Processing page between two other pages.
Message-Id: <1001502332.11571@itz.pp.sci.fi>

In article <979ae699.0109240644.2015597@posting.google.com>, Phil Hibbs wrote:
>phil@snark.freeserve.co.uk (Phil Hibbs) wrote in message news:<979ae699.0109210322.7532e7a4@posting.google.com>...
>> You could do it by serving up a partial HTML page and relying on the
>> browser to render it despite the lack of a </BODY> and </HTML> tag,
>> and then when the processing is finished, send a <meta
>> HTTP-EQUIV="Refresh"...> tag that shows the results.
>
>Sorry, I think the "Refresh" tag goes in between the </BODY> and
></HTML> tag, at least I've seen it put there.

*Nothing* goes between the </BODY> and </HTML> tags.

The proper place for <META> tags is between <HEAD> and </HEAD>.

But this is the wrong newsgroup for this discussion.  You want
comp.infosystems.www.authoring.html.  Or better yet, you ought to read
the HTML specification yourself, at http://www.w3.org/.

[Followups set.]

-- 
Ilmari Karonen -- http://www.sci.fi/~iltzu/
"Get real!  This is a discussion group, not a helpdesk.  You post something,
we discuss its implications.  If the discussion happens to answer a question
you've asked, that's incidental."           -- nobull in comp.lang.perl.misc



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

Date: 26 Sep 2001 10:30:12 GMT
From: Ilmari Karonen <iltzu@sci.invalid>
Subject: Re: Regular Expression Problem
Message-Id: <1001499936.6639@itz.pp.sci.fi>

In article <6fstqtg8lcfpngmvovtigd882uvmn82irn@4ax.com>, Bart Lateur wrote:
>Scott wrote:
>
>>(please forgive the Java style code...i am using a library)
>>
>>myString = " ....multi-lines of text i don't need...\n"
>>myString += "#DATA"     // this flags my data section
>>myString += "..multi-lines of data i DO need....\n"
>>myString += "#0"        // this flags the end of my data.
>
>use .= not += .  Perhaps now it will work?

Not unless he also adds a few dollar signs, and makes the comments start
with #, and adds semicolons..  (Wait, doesn't Java need semicolons too?)

Anyway, the code given by the original poster isn't Perl.  It's Java,
and he's using a "Perl-compatible" regex library for Java.  We really
need a newsgroup or a mailing list for these questions, so that we can
shove them out of clpm where they're just confusing.

-- 
Ilmari Karonen -- http://www.sci.fi/~iltzu/
"Get real!  This is a discussion group, not a helpdesk.  You post something,
we discuss its implications.  If the discussion happens to answer a question
you've asked, that's incidental."           -- nobull in comp.lang.perl.misc



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

Date: 26 Sep 2001 00:16:18 -0700
From: sgarfunkle@hotmail.com (Jay McGavren)
Subject: Security of letting user specify regex in CGI script?
Message-Id: <6bb557e1.0109252316.38b31e26@posting.google.com>

I'm writing a CGI script to search an XML file and I'd like to have
AND, OR, etc. capability.  The simplest way I can think of is to let
the user specify a regex in a form field, store that in a variable,
and interpolate it into a regex:

-----Begin Perl code
#Take input from HTTP GET or POST
if ($ENV{'REQUEST_METHOD'} =~ /^post$/i) {read(STDIN, $_,
$ENV{'CONTENT_LENGTH'});}
else {$_ = $ENV{'QUERY_STRING'};}
#De-Webification
foreach (split /&/, $input) {
  ($name, $value) = split(/=/);
  $value =~ tr/+/ /;
  $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
  $input{$name} = $value;
}
#Search!
if ("my random string" =~ /$input{'regex'}/i) {print "Content-type:
text/html\n\n<HTML>Matched $input{'regex'}!</HTML>";}
-----End Perl code

But although I can't think of a specific attack, that seems highly
hackable to me.  Would this approach be OK or would I need to modify
the user-specified regex to render it safe?  Better yet, anyone know
of any modules that have done all the hard work for me?  Ideally,
instead of a Perl regex, the user could type in a search like
'"continuous string" AND otherstuff NOT badstuff'...

Many thanks to anyone who has any leads!


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

Date: 26 Sep 2001 00:30:07 -0700
From: merlyn@stonehenge.com (Randal L. Schwartz)
Subject: Re: Security of letting user specify regex in CGI script?
Message-Id: <m18zf2if40.fsf@halfdome.holdit.com>

>>>>> "Jay" == Jay McGavren <sgarfunkle@hotmail.com> writes:

Jay> I'm writing a CGI script to search an XML file and I'd like to have
Jay> AND, OR, etc. capability.  The simplest way I can think of is to let
Jay> the user specify a regex in a form field, store that in a variable,
Jay> and interpolate it into a regex:

Jay> -----Begin Perl code

No No NO!  Cargo cult CGI-decoding crap deleted.

use CGI qw(param);
$input{'regex'} = param('regex');

Jay> #Search!
Jay> if ("my random string" =~ /$input{'regex'}/i) {print "Content-type:
Jay> text/html\n\n<HTML>Matched $input{'regex'}!</HTML>";}
Jay> -----End Perl code

Jay> But although I can't think of a specific attack, that seems highly
Jay> hackable to me.  Would this approach be OK or would I need to modify
Jay> the user-specified regex to render it safe?

It's safe this way, except that a denial-of-service attack is
possible.  But they won't be able to do anything that you wouldn't
want them to do, if that's what you're worried about.

Jay>   Better yet, anyone know
Jay> of any modules that have done all the hard work for me?  Ideally,
Jay> instead of a Perl regex, the user could type in a search like
Jay> '"continuous string" AND otherstuff NOT badstuff'...

Yes... there are various modules to parse and execute searches like
that.  The CPAN is a wonderful thing... www.cpan.org

-- 
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!


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

Date: Wed, 26 Sep 2001 12:14:58 +0200
From: EXP <nospaming@gmx.net>
Subject: Re: Setting max. values (cpu/ram usage) for mod_perl scripts?
Message-Id: <3BB1AAA2.AF656E6D@gmx.net>


Ilya Martynov wrote:
> 
> >>>>> On Tue, 25 Sep 2001 14:33:19 +0200, EXP <nospaming@gmx.net> said:
> >...
>
> Use ulimit. There is no anything terribly wrong with killing apache
> child process (at least when it happens relatively seldom). Apache
> will spawn another.
> 

hm,

but I can't restrict the cpu time via ulimit, or?
However, setting a memory restriction via ulimit is certainly better
than no restriction at all.

BYe!
EXP


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

Date: 26 Sep 2001 15:06:34 +0400
From: Ilya Martynov <ilya@martynov.org>
Subject: Re: Setting max. values (cpu/ram usage) for mod_perl scripts?
Message-Id: <87wv2mi539.fsf@abra.ru>

>>>>> On Wed, 26 Sep 2001 12:14:58 +0200, EXP <nospaming@gmx.net> said:

E> hm,

E> but I can't restrict the cpu time via ulimit, or?

Various OS'es have different set of configurable limits. At least on
Linux it is possible to limit cpu time:

    bash-2.05$ ulimit -a
    core file size (blocks)     0
    data seg size (kbytes)      unlimited
    file size (blocks)          unlimited
    max locked memory (kbytes)  unlimited
    max memory size (kbytes)    unlimited
    open files                  1024
    pipe size (512 bytes)       8
    stack size (kbytes)         8192
    cpu time (seconds)          unlimited
  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    max user processes          256
    virtual memory (kbytes)     unlimited

-- 
 -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
| Ilya Martynov (http://martynov.org/)                                    |
| GnuPG 1024D/323BDEE6 D7F7 561E 4C1D 8A15 8E80  E4AE BE1A 53EB 323B DEE6 |
| AGAVA Software Company (http://www.agava.com/)                          |
 -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-


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

Date: Wed, 26 Sep 2001 13:23:09 +0200
From: EXP <nospaming@gmx.net>
Subject: Re: Setting max. values (cpu/ram usage) for mod_perl scripts?
Message-Id: <3BB1BA9D.3BDBA025@gmx.net>



Ilya Martynov wrote:
> 
> >>>>> On Wed, 26 Sep 2001 12:14:58 +0200, EXP <nospaming@gmx.net> said:
> 
> E> hm,
> 
> E> but I can't restrict the cpu time via ulimit, or?
> 
>     cpu time (seconds)          unlimited
>   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
> 

sorry, I put that wrong. IF I restrict the cpu time via ulimt all apache
childs would be killed after serving a certain amount of http requests.
But thats not what I intended. I want to kill a mod_perl script if it
exceeds a certain limit.

Anyway, I seem to have found something better than "shell" ulimit.
  man Apache::Resource

BYe!
EXP


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

Date: 26 Sep 2001 15:33:51 +0400
From: Ilya Martynov <ilya@martynov.org>
Subject: Re: Setting max. values (cpu/ram usage) for mod_perl scripts?
Message-Id: <87ofnyi3ts.fsf@abra.ru>

>>>>> On Wed, 26 Sep 2001 13:23:09 +0200, EXP <nospaming@gmx.net> said:


E> sorry, I put that wrong. IF I restrict the cpu time via ulimt all apache
E> childs would be killed after serving a certain amount of http requests.
E> But thats not what I intended. I want to kill a mod_perl script if it
E> exceeds a certain limit.

E> Anyway, I seem to have found something better than "shell" ulimit.
E>   man Apache::Resource

What is the difference? Both Apache::Resource and 'shell' ulimit use
setrlimit syscall internally.

But you are right: limiting CPU is not so easy as it looks
first time. 

-- 
 -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
| Ilya Martynov (http://martynov.org/)                                    |
| GnuPG 1024D/323BDEE6 D7F7 561E 4C1D 8A15 8E80  E4AE BE1A 53EB 323B DEE6 |
| AGAVA Software Company (http://www.agava.com/)                          |
 -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-


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

Date: 26 Sep 2001 11:02:48 GMT
From: Ilmari Karonen <iltzu@sci.invalid>
Subject: Re: The joys of segmentation faults
Message-Id: <1001501906.11196@itz.pp.sci.fi>

In article <874rpr993n.fsf@homer.cghm>, Andrew Cady wrote:
>Ilya Martynov <ilya@martynov.org> writes:
>
>> 4) You OS is configured to limit available memory for processes. In
>>    this case if Perl tries to allocate memory and can't get it Perl
>>    dies with segfault.
>
>No, this should not happen.  Segfaults are caused by trying to ACCESS
>unallocated memory.  If perl tries unsuccessfully to allocate memory,
>it should get an error from sbrk, or malloc, or whatever it uses, and
>it should handle that error gracefully.  Anything else is a bug.

 ...except that the way perl handles out-of-memory errors is only
marginally more "graceful" than segfaulting.  But still, you do have a
point -- at least the error message is different.

And do note that there are a few holes in the perl memory abstraction
layer, through which a deliberately written program can poke at random
memory locations to cause segfaults.  The "p" template for unpack() is
one of these.

-- 
Ilmari Karonen -- http://www.sci.fi/~iltzu/
"Get real!  This is a discussion group, not a helpdesk.  You post something,
we discuss its implications.  If the discussion happens to answer a question
you've asked, that's incidental."           -- nobull in comp.lang.perl.misc



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

Date: 26 Sep 2001 10:21:00 GMT
From: Ilmari Karonen <iltzu@sci.invalid>
Subject: Re: This has got to be a bug
Message-Id: <1001499268.5278@itz.pp.sci.fi>

In article <slrn9qtjmf.eug.mgjv@verbruggen.comdyn.com.au>, Martien Verbruggen wrote:
>On 24 Sep 2001 05:42:38 GMT,
>	David Combs <dkcombs@panix.com> wrote:
>> For instance, from time to time an item from the faq gets
>> "autoposted" here, to cplmisc.  People comment on it,
>> note errors in it, show better ways of saying things,
>> show better examples, etc, etc.
>> 
>> QUESTION: *when*, if ever, do those fixes get incorporated
>> *into* that comes-with-perl documentation?
>
>If the comments get submitted as a bug report, and that bug report
>gets incorporated, then it should appear in the next release.

And for the autoposted FAQs, CC-ing the suggestions to faq@denver.pm.org
also works -- as it says on each FAQ posting.  I've had several of my
suggestions incorporated that way.  Once the next release of perl is
made, they'll be in there too.

I agree that the latency between "gets approved on p5p" and "is part of
most perl installations around the world" is a bit excessive for simple
documentation changes.  Something Ought To Be Done About It(TM).

-- 
Ilmari Karonen -- http://www.sci.fi/~iltzu/
"Get real!  This is a discussion group, not a helpdesk.  You post something,
we discuss its implications.  If the discussion happens to answer a question
you've asked, that's incidental."           -- nobull in comp.lang.perl.misc



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

Date: Wed, 26 Sep 2001 12:24:44 +0100
From: "Leo Hemmings" <leapius@hotmail.com>
Subject: Use of 'our' in older perl versions
Message-Id: <9osdti$9cm$1@uranium.btinternet.com>

Hi all,

I am using 'strict' and have decalred many of my variables as 'our
$varname'. Using 'our' only seems to work with perl v5.6. No older version
5's like the use of 'our'. Is this correct? I find it hard to believe that
perl did not encorporate decalaration of global variables before version
5.6! Is there any other way apart from using 'our', one can declare a global
variable?

cheers,
Leo




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

Date: 26 Sep 2001 15:38:41 +0400
From: Ilya Martynov <ilya@martynov.org>
Subject: Re: Use of 'our' in older perl versions
Message-Id: <87k7ymi3lq.fsf@abra.ru>

>>>>> On Wed, 26 Sep 2001 12:24:44 +0100, "Leo Hemmings" <leapius@hotmail.com> said:

LH> Hi all,

LH> I am using 'strict' and have decalred many of my variables as 'our
LH> $varname'. Using 'our' only seems to work with perl v5.6. No older
LH> version 5's like the use of 'our'. Is this correct? I find it hard
LH> to believe that perl did not encorporate decalaration of global
LH> variables before version 5.6! Is there any other way apart from
LH> using 'our', one can declare a global variable?

You are right. 'our' was introduced in 5.6.0.

In most cases you can replace 'our' with 'use vars' if you need
compatiblity with old Perl's:

Instead of

    our $var;

use

    use vars qw($var);

See 'perldoc -tf our' and 'perldoc vars' for more info. There is exist
some difference between 'our' and 'use vars'.

-- 
 -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
| Ilya Martynov (http://martynov.org/)                                    |
| GnuPG 1024D/323BDEE6 D7F7 561E 4C1D 8A15 8E80  E4AE BE1A 53EB 323B DEE6 |
| AGAVA Software Company (http://www.agava.com/)                          |
 -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-


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

Date: 26 Sep 2001 11:38:21 GMT
From: rgarciasuarez@free.fr (Rafael Garcia-Suarez)
Subject: Re: Use of 'our' in older perl versions
Message-Id: <slrn9r3fif.rrf.rgarciasuarez@rafael.kazibao.net>

Leo Hemmings wrote in comp.lang.perl.misc:
} 
} I am using 'strict' and have decalred many of my variables as 'our
} $varname'. Using 'our' only seems to work with perl v5.6. No older version
} 5's like the use of 'our'. Is this correct?

Yes, as documented in the perldelta manpage.

} I find it hard to believe that
} perl did not encorporate decalaration of global variables before version
} 5.6! Is there any other way apart from using 'our', one can declare a global
} variable?

With the "use vars" directive :

    use strict;
    use vars qw/$foo $bar/;
    $foo = 1;
    $bar = 2;

See the vars manpage, and also the description of 'our' in perlfunc.

-- 
Rafael Garcia-Suarez / http://rgarciasuarez.free.fr/
Owner: There, he moved!
Customer: No, he didn't, that was you hitting the cage!
    -- Monty Python, The Pet Shop


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

Date: Wed, 26 Sep 2001 12:50:09 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: Use of 'our' in older perl versions
Message-Id: <omj3rt471tthdhfvv8mid8p3rlbtio461g@4ax.com>

Leo Hemmings wrote:

>I am using 'strict' and have decalred many of my variables as 'our
>$varname'. Using 'our' only seems to work with perl v5.6. No older version
>5's like the use of 'our'. Is this correct? I find it hard to believe that
>perl did not encorporate decalaration of global variables before version
>5.6! Is there any other way apart from using 'our', one can declare a global
>variable?

use vars qw/$varname/;

our() was added because the above was a bit, er, verbose.

-- 
	Bart.


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

Date: 26 Sep 2001 10:09:39 GMT
From: Ilmari Karonen <iltzu@sci.invalid>
Subject: Re: Using URLs as hash keys
Message-Id: <1001498930.3531@itz.pp.sci.fi>

In article <slrn9qtvuv.8ai.mgjv@martien.heliotrope.home>, Martien Verbruggen wrote:
>
>It's probably system dependent, and will most likely depend on the
>largest number of bytes malloc can return. On most systems, this is
>limited by the amount of memory your application has available.
>
>A URL is very unlikely to be long enough to break that limit.

Well, I suppose someone *could* play silly games with the "data" URI
scheme...

-- 
Ilmari Karonen -- http://www.sci.fi/~iltzu/
"Get real!  This is a discussion group, not a helpdesk.  You post something,
we discuss its implications.  If the discussion happens to answer a question
you've asked, that's incidental."           -- nobull in comp.lang.perl.misc



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

Date: 26 Sep 2001 07:56:13 GMT
From: rgarciasuarez@free.fr (Rafael Garcia-Suarez)
Subject: Re: What good is the hyphen for named parameters?
Message-Id: <slrn9r32i0.qa3.rgarciasuarez@rafael.kazibao.net>

Bart Lateur wrote in comp.lang.perl.misc:
} I don't see the point for using hyphens for "named parameters" for
} subroutines. Although it doesn't prevent bareword quoting on the left
} side of a "=>", it doesn't appear to add anything else.

You might also been interested in the fact that perl's lexer has special
support to handle specific cases as :
    -e => 'foo'
to prevent '-e' being parsed as a filetest operator.

-- 
But what about a bit of artistic license?
    -- Monty Python, The Penultimate Supper


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

Date: 26 Sep 2001 10:41:17 GMT
From: Ilmari Karonen <iltzu@sci.invalid>
Subject: Re: What good is the hyphen for named parameters?
Message-Id: <1001500459.9600@itz.pp.sci.fi>

In article <x7hetrath4.fsf@home.sysarch.com>, Uri Guttman wrote:
>>>>>> "BG" == Benjamin Goldberg <goldbb2@earthlink.net> writes:
>  BG> Bart Lateur wrote:
>  >> 
>  >> I don't see the point for using hyphens for "named parameters" for
>  >> subroutines. Although it doesn't prevent bareword quoting on the left
>  >> side of a "=>", it doesn't appear to add anything else. So what are
>  >> they good for?
>
>  BG> Well, in CGI.pm, it helps differentiate parameters for a tag from the
>  BG> contents of a tag.  I think.
>
>it is not needed for that. cgi.pm uses key/value pairs for much of its
>api and the key could be any string. you tell the difference between the
>key and value just by positions in the arg list. lincoln stein just
>decided to use -foo for visual reasons and his taste. there is no

Actually, CGI.pm uses the hyphen as a compatibility kluge -- it looks
for a hyphen at the beginning of the first argument, and based on that,
guesses whether the arguments are supposed to be named or positional.

That way, both of these work and are identical:

  $cgi->param('parameter', 'some text');  # positional shorthand

  $cgi->param( -name  => 'parameter',
               -value => 'some text', );  # named args for legibility

Of course, the scheme is far from foolproof, since valid parameter names
can indeed begin with a hyphen.

-- 
Ilmari Karonen -- http://www.sci.fi/~iltzu/
"Get real!  This is a discussion group, not a helpdesk.  You post something,
we discuss its implications.  If the discussion happens to answer a question
you've asked, that's incidental."           -- nobull in comp.lang.perl.misc



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

Date: Wed, 26 Sep 2001 11:10:44 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: What good is the hyphen for named parameters?
Message-Id: <lhd3rtooql0rkg9c9ne2f52ubnna6sp56g@4ax.com>

Ilmari Karonen wrote:

>Actually, CGI.pm uses the hyphen as a compatibility kluge -- it looks
>for a hyphen at the beginning of the first argument, and based on that,
>guesses whether the arguments are supposed to be named or positional.
>
>That way, both of these work and are identical:
>
>  $cgi->param('parameter', 'some text');  # positional shorthand
>
>  $cgi->param( -name  => 'parameter',
>               -value => 'some text', );  # named args for legibility
>
>Of course, the scheme is far from foolproof, since valid parameter names
>can indeed begin with a hyphen.

CGI.pm contains more than one kludge. It uses a similar kludge to see if
a sub is called as a method or as a function.

I really don't see why this module, of all modules, is so highly
recommended. There are many obscure ways in which you can introduce bugs
without even knowing, because the module uses such an ad hoc way to
determine what you might have ment. IMO the API should be cleaned up and
simplified, possibly even by reducing the number of ways you can call a
sub, so that there is 100% certainty on how to interpret your
parameters, in all cases. Alternatively, named parameters should be
required to be passed in a hash (reference).

But, I'm getting sidetracked.

-- 
	Bart.


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

Date: Wed, 26 Sep 2001 09:49:48 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: XL saveas doesn't work (excel)
Message-Id: <8393rtsn9af46s970fkoneje8r0lgl3slo@4ax.com>

Jeff Wright wrote:

>OK perl win32 OLE Excel gurus...
>I cannot figure out why this doesn't work: I am trying to convert an
>excel macro to perl and it just doesn't work.  It saves the .csv file,
>but it is excel format, not csv.
>Here is the basic vb:
> ActiveWorkbook.SaveAs FileName:= _
>        "C:\temp\New Microsoft Excel Worksheet.csv", _
>        FileFormat:=xlCSV, CreateBackup:=False

xlCSV is likely an integer constant, of which, in some way, you should
find out the value and use it.

   HTH,
   Bart.


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

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


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