[23799] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 6002 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Jan 29 19:06:02 2004

Date: Thu, 29 Jan 2004 16:05:32 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Thu, 29 Jan 2004     Volume: 10 Number: 6002

Today's topics:
        Cursing my objects? (Eduardo)
    Re: Cursing my objects? <usenet@morrow.me.uk>
    Re: Cursing my objects? (Eduardo)
    Re: Cursing my objects? (Anno Siegel)
        defined(&func) and Exporter <dog@dog.dog>
    Re: defined(&func) and Exporter (Rafael Garcia-Suarez)
        Detecting last match from within loop <neil.shadrach@corryn.com>
    Re: Detecting last match from within loop <nospam@bigpond.com>
    Re: Detecting last match from within loop <usenet@morrow.me.uk>
    Re: Detecting last match from within loop <neil.shadrach@corryn.com>
        Distinguishing string and numerical context? <not_a_real@adress.getting.too.much.spam.org>
    Re: Distinguishing string and numerical context? <usenet@morrow.me.uk>
    Re: Distinguishing string and numerical context? (Walter Roberson)
    Re: Distinguishing string and numerical context? (Anno Siegel)
    Re: Distinguishing string and numerical context? <not_a_real@adress.getting.too.much.spam.org>
    Re: Distinguishing string and numerical context? <not_a_real@adress.getting.too.much.spam.org>
    Re: Distinguishing string and numerical context? <nobull@mail.com>
    Re: Distinguishing string and numerical context? <usenet@morrow.me.uk>
    Re: Distinguishing string and numerical context? (Anno Siegel)
        Does unpack('P', ...) create a copy? <spamtrap@dot-app.org>
    Re: Does unpack('P', ...) create a copy? <tassilo.parseval@rwth-aachen.de>
    Re: Does unpack('P', ...) create a copy? <spamtrap@dot-app.org>
        Drawing reference lines with GD::Graph (Phil)
    Re: Drawing reference lines with GD::Graph <smackdab1@hotmail.com>
    Re: Drawing reference lines with GD::Graph <mgjv@tradingpost.com.au>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: 26 Jan 2004 15:30:06 -0800
From: oso@uncoma.edu.ar (Eduardo)
Subject: Cursing my objects?
Message-Id: <3d281369.0401261530.2d690d33@posting.google.com>

Hello, I want to have a subclass of Class::DBI which can manage its
own HTML editing form.
I would create an instance from this class and have it yield its form
with default values. This is probably a mess among data
storage/presentation, which is the proper way to go about it?
The examples in FormBuilder's docs always show the values coming from
queries, or from other objects (typically an $sth result), but I want
something like:

	my $t = MyApp::MyTable->retrieve(something); # a Class::DBI
descendant
	my $form = $t->form;
	print $form->render(values => $t);

However, the values() method as applied by render() seems to require
'a hashref or an object'. I am evidently getting something wrong on
the object side, as I need to access the blessed data inside $t
instead of $t proper. This seems rather quirky. Should I be getting
the values hashref from $t before the call to render? How? I've seen
an ACME::Damn module, is this pure nonsense? What's the recommended
approach?
Thanks in advance!

--Very confused


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

Date: Mon, 26 Jan 2004 23:51:53 +0000 (UTC)
From: Ben Morrow <usenet@morrow.me.uk>
Subject: Re: Cursing my objects?
Message-Id: <bv496p$r5b$1@wisteria.csv.warwick.ac.uk>


oso@uncoma.edu.ar (Eduardo) wrote:
> Hello, I want to have a subclass of Class::DBI which can manage its
> own HTML editing form.
> I would create an instance from this class and have it yield its form
> with default values. This is probably a mess among data
> storage/presentation, which is the proper way to go about it?
> The examples in FormBuilder's docs always show the values coming from
> queries, or from other objects (typically an $sth result), but I want
> something like:
> 
> 	my $t = MyApp::MyTable->retrieve(something); # a Class::DBI
> descendant
> 	my $form = $t->form;
> 	print $form->render(values => $t);
> 
> However, the values() method as applied by render() seems to require
> 'a hashref or an object'. I am evidently getting something wrong on
> the object side, as I need to access the blessed data inside $t
> instead of $t proper. This seems rather quirky. Should I be getting
> the values hashref from $t before the call to render? How? I've seen
> an ACME::Damn module, is this pure nonsense? What's the recommended
> approach?

