[28290] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 9654 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sun Aug 27 14:05:40 2006

Date: Sun, 27 Aug 2006 11:05:04 -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           Sun, 27 Aug 2006     Volume: 10 Number: 9654

Today's topics:
    Re: Beginner: read $array with line breaks line by line <mstep@t-online.de>
    Re: Beginner: read $array with line breaks line by line <bik.mido@tiscalinet.it>
    Re: Beginner: read $array with line breaks line by line <hjp-usenet2@hjp.at>
        Out of memory! When running perl script on windows <felad@walla.co.il>
    Re: Out of memory! When running perl script on windows <mgarrish@gmail.com>
    Re: Out of memory! When running perl script on windows <hjp-usenet2@hjp.at>
    Re: Perl's GUI <justin.0608@purestblue.com>
    Re: regular expression variables under debugger - SOME  <mgarrish@gmail.com>
    Re: regular expression variables under debugger - SOME  <hjp-usenet2@hjp.at>
    Re: regular expression variables under debugger - SOME  <mgarrish@gmail.com>
    Re: regular expression variables under debugger - SOME  <David.Squire@no.spam.from.here.au>
    Re: regular expression variables under debugger - SOME  <David.Squire@no.spam.from.here.au>
    Re: regular expression variables under debugger - SOME  <David.Squire@no.spam.from.here.au>
    Re: regular expression variables under debugger - SOME  <wlcna@nospam.com>
        send keypress to firefox billmoroz@gmail.com
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Sun, 27 Aug 2006 18:30:18 +0200
From: Marek Stepanek <mstep@t-online.de>
Subject: Re: Beginner: read $array with line breaks line by line
Message-Id: <C117953A.2B68D%mstep@t-online.de>

On 27.08.2006 16:35, in article 5fa3f2l3f0s6rq411k8jnocih6tmcis1fu@4ax.com,
"Michele Dondi" <bik.mido@tiscalinet.it> wrote:

>  foreach my $addr (@competitions) {
>      open my $fh, '<', \$addr or die "D'Oh! $!\n";
>      local $/ = "\n";
>      while (<$fh>) {
>        # ...
>      }
>  }
> 
> BUT BEFORE I GET CHASTISED FOR POINTING YOU TO THIS "SOLUTION", let me
> tell you that you DON'T want to do so. You most probably want to
> split() on \n, instead.
> 
> 
> Michele

:-) Looks funny your trick!

Thank you Michele, Thank you Peter,


for your answers. Something is not working. I am understanding, what you
mean with split(/\n/, $addr)). But my script is hanging now! So I suppose,
the global Variable, which I inserted $_ is not working on it?

I am sure there is an obvious mistake; sorry to bother you again, which this
long script:


#! /usr/bin/perl

use strict;
use warnings;
use HTML::Entities;

$/ = undef;

my (@competitions, @complete_address);

while (<>)
  {
    foreach my $entry (m"<dd>(.+?)</dd>"g)
      {
        push (@complete_address, $entry);
      }
  }
    
foreach my $e (@complete_address)
  {
    $e =~ s!<span\s+class="comp2">([^<]+)</span>!"Competition: " . $1 .
"\n\n"!ge;
    $e =~ s!<br />!\n!g;
    $e =~ s!<[^>]+>!!g;
    push (@competitions, $e);
  }

my $out_file1 = 'letter_comp_addr_01.adr';
open OUT1, "> $out_file1" or die "Connot create your out_file: $!";
my $out_file2 = 'letter_comp_addr_02.adr';
open OUT2, ">> $out_file2" or die "Connot create your out_file: $!";

