[27115] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 8987 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Feb 23 11:05:41 2006

Date: Thu, 23 Feb 2006 08:05:05 -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, 23 Feb 2006     Volume: 10 Number: 8987

Today's topics:
        CAM::PDF and create image in document <boss replace_this_with_@ gregerhaga.net>
    Re: Questions about globs <rwxr-xr-x@gmx.de>
        read from file or from <DATA>? <friendly@yorku.ca>
    Re: read from file or from <DATA>? xhoster@gmail.com
    Re: Reading Mac / Unix / DOS text files <rwxr-xr-x@gmx.de>
    Re: savely change permission and group on files <michael@thegrebs.com>
    Re: Scalars Leaked and Segmentation Fault <zentara@highstream.net>
        sharing variables-data perl-asp <jay@cutmeukjay.com>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Thu, 23 Feb 2006 15:15:48 +0200
From: Greger <boss replace_this_with_@ gregerhaga.net>
Subject: CAM::PDF and create image in document
Message-Id: <dtkbq7$cem$1@phys-news4.kolumbus.fi>

Hi
I hope to find somebody with some experience using CAM::PDF module(s)
I simply want to add an image ( png ) to a pre-existing pdf document, but
can't seem to figure this one out. 
Could somebody please advice as how to do this, thank you.
Greger 


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

Date: Thu, 23 Feb 2006 15:40:01 +0100
From: "Lukas Mai" <rwxr-xr-x@gmx.de>
Subject: Re: Questions about globs
Message-Id: <dtkhg1$hqs$02$1@news.t-online.com>

Ferry Bolhar <bol@adv.magwien.gv.at> schrob:
[...]
> *a = \$b;     Assign a reference of 'b' to glob 'a'
> *b = 4;        Assign the value 4 to the glob
> *c = sub {...};   Assign an (anonymous) subroutine to the glob
> $d = *a;     Assign glob 'a' (whatever this is) to scalar 'd'
> 
> What exactly happens here? Which data structures are set up here
> in which ways?

I have no idea how globs are really implemented, but I think of them as
pointers to structs that contain references to variables. What follows
is a description of my mental model of perl.

Assigning a reference to a glob changes the internal reference of the
appropriate type, i.e. *a = \$b does something like
typeglob("a")->scalar = reference($b) and *c = sub {...} is
typeglob("c")->code = coderef(...).

*glob = value (where value is not a reference) stringifies value and
uses it as a symbolic reference (to a glob). *b = 4 is *b = *{"4"} (or
*b = *4).

*foo = *bar changes the struct pointer of foo; it doesn't copy all
struct members from bar to foo. local $foo allocates a new scalar and
puts a reference to it into *foo{SCALAR}. This is why the following
works as it does:

$ perl -wle '*foo = *bar; local $foo = 42; print $bar'
42
$ perl -wle '*foo = \$bar; local $foo = 42; print $bar'
Use of uninitialized value in print at -e line 1.


> Is '*b = 4' the same like '$b = 4'? It doesn't seem so. But what else?
> Is a glob just a special value type which can be assigned to a scalar,
> just like a reference?

Yes, there are glob values and glob containers (*foo).

> And what exactly is the difference between
> 
> *XX::aa = *YY::bb;          and
> $XX::{aa} = $YY::{bb};

I'm not sure but I think the former resolves names at compile time, the
latter at runtime. See also:

$ perl -le '*XX:: = \%main::; *XX::aa = *YY::bb; $YY::bb = 42; print $::aa'

$ perl -le '*XX:: = \%main::; $XX::{aa} = $YY::{bb}; $YY::bb = 42; print $::aa'
42

> BTW: while playing a little bit with Devel::Peek, I saw that the
> gp_sv entry in a gp is always used, even when no scalar is assigned
> to the glob. For example, with
> 
> @a = qw (1 2 3);
> Dump *a;
> 
> I can see that an address is shown in the GV as well in the AV
> entry of the gp. What is stored in the SV entry in this case?

Looks like perl automatically creates a scalar for each glob you use.
All other fields are only set when you use the corresponding variable.

> When dumping an array or a hash with Dump, I have it to preceede
> with a '\' because Dump accepts scalars only. However, Dump still
> accepts glob values without a '\' (see above). Does this mean that *a
> is a sv? And if so, what it can be used for?