The OO-recommended approach is to give $t a method, say as_hashref,
that returns an unblessed copy of the data like this:

sub as_hashref {
    my $s = shift;
    return { %$s };
}

and then use

print $form->render(values => $t->as_hashref);

Then you can redo as_hashref if your implementation changes. If you
aren't bothered about breaking OO encapsulation (essentially, if you
don't mind making the fact that $t is a ref to a blessed hash part of
the published interface) then you can simply use

print $form->render(values => { %$t });

 .

Ben

-- 
Musica Dei donum optimi, trahit homines, trahit deos.    |
Musica truces mollit animos, tristesque mentes erigit.   |   ben@morrow.me.uk
Musica vel ipsas arbores et horridas movet feras.        |


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

Date: 27 Jan 2004 04:59:09 -0800
From: oso@uncoma.edu.ar (Eduardo)
Subject: Re: Cursing my objects?
Message-Id: <3d281369.0401270459.4133579b@posting.google.com>

> The OO-recommended approach is to give $t a method, say as_hashref,
> that returns an unblessed copy of the data like this:
> 
> sub as_hashref {
>     my $s = shift;
>     return { %$s };
> }
G   R   E   A   T  !   !   !   !   !   !
For the life of me, I couldn't get that syntax. I had tried
$form->render(%$t), but omitted the curly brackets. By the way, I
still don't catch why I need them.
I owe you 5 terathanks anyway!


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

Date: 29 Jan 2004 13:45:24 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Cursing my objects?
Message-Id: <bvb2pk$5r7$1@mamenchi.zrz.TU-Berlin.DE>

Ben Morrow  <usenet@morrow.me.uk> wrote in comp.lang.perl.misc:
> oso@uncoma.edu.ar (Eduardo) wrote:

[how to access a blessed hashref as a hash]

> The OO-recommended approach is to give $t a method, say as_hashref,
> that returns an unblessed copy of the data like this:
> 
> sub as_hashref {
>     my $s = shift;
>     return { %$s };
> }
> 
> and then use
> 
> print $form->render(values => $t->as_hashref);
> 
> Then you can redo as_hashref if your implementation changes. If you
> aren't bothered about breaking OO encapsulation (essentially, if you
> don't mind making the fact that $t is a ref to a blessed hash part of
> the published interface) then you can simply use
> 
> print $form->render(values => { %$t });

This doesn't break encapsulation as badly as it seems to.  If the
implementation changes and object isn't a hashref anymore, you can
always overload "%{}" to restore the behavior of "%$t".  It gets
cumbersome when the object remains a hashref, but the contents change
so that "%$t" isn't usable in the old way any longer, but that can be
worked around too.

Anno


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

Date: Tue, 30 Dec 2003 15:11:40 +0100
From: "Peter Michael" <dog@dog.dog>
Subject: defined(&func) and Exporter
Message-Id: <bsrvjp$lsd2@news-1.bank.dresdner.net>

Hi,

can anyone please explain to me why subroutines resulting 
from constants imported with Exporter are not considered 
to be defined?

    perl -MFcntl -le 'print &F_SETLK'

shows that a subroutine F_SETLK can be called. But

    perl -MFcntl -le 'print "defined" if defined &F_SETLK'

shows that it is not considered to be defined.

The consequence is that a constant imported this way can
accidentely be overridden by a 'require "fcntl.ph"'. The 
 .ph contains (on Linux)

     eval 'sub F_SETLK () {6;}' unless defined(&F_SETLK);

but &F_SETLK is not considered to be defined after the use()age
of Fcntl and is thus overridden.

Thanks for any explanations.

    Peter



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

Date: 30 Dec 2003 14:51:14 GMT
From: rgarciasuarez@free.fr (Rafael Garcia-Suarez)
Subject: Re: defined(&func) and Exporter
Message-Id: <slrnbv33u4.c06.rgarciasuarez@rafael.serd.lyon.hexaflux.loc>