my ($competition, $email, $first_name, $last_name, $gender);
foreach my $addr (@competitions)
  {
    foreach (split(/\n/, $addr)) #<-- did I understand it well?
      {
        ($competition) = $_ =~ m"^Competition:\s+(.+)";
        $_ =~ s/^(International|National) Competition\s*$//i;
        ($gender, $first_name, $last_name) = $_ =~
/^(Mr\.?|Mrs\.?)?([A-Z][a-z]+(?:\s+[A-Z][a-z]+\.?)?)\s+([A-Z][a-z]+)\s*$/;
        if ($gender)
          {
            if ( $gender eq m/Mrs\.?/ )
              {
                $gender = "w";
              }
              elsif ( $gender eq m/Mr\.?/ )
              {
                $gender = "m";
              }
              elsif ( $gender == 'undef' )
              {
                $gender = "u";
              }
            }
        ($email) = $_ =~ m"((&#\d+;)+)";
        $email = decode_entities($email) if $email;
      }
  }

print OUT1 join ("\n\n", @competitions);
print OUT1 "\n\n";
print OUT2 "\\addrentry\n";
print OUT2 "\t{$first_name}\n" if $first_name;
print OUT2 "\t{$last_name}\n" if $last_name;
print OUT2 "\t{$competition}\n" if $competition;
print OUT2 "\t{$gender}\n" if $gender;
print OUT2 "\t{$email}\n" if $email;

close OUT1;
close OUT2;



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

Date: 27 Aug 2006 19:38:20 +0200
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: Beginner: read $array with line breaks line by line
Message-Id: <8bl3f2d0s1i710eki232hosvfqko3ut1ac@4ax.com>

On Sun, 27 Aug 2006 18:30:18 +0200, Marek Stepanek <mstep@t-online.de>
wrote:

>for your answers. Something is not working. I am understanding, what you
>mean with split(/\n/, $addr)). But my script is hanging now! So I suppose,
>the global Variable, which I inserted $_ is not working on it?

OTOH the following minimal example *does* work. So your problem must
be somewhere else.


  #!/usr/bin/perl
  
  use strict;
  use warnings;
  use Data::Dumper;
  
  $/='';
  my @got;
  push @got, [split /\n/, $_] while <DATA>;
  
  print Dumper \@got;
  
  __END__
  foo
  bar
  baz
  
  fred
  barney
  wilma


OTOH your script is (not huge but) long and *convoluted* enough for me
not to want to peek into it and find the actual problem, but...

>    foreach (split(/\n/, $addr)) #<-- did I understand it well?

Yes.

>        ($competition) = $_ =~ m"^Competition:\s+(.+)";

BTW: although valid, you don't want that. You either want 

  $explicit_var =~ m/something/;
  # or
  m/something/;

>            if ( $gender eq m/Mrs\.?/ )

Huh?!? You certainly either want 

  if ($gender eq 'Mrs') {  # ...

or

  if ($gender =~ /Mrs\.?/) {  # ...

How 'bout a %gender hash, anyway?


Michele
-- 
{$_=pack'B8'x25,unpack'A8'x32,$a^=sub{pop^pop}->(map substr
(($a||=join'',map--$|x$_,(unpack'w',unpack'u','G^<R<Y]*YB='
 .'KYU;*EVH[.FHF2W+#"\Z*5TI/ER<Z`S(G.DZZ9OX0Z')=~/./g)x2,$_,
256),7,249);s/[^\w,]/ /g;$ \=/^J/?$/:"\r";print,redo}#JAPH,


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

Date: Sun, 27 Aug 2006 19:36:53 +0200
From: "Peter J. Holzer" <hjp-usenet2@hjp.at>
Subject: Re: Beginner: read $array with line breaks line by line
Message-Id: <slrnef3m1o.c3m.hjp-usenet2@yoyo.hjp.at>

On 2006-08-27 16:30, Marek Stepanek <mstep@t-online.de> wrote:
> On 27.08.2006 16:35, in article 5fa3f2l3f0s6rq411k8jnocih6tmcis1fu@4ax.com,
> "Michele Dondi" <bik.mido@tiscalinet.it> wrote:
>
>>  foreach my $addr (@competitions) {
>>      open my $fh, '<', \$addr or die "D'Oh! $!\n";
>>      local $/ = "\n";
>>      while (<$fh>) {
>>        # ...
>>      }
>>  }
>> 
>> BUT BEFORE I GET CHASTISED FOR POINTING YOU TO THIS "SOLUTION", let me
>> tell you that you DON'T want to do so. You most probably want to
>> split() on \n, instead.
>> 
>> 
>> Michele
>
>:-) Looks funny your trick!
>
> Thank you Michele, Thank you Peter,
>
>
> for your answers. Something is not working. I am understanding, what you
> mean with split(/\n/, $addr)). But my script is hanging now!