Glob values can be assigned to scalars and glob variables, and they can
be dereferenced. Each dereferencing operator uses the field of the
corresponding type, so ${*foo} is ${*foo{SCALAR}}, *{*foo} is
*{*foo{GLOB}}, etc (note that *foo{GLOB} == \*foo, which is why you can
do $x = *foo; *{$x}{whatever} even though $x is a glob, not a glob ref
(this is similar to function pointers in C (e.g.
(******printf)("hello\n"), except Perl requires braces: print
*{*{*{*foo}}}))).

> And finally: is a glob always magic? What are a glob's magics?
> (In other words, what do the 'get' and 'set' entries in PL_vtbl_glob)?

Sorry, no idea.

HTH, Lukas


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

Date: Thu, 23 Feb 2006 09:11:23 -0500
From: Michael Friendly <friendly@yorku.ca>
Subject: read from file or from <DATA>?
Message-Id: <dtkfq0$j0m$1@sunburst.ccs.yorku.ca>

This is probably simple, but I can't find it...
I frequently write scripts to take input from STDIN or from a named file 
by doing

open(STDIN, "<$opt_i") or die "-i $opt_i: can't open.\n" if $opt_i ;
  ...
while (<>) {
}

but how can I read from <DATA> if no file is given on the command line?

undef $/;      # slurp whole file
my $lines = @ARGV ? <> : <DATA>;

will work, but I need to read in a while loop.


-- 
Michael Friendly     Email: friendly@yorku.ca
Professor, Psychology Dept.
York University      Voice: 416 736-5115 x66249 Fax: 416 736-5814
4700 Keele Street    http://www.math.yorku.ca/SCS/friendly.html
Toronto, ONT  M3J 1P3 CANADA


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

Date: 23 Feb 2006 15:48:47 GMT
From: xhoster@gmail.com
Subject: Re: read from file or from <DATA>?
Message-Id: <20060223105125.274$xc@newsreader.com>

Michael Friendly <friendly@yorku.ca> wrote:
> This is probably simple, but I can't find it...
> I frequently write scripts to take input from STDIN or from a named file
> by doing
>
> open(STDIN, "<$opt_i") or die "-i $opt_i: can't open.\n" if $opt_i ;
>   ...
> while (<>) {
> }

Why not just let <> do it's magic?