Peter Michael wrote:
>Hi,
>
>can anyone please explain to me why subroutines resulting 
>from constants imported with Exporter are not considered 
>to be defined?
>
>    perl -MFcntl -le 'print &F_SETLK'
>
>shows that a subroutine F_SETLK can be called. But
>
>    perl -MFcntl -le 'print "defined" if defined &F_SETLK'
>
>shows that it is not considered to be defined.

Because you haven't called it : Fcntl constants are autoloaded.
However, it exists.

-- 
Unilluminating is not *NIX


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

Date: Fri, 23 Jan 2004 11:30:55 +0000 (UTC)
From: Neil Shadrach <neil.shadrach@corryn.com>
Subject: Detecting last match from within loop
Message-Id: <bur0lf$924$1@visp.bt.co.uk>

$ perl -wle 'foreach (q(/level1/level2/level3)=~m|/([^/]*)|g) { print }'
level1
level2
level3

What is the simplest way of determining from within the above loop whether it is the last iteration?
I could use an intermediate array ( below ) and compare a loop counter with $#a but I'm sure
some kind soul can point me at a neater way that is so obvious that I can't think of it :)

$ perl -wle '@a=q(/level1/level2/level3)=~m|/([^/]*)|g;foreach (@a) { print }'
level1
level2
level3
$



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

Date: Fri, 23 Jan 2004 21:48:36 +1000
From: Gregory Toomey <nospam@bigpond.com>
Subject: Re: Detecting last match from within loop
Message-Id: <bur1o2$ld6lb$1@ID-202028.news.uni-berlin.de>

Neil Shadrach wrote:

> $ perl -wle 'foreach (q(/level1/level2/level3)=~m|/([^/]*)|g) { print }'
> level1
> level2
> level3
> 
> What is the simplest way of determining from within the above loop whether
> it is the last iteration? I could use an intermediate array ( below ) and
> compare a loop counter with $#a but I'm sure some kind soul can point me
> at a neater way that is so obvious that I can't think of it :)
> 
> $ perl -wle '@a=q(/level1/level2/level3)=~m|/([^/]*)|g;foreach (@a) {
> print }' level1
> level2
> level3
> $

See this thread
http://tinyurl.com/3hmom

gtoomey


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

Date: Fri, 23 Jan 2004 13:45:07 +0000 (UTC)
From: Ben Morrow <usenet@morrow.me.uk>
Subject: Re: Detecting last match from within loop
Message-Id: <bur8h3$l0o$2@wisteria.csv.warwick.ac.uk>


Neil Shadrach <neil.shadrach@corryn.com> wrote:
> $ perl -wle 'foreach (q(/level1/level2/level3)=~m|/([^/]*)|g) { print }'
> level1
> level2
> level3
> 
> What is the simplest way of determining from within the above loop whether it is the last iteration?
> I could use an intermediate array ( below ) and compare a loop counter with $#a but I'm sure
> some kind soul can point me at a neater way that is so obvious that I can't think of it :)
> 
> $ perl -wle '@a=q(/level1/level2/level3)=~m|/([^/]*)|g;foreach (@a) { print }'
> level1
> level2
> level3
> $

If this is (as it appears to be) to split pathnames, then you have an
xy problem. Use File::Spec.

Ben


-- 
'Deserve [death]? I daresay he did. Many live that deserve death. And some die
that deserve life. Can you give it to them? Then do not be too eager to deal
out death in judgement. For even the very wise cannot see all ends.'
 :-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-: ben@morrow.me.uk


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

Date: Fri, 23 Jan 2004 15:05:31 +0000 (UTC)
From: Neil Shadrach <neil.shadrach@corryn.com>
Subject: Re: Detecting last match from within loop
Message-Id: <burd7q$924$2@visp.bt.co.uk>

Ben Morrow:

> If this is (as it appears to be) to split pathnames, then you have an
> xy problem. Use File::Spec.