I don't see where your script could "hang" except while reading its
input file and you didn't change that. It terminates just fine if I
invoke it as

 ./marek competitionsfunds.htm

Of course if you omit the file, it will read from STDIN, so you will
have to type in the html file :-).


> So I suppose, the global Variable, which I inserted $_ is not working
> on it?

I don't think I understand that sentence. 

>     foreach (split(/\n/, $addr)) #<-- did I understand it well?
>       {
 ...
>       }

split returns a list of the lines in $addr. The loop will run once for
each line, with $_ set to each line in turn ("for (@list)" is actually a
shorthand for "for local $_ (@list)"). So if $addr contains something
like

"Competition: Gradus ad Parnassum


National competition
Mrs. Barbara Schierl 
Musik der Jugend
Promenade 37
A-4021 Linz
Fon: +43 732772015483
 ..."

$_ will be "Competition: Gradus ad Parnassum" during the first run of
the loop, "" during the second and third, "National competition" during
the fourth, etc.


> I am sure there is an obvious mistake;

There are a few obvious mistakes in your script, but none that would
cause it to hang.

> my ($competition, $email, $first_name, $last_name, $gender);
> foreach my $addr (@competitions)
>   {
[...]
>   }
>
> print OUT1 join ("\n\n", @competitions);
> print OUT1 "\n\n";
> print OUT2 "\\addrentry\n";
> print OUT2 "\t{$first_name}\n" if $first_name;
> print OUT2 "\t{$last_name}\n" if $last_name;
> print OUT2 "\t{$competition}\n" if $competition;
> print OUT2 "\t{$gender}\n" if $gender;
> print OUT2 "\t{$email}\n" if $email;
>

There a lot of addresses in your input file, yet you write only one to your
output file. Since you wrote earlier that you wanted to create a serial
letter (question to native speakers: is serial letter the right word?),
I guess you want all of them, so you have to move the print statements
into the loop.