unshift @ARGV, $opt_i if $opt_i;
while (<>) {

Or, if $opt_i came from @ARGV in the first place, then stop removing it
from @ARGV and just do:

while (<>) {


>
> but how can I read from <DATA> if no file is given on the command line?
>
> undef $/;      # slurp whole file
> my $lines = @ARGV ? <> : <DATA>;
>
> will work, but I need to read in a while loop.

Paul answered this.  But you don't have to use glob-refs, you can just
use strings.

my $fh = @ARGV ? 'ARGV' : 'DATA';
while (<$fh>) {

Xho

-- 
-------------------- http://NewsReader.Com/ --------------------
Usenet Newsgroup Service                        $9.95/Month 30GB


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

Date: Thu, 23 Feb 2006 15:49:22 +0100
From: "Lukas Mai" <rwxr-xr-x@gmx.de>
Subject: Re: Reading Mac / Unix / DOS text files
Message-Id: <dtki1i$hqs$02$2@news.t-online.com>

January Weiner <january.weiner@gmail.com> schrob:
> Rick Scott <rick@shadowspar.dyndns.org> wrote:
>> [lexical filehandles vs. package/bareword fhs]
> 
> Thanks for these explanation, but read what I have written above. Yeah, I
> know that, I use it in larger projects.  I don't care about that in the
> five liners.  Frankly, do you use "use strict ; use warnings ;" with
> one-liners run with "perl -e"?  Will you try to convince me that omitting
> these is a serious danger and causes a greater propensity to introduce
> errors? ...with "perl -e"?  Well -- I agree.  Of course it does - so what?

I 'use warnings; use script;' in every Perl script that's stored in a
file. I use perl -w(l)e for one liners (except when
golfing/obfuscating). Sometimes I add -Mstrict to quickly check how
exactly a perl feature/bug works.

Just my 2˘, Lukas


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

Date: Thu, 23 Feb 2006 08:03:58 -0600
From: Michael Greb <michael@thegrebs.com>
Subject: Re: savely change permission and group on files
Message-Id: <michael-CD38DE.08035823022006@[192.168.2.100]>

In article <slrndvpvnq.h1.abigail@alexandra.abigail.nl>,
 Abigail <abigail@abigail.nl> wrote:

> Lars Madsen (daleif@imf.au.dk) wrote on MMMMDLIX September MCMXCIII in
> <URL:news:43fcfe5c$0$11674$ba624c82@nntp02.dk.telia.net>:
> ??  
> ?? > Huh? I don't get it. Why would you be vulnerable if you're doing 
> something
> ?? > simple as changing the permissions of files?
> ?? > 
> ??  
> ??  if one (by mistake) runs sys commands on unchecked data
> 
> If you are afraid you make mistakes like that, you shouldn't program
> at all. There's no defence.
> 
> ??  as in doing a naive delete of a file named '-rf /'
> 
> 
> Huh? A native delete of a file in Perl is quite safe, and spelled 'unlink'.

'native' ne 'naive'


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

Date: Thu, 23 Feb 2006 15:57:40 GMT
From: zentara <zentara@highstream.net>
Subject: Re: Scalars Leaked and Segmentation Fault
Message-Id: <5ukrv1pbntmjgqhudq8h6pint1lqk7m09m@4ax.com>

On Tue, 21 Feb 2006 12:53:19 GMT, AMLiapunov <liapunov@3more.it> wrote:

>Hi all,
>this is my first post on this group.
>I'm developing a distribuited application with perl 5.8.7 and ithreads.
>I'm experiencing scalars leaked problem and segmentation fault too.
>Each module of the code uses strict and warnings.
>As you can imagine it is very difficult to perform a debug of the code
>as i've no debug informations from the interpreter.
>
>Anyone could share opinions or comments.

You should show a minimum example of code, but in general......

You can get those scalars leaked error messages IIRC, if you
do something like let a thread(s) die before joining. I guess it means
that there are still refs to some variable used in the thread, but
the thread no longer exists. Like I said IIRC....I remember seeing
a few of those errors, last time I played with the newer threads in
Gtk2, where you can launch threads after a gui was created.
 I have some code which will produce those errors, but really havn't
found the cause.

The only way I have found, to safely run threads, is to create all
threads, before you create the main part of your script. That way,
they don't share any code, (and possibly refs). 
Also I am guessing it is a harmless error, as long as your memory use
is not rising, much like the common "a thread exited while others were
running". The warnings may be annoying, but are harmless. 

The segfault is more serious, and most likely comes from shraing objects
across threads, or creating a thread after the main thread already has
an object ( which gets copied ) and raises havoc, ( google for objects
and thread safety).

In case you are running the threads from a GUI, the latest Gtk2 libs
have some extra thread-safety included, where you start the script with
##############################################
use Gtk2 qw/-init -threads-init/;

#this line causes the warning, but dosn't die 
die "Glib::Object thread safetly failed"
        unless Glib::Object->set_threadsafe (TRUE);
##############################################

Under carefully controlled conditions, this lets you launch threads
after the GUI is created, and you control when you enter and leave a
thread with
 Gtk2::Gdk::Threads->enter;
 Gtk2::Gdk::Threads->leave;


But even with those features, you can still get scalars-leaked errors
when you spawn-and-join threads in a running program, but they seem
harmless and don't affect memory usage. In my tests, they seem to happen
when I join a thread, which was created after the main script was up and
running. Like I said, I'm guessing that the new thread got a useless
copy of some variable from main, and the ref count went up, but when the
thread was joined, it was cleaned up properly.





-- 
I'm not really a human, but I play one on earth.
http://zentara.net/japh.html


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

Date: Thu, 23 Feb 2006 14:44:55 -0000
From: "UkJay" <jay@cutmeukjay.com>
Subject: sharing variables-data perl-asp
Message-Id: <dtkhp3$4va$1@news6.svr.pol.co.uk>
Keywords: data

Is it possible to pass data between variables when using active server pages
and inserting some perl script in asp?

Also how do you invoke a perl script from an active server page?

Yes I want the best of both worlds ;-)

-- 
Best Regards,
James (ukjay)

http://www.ukjay.co.uk

Garden WebCam,Photography,Competitions,Weather (AWS)







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

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


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