The example was simplified to concentrate on the question.
What is actually being split is a string containing a series of regular expressions specifying a set of files of interest.
File::Spec doesn't appear to be useful for this.
Splitting into an array is fine as would be counting the separators - I just got thinking about it so I thought I'd ask.
Thanks



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

Date: Thu, 22 Jan 2004 01:19:47 -0800
From: "Damian" <not_a_real@adress.getting.too.much.spam.org>
Subject: Distinguishing string and numerical context?
Message-Id: <buo4gf$kfaou$1@ID-196529.news.uni-berlin.de>

Is there anyway to tell, for a function thats being called in a scalar
context, weather it's expected to return a string or a number? sorta
like localtime, which returns a number and returns a string if you put
"". before it like:

[damian@me ~]# perl -e 'print localtime(), "\n";'
321512201044210
[damian@me ~]# perl -e 'print "". localtime(), "\n";'
Thu Jan 22 01:15:39 2004

It some how *knows* if it's being used with a string (concatenated) or
not, orta like an array seems to know too.

Thanks for any help.





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

Date: Thu, 22 Jan 2004 09:31:20 +0000 (UTC)
From: Ben Morrow <usenet@morrow.me.uk>
Subject: Re: Distinguishing string and numerical context?
Message-Id: <buo598$deg$1@wisteria.csv.warwick.ac.uk>


"Damian" <not_a_real@adress.getting.too.much.spam.org> wrote:
> Is there anyway to tell, for a function thats being called in a scalar
> context, weather it's expected to return a string or a number? sorta
> like localtime, which returns a number and returns a string if you put
> "". before it like:
> 
> [damian@me ~]# perl -e 'print localtime(), "\n";'
> 321512201044210
> [damian@me ~]# perl -e 'print "". localtime(), "\n";'
> Thu Jan 22 01:15:39 2004

You can create such values with Scalar::Util::dualvar. Those default
to string, though, like $!; if you need them to default to number
you'll have to write a pretty simple bit of XS.

Ben

-- 
And if you wanna make sense / Whatcha looking at me for?          (Fiona Apple)
                            * ben@morrow.me.uk *


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

Date: 22 Jan 2004 09:59:43 GMT
From: roberson@ibd.nrc-cnrc.gc.ca (Walter Roberson)
Subject: Re: Distinguishing string and numerical context?
Message-Id: <buo6uf$eu2$1@canopus.cc.umanitoba.ca>

In article <buo4gf$kfaou$1@ID-196529.news.uni-berlin.de>,
Damian <not_a_real@adress.getting.too.much.spam.org> wrote:
:Is there anyway to tell, for a function thats being called in a scalar
:context, weather it's expected to return a string or a number? sorta
:like localtime, which returns a number and returns a string if you put
:"". before it like:

:[damian@me ~]# perl -e 'print localtime(), "\n";'
:321512201044210
:[damian@me ~]# perl -e 'print "". localtime(), "\n";'
:Thu Jan 22 01:15:39 2004

:It some how *knows* if it's being used with a string (concatenated) or
:not, orta like an array seems to know too.

You have misinterpreted. localtime() does not return a number in
that first example. When you invoke localtime() like that within
print, print is supplying a list context, and localtime() is returning
a list value which print is kindly jamming together due to the default
element separator being the empty string.

$ perl -e '$,="|";print localtime,"\n"'                    
43|57|3|22|0|104|4|21|0|

In your second example, the "". supplies a scalar context, and
localtime() reacts accordingly.

$ perl -e 'print scalar(localtime),"\n"'                   
Thu Jan 22 03:59:13 2004

-- 
   "No one has the right to destroy another person's belief by
   demanding empirical evidence."            -- Ann Landers


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

Date: 22 Jan 2004 10:16:40 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Distinguishing string and numerical context?
Message-Id: <buo7u8$6t8$1@mamenchi.zrz.TU-Berlin.DE>

