[32445] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 3712 Volume: 11

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Jun 11 21:09:23 2012

Date: Mon, 11 Jun 2012 18:09:10 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Mon, 11 Jun 2012     Volume: 11 Number: 3712

Today's topics:
        A remark <rweikusat@mssgmbh.com>
    Re: A remark (Randal L. Schwartz)
    Re: A remark <rweikusat@mssgmbh.com>
    Re: calling graph for a Perl module <bugbear@trim_papermule.co.uk_trim>
    Re: new topic: I call length($<string>) and get number  (Randal L. Schwartz)
    Re: new topic: I call length($<string>) and get number  <ben@morrow.me.uk>
    Re: new topic: I call length($<string>) and get number  <kquirici@yahoo.com>
    Re: new topic: I call length($<string>) and get number  <kquirici@yahoo.com>
    Re: new topic: I call length($<string>) and get number  <ben@morrow.me.uk>
    Re: new topic: I call length($<string>) and get number  <marc.girod@gmail.com>
    Re: new topic: I call length($<string>) and get number  <ben@morrow.me.uk>
        Odd behaviour on Mac OS X Lion <trudge@gmail.com>
    Re: Odd behaviour on Mac OS X Lion <dave@invalid.invalid>
    Re: Odd behaviour on Mac OS X Lion <trudge@gmail.com>
    Re: Odd behaviour on Mac OS X Lion (Alan Curry)
    Re: Odd behaviour on Mac OS X Lion <ben@morrow.me.uk>
    Re: Odd behaviour on Mac OS X Lion <trudge@gmail.com>
    Re: Odd behaviour on Mac OS X Lion <trudge@gmail.com>
        Very Sluggish Code <glenmillard@gmail.com>
    Re: Very Sluggish Code <ben@morrow.me.uk>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Mon, 11 Jun 2012 20:53:18 +0100
From: Rainer Weikusat <rweikusat@mssgmbh.com>
Subject: A remark
Message-Id: <87zk8962xd.fsf@sapphire.mobileactivedefense.com>

Removing possibly useful documentation texts because they contain
'politically unwelcome information' in order to help with forcing
people to download $random_non_perl_oo_crap from CPAN even for really
basic problems is a tacit admission that said $random_non_perl_oo_crap
failed to supplant the actually very nice Perl OO system based on its
technical merits.



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

Date: Mon, 11 Jun 2012 14:25:36 -0700
From: merlyn@stonehenge.com (Randal L. Schwartz)
Subject: Re: A remark
Message-Id: <86d355zgkv.fsf@red.stonehenge.com>

>>>>> "Rainer" == Rainer Weikusat <rweikusat@mssgmbh.com> writes:

Rainer> Removing possibly useful documentation texts because they contain
Rainer> 'politically unwelcome information' in order to help with forcing
Rainer> people to download $random_non_perl_oo_crap from CPAN even for really
Rainer> basic problems is a tacit admission that said $random_non_perl_oo_crap
Rainer> failed to supplant the actually very nice Perl OO system based on its
Rainer> technical merits.

/me holds up secret decoder ring

Nothing.

/me pushes message through "content vs useless pointless rant" filter

Aha.  Pointless rant.  Nobody knows *what* you're talking about.

-- 
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Smalltalk/Perl/Unix consulting, Technical writing, Comedy, etc. etc.
See http://methodsandmessages.posterous.com/ for Smalltalk discussion


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

Date: Mon, 11 Jun 2012 23:14:27 +0100
From: Rainer Weikusat <rweikusat@mssgmbh.com>
Subject: Re: A remark
Message-Id: <87r4tl5we4.fsf@sapphire.mobileactivedefense.com>

merlyn@stonehenge.com (Randal L. Schwartz) writes:
>>>>> "Rainer" == Rainer Weikusat <rweikusat@mssgmbh.com> writes:
>
> Rainer> Removing possibly useful documentation texts because they contain
> Rainer> 'politically unwelcome information' in order to help with forcing
> Rainer> people to download $random_non_perl_oo_crap from CPAN even for really
> Rainer> basic problems is a tacit admission that said $random_non_perl_oo_crap
> Rainer> failed to supplant the actually very nice Perl OO system based on its
> Rainer> technical merits.
>
> /me holds up secret decoder ring
>
> Nothing.
>
> /me pushes message through "content vs useless pointless rant" filter
>
> Aha.  Pointless rant.  Nobody knows *what* you're talking about.