>     foreach (split(/\n/, $addr)) #<-- did I understand it well?
>       {
>         ($competition) = $_ =~ m"^Competition:\s+(.+)";
>         $_ =~ s/^(International|National) Competition\s*$//i;
>         ($gender, $first_name, $last_name) = $_ =~
> /^(Mr\.?|Mrs\.?)?([A-Z][a-z]+(?:\s+[A-Z][a-z]+\.?)?)\s+([A-Z][a-z]+)\s*$/;

You assign a value to the variables $competition, $gender, etc. on every
run through the loop. After the loop you will have only the information
from the last line. You should assign these variables only if the
information you look for is in the line you are currently processing,
e.g.:

    $competition = $1 if /^Competition:\s+(.+)/;

I think you are making it more difficult by splitting the
address block into lines. Just use regexps to extract the data you are
interested in from $addr;


>         if ($gender)
>           {
[...]
>               elsif ( $gender == 'undef' )

There are two errors in this line. First, the undefined value is not the
same as the string 'undef'. To check if $gender is undef you would have
to write 

                elsif ( !defined($gender) )

Second, if you really wanted to compare $gender to the string 'undef',
you would have to use the string comparison operator eq, not the
numerical comparison operator ==.

Oh, and third, if $gender is true, it has to be defined, so the test is
useless as it can never succeed.

	hp


-- 
   _  | Peter J. Holzer    | > Wieso sollte man etwas erfinden was nicht
|_|_) | Sysadmin WSR       | > ist?
| |   | hjp@hjp.at         | Was sonst wäre der Sinn des Erfindens?
__/   | http://www.hjp.at/ |	-- P. Einstein u. V. Gringmuth in desd


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

Date: 27 Aug 2006 08:30:28 -0700
From: "felad" <felad@walla.co.il>
Subject: Out of memory! When running perl script on windows
Message-Id: <1156692628.259140.275840@75g2000cwc.googlegroups.com>

Hi

I have Perl program on windows that suppose to run on about 10,000
items in a loop ( should take 2-3 days for it to run )
The problem is that after several hours I get this error:
Out of memory!
Callback called exit.

I have found that every single loop the commit memory grow by 6000 K so
I guess this is why the program crash
But I really can't find that cause of it, most of my variable are local
and I can't find any infinite loop

Any ideas ?



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

Date: 27 Aug 2006 09:00:43 -0700
From: "Matt Garrish" <mgarrish@gmail.com>
Subject: Re: Out of memory! When running perl script on windows
Message-Id: <1156694443.237194.273850@b28g2000cwb.googlegroups.com>


felad wrote:

>
> I have Perl program on windows that suppose to run on about 10,000
> items in a loop ( should take 2-3 days for it to run )
> The problem is that after several hours I get this error:
> Out of memory!
> Callback called exit.
>
> I have found that every single loop the commit memory grow by 6000 K so
> I guess this is why the program crash
> But I really can't find that cause of it, most of my variable are local
> and I can't find any infinite loop
>
> Any ideas ?

Why does it take 2-3 days to run 10,000 items? What is it that you are
doing? Are you calling some other program that has a memory leak? Are
you appending data to a variable that doesn't get reset with each
iteration of the loop?

It's nearly impossible to give you any meaningful advice if you don't
give specifics and show some code.

Matt



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

Date: Sun, 27 Aug 2006 18:16:01 +0200
From: "Peter J. Holzer" <hjp-usenet2@hjp.at>
Subject: Re: Out of memory! When running perl script on windows
Message-Id: <slrnef3ha4.asm.hjp-usenet2@yoyo.hjp.at>

On 2006-08-27 15:30, felad <felad@walla.co.il> wrote:
> I have found that every single loop the commit memory grow by 6000 K so
> I guess this is why the program crash
> But I really can't find that cause of it, most of my variable are local
> and I can't find any infinite loop
>
> Any ideas ?

First, check that you aren't creating cyclic data structures: The perl
garbage collector cannot free cyclic data structures. If you really need
them, use weak references or destroy them explicitely after you are done
with them.

Second, lexical variables aren't freed immediately after they go out of
scope but only after the function returns. So if you create large
temporary variables, use them inside functions, not in the main program.

Third, modules which may be helpful: Devel::Cycle, Devel::Leak.

Fourth, perl has quite a bit overhead for each object: If you must keep
lots of data in memory, try to keep few large objects instead of many
little ones.

	hp

-- 
   _  | Peter J. Holzer    | > Wieso sollte man etwas erfinden was nicht
|_|_) | Sysadmin WSR       | > ist?
| |   | hjp@hjp.at         | Was sonst wäre der Sinn des Erfindens?
__/   | http://www.hjp.at/ |	-- P. Einstein u. V. Gringmuth in desd


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

Date: Sun, 27 Aug 2006 16:50:52 -0000
From: Justin C <justin.0608@purestblue.com>
Subject: Re: Perl's GUI
Message-Id: <slrnef3j9i.8c0.justin.0608@moonlight.purestblue.com>

On 2006-08-27, zentara <zentara@highstream.net> wrote:
> On Sat, 26 Aug 2006 17:37:03 +0100, Ben Morrow <benmorrow@tiscali.co.uk>
> wrote:
>>
>>It's not a problem: that's the *whole* *point*. You shouldn't be messing
>>about making everything silly colours: it just makes things harder for
>>your users.
>
> Why does making a textbox with a black background, (which is easier on
> the eyes), make things hard for the user?
>
> I was chastised by other Perl/Gtk2 users for saying this, and their
> reason was that "themes" should never be tampered with..... like
> some mantra learned in CS classes.

Because the user's theme may be set because of visual impairment or some
other accessibility problem. It's none of anyone's business what or how
any else themes their system, and no one should go around messing with
that.

	Justin.