Ben Morrow  <usenet@morrow.me.uk> wrote in comp.lang.perl.misc:
> 
> "Damian" <not_a_real@adress.getting.too.much.spam.org> wrote:
> > Is there anyway to tell, for a function thats being called in a scalar
> > context, weather it's expected to return a string or a number? sorta
> > like localtime, which returns a number and returns a string if you put
> > "". before it like:
> > 
> > [damian@me ~]# perl -e 'print localtime(), "\n";'
> > 321512201044210
> > [damian@me ~]# perl -e 'print "". localtime(), "\n";'
> > Thu Jan 22 01:15:39 2004
> 
> You can create such values with Scalar::Util::dualvar. Those default
> to string, though, like $!; if you need them to default to number
> you'll have to write a pretty simple bit of XS.

True, and probably what the OP wanted to know, but this isn't what
happens with localtime.

The OP has misinterpreted the results.   The difference isn't numeric
vs. string context, it's array vs. scalar context.  The first example
calls localtime() in array context, so it returns a list of numbers
(sec, min, ...).  Printing runs them all together, so the result looks
like one big number.  The second example calls it in scalar context
(the "." operator), so localtime returns its result as a string.

Anno


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

Date: Thu, 22 Jan 2004 03:03:02 -0800
From: "Damian" <not_a_real@adress.getting.too.much.spam.org>
Subject: Re: Distinguishing string and numerical context?
Message-Id: <buoahi$jnr06$1@ID-196529.news.uni-berlin.de>

"Anno Siegel" <anno4000@lublin.zrz.tu-berlin.de> wrote in message
news:buo7u8$6t8$1@mamenchi.zrz.TU-Berlin.DE...
> Ben Morrow  <usenet@morrow.me.uk> wrote in comp.lang.perl.misc:
> >
> > "Damian" <not_a_real@adress.getting.too.much.spam.org> wrote:
> > > Is there anyway to tell, for a function thats being called in a
scalar
> > > context, weather it's expected to return a string or a number?
sorta
> > > like localtime, which returns a number and returns a string if you
put
> > > "". before it like:
> > >
> > > [damian@me ~]# perl -e 'print localtime(), "\n";'
> > > 321512201044210
> > > [damian@me ~]# perl -e 'print "". localtime(), "\n";'
> > > Thu Jan 22 01:15:39 2004
> >
> > You can create such values with Scalar::Util::dualvar. Those default
> > to string, though, like $!; if you need them to default to number
> > you'll have to write a pretty simple bit of XS.
>
> True, and probably what the OP wanted to know, but this isn't what
> happens with localtime.
>
> The OP has misinterpreted the results.   The difference isn't numeric
> vs. string context, it's array vs. scalar context.  The first example
> calls localtime() in array context, so it returns a list of numbers
> (sec, min, ...).  Printing runs them all together, so the result looks
> like one big number.  The second example calls it in scalar context
> (the "." operator), so localtime returns its result as a string.

Thank you for pointing that out. I even did al ittle test to be sure:

$ perl -e 'print localtime(), "\nLocaltime Array:\n[".
join("][",localtime()), "]\n";'
345922201044210
Localtime Array:
[34][59][2][22][0][104][4][21][0]

I had always thoguht it returned the time in seconds, silly me.




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

Date: Thu, 22 Jan 2004 03:07:54 -0800
From: "Damian" <not_a_real@adress.getting.too.much.spam.org>
Subject: Re: Distinguishing string and numerical context?
Message-Id: <buoaqm$ein4f$1@ID-196529.news.uni-berlin.de>