,----
| New Documentation
| 
| [...]
| 
| perlootut
| 
| This a new OO tutorial. It focuses on basic OO concepts, and then
| recommends that readers choose an OO framework from CPAN.
| 
| [...]
| 
| Removed Documentation
| Old OO Documentation
| 
| The old OO tutorials, perltoot, perltooc, and perlboot, have been
| removed.
`----
http://perldoc.perl.org/perldelta.html

I especially like statements like the following:

	As we said before, Perl's minimal OO system has led to a
	profusion of OO systems on CPAN. While you can still drop down
	to the bare metal and write your classes by hand, there's
	really no reason to do that with modern Perl.
        
	http://perldoc.perl.org/perlootut.html#CONCLUSION

I can immediately provide such a 'good reason': Obviously, according
to the opinions of the one bazillion people who wasted there spare
time on implementing YARFPOO (yet another replacement for Perl OO) all
other RFPOOs have serious drawbacks and in this case, I'd vote for the
built-in mechanism because it is the built-in mechanism. I have enough
deficient third-party written code I need to maintain already ...


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

Date: Mon, 11 Jun 2012 10:38:42 +0100
From: bugbear <bugbear@trim_papermule.co.uk_trim>
Subject: Re: calling graph for a Perl module
Message-Id: <1OqdnTFMeog_IUjSnZ2dnUVZ7qudnZ2d@brightview.co.uk>

jaialai.technology@gmail.com wrote:
> I am looking to present some code to a group of people and someone in
> the group suggested that I show them a "calling graph" of the code.
> This code is just a single module consisting of one .pm file.
> Now, I figured I could just sketch out something in Visio
> quickly enough. However, a Google search reveals some tools for automating
> this sort of thing and creating the graph for me automatically.
> The problem is that none of these seem to be able to restrict the
> calling graph to just the functions within the namespace of the module.
> All the functions located in the modules use()d by this one are included
> and it the resulting graphic is just a giant mess.
> Specifically I am thinking of the calling graph generated by NYTProf
> or by Autodia. So, back to hand creating something in Visio...unless
> someone here has a suggestion? Does anyone have a favorite way of
> generating a calling graph or UML-ish diagram of a perl module
> that restricts itself to just the function defined within that module?
> Perhaps that is already possible with a tool that I tried but I somehow
> missed how to do it?
> Any advice?

I will leave the perl parsing issue to others,
but for a graph, I would heartily recommend
GraphViz

http://www.graphviz.org/

  BugBear


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

Date: Mon, 11 Jun 2012 14:23:59 -0700
From: merlyn@stonehenge.com (Randal L. Schwartz)
Subject: Re: new topic: I call length($<string>) and get number of lines - code frag below - on MAC OS X 10.7
Message-Id: <86hauhzgnk.fsf@red.stonehenge.com>

>>>>> "kquirici" == kquirici  <kquirici@yahoo.com> writes:

kquirici> 	$journalin = $journalin . %_;

Did you want %_ there, or $_?

print "Just another Perl hacker,"; # the original

-- 
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Smalltalk/Perl/Unix consulting, Technical writing, Comedy, etc. etc.
See http://methodsandmessages.posterous.com/ for Smalltalk discussion


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

Date: Sun, 10 Jun 2012 19:17:45 +0100
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: new topic: I call length($<string>) and get number of lines - code frag below - on MAC OS X 10.7
Message-Id: <9v4fa9-dvd1.ln1@anubis.morrow.me.uk>


Quoth kquirici <kquirici@yahoo.com>:
> if( ! open JOURNALTXT, $inputfilename) {
>  die "cannot open ".$inputfilename;
> }

Checking the return value of open is very good; but if you do it this
clumsily it will soon become infuriating and you will start leaving it
out. You should also include $! in the error message so you know what
went wrong.

You should be keeping your filehandles in variables, rather than using
global barewords. You should also be using 3-arg open.

    open my $JOURNALTXT, "<", $inputfilename
        or die "cannot open '$inputfilename': $!";

Alternatively, you can 'use autodie', which will handle the error for
you.

> while (<JOURNALTXT>){
> 	$journalin = $journalin . %_;

What do you think this does? (Specifically, %_ in scalar context.)

> }
> 
> close JOURNALTXT;
> 
> $journal_txt_len = length($journalin);	
> print "journal length: " . $journal_txt_len;
> 
> 
> -----------------
> the last print statement returns 159 which is the number of  lines; there are
> actually around 8k chars.

Did you try printing $journalin, to see what's in it? It isn't what you
expect.

More generally, this is an extremely roundabout way of reading a file
into a variable. Either use

    {
        local $/; # this sets $/ to undef
        $journalin = <$JOURNALTXT>;
    }

or use File::Slurp.

Ben



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

Date: Sun, 10 Jun 2012 11:53:31 -0700 (PDT)
From: kquirici <kquirici@yahoo.com>
Subject: Re: new topic: I call length($<string>) and get number of lines - code frag below - on MAC OS X 10.7
Message-Id: <c6c176f3-7d00-42e2-8d85-8c3955f36faf@googlegroups.com>

On Sunday, June 10, 2012 2:17:45 PM UTC-4, Ben Morrow wrote:
> Quoth kquirici <kquirici@yahoo.com>:
> > if( ! open JOURNALTXT, $inputfilename) {
> >  die "cannot open ".$inputfilename;
> > }
> 
> Checking the return value of open is very good; but if you do it this
> clumsily it will soon become infuriating and you will start leaving it
> out. You should also include $! in the error message so you know what
> went wrong.
> 
> You should be keeping your filehandles in variables, rather than using
> global barewords. You should also be using 3-arg open.
> 
>     open my $JOURNALTXT, "<", $inputfilename
>         or die "cannot open '$inputfilename': $!";
> 
> Alternatively, you can 'use autodie', which will handle the error for
> you.
> 
> > while (<JOURNALTXT>){
> > 	$journalin = $journalin . %_;
> 
> What do you think this does? (Specifically, %_ in scalar context.)
> 
> > }
> > 
> > close JOURNALTXT;
> > 
> > $journal_txt_len = length($journalin);	
> > print "journal length: " . $journal_txt_len;
> > 
> > 
> > -----------------
> > the last print statement returns 159 which is the number of  lines; there are
> > actually around 8k chars.
> 
> Did you try printing $journalin, to see what's in it? It isn't what you
> expect.
> 
> More generally, this is an extremely roundabout way of reading a file
> into a variable. Either use
> 
>     {
>         local $/; # this sets $/ to undef
>         $journalin = <$JOURNALTXT>;
>     }
> 
> or use File::Slurp.
> 
> Ben

Thanks for your reply Ben. I got it to work. Oddly enuf I have no idea
why it works, because it looks exactly the same as before - I made some
mods that I deleted and returned it to its original form except now it works:

if( ! open JOURNALTXT, $inputfilename) {
 die "cannot open ".$inputfilename;
}

while (<JOURNALTXT>){
	$journalin = $journalin . $_;
}

close JOURNALTXT;
#print $journalin;

my $journalen = length($journalin);	
print "\njournal length: " . $journalen;

prints the correct number of chars.

Thanks & Regards & Mystified,

Ken Quirici


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

Date: Sun, 10 Jun 2012 12:08:19 -0700 (PDT)
From: kquirici <kquirici@yahoo.com>
Subject: Re: new topic: I call length($<string>) and get number of lines - code frag below - on MAC OS X 10.7
Message-Id: <0bb566e1-cc96-4160-885a-5f5cf24f45c8@googlegroups.com>

On Sunday, June 10, 2012 2:17:45 PM UTC-4, Ben Morrow wrote:
> Quoth kquirici <kquirici@yahoo.com>:
> > if( ! open JOURNALTXT, $inputfilename) {
> >  die "cannot open ".$inputfilename;
> > }
> 
> Checking the return value of open is very good; but if you do it this
> clumsily it will soon become infuriating and you will start leaving it
> out. You should also include $! in the error message so you know what
> went wrong.
> 
> You should be keeping your filehandles in variables, rather than using
> global barewords. You should also be using 3-arg open.
> 
>     open my $JOURNALTXT, "<", $inputfilename
>         or die "cannot open '$inputfilename': $!";
> 
> Alternatively, you can 'use autodie', which will handle the error for
> you.
> 
> > while (<JOURNALTXT>){
> > 	$journalin = $journalin . %_;
> 
> What do you think this does? (Specifically, %_ in scalar context.)
> 
> > }
> > 
> > close JOURNALTXT;
> > 
> > $journal_txt_len = length($journalin);	
> > print "journal length: " . $journal_txt_len;
> > 
> > 
> > -----------------
> > the last print statement returns 159 which is the number of  lines; there are
> > actually around 8k chars.
> 
> Did you try printing $journalin, to see what's in it? It isn't what you
> expect.
> 
> More generally, this is an extremely roundabout way of reading a file
> into a variable. Either use
> 
>     {
>         local $/; # this sets $/ to undef
>         $journalin = <$JOURNALTXT>;
>     }
> 
> or use File::Slurp.
> 
> Ben

Ah, I see what the problem was - I had %_ instead of $_. 

Thanks & Regards,

Ken Quirici




> 
> Checking the return value of open is very good; but if you do it this
> clumsily it will soon become infuriating and you will start leaving it
> out. You should also include $! in the error message so you know what
> went wrong.
> 
> You should be keeping your filehandles in variables, rather than using
> global barewords. You should also be using 3-arg open.
> 
>     open my $JOURNALTXT, "<", $inputfilename
>         or die "cannot open '$inputfilename': $!";
> 
> Alternatively, you can 'use autodie', which will handle the error for
> you.
> 
> > while (<JOURNALTXT>){
> > 	$journalin = $journalin . %_;
> 
> What do you think this does? (Specifically, %_ in scalar context.)
> 
> > }
> > 
> > close JOURNALTXT;
> > 
> > $journal_txt_len = length($journalin);	
> > print "journal length: " . $journal_txt_len;
> > 
> > 
> > -----------------
> > the last print statement returns 159 which is the number of  lines; there are
> > actually around 8k chars.
> 
> Did you try printing $journalin, to see what's in it? It isn't what you
> expect.
> 
> More generally, this is an extremely roundabout way of reading a file
> into a variable. Either use
> 
>     {
>         local $/; # this sets $/ to undef
>         $journalin = <$JOURNALTXT>;
>     }
> 
> or use File::Slurp.
> 
> Ben



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

Date: Sun, 10 Jun 2012 20:46:14 +0100
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: new topic: I call length($<string>) and get number of lines - code frag below - on MAC OS X 10.7
Message-Id: <65afa9-aee1.ln1@anubis.morrow.me.uk>


Quoth kquirici <kquirici@yahoo.com>:
> On Sunday, June 10, 2012 2:17:45 PM UTC-4, Ben Morrow wrote:
> > Quoth kquirici <kquirici@yahoo.com>:
> 
> Thanks for your reply Ben. I got it to work. Oddly enuf I have no idea
                                                     ^^^^
Please write in English.

> why it works, because it looks exactly the same as before - I made some
> mods that I deleted and returned it to its original form except now it works:

These two lines are not the same:

> > > 	$journalin = $journalin . %_;

> 	$journalin = $journalin . $_;

Ben



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

Date: Sun, 10 Jun 2012 13:59:54 -0700 (PDT)
From: Marc Girod <marc.girod@gmail.com>
Subject: Re: new topic: I call length($<string>) and get number of lines - code frag below - on MAC OS X 10.7
Message-Id: <16a40b2f-c215-4291-a5e1-02eab7c1d28f@fr28g2000vbb.googlegroups.com>

On Jun 10, 8:46=A0pm, Ben Morrow <b...@morrow.me.uk> wrote:

> > =A0 =A0$journalin =3D $journalin . $_;

Sorry, but what is %_?
I cannot find it in perlvar, yet I don't get an error with:

perl -Mstrict -wle 'print %_'

Marc


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

Date: Sun, 10 Jun 2012 23:59:34 +0100
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: new topic: I call length($<string>) and get number of lines - code frag below - on MAC OS X 10.7
Message-Id: <mflfa9-75g1.ln1@anubis.morrow.me.uk>


Quoth Marc Girod <marc.girod@gmail.com>:
> On Jun 10, 8:46 pm, Ben Morrow <b...@morrow.me.uk> wrote:
> 
> > >    $journalin = $journalin . $_;
> 
> Sorry, but what is %_?
> I cannot find it in perlvar, yet I don't get an error with:
> 
> perl -Mstrict -wle 'print %_'

It's not currently assigned any special meaning by perl, though you
should not assume this will continue to be the case. (For instance, %+
and %- were given meanings in 5.10; before that they were just ordinary
hashes.)

All the punctuation variables, including any variable of the form
*{^FOO}, are exempt from 'strict' and forced into package main, along
with a small handful of ordinary variable names (I think the complete
list is ARGV ARGVOUT ENV INC SIG STDIN STDOUT STDERR). The fact this
happens to all parts of the globs concerned, rather than just the parts
which are treated specially by perl, is pretty-much just an accident of
implementation.

Ben



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

Date: Sun, 10 Jun 2012 23:54:20 -0700 (PDT)
From: Trudge <trudge@gmail.com>
Subject: Odd behaviour on Mac OS X Lion
Message-Id: <b53d714f-4b7e-470a-a3c0-a49d27fd134e@googlegroups.com>

I've been having some odd behaviour lately on our work computer running the installed Apple Perl. I have the following few lines of code:

#!/usr/bin/perl
BEGIN
{
	open (STDERR,">>$0-err.txt");
	print STDERR "\n",scalar localtime,"\n";
}
use strict;
use warnings;

my $ext="pdf";
my $Source = "/Desktop/test1";
my $Destination = "/Desktop/test2";

print "Now running $0 ...\n";
print "\$ext: $ext\n";
print "\$Source: $Source\n";
print "\$Destination: $Destination\n";

However, there is no output to the Terminal window, and no entry is made in the log file. There should at least be a date/time stamp.

If I remove the 'shebang' line, the script outputs as expected, and an entry is made in the log file indicating the timestamp.

What gives?


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

Date: Mon, 11 Jun 2012 07:13:44 +0000 (UTC)
From: "Dave Saville" <dave@invalid.invalid>
Subject: Re: Odd behaviour on Mac OS X Lion
Message-Id: <fV45K0OBJxbE-pn2-jLOo4RwwR1m3@localhost>

On Mon, 11 Jun 2012 06:54:20 UTC, Trudge <trudge@gmail.com> wrote:

> I've been having some odd behaviour lately on our work computer running the installed Apple Perl. I have the following few lines of code:
> 
> #!/usr/bin/perl

<snip>

> What gives?

I take it that *is* the correct path to your perl executable?
-- 
Regards
Dave Saville


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

Date: Mon, 11 Jun 2012 10:55:30 -0700 (PDT)
From: Trudge <trudge@gmail.com>
Subject: Re: Odd behaviour on Mac OS X Lion
Message-Id: <e8221ea4-b05f-46d5-96d1-f0abe78e8a37@googlegroups.com>

On Monday, June 11, 2012 3:13:44 AM UTC-4, Dave Saville wrote:
> On Mon, 11 Jun 2012 06:54:20 UTC, Trudge wrote:
> 
> > I've been having some odd behaviour lately on our work computer running the installed Apple Perl. I have the following few lines of code:
> > 
> > #!/usr/bin/perl
> 
> <snip>
> 
> > What gives?
> 
> I take it that *is* the correct path to your perl executable?
> -- 
> Regards
> Dave Saville

Heh. Yes. I have several other scripts on this box all running just fine.
-- 


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

Date: Mon, 11 Jun 2012 21:26:41 +0000 (UTC)
From: pacman@kosh.dhis.org (Alan Curry)
Subject: Re: Odd behaviour on Mac OS X Lion
Message-Id: <jr5nqg$b8q$1@speranza.aioe.org>

In article <e8221ea4-b05f-46d5-96d1-f0abe78e8a37@googlegroups.com>,
Trudge  <trudge@gmail.com> wrote:
>On Monday, June 11, 2012 3:13:44 AM UTC-4, Dave Saville wrote:
>> On Mon, 11 Jun 2012 06:54:20 UTC, Trudge wrote:
>> 
>> > I've been having some odd behaviour lately on our work computer
>running the installed Apple Perl. I have the following few lines of
>code:
>> > 
>> > #!/usr/bin/perl
>> 
>> <snip>
>> 
>> > What gives?
>> 
>> I take it that *is* the correct path to your perl executable?
>> -- 
>> Regards
>> Dave Saville
>
>Heh. Yes. I have several other scripts on this box all running just fine.

There's probably something extra in the #! line, like a ^M or some Unicode
fluff, that you're not seeing because you're using the wrong editor.

-- 
Alan Curry


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

Date: Mon, 11 Jun 2012 22:29:03 +0100
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: Odd behaviour on Mac OS X Lion
Message-Id: <vh4ia9-7662.ln1@anubis.morrow.me.uk>


Quoth Trudge <trudge@gmail.com>:
> I've been having some odd behaviour lately on our work computer running
> the installed Apple Perl. I have the following few lines of code:
> 
> #!/usr/bin/perl
> BEGIN
> {
> 	open (STDERR,">>$0-err.txt");
> 	print STDERR "\n",scalar localtime,"\n";
> }
<snip>
> 
> However, there is no output to the Terminal window, and no entry is made
> in the log file. There should at least be a date/time stamp.
> 
> If I remove the 'shebang' line, the script outputs as expected, and an
> entry is made in the log file indicating the timestamp.

Are you running it with

    perl script

or with

    ./script

? If the latter, does it make a difference if you invoke perl directly?

I ask because I wonder if something is inserting a UTF-8 BOM (or some
other such invisible character) at the beginning of the file, which is
causing the kernel not to recognise the #!. Of course, I would then
expect you to get some sort of error message...

Otherwise, start with something completely minimal, like

    #!/usr/bin/perl
    1;

and add pieces of the original script until it stops working. If you get
as far as replacing the whole script, compare the two files with 'cmp'
to see if they are actually identical, and if they aren't hex-dump them
both to see what the difference is.

Ben



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

Date: Mon, 11 Jun 2012 16:30:15 -0700 (PDT)
From: Trudge <trudge@gmail.com>
Subject: Re: Odd behaviour on Mac OS X Lion
Message-Id: <a694a422-711f-4413-8494-2dc4d1a43b63@5g2000vbf.googlegroups.com>

On Jun 11, 5:29=A0pm, Ben Morrow <b...@morrow.me.uk> wrote:
> Quoth Trudge <tru...@gmail.com>:
>
>
>
>
>
>
>
>
>
> > I've been having some odd behaviour lately on our work computer running
> > the installed Apple Perl. I have the following few lines of code:
>
> > #!/usr/bin/perl
> > BEGIN
> > {
> > =A0 =A0open (STDERR,">>$0-err.txt");
> > =A0 =A0print STDERR "\n",scalar localtime,"\n";
> > }
> <snip>
>
> > However, there is no output to the Terminal window, and no entry is mad=
e
> > in the log file. There should at least be a date/time stamp.
>
> > If I remove the 'shebang' line, the script outputs as expected, and an
> > entry is made in the log file indicating the timestamp.
>
> Are you running it with
>
> =A0 =A0 perl script
>
> or with
>
> =A0 =A0 ./script
>
> ? If the latter, does it make a difference if you invoke perl directly?
>
> I ask because I wonder if something is inserting a UTF-8 BOM (or some
> other such invisible character) at the beginning of the file, which is
> causing the kernel not to recognise the #!. Of course, I would then
> expect you to get some sort of error message...
>
> Otherwise, start with something completely minimal, like
>
> =A0 =A0 #!/usr/bin/perl
> =A0 =A0 1;
>
> and add pieces of the original script until it stops working. If you get
> as far as replacing the whole script, compare the two files with 'cmp'
> to see if they are actually identical, and if they aren't hex-dump them
> both to see what the difference is.
>
> Ben

I'm running 'perl -f test.pl', but I did try your suggestion of
'perl ./test.pl' with identical results.

I'll now try your 2nd one and build it a line at a time.

btw, I'm using TextWrangler with 'Invisibles' turned on but don't see
anything strange.
--
Amer Neely


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

Date: Mon, 11 Jun 2012 17:33:46 -0700 (PDT)
From: Trudge <trudge@gmail.com>
Subject: Re: Odd behaviour on Mac OS X Lion
Message-Id: <fe917735-cc0a-4559-95a3-9b714fbdc6df@w24g2000vby.googlegroups.com>

On Jun 11, 7:30=A0pm, Trudge <tru...@gmail.com> wrote:
> On Jun 11, 5:29=A0pm, Ben Morrow <b...@morrow.me.uk> wrote:
>
>
>
>
>
>
>
>
>
> > Quoth Trudge <tru...@gmail.com>:
>
> > > I've been having some odd behaviour lately on our work computer runni=
ng
> > > the installed Apple Perl. I have the following few lines of code:
>
> > > #!/usr/bin/perl
> > > BEGIN
> > > {
> > > =A0 =A0open (STDERR,">>$0-err.txt");
> > > =A0 =A0print STDERR "\n",scalar localtime,"\n";
> > > }
> > <snip>
>
> > > However, there is no output to the Terminal window, and no entry is m=
ade
> > > in the log file. There should at least be a date/time stamp.
>
> > > If I remove the 'shebang' line, the script outputs as expected, and a=
n
> > > entry is made in the log file indicating the timestamp.
>
> > Are you running it with
>
> > =A0 =A0 perl script
>
> > or with
>
> > =A0 =A0 ./script
>
> > ? If the latter, does it make a difference if you invoke perl directly?
>
> > I ask because I wonder if something is inserting a UTF-8 BOM (or some
> > other such invisible character) at the beginning of the file, which is
> > causing the kernel not to recognise the #!. Of course, I would then
> > expect you to get some sort of error message...
>
> > Otherwise, start with something completely minimal, like
>
> > =A0 =A0 #!/usr/bin/perl
> > =A0 =A0 1;
>
> > and add pieces of the original script until it stops working. If you ge=
t
> > as far as replacing the whole script, compare the two files with 'cmp'
> > to see if they are actually identical, and if they aren't hex-dump them
> > both to see what the difference is.
>
> > Ben
>
> I'm running 'perl -f test.pl', but I did try your suggestion of
> 'perl ./test.pl' with identical results.
>
> I'll now try your 2nd one and build it a line at a time.
>
> btw, I'm using TextWrangler with 'Invisibles' turned on but don't see
> anything strange.
> --
> Amer Neely

OK, this is very strange. According to TextWrangler this is my code
for perl_test.pl:

#!/usr/bin/perl
BEGIN
{
	open (STDERR,">>$0-err.txt");
	print STDERR "\n",scalar localtime,"\n";
}

$|=3D1;
use strict;
use warnings;

my $Source=3D"/Users/prepress/Desktop/northbay_three";
my $Destination=3D"/Users/prepress/Desktop/northbay_two";
my $ext=3D"pdf";
my $f;
my @pdfs=3D();

print "Now runnng $0.\n";
print "\$Source: $Source\n";
print "\$Destination: $Destination\n";
print "\$ext: $ext\n";


*But* according to cat it is really:
Prepress-Mac-Pro:scripts prepress$ cat perl_test.pl
Prepress-Mac-Pro:scripts prepress$ n";op/northbay_two";

And then cmp tells me:
Prepress-Mac-Pro:scripts prepress$ cmp perl_test.pl perl_test.1.pl
perl_test.pl perl_test.1.pl differ: char 2, line 1

Ben, it looks like you may have hit on the culprit. Where do I go from
here?
--
Amer Neely



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

Date: Mon, 11 Jun 2012 11:31:48 -0700 (PDT)
From: GlenM <glenmillard@gmail.com>
Subject: Very Sluggish Code
Message-Id: <22849763-a23c-4d6f-a054-4d733277994d@googlegroups.com>

Hi;

I was hoping someone could help me shed some light on this.

I have a Perl script, which I will post the contents below. It seems to get 'stuck' and I have to do an actually kill of the process.

I ran it using the Perl debugger (perl -d <script.pl>) and it seems to slow right down when reading back the array.

However, it does work - it does populate the database with the XML files as it is supposed to - so, that much I know.

So, any assistance I can get. I would much appreciate the help.

++++++++++++++++++++++++++++++
#!/usr/bin/perl

#use strict;
use DBI;
use XML::XPath;
use XML::XPath::XMLParser;

# Set the input dir where all of the XML files live
my $input_dir = ".";

# Begin reading the directory
opendir(DIR, $input_dir) || die "sorry shit the bed $input_dir: $!";

# Read them into an array
my @files_in_dir = grep { /xml/ } readdir(DIR);
closedir DIR;

# connect to database and create parser object
my $dbh = DBI->connect ("DBI:mysql:can_us_ratecenters",
                           "xxxxx", "xxxxxxx",
                           { RaiseError => 1, PrintError => 0});

# clear the database - new DIDs coming in
$dbh->do ('TRUNCATE TABLE rc_city_town');

#Now the fun begins - read each file and put it in the database
foreach my $f (@files_in_dir) {
        open IN, "<$f";

my $xp = XML::XPath->new (filename => "./$f");
my $nodelist = $xp->find ("//row");
foreach my $row ($nodelist->get_nodelist ())
   {
       $dbh->do (
           "INSERT IGNORE INTO rc_city_town (state_prov, city_town, did_number) VALUES (?,?,?)",
               undef,
               $row->find ("state")->string_value (),
               $row->find ("ratecenter")->string_value (),
               $row->find ("number")->string_value (),
           );
   }
        close IN;
}
$dbh->disconnect ();

++++++++++++++++++++++++++++++++++++++++++++==


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

Date: Mon, 11 Jun 2012 22:40:55 +0100
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: Very Sluggish Code
Message-Id: <785ia9-7662.ln1@anubis.morrow.me.uk>


Quoth GlenM <glenmillard@gmail.com>:
> 
> I have a Perl script, which I will post the contents below. It seems to
> get 'stuck' and I have to do an actually kill of the process.

Is the process using a huge amount of memory at that point? Is the
system swapping?

> I ran it using the Perl debugger (perl -d <script.pl>) and it seems to
> slow right down when reading back the array.
> 
> However, it does work - it does populate the database with the XML files
> as it is supposed to - so, that much I know.
> 
> So, any assistance I can get. I would much appreciate the help.
> 
> ++++++++++++++++++++++++++++++
> #!/usr/bin/perl
> 
> #use strict;

Why is this commented out? Where is 'use warnings'?

> use DBI;
> use XML::XPath;
> use XML::XPath::XMLParser;
> 
> # Set the input dir where all of the XML files live
> my $input_dir = ".";
> 
> # Begin reading the directory
> opendir(DIR, $input_dir) || die "sorry shit the bed $input_dir: $!";

Keep your filehandles (and dirhandles) in real variables:

    opendir(my $DIR, $input_dir) || die ...;

> 
> # Read them into an array
> my @files_in_dir = grep { /xml/ } readdir(DIR);

Is this the line which goes slowly? Are there a huge number of files in
that directory (whether they match or not)? Is the directory mounted
over the network? What filesystem are you using?

This line reads the entire directory into a list in memory, then
iterates over the list matching the pattern and builds another list of
the results. You can make it more efficient by reading the entries one
at a time; replace the for loop below with

    while (my $f = readdir $DIR) {
        /xml/ or next;

        # as before
    }

> closedir DIR;
> 
> # connect to database and create parser object
> my $dbh = DBI->connect ("DBI:mysql:can_us_ratecenters",
>                            "xxxxx", "xxxxxxx",
>                            { RaiseError => 1, PrintError => 0});
> 
> # clear the database - new DIDs coming in
> $dbh->do ('TRUNCATE TABLE rc_city_town');
> 
> #Now the fun begins - read each file and put it in the database
> foreach my $f (@files_in_dir) {
>         open IN, "<$f";

Use a variable for the filehandle, as above. Also use 3-arg open, and
check the return value.

    open my $IN, "<", $f or die ...;

> 
> my $xp = XML::XPath->new (filename => "./$f");

You open the file and then do nothing with the filehandle.

> my $nodelist = $xp->find ("//row");
> foreach my $row ($nodelist->get_nodelist ())
>    {
>        $dbh->do (
>            "INSERT IGNORE INTO rc_city_town (state_prov, city_town,
> did_number) VALUES (?,?,?)",
>                undef,
>                $row->find ("state")->string_value (),
>                $row->find ("ratecenter")->string_value (),
>                $row->find ("number")->string_value (),
>            );

This will in principle go faster if you use ->prepare and ->execute
rather than ->do. I don't actually know whether DBD::mysql supports
server-side prepared statements, so it's possible this will make no
difference in practice.

>    }
>         close IN;
> }
> $dbh->disconnect ();
> 
> ++++++++++++++++++++++++++++++++++++++++++++==

Ben



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

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:

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

Back issues are available via anonymous ftp from
ftp://cil-www.oce.orst.edu/pub/perl/old-digests. 

#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 V11 Issue 3712
***************************************


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