[16051] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 3463 Volume: 9

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Jun 23 11:10:33 2000

Date: Fri, 23 Jun 2000 08:10:19 -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: <961773018-v9-i3463@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Fri, 23 Jun 2000     Volume: 9 Number: 3463

Today's topics:
    Re: REGEX Mystery <khampton@totalcinema.com>
    Re: REGEX Mystery <khampton@totalcinema.com>
    Re: REGEX Mystery (Steven Smolinski)
    Re: REGEX Mystery <khampton@totalcinema.com>
    Re: return by value <panderse@us.ibm.com>
    Re: return by value (Tad McClellan)
    Re: return by value (Tad McClellan)
    Re: return by value <abe@ztreet.demon.nl>
    Re: return by value <W.Hielscher@mssys.com>
    Re: Simple regular expression question <abe@ztreet.demon.nl>
    Re: strict and @ISA <abe@ztreet.demon.nl>
    Re: sybperl question mpeppler@mbay.net
    Re: sybperl question mpeppler@mbay.net
    Re: synonyms (Abigail)
        system date/time <braisp@earthlink.net>
    Re: system date/time <naidenm@americasm01.nt.com>
    Re: Urgent: Perl Access to MySql wihout DBI.pm possible <sariq@texas.net>
    Re: Urgent: Perl Access to MySql wihout DBI.pm possible (Michael Budash)
    Re: use of eval and strict does not correctly set  $@ (Sean McAfee)
    Re: Why I can't use -d:DProf? <pl@cs.virginia.edu>
        Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)

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

Date: Fri, 23 Jun 2000 07:06:26 -0400
From: Kip Hampton <khampton@totalcinema.com>
Subject: Re: REGEX Mystery
Message-Id: <395344B2.21DE6608@totalcinema.com>



Cameron Kennedy wrote:

> try this if you want //g
> 
> foreach my $elem ('hi', 'ih') {
>   print "found an i in $elem\n" if $elem =~ /i/g; pos $elem=0;
>   print "found an h in $elem\n" if $elem =~ /h/g;
> }
> 

That nailed it. 
Thanks, Cameron.

-kip


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

Date: Fri, 23 Jun 2000 07:06:52 -0400
From: Kip Hampton <khampton@totalcinema.com>
Subject: Re: REGEX Mystery
Message-Id: <395344CC.2A48A802@totalcinema.com>



nobull@mail.com wrote:

> Yes I think they could.  As indeed could anyone who had carefully read
> the perlre and perlop manpages.
> The behavior is correct.  Check the docs for the meaning of m//g in a
> scalar context.  (Start this search where the previous one left off).

From the fine manual:
-------------------------
Options are:

         c   Do not reset search position on a failed match when /g is
in effect.
         g   Match globally, i.e., find all occurrences.

<snip for bandwith>