Damian wrote:
> "Anno Siegel" <anno4000@lublin.zrz.tu-berlin.de> wrote in message
> news:buo7u8$6t8$1@mamenchi.zrz.TU-Berlin.DE...
>> Ben Morrow  <usenet@morrow.me.uk> wrote in comp.lang.perl.misc:
>>>
>>> "Damian" <not_a_real@adress.getting.too.much.spam.org> wrote:
>>>> Is there anyway to tell, for a function thats being called in a
>>>> scalar context, weather it's expected to return a string or a
>>>> number? sorta like localtime, which returns a number and returns a
>>>> string if you put "". before it like:
>>>>
>>>> [damian@me ~]# perl -e 'print localtime(), "\n";'
>>>> 321512201044210
>>>> [damian@me ~]# perl -e 'print "". localtime(), "\n";'
>>>> Thu Jan 22 01:15:39 2004
>>>
>>> You can create such values with Scalar::Util::dualvar. Those default
>>> to string, though, like $!; if you need them to default to number
>>> you'll have to write a pretty simple bit of XS.
>>
>> True, and probably what the OP wanted to know, but this isn't what
>> happens with localtime.
>>
>> The OP has misinterpreted the results.   The difference isn't numeric
>> vs. string context, it's array vs. scalar context.  The first example
>> calls localtime() in array context, so it returns a list of numbers
>> (sec, min, ...).  Printing runs them all together, so the result
>> looks like one big number.  The second example calls it in scalar
>> context (the "." operator), so localtime returns its result as a
>> string.
>
> Thank you for pointing that out. I even did al ittle test to be sure:
>
> $ perl -e 'print localtime(), "\nLocaltime Array:\n[".
> join("][",localtime()), "]\n";'
> 345922201044210
> Localtime Array:
> [34][59][2][22][0][104][4][21][0]
>
> I had always thoguht it returned the time in seconds, silly me.

Bah, I was mixing it with timelocal(), which takes a localtime-type
array and spits out the time in raw seconds. Sorry its 3am...




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

Date: 22 Jan 2004 17:39:41 +0000
From: Brian McCauley <nobull@mail.com>
Subject: Re: Distinguishing string and numerical context?
Message-Id: <u9oesvc276.fsf@wcl-l.bham.ac.uk>

Ben Morrow <usenet@morrow.me.uk> writes:

> "Damian" <not_a_real@adress.getting.too.much.spam.org> wrote:
> > Is there anyway to tell, for a function thats being called in a scalar
> > context, weather it's expected to return a string or a number? sorta
> > like localtime, which returns a number and returns a string if you put
> > "". before it like:
> > 
> > [damian@me ~]# perl -e 'print localtime(), "\n";'
> > 321512201044210
> > [damian@me ~]# perl -e 'print "". localtime(), "\n";'
> > Thu Jan 22 01:15:39 2004

Other's have pointed out the question actaully wanted to ask is about
scalar v list not numeric v string context however...

> You can create such values with Scalar::Util::dualvar. Those default
> to string, though, like $!; if you need them to default to number
> you'll have to write a pretty simple bit of XS.