-- 
Justin C, by the sea. 


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

Date: 27 Aug 2006 08:39:36 -0700
From: "Matt Garrish" <mgarrish@gmail.com>
Subject: Re: regular expression variables under debugger - SOME RESOLUTION!
Message-Id: <1156693176.078331.172570@h48g2000cwc.googlegroups.com>


David Squire wrote:

>
> I think that the lesson of this thread is that both sides of the
> discussion got angry early, with the result that very few people
> actually read deeply or tried things. Once the insults and name-calling
> starts, the chances of analysis and help drop dramatically. There are
> lessons for both sides here.
>

You got that part right, but it's not a burden on any of us to be
responsive to an ass, which is what this fellow has proven to be time
and again in this thread. Hopefully this person will learn from your
example on how to properly diagnose and report a problem, though.

Matt



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

Date: Sun, 27 Aug 2006 17:39:50 +0200
From: "Peter J. Holzer" <hjp-usenet2@hjp.at>
Subject: Re: regular expression variables under debugger - SOME RESOLUTION!
Message-Id: <slrnef3f68.86f.hjp-usenet2@yoyo.hjp.at>

On 2006-08-27 13:54, David Squire <David.Squire@no.spam.from.here.au> wrote:
> Matt Garrish wrote:
>> If you can't write a minimal script to do this then, gee, perhaps you
>> haven't really found a bug in perl.
>
> This is not true. wlcna *did* post scripts that exhibit a problem.

He did post scripts, and he claimed that they exhibit the problem. He
didn't show that they did, however (the behaviour depends on the
contents of the variable $str, and since that in turn depends on the
successful retrieval and contents of a web page, and he didn't print it,
we didn't know whether it did contain what he thinks it contained).

I also ran his scripts and could not reproduce the behaviour. I also ran
your scripts with and without the debugger with perl 5.8.4 (debian sarge
package) and 5.8.8 (compiled from source) and couldn't reproduce the
problem, either.

[Excerpts from your transscripts:]
> main::(test_with_HTML::TreeBuilder.pl:20):
> 20:     print "\$str = $str\n";
>  
>             DB<1> n
> $str = Yahoo! News: U.S. News


> main::(test_with_XML::TreeBuilder.pl:21):
> 21:     print "\$str = $str\n";
>  
>             DB<1> n
> $str = Yahoo! News: U.S. News

These do look the same, but what happens when you replace the print with