A failed match normally resets the search position to the beginning of
the string, but you can avoid that by adding the /c modifier (e.g.
m//gc). Modifying the target string also resets the search position.
-------------------------

The fact that the engine would save position even though the string
being tested has changed is neither intuitive nor explicitly clear in
the above description. 

Thanks for you help, though.

-kip


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

Date: Fri, 23 Jun 2000 11:33:43 GMT
From: sjs@yorku.ca (Steven Smolinski)
Subject: Re: REGEX Mystery
Message-Id: <slrn8l6inn.4an.sjs@john.sympatico.ca>

Kip Hampton <khampton@totalcinema.com> wrote:
>nobull@mail.com wrote:

>> Yes I think they could.  As indeed could anyone who had carefully read
>> the perlre and perlop manpages.
>> The behavior is correct.  Check the docs for the meaning of m//g in a
>> scalar context.  (Start this search where the previous one left off).

[...snip selective cut from manual...]

>The fact that the engine would save position even though the string
>being tested has changed is neither intuitive nor explicitly clear in
>the above description. 

If you only read those selections, that's true.  But there's a page of
examples, a specific (though not trivial) discussion of the m//g
construct in scalar context that you skipped.  It includes the line:

               Each regexp tries to match where the previous one
               leaves off. 

I agree, it could be more explicitly and simply stated near the beginning
of the m//g description, but it's there for anyone who carefully reads the
man page.  Otherwise, what are all those examples for?

Steve


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

Date: Fri, 23 Jun 2000 08:32:09 -0400
From: Kip Hampton <khampton@totalcinema.com>
Subject: Re: REGEX Mystery
Message-Id: <395358C9.374CCAC8@totalcinema.com>



Steven Smolinski wrote:

> I agree, it could be more explicitly and simply stated near the beginning
> of the m//g description, but it's there for anyone who carefully reads the
> man page.  Otherwise, what are all those examples for?

Point conceded. It's just that the "save position even though the string
has changed" behavior seems really backwards to me.

Live and learn.

-kip


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

Date: Fri, 23 Jun 2000 07:48:01 -0500
From: "Paul R. Andersen" <panderse@us.ibm.com>
Subject: Re: return by value
Message-Id: <39535C80.61F9921E@us.ibm.com>

"Amri, Kuross [WOLL:4009-I:EXCH]" wrote:
> 
> Hello,
> 
> I have a hash say -> %hash
> 
>  I have passed it by value to a subroutine but now when I try to pass it
> back, I can't get the values from it.
> 
> How do you pass a value already passed by value it it like
> 
> return %$hash; ?
> 
> or return $hash; ?
> 
> or return \%hash;  ?
> 
> I'd like to return it by value as well.

The following worked for me.  If I understood your question, this is
what you want.

#!/usr/contrib/bin/perl -w
%hash = ();
$hash{key1} = 'val1';
$hash{key2} = 'val2';
$hash{key3} = 'val3';
$hash{key4} = 'val4';

foreach (keys %hash)
{ print "hash{$_} => $hash{$_}\n"; }
print "\n";

%nhash = tsub(%thash);

foreach (keys %nhash)
{ print "nhash{$_} => $nhash{$_}\n"; }

sub tsub
{
  %h2 = @_;
  $h2{kx1} = vx1;
  $h2{kx2} = vx2;
  $h2{kx3} = vx3;
  return %h2;
}

Hope this will shed some light for you.

-- 
Paul Andersen
+++++++++++++
The difference between theory and practice is that in theory there is no
difference between theory and practice; but in practice there is.


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

Date: Fri, 23 Jun 2000 07:22:02 -0500
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: return by value
Message-Id: <slrn8l6lja.t0.tadmc@maxim.metronet.com>

On Fri, 23 Jun 2000 15:21:05 +1000, Amri, Kuross [WOLL:4009-I:EXCH] 
   <kamri@asiapacificm01.nt.com> wrote:

>I have a hash say -> %hash
>
> I have passed it by value to a subroutine but now when I try to pass it
>back, I can't get the values from it.


You should show us the code if you want us to fix the code!


>How do you pass a value already passed by value it it like
>
>return %$hash; ?


You did not say anything about using references, so dereferencing
isn't applicable.


>or return $hash; ?


You did not say anything about a scalar named $hash either.

That is a completely separate variable. It has nothing to
do with %hash.


>or return \%hash;  ?

You did not say anything about using references, so taking a
reference isn't applicable either.


>I'd like to return it by value as well.

return %hash;


-- 
    Tad McClellan                          SGML Consulting
    tadmc@metronet.com                     Perl programming
    Fort Worth, Texas


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

Date: Fri, 23 Jun 2000 07:24:32 -0500
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: return by value
Message-Id: <slrn8l6lo0.t0.tadmc@maxim.metronet.com>

On Fri, 23 Jun 2000 06:59:38 GMT, Benji Lilley <lilleyb001@hawaii.rr.com> wrote:

>Assuming that you passed the hash by value like this:
>    &subroutine(%hash);
>

>sub return_by_value{
>    my %subroutine_hash = shift;
>    $subroutine_hash{name} = 'bar';
                      ^^^^


But that requires that you know all of the hash keys.

You can replace the two lines above with just:

   my(%subroutine_hash) = @_;


-- 
    Tad McClellan                          SGML Consulting
    tadmc@metronet.com                     Perl programming
    Fort Worth, Texas


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

Date: Fri, 23 Jun 2000 17:00:03 +0200
From: Abe Timmerman <abe@ztreet.demon.nl>
Subject: Re: return by value
Message-Id: <08u6ls43k5aq7bmfacnpn2jsffsjfle781@4ax.com>

On Fri, 23 Jun 2000 06:59:38 GMT, "Benji Lilley"
<lilleyb001@hawaii.rr.com> wrote:

 ...
> 
> a simple working example:

Nope, _not_ working! Please test your code before posting, especially if
you say it's _working_.

> #--------
Just to let perl help you find mistakes start your programs with:

	#!/usr/bin/perl -w
	use strict;

> %hash = ('name' => 'foo');

	my %hash = ( name => 'foo');

> sub return_by_value{
>     my %subroutine_hash = shift;

That gives an error:

	"Odd number of elements in hash assignment at..."

Passing the hash by value 'flattens' the hash to a list.

	my %subroutine_hash = @_;

 ...
> would produce:
> 
> foo
> bar

If you'd got it right :-)

-- 
Good luck,
Abe


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

Date: Fri, 23 Jun 2000 17:03:33 +0200
From: Wolfgang Hielscher <W.Hielscher@mssys.com>
Subject: Re: return by value
Message-Id: <39537C45.57214072@mssys.com>

Hi,

I'd like to share some "wisdom" I got from the camel book:

   All function parameters are passed as one single, flat list of
scalars, and all return values are likewise returned to the caller as
one single, flat list of scalars.


IMHO there's no good reason for passing complete lists. Why not simply
passing references. And if you need the "called by value"-behavior, just
make a copy of the hash being referenced at the beginning of the sub.

And what happens if you pass more than one hash "by value" to a sub? You
won't be able to seperate them there anyhow!

Cheers
	Wolfgang


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

Date: Fri, 23 Jun 2000 16:44:23 +0200
From: Abe Timmerman <abe@ztreet.demon.nl>
Subject: Re: Simple regular expression question
Message-Id: <1mt6ls4stab8a719bh42ira8k1k520b8qm@4ax.com>

On Fri, 23 Jun 2000 01:46:26 GMT, "Kenny Lim" <kennylim@techie.com>
wrote:

> 
> Hi All,
Hi,
> 
> I have a simple question here :
> 
> I have the following id's that are stored in result.txt files.
> 
> {B2165B0A-9D18-11d3-BA27-006008AF680E}|{BBBDDE80-488B-11D4-85D7-00105AE3A355
> }
> {B2165B09-9D18-11d3-BA27-006008AF680E}|{BB9623A0-488B-11D4-85D7-00105AE3A355
> }
> {308C177E-9BAA-11d3-9465-005004D9BC31}|{BB9C4060-488B-11D4-85D7-00105AE3A355
> }
> {B2B98458-9D15-11d3-9466-005004D9BC31}|{BBAD0F70-488B-11D4-85D7-00105AE3A355
> }
> {B2165B0A-9D18-11d3-BA27-006008AF680E}|{BBBDDE80-488B-11D4-85D7-00105AE3A355
> }
> 
> My objective here is to be able to separate and parsed both the contents in
> {a..} | {b..} to the following :
> 
> ie.
> 
> {B2165B0A-9D18-11d3-BA27-006008AF680E}|{BBBDDE80-488B-11D4-85D7-00105AE3A355
> }
> 
> $search = {B2165B0A-9D18-11d3-BA27-006008AF680E}
> $replace = {BBBDDE80-488B-11D4-85D7-00105AE3A355}
> 
	my($search, $replace) = split /\|/;

-- 
Good luck,
Abe


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

Date: Fri, 23 Jun 2000 14:06:51 +0200
From: Abe Timmerman <abe@ztreet.demon.nl>
Subject: Re: strict and @ISA
Message-Id: <a9j6ls0s9l9cdgt741i5d5s0e7krdu0voc@4ax.com>

On 22 Jun 2000 18:30:48 -0700, Andrew Perrin - Demography
<aperrin@famine.DEMOG.Berkeley.EDU> wrote:

> 
> I appreciate all the responses, which are generally in the class of
> "the same way you'd get rid of the error message for any other global
> variable," e.g., use base, our(), or use vars.  
> 
> However, the reason I *wrote* the message was basically along the
> lines of Bart Lateur's answer: @ISA behaves much like other built-in
> variables in perl, such as $_, $0, etc., etc., in that its value
> determines built-in behavior of the language.

You may have noticed that @ISA isn't mentioned in 'perlvar', so from
that point of view I'd say it is not a 'built-in' variable.

I suspect @ISA is implemented within 'UNIVERSAL', just like @EXPORT and
friends are implemented within 'Exporter'.
This is vaguely mentioned in 'perltoot'.

-- 
Good luck,
Abe


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

Date: Fri, 23 Jun 2000 14:25:19 GMT
From: mpeppler@mbay.net
Subject: Re: sybperl question
Message-Id: <8ivrvs$1pl$1@nnrp1.deja.com>

In article
<Pine.GSO.4.10.10006221330580.4312-100000@user2.teleport.com>,
  Tom Phoenix <rootbeer@redcat.com> wrote:
> On 22 Jun 2000, Jim Anderson wrote:
>
> > sybperl appears to be missing the functionality of DBlib's
> > dbsetmaxprocs. I hope the functionality is really available but
> > hidden.
>
> Unless I'm misinformed, no one should be using sybperl any longer.
It's
> really just an offshoot of ancient Perl 4, isn't it?

No - unlike oraperl, sybperl (which is just a name for
Sybase::DBlib, Sybase::CTlib, Sybase::BCP and Sybase::Sybperl)
was re-written from scratch for perl5, starting with the 5a12
release, IIRC.

DBI/DBD::Sybase may be more portable, but the Sybase::* modules
offer the experienced Sybase programmer a familiar interface close
to the C level APIs.

Michael


Sent via Deja.com http://www.deja.com/
Before you buy.


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

Date: Fri, 23 Jun 2000 14:27:02 GMT
From: mpeppler@mbay.net
Subject: Re: sybperl question
Message-Id: <8ivs33$1rr$1@nnrp1.deja.com>

In article <wkbhfalwnzg.fsf@ml.com>,
  Jim Anderson  <jander@ml.com> wrote:
> sybperl appears to be missing the functionality of DBlib's
> dbsetmaxprocs. I hope the functionality is really available but
> hidden.

No, dbsetmaxprocs() is not implemented.

If you *really* need more than 25 DBPROCESSes for a single process
you'll have to patch the source...

Michael


Sent via Deja.com http://www.deja.com/
Before you buy.


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

Date: 23 Jun 2000 08:41:36 EDT
From: abigail@delanet.com (Abigail)
Subject: Re: synonyms
Message-Id: <slrn8l6nq1.iu4.abigail@alexandra.delanet.com>

Koen Aerts (aertsko@se.bel.alcatel.be) wrote on MMCDLXXXVII September
MCMXCIII in <URL:news:39523B36.7A3B3FAE@se.bel.alcatel.be>:
// Does perl support the use of synonyms (like the #define in C), and if
// so, how?
// 


C doesn't support # define.

It's the C _preprocessor_ that uses # define, and what it does is
textual substitution. 

If you really want, you can use the C preprocessor, by using the -P 
switch. (see man perlrun).

However, depending on what you want, you might want to look into
"use constant" and aliasing (ala Exporter).



Abigail
-- 
perl -Mstrict -we '$_ = "goto L.print chop;\n=rekcaH lreP rehtona tsuJ";L1:eval'


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

Date: Fri, 23 Jun 2000 14:35:20 GMT
From: "PaulB" <braisp@earthlink.net>
Subject: system date/time
Message-Id: <IAK45.23672$ds.689079@newsread2.prod.itd.earthlink.net>

How can I get the system date and time using perl.
I am using the Win32 version of perl,
I thought I could use system or exec but on windowsNT it doesn't work.






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

Date: Fri, 23 Jun 2000 10:43:18 -0400
From: "Markachev, Naiden [SKY:4Y21:EXCH]" <naidenm@americasm01.nt.com>
Subject: Re: system date/time
Message-Id: <39537786.50838502@americasm01.nt.com>

PaulB wrote:
> 
> How can I get the system date and time using perl.
> I am using the Win32 version of perl,
> I thought I could use system or exec but on windowsNT it doesn't work.


try localtime()

-- 
"Witty quotes mean nothing" -- Voltaire


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

Date: Fri, 23 Jun 2000 09:14:22 -0500
From: Tom Briles <sariq@texas.net>
Subject: Re: Urgent: Perl Access to MySql wihout DBI.pm possible ???
Message-Id: <395370BE.678D3478@texas.net>

WWW_DESIGN_HOSTING wrote:
> 
> Hi
> 
> can anybody tell me how i can access from a Perl-Script to a Mysql Database
> ( MySql is on a Linux Server ).
> 
> I have to make the exam and the system administrator told me, that the
> DBI.pm Perl Module
> is not installed on the Server. He also told me, that they will never
> install DBI.pm on the server !

Then install it yourself.

perldoc -q 'own module'

- Tom


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

Date: Fri, 23 Jun 2000 07:24:34 -0700
From: mbudash@sonic.net (Michael Budash)
Subject: Re: Urgent: Perl Access to MySql wihout DBI.pm possible ???
Message-Id: <mbudash-2306000724340001@adsl-216-103-91-123.dsl.snfc21.pacbell.net>

In article <961747156.4128.0.nnrp-09.c3ad6973@news.demon.co.uk>, "W Kemp"
<bill.kemp@wire2.com> wrote:

> >But how can i have access to MySql from a Perl-Script without the DBI
> Module
> >?????
> 
> 
> (1) by writing a huge and complex piece of code that will take years and
> years to do
> (2) Change the name of the module, and tell the system administrator that it
> isn't DBI

or go to cpan and get the [now deprecated] Mysql.pm module...

sorry, but i missed the first part of this thread - does your sysadmin not
want DBI installed for some reason?
-- 
Michael Budash ~~~~~~~~~~ mbudash@sonic.net


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

Date: Fri, 23 Jun 2000 14:41:43 GMT
From: mcafee@waits.facilities.med.umich.edu (Sean McAfee)
Subject: Re: use of eval and strict does not correctly set  $@
Message-Id: <HGK45.436$GA3.7661@news.itd.umich.edu>

In article <10417584.c85045d9@usw-ex0103-018.remarq.com>,
dfdf  <adamsch1NOadSPAM@yahoo.com.invalid> wrote:
>I'm trying to eval a piece of code that is loaded up from a file.
>I want to trap any compile time or runtime errors using $@.  The
>thing is if the script that I load 'uses' strict, and there is a
>strict related error, that error message is printed to STDOUT,
>but not set in $@.

As previously mentioned, this is a bug.  I got around it in the code I'm
currently developing like this:

sub somesub {
    local $SIG{__WARN__} = \&promote_strictness_warnings;
    eval 'strictness_violating_code';
    # ...
}

# ...

sub promote_strictness_warnings {
    local $_ = shift;
    /^Global symbol ".*" requires explicit package name/
        ||
    /^Variable ".*" is imported/
        ||
    /^Bareword ".*" not allowed while "strict subs" in use/
        ||
    /^Can't use string (".*") as .* ref while "strict refs" in use/
        ||
    /^Can't use bareword (".*") as .* ref while "strict refs" in use/
        and
    die $_;
}

Not very pretty, but I couldn't find any better way.

-- 
Sean McAfee                                                mcafee@umich.edu
print eval eval eval eval eval eval eval eval eval eval eval eval eval eval
q!q@q#q$q%q^q&q*q-q=q+q|q~q:q? Just Another Perl Hacker ?:~|+=-*&^%$#@!


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

Date: Fri, 23 Jun 2000 06:31:01 -0400
From: k <pl@cs.virginia.edu>
Subject: Re: Why I can't use -d:DProf?
Message-Id: <39533C65.2ECCD407@cs.virginia.edu>


The error log is:

[Fri Jun 23 06:08:13 2000] [error] (8)Exec format error: exec of
/path/myperl.pl failed
[Fri Jun 23 06:08:13 2000] [error] [client xxx.xx.xx.xxx] Premature end
of script headers: /path/myperl.pl


k wrote:
> 
> Hi,
> 
> I want to profile the perl scripts on my web site. I can use DProf
> through command line like this: perl5 -d:DProf myperl.pl
> 
> However, how can I use -d:DProf when myperl.pl is browsed througth
> browsers?
> 
> I change the first line of myperl.pl from
> #!/usr/bin/perl5
> to
> #!/usr/bin/perl5 -d:DProf
> 
> but when I browse myperl.pl, I got error message like this:
> 
> =================================
> Internal Server Error
> 
> The server encountered an internal error or misconfiguration and was
> unable to complete your request.
> 
> Please contact the server administrator, root@badlands.cs.virginia.edu
> and inform them of the time the error occurred, and anything you might
> have done that may have caused the error.
> 
> More information about this error may be available in the server error
> log.
> 
> =================================
> 
> Then I tried another way:
> 
> I renamed /usr/bin/perl5 as /usr/bin/myperl5, and write a shell script
> named perl5. There is only one line in script perl5 --
> /usr/bin/myperl5 -d:DProf
> 
> However, I got the same error message.
> 
> So, DProf only can be used through command line???
> 
> Thanks for helping!
> 
> --- Rick


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

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


Administrivia:

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

	subscribe perl-users
or:
	unsubscribe perl-users

to almanac@ruby.oce.orst.edu.  

| NOTE: The mail to news gateway, and thus the ability to submit articles
| through this service to the newsgroup, has been removed. I do not have
| time to individually vet each article to make sure that someone isn't
| abusing the service, and I no longer have any desire to waste my time
| dealing with the campus admins when some fool complains to them about an
| article that has come through the gateway instead of complaining
| to the source.

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

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

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


------------------------------
End of Perl-Users Digest V9 Issue 3463
**************************************


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