If calculating the string value is inexpensive (or if the string value
is usually what's wanted anyhow) then Scalar::Util::dualvar certainly
the way to do it.

If calculating the string value is expensive (e.g. a database lookup)
and rarely necessary then you may want to consider deferring
stringification by returning an object that has '0+' and '""' overload
semantics.

>   [ speaking of Scalar::Util::dualvar ]. Those default to string,
> though, like $!;

I'm sorry I don't understand what you mean by that.

use Scalar::Util qw( dualvar );
my $q = dualvar(3,'three');
$! = 3;
print 'dualvar defaults to ', $q^$q eq '0' ? 'numeric' : 'string',"\n";
print '$! defaults to ', $!^$! eq '0' ? 'numeric' : 'string',"\n";
__END__
dualvar defaults to numeric
$! defaults to numeric

-- 
     \\   ( )
  .  _\\__[oo
 .__/  \\ /\@
 .  l___\\
  # ll  l\\
 ###LL  LL\\


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

Date: Thu, 22 Jan 2004 18:01:49 +0000 (UTC)
From: Ben Morrow <usenet@morrow.me.uk>
Subject: Re: Distinguishing string and numerical context?
Message-Id: <bup36d$5re$1@wisteria.csv.warwick.ac.uk>


Brian McCauley <nobull@mail.com> wrote:
> Ben Morrow <usenet@morrow.me.uk> writes:
> >   [ speaking of Scalar::Util::dualvar ]. Those default to string,
> > though, like $!;
> 
> I'm sorry I don't understand what you mean by that.

Sorry, I was implicitly falling into the same confusion as the OP wrt
localtime and print (see Anno's post). I was thinking the difference
between

perl -le'my $x = dualvar 3, "three"; print $x'
three

and

perl -le'print localtime'
<number>

was due to localtime returning a number-with-a-string-representation
rather than a string-with-a-numeric-representation; in fact it is due
to localtime returning a list (which happens to be of numbers).

I keep getting bitten by this :(. print gives *list* *context*,
dammit!

Ben

-- 
I've seen things you people wouldn't believe: attack ships on fire off the
shoulder of Orion; I've watched C-beams glitter in the darkness near the
Tannhauser Gate. All these moments will be lost, in time, like tears in rain.
Time to die.  |-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-|  ben@morrow.me.uk


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

Date: 22 Jan 2004 20:37:57 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Distinguishing string and numerical context?
Message-Id: <bupcb5$1ej$1@mamenchi.zrz.TU-Berlin.DE>

Brian McCauley  <nobull@mail.com> wrote in comp.lang.perl.misc:

> print 'dualvar defaults to ', $q^$q eq '0' ? 'numeric' : 'string',"\n";

 ...ah, the simple answer to the number-or-string question, at least in
one of its guises.  I keep forgetting that.  Have you been using it
for long?  I thought there was a bug in earlier versions that kept it
from working.

Anno


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

Date: Tue, 27 Jan 2004 15:52:55 -0500
From: Sherm Pendley <spamtrap@dot-app.org>
Subject: Does unpack('P', ...) create a copy?
Message-Id: <iOWdnSTM2Jo1Uovd4p2dnA@adelphia.com>

Consider the following snippet:

use Socket;

my $bytes = pack('L', $obj->bytes());
my $sockaddr = unpack('P2', $bytes);
my ($size, $family) = unpack('cc', $sockaddr);
if ($family == AF_INET) {
    my ($port, $address) = sockaddr_in(unpack("P$size", $bytes));
    $address = inet_ntoa($address);
    # ... do some stuff with $address and $port ...
} elsif ($family == AF_UNIX) {
    my ($port, $path) = sockaddr_un(unpack("P$size", $bytes));
    # ... do some stuff with $path and $port ...
}

In the above, $obj is a Perl object wrapper around a native object (in this
case an Objective-C object of class NSData), and the native -bytes method
returns a void*. The XS wrapper for the native method is written and
working, passing the void* to Perl as an integer.

What I'd like to know is whether unpack('P2', $bytes) creates a copy of the
structure pointed to. Obviously in this example it doesn't matter a great
deal, as the above is working with a small, read-only struct.

But, the same XS wrapper can be used with any native object, and some native
methods can return pointers to *huge* buffers - image bitmaps, for example.
Also, a pointer can be returned in anticipation of it being used to make
changes to the pointed-to data - once again, image bitmaps are a good
example. In both cases, copying would be undesirable.

So, does anyone know the answer off the top of their head? Or do I need to
start writing test cases?

sherm--


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

Date: 27 Jan 2004 21:07:48 GMT
From: "Tassilo v. Parseval" <tassilo.parseval@rwth-aachen.de>
Subject: Re: Does unpack('P', ...) create a copy?
Message-Id: <bv6jv4$4te$1@nets3.rz.RWTH-Aachen.DE>

Also sprach Sherm Pendley:

> Consider the following snippet:
> 
> use Socket;
> 
> my $bytes = pack('L', $obj->bytes());
> my $sockaddr = unpack('P2', $bytes);
> my ($size, $family) = unpack('cc', $sockaddr);
> if ($family == AF_INET) {
>     my ($port, $address) = sockaddr_in(unpack("P$size", $bytes));
>     $address = inet_ntoa($address);
>     # ... do some stuff with $address and $port ...
> } elsif ($family == AF_UNIX) {
>     my ($port, $path) = sockaddr_un(unpack("P$size", $bytes));
>     # ... do some stuff with $path and $port ...
> }
> 
> In the above, $obj is a Perl object wrapper around a native object (in this
> case an Objective-C object of class NSData), and the native -bytes method
> returns a void*. The XS wrapper for the native method is written and
> working, passing the void* to Perl as an integer.
> 
> What I'd like to know is whether unpack('P2', $bytes) creates a copy of the
> structure pointed to. Obviously in this example it doesn't matter a great
> deal, as the above is working with a small, read-only struct.

No copy is created in case of 'P' and 'p'. Note that creating a copy of
a structure when you only have a pointer to it (and not the type of it,
that is, its size) isn't even possible.

Tassilo
-- 
$_=q#",}])!JAPH!qq(tsuJ[{@"tnirp}3..0}_$;//::niam/s~=)]3[))_$-3(rellac(=_$({
pam{rekcahbus})(rekcah{lrePbus})(lreP{rehtonabus})!JAPH!qq(rehtona{tsuJbus#;
$_=reverse,s+(?<=sub).+q#q!'"qq.\t$&."'!#+sexisexiixesixeseg;y~\n~~dddd;eval


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

Date: Tue, 27 Jan 2004 16:35:14 -0500
From: Sherm Pendley <spamtrap@dot-app.org>
Subject: Re: Does unpack('P', ...) create a copy?
Message-Id: <jo2dnTtqzJ4ORIvdRVn-vg@adelphia.com>

Tassilo v. Parseval wrote:

> No copy is created in case of 'P' and 'p'.

Most excellent, thank you.

sherm--


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

Date: 21 Jan 2004 13:34:16 -0800
From: phil@dodgeit.com (Phil)
Subject: Drawing reference lines with GD::Graph
Message-Id: <c4999930.0401211334.436331c6@posting.google.com>

Hello - I have a pretty PNG:
http://dodgeit.com/temp/file.png

created with this code:

my $chart = GD::Graph::lines->new(1000,480);
$chart->set(x_label => "time",      # no axes for pie chart
			x_labels_vertical => 1,
			x_label_skip => 50,
			y_label => "price",
			title   => "misc stock",
			long_ticks => 0,  # make a grid of all the ticks
		   );
my $plot = $chart->plot($dataref) or die $chart->error;


I'd like to draw a horizontal reference line right at the number 11.

Any ideas? I looked through the /samples dir that came with the
GD::Graph dist and didn't find anything promising and have also
googled around quite a bit.

TIA -> Phil


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

Date: Thu, 22 Jan 2004 17:47:18 -0800
From: "smackdab" <smackdab1@hotmail.com>
Subject: Re: Drawing reference lines with GD::Graph
Message-Id: <r2%Pb.43463$Ar1.12353@fed1read04>

> I'd like to draw a horizontal reference line right at the number 11.
>
> Any ideas? I looked through the /samples dir that came with the
> GD::Graph dist and didn't find anything promising and have also
> googled around quite a bit.
>

I am also going to need to do this soon...
I think you could create another dataset with all values equal to 11, a
little wastful though..
Or you could look into 'mixed' graphs...haven't looked yet myself ;-)

If you find a good solution, post it ;-)




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

Date: Sat, 24 Jan 2004 12:26:37 +1100
From: Martien Verbruggen <mgjv@tradingpost.com.au>
Subject: Re: Drawing reference lines with GD::Graph
Message-Id: <slrnc13ied.kkb.mgjv@martien.heliotrope.home>

On Thu, 22 Jan 2004 17:47:18 -0800,
	smackdab <smackdab1@hotmail.com> wrote:
>> I'd like to draw a horizontal reference line right at the number 11.
>>
>> Any ideas? I looked through the /samples dir that came with the
>> GD::Graph dist and didn't find anything promising and have also
>> googled around quite a bit.
>>
> 
> I am also going to need to do this soon...
> I think you could create another dataset with all values equal to 11, a
> little wastful though..

At the moment that is the only way.

It's not that wasteful. Compared to all the other work that goes on,
drawing one extra data set isn't going to be significant.

> Or you could look into 'mixed' graphs...haven't looked yet myself ;-)

If your "real" data sets are not lines, then that's what you'l need to
use, yes.

> If you find a good solution, post it ;-)

I'll put it o the Todo list.

Martien
-- 
                        | 
Martien Verbruggen      | 
                        | Curiouser and curiouser, said Alice.
                        | 


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

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.  

NOTE: due to the current flood of worm email banging on ruby, the smtp
server on ruby has been shut off until further notice. 

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


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