dumpstr($str);
sub dumpstr {
    my ($s) = @_;
    print utf8::is_utf8($s) ? "char" : "byte", " string: ";
    for (split(//, $s)) {
        printf("%#x %s  ", ord($_), /[[:print:]]/ ? $_ : '.');
    }
    print "\n";
}

?

On my system test_with_HTML::TreeBuilder prints:

byte string: 0x59 Y  0x61 a  0x68 h  0x6f o  0x6f o  0x21 !  0x20
0x4e N  0x65 e  0x77 w  0x73 s  0x3a :  0x20    0x55 U  0x2e .  0x53 S
0x2e .  0x20    0x4e N  0x65 e  0x77 w  0x73 s  

but test_with_XML::TreeBuilder prints:

char string: 0x59 Y  0x61 a  0x68 h  0x6f o  0x6f o  0x21 !  0x20
0x4e N  0x65 e  0x77 w  0x73 s  0x3a :  0x20    0x55 U  0x2e .  0x53 S
0x2e .  0x20    0x4e N  0x65 e  0x77 w  0x73 s  

So one returns a byte string and the other a character string. Perl
should handle both identically, but maybe yours and the OP's doesn't. 

So there is an even simpler (Look Ma! No TreeBuilder!) script to test
this:

----- test_without_TreeBuilder ---------------------------------
#!/usr/local/bin/perl

use strict;
use warnings;

my $str = 'Yahoo! News: U.S. News';
utf8::upgrade($str);
dumpstr($str);
($str =~ /(.*)news/i) or warn "No match!\n";
my $testPart = $1;
my $testWhole = $&;

my $breakpoint = 3;
print "testPart: <$testPart>, testWhole: <$testWhole>\n";

sub dumpstr {
    my ($s) = @_;
    print utf8::is_utf8($s) ? "char" : "byte", " string: ";
    for (split(//, $s)) {
	printf("%#x %s  ", ord($_), /[[:print:]]/ ? $_ : '.');
    }
    print "\n";
}
----------------------------------------------------------------

> I think that the lesson of this thread is that both sides of the
> discussion got angry early, with the result that very few people
> actually read deeply or tried things. Once the insults and
> name-calling starts, the chances of analysis and help drop
> dramatically.

ACK. I did run the OP's script but by then the thread had degenerated
into name-calling and since I couldn't reproduce the problem I didn't
see much value in posting my results.

> First and foremost, if you *have* done tests to eliminate cases such as 
> regexes not matching, leave them in the minimal example script so that 
> folks don't leap on that common newbie error as the likely explanation 
> for the problem.

Right. This is especially important if your script reads data from an
external source. If you get data from a web page and don't test if that
was actually successful, most people (myself included) will assume that
the retrieval of the web page failed and not that there is a bug in
perl, as the former is far more likely.

	hp


-- 
   _  | Peter J. Holzer    | > Wieso sollte man etwas erfinden was nicht
|_|_) | Sysadmin WSR       | > ist?
| |   | hjp@hjp.at         | Was sonst wäre der Sinn des Erfindens?
__/   | http://www.hjp.at/ |	-- P. Einstein u. V. Gringmuth in desd


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

Date: 27 Aug 2006 08:53:44 -0700
From: "Matt Garrish" <mgarrish@gmail.com>
Subject: Re: regular expression variables under debugger - SOME RESOLUTION!
Message-Id: <1156694024.784044.247230@i3g2000cwc.googlegroups.com>


David Squire wrote:

>
> #!/usr/bin/perl
>
> use strict;
> use warnings;
>
> # *SECOND* XML and RSS VERSION
> use LWP::Simple;
> use XML::TreeBuilder;
>
> my $strUrl = 'http://rss.news.yahoo.com/rss/us';
>
> # retrieve
> my $strHtml = get( $strUrl );
>
> # parse the data retrieved.
> my $t = new XML::TreeBuilder;
> $t->parse( $strHtml );
> $t->eof;
>
> my $str = $t->content->[1]->content->[1]->as_text;
> print "\$str = $str\n";
> ($str =~ /(.*)news/i) or warn "No match!\n";
> my $testPart = $1;
> my $testWhole = $&;
>
> my $breakpoint = 3;
> print "testPart: <$testPart>, testWhole: <$testWhole>\n";
>

>
>             DB<1> n
> perl(4560) malloc: *** vm_allocate(size=4291080192) failed (error code=3)
> perl(4560) malloc: *** error: can't allocate region
> perl(4560) malloc: *** set a breakpoint in szone_error to debug
> Out of memory!
> Debugged program terminated.  Use q to quit or R to restart,

>
> Now, I know next to nothing about using the Perl debugger, but the
> behaviour above is not what I would have expected. If this is because I
> don't know how to use the debugger, I will be glad to be informed of how
> to do it properly.
>

I tried your code above, and can't reproduce the malloc error in the
debugger or out (on ActivePerl 5.8.8 build 817) . Of course, going back
to the OPs original question, this was never an issue. He seemed to be
having some problem with undefined variables that he never proved was
anything.

Matt



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

Date: Sun, 27 Aug 2006 17:19:22 +0100
From: David Squire <David.Squire@no.spam.from.here.au>
Subject: Re: regular expression variables under debugger - SOME RESOLUTION!
Message-Id: <ecsgma$p7$1@gemini.csx.cam.ac.uk>

Peter J. Holzer wrote:
> On 2006-08-27 13:54, David Squire <David.Squire@no.spam.from.here.au> wrote:
> 
> I also ran his scripts and could not reproduce the behaviour. I also ran
> your scripts

Well, they're the OP's scripts, with a few little additions of mine.

> with and without the debugger with perl 5.8.4 (debian sarge
> package) and 5.8.8 (compiled from source) and couldn't reproduce the
> problem, either.
> 
> [Excerpts from your transscripts:]
>> main::(test_with_HTML::TreeBuilder.pl:20):
>> 20:     print "\$str = $str\n";
>>  
>>             DB<1> n
>> $str = Yahoo! News: U.S. News
> 
> 
>> main::(test_with_XML::TreeBuilder.pl:21):
>> 21:     print "\$str = $str\n";
>>  
>>             DB<1> n
>> $str = Yahoo! News: U.S. News
> 
> These do look the same, but what happens when you replace the print with
> 
> dumpstr($str);
> sub dumpstr {
>     my ($s) = @_;
>     print utf8::is_utf8($s) ? "char" : "byte", " string: ";
>     for (split(//, $s)) {
>         printf("%#x %s  ", ord($_), /[[:print:]]/ ? $_ : '.');
>     }
>     print "\n";
> }
> 
> ?
> 
> On my system test_with_HTML::TreeBuilder prints:
> 
> byte string: 0x59 Y  0x61 a  0x68 h  0x6f o  0x6f o  0x21 !  0x20
> 0x4e N  0x65 e  0x77 w  0x73 s  0x3a :  0x20    0x55 U  0x2e .  0x53 S
> 0x2e .  0x20    0x4e N  0x65 e  0x77 w  0x73 s  
> 
> but test_with_XML::TreeBuilder prints:
> 
> char string: 0x59 Y  0x61 a  0x68 h  0x6f o  0x6f o  0x21 !  0x20
> 0x4e N  0x65 e  0x77 w  0x73 s  0x3a :  0x20    0x55 U  0x2e .  0x53 S
> 0x2e .  0x20    0x4e N  0x65 e  0x77 w  0x73 s  
> 
> So one returns a byte string and the other a character string. Perl
> should handle both identically, but maybe yours and the OP's doesn't. 
> 

Ah. My hunch was that this was an encoding issue, especially since the 
OP reported something about utf8_heavy.pl earlier in the thread (which 
seemed to be related to the earlier "$1 undefined" issue). I have never 
played around with encodings though, so I thought it best to wait for 
someone else to jump in :)

The debugger "Out of Memory" error is a real beauty though.

BTW my Perl (today) is the Mac OS X out-of-the box one.


DS


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

Date: Sun, 27 Aug 2006 17:34:23 +0100
From: David Squire <David.Squire@no.spam.from.here.au>
Subject: Re: regular expression variables under debugger - SOME RESOLUTION!
Message-Id: <ecshig$2av$1@gemini.csx.cam.ac.uk>

Peter J. Holzer wrote:
> 
> So there is an even simpler (Look Ma! No TreeBuilder!) script to test
> this:
> 
> ----- test_without_TreeBuilder ---------------------------------
> #!/usr/local/bin/perl
> 
> use strict;
> use warnings;
> 
> my $str = 'Yahoo! News: U.S. News';
> utf8::upgrade($str);
> dumpstr($str);
> ($str =~ /(.*)news/i) or warn "No match!\n";
> my $testPart = $1;
> my $testWhole = $&;
> 
> my $breakpoint = 3;
> print "testPart: <$testPart>, testWhole: <$testWhole>\n";
> 
> sub dumpstr {
>     my ($s) = @_;
>     print utf8::is_utf8($s) ? "char" : "byte", " string: ";
>     for (split(//, $s)) {
> 	printf("%#x %s  ", ord($_), /[[:print:]]/ ? $_ : '.');
>     }
>     print "\n";
> }
> ----------------------------------------------------------------
 >

Interesting. This gives different, but still unexpected behaviour for me 
when run under the debugger (no problems when run with out it):

---- Start transcript ----

~/tmp (davids : dms54)
Aug 27 - 17:26 % perl -d test_without_TreeBuilder.pl

Loading DB routines from perl5db.pl version 1.28
Editor support available.

Enter h or `h h' for help, or `man perldebug' for more help.

main::(test_without_TreeBuilder.pl:6):
6:      my $str = 'Yahoo! News: U.S. News';
   DB<1> n 

main::(test_without_TreeBuilder.pl:7):
7:      utf8::upgrade($str);
   DB<1> n 

main::(test_without_TreeBuilder.pl:8):
8:      dumpstr($str);
   DB<1> n 

char string: 0x59 Y  0x61 a  0x68 h  0x6f o  0x6f o  0x21 !  0x20 
0x4e N  0x65 e  0x77 w  0x73 s  0x3a :  0x20    0x55 U  0x2e .  0x53 S 
0x2e .  0x20    0x4e N  0x65 e  0x77 w  0x73 s
main::(test_without_TreeBuilder.pl:9):
9:      ($str =~ /(.*)news/i) or warn "No match!\n";
   DB<1> n

---- End transcript ---- 


It never returned from that state (well, not yet :), and it's been going 
for ~3 minutes). top shows that perl is running and taking up about 
30-40% of my CPU, but is not growing in size.

I always have the DarwinPorts version of perl installed, which is:

----

~/tmp (davids : dms54)
Aug 27 - 17:30 % /opt/local/bin/perl -v

This is perl, v5.8.8 built for darwin-2level

----

With this version, there is no error running test_without_TreeBuilder.pl 
under the debugger. The out-of-the-box Mac OS X perl is:

----

~/tmp (davids : dms54)
Aug 27 - 17:30 % perl -v

This is perl, v5.8.6 built for darwin-thread-multi-2level
(with 2 registered patches, see perl -V for more detail)

----

So I guess this is a problem that either went away in 5.8.8, or is 
related to multithreading.


DS


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

Date: Sun, 27 Aug 2006 17:36:15 +0100
From: David Squire <David.Squire@no.spam.from.here.au>
Subject: Re: regular expression variables under debugger - SOME RESOLUTION!
Message-Id: <ecshlv$2av$2@gemini.csx.cam.ac.uk>

David Squire wrote:

> I always have the DarwinPorts version of perl installed, which is:

s/always/also/


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

Date: Sun, 27 Aug 2006 17:44:22 GMT
From: "wlcna" <wlcna@nospam.com>
Subject: Re: regular expression variables under debugger - SOME RESOLUTION!
Message-Id: <WRkIg.12404$1f6.3411@newssvr27.news.prodigy.net>


"David Squire" <David.Squire@no.spam.from.here.au> wrote in message 
news:ecshig$2av$1@gemini.csx.cam.ac.uk...
> Interesting. This gives different, but still unexpected behaviour for 
> me when run under the debugger (no problems when run with out it):
> ...

EXTREMELY INTERESTING.  So I guess my "lightning" and someone else's 
"acorn" have been eliminated as explanations.  But still looks like an 
issue hopefully entirely resolved by latest version.

FYI, as reported previously I tried this under 5.8.7 under Windows and 
did not see the problem but right now I also just reinstalled the 
universe from source under Linux and didn't see the problem there 
either.  Hopefully that's the status, but I'm keeping my eye on it. 




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

Date: 27 Aug 2006 10:35:38 -0700
From: billmoroz@gmail.com
Subject: send keypress to firefox
Message-Id: <1156700138.903565.324510@75g2000cwc.googlegroups.com>

I spent the last few days trying to figure this out.. but am at a dead
end.

What I want to do is interact with a website that uses javascript.
Specifically it uses document.onkeypress to wait for key presses.   My
goal is to first send a "T", five seconds later send a "U", then loop
it 2 times.

I am using Firefox as the browser, and this is on Ubuntu linux.  I
looked at doing a javascript for this via greasemonkey.mozdev.org, but
could not find a way for js to send keypresses.  Also tried to code
something via glade/gtk on gnome, but came a bit complex too quickly.

I am wondering if this is doable with Perl, and if so how should I go
about doing this?  If anyone can steer me in the right direction, I'd
be most appreciative!



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

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


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