[30131] in Perl-Users-Digest
Perl-Users Digest, Issue: 1374 Volume: 11
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Mar 19 21:10:22 2008
Date: Wed, 19 Mar 2008 18:09:12 -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 Wed, 19 Mar 2008 Volume: 11 Number: 1374
Today's topics:
Re: called too early to check prototype at <test@example.com>
Re: DBD::ODBC as "middleware" between Crystal Reports a <dh1760@gmail.com>
Re: FAQ 6.5 How do I substitute case insensitively on t <brian.d.foy@gmail.com>
Re: FAQ 6.5 How do I substitute case insensitively on t <hjp-usenet2@hjp.at>
Re: Hell of a time extracting bits from a vector <idgarad@gmail.com>
Re: Is substr only way of getting nth character of stri <see.my.signature@for.my.email.address>
Re: Is substr only way of getting nth character of stri <uri@stemsystems.com>
Re: Is substr only way of getting nth character of stri <see.my.signature@for.my.email.address>
Re: Is substr only way of getting nth character of stri <uri@stemsystems.com>
Re: Is substr only way of getting nth character of stri <benkasminbullock@gmail.com>
Re: Is substr only way of getting nth character of stri <benkasminbullock@gmail.com>
Re: problem starting perl script from cron environment <michael.andrassy@gmail.com>
Re: problem starting perl script from cron environment <nospam@com.invalid>
Re: Problem with loop control LAST exiting prematurely <hitodenashi@alexandria.cc>
Re: Problem with loop control LAST exiting prematurely <uri@stemsystems.com>
Re: Problem with loop control LAST exiting prematurely <brian.helterline@hp.com>
segfault in perl <mikee@mikee.ath.cx>
Re: segfault in perl <joost@zeekat.nl>
Re: segfault in perl xhoster@gmail.com
Re: segfault in perl <mikee@mikee.ath.cx>
Re: segfault in perl <mikee@mikee.ath.cx>
very strange bug (in perl?) dummy@phony.info
Re: very strange bug (in perl?) <benkasminbullock@gmail.com>
Re: very strange bug (in perl?) <noreply@gunnar.cc>
Re: XML Parsing in Perl <tadmc@seesig.invalid>
Re: XML Parsing in Perl <benkasminbullock@gmail.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Wed, 19 Mar 2008 20:45:37 GMT
From: Ron Eggler <test@example.com>
Subject: Re: called too early to check prototype at
Message-Id: <RXeEj.92107$FO1.85304@edtnps82>
Jürgen Exner wrote:
> for(@dbset){
> my $myDBI = "DBI:mysql:$_ :localhost";
Alright,
Thanks for that but when i try it like this:
#
# Open the DB connection
#
my @dbset=(xmlparse($nemsconf,"DBNAME"));
print "DB name: ". xmlparse($nemsconf,"DBNAME")."\n";
#for(my $count = 0; $count < scalar(@dbset); $count++){
# my $myDBI = 'DBI:mysql:' . $dbset[$count] . ':localhost';
for(@dbset){
my $myDBI = "DBI:mysql:$_ :localhost";
my $dbh =
DBI->connect($myDBI,xmlparse($nemsconf,"DBUSER"),xmlparse($nemsconf,"DBPASS"))
or die "Couldn't connect to database: " . DBI->errstr . "\n";
}
It's telling me only:
[shell]
DB name: toronto
DBI connect('toronto :localhost','root',...) failed: Incorrect database
name 'toronto ' at ./log_parser.pl line 39
Couldn't connect to database: Incorrect database name 'toronto '
[/shell]
eventho i can connect nicely with:
mysql -u root -p toronto
any idea what could be wrong there?
I first thought where it says "Couldn't connect to database: Incorrect
database name 'toronto '" that would be a mistake because of the space at
the end but when I hardcode "toronto" it is displaaying it the same way. So
I'm pretty stuck here.
Thanks for any further help!
--
Ron
------------------------------
Date: Wed, 19 Mar 2008 17:42:02 -0700 (PDT)
From: Dave Hammond <dh1760@gmail.com>
Subject: Re: DBD::ODBC as "middleware" between Crystal Reports and MySQL
Message-Id: <9942aa7c-783b-455d-88d5-938bcd61ec65@8g2000hsu.googlegroups.com>
On Mar 18, 3:52 pm, Ben Morrow <b...@morrow.me.uk> wrote:
> Quoth Dave Hammond <dh1...@gmail.com>:
>
>
>
> > For those who are thinking "just install the MySQL ODBC driver and
> > point Crystal to it", bear with me...
>
> > Most users connect to our MySQL databases via web applications. The
> > web apps and databases live on hosts which are in a "DMZ" segment of
> > our network, thus protecting our LAN from any direct Internet access.
> > However, in addition to the web apps, some power users useCrystal> Reportsto directly access the databases, in exactly the manner you
> > might have assumed -- via the MySQL ODBC driver.
>
> > We have been tasked with moving the MySQL databases off the DMZ hosts
> > and into the LAN. This won't cause problems for the web apps, however
> > the Crystal users will be S.O.L. unless we can install some kind of
> > middleware app which lives in the DMZ and shuttles data between
> > Crystal and the MySQL databases.
>
> > I was thinking that we might be able to use DBD::ODBC for such an
> > app. Ideally, Crystal would connect to the middleware app via
> > DBD::ODBC, the app would validate and forward the SQL query to the
> > MySQL server, and then shuttle the results back to Crystal.
>
> > Does anyone have any comments on if something like this would be do-
> > able with DBD::ODBC? Or, maybe I'm trying to reinvent the wheel and
> > there is something already existing which does what we need?
>
> No, you've got your thinking backwards. DBD::ODBC is an ODBC *client*:
> that is, it runs at the application end of the connection. What you want
> is an ODBC-capable *server*: something that runs at the database end, so
> Crystal can talk to it. DBIx::MyServer allows you to create a fake MySQL
> server that forwards all requests to another database; in combination
> with the MySQL ODBC driver at the Crystal end, this may do what you
> need.
>
> Ben
Well, only as regards using DBD::ODBC ... the project concept itself
seems reasonable enough :-) That aside, your pointer to
DBIx::MyServer looks to be just what I need. Thanks very much.
-Dave H.
------------------------------
Date: Wed, 19 Mar 2008 15:30:40 -0500
From: brian d foy <brian.d.foy@gmail.com>
Subject: Re: FAQ 6.5 How do I substitute case insensitively on the LHS while preserving case on the RHS?
Message-Id: <190320081530405540%brian.d.foy@gmail.com>
In article <47E0ECFC.8000300@gmx.de>, Achim Peters <achimpeters@gmx.de>
wrote:
> brian d foy schrieb:
> > Yes, using $a outside of a sort subroutine is now bad form. It's not
> > wrong, just bad practice. It wasn't always a bad practice though,
>
> Interesting. You mean, $a and $b got their special meaning later in the
> process of developing the perl language?
No, I mean that people didn't pay attention to using $a or $b outside
of a sort black. The best practice came later, as they always do.
------------------------------
Date: Wed, 19 Mar 2008 15:16:33 +0100
From: "Peter J. Holzer" <hjp-usenet2@hjp.at>
Subject: Re: FAQ 6.5 How do I substitute case insensitively on the LHS while preserving case on the RHS?
Message-Id: <slrnfu2821.sc8.hjp-usenet2@hrunkner.hjp.at>
On 2008-03-19 10:37, Achim Peters <achimpeters@gmx.de> wrote:
> brian d foy schrieb:
>> In article <47DE486E.9060102@gmx.de>, Achim Peters <achimpeters@gmx.de>
>> wrote:
>>
>>> PerlFAQ Server schrieb:
>>
>>>> 6.5: How do I substitute case insensitively on the LHS while preserving
>>>> case on the RHS?
>>
>>>> $a = "this is a TEsT case";
>>> I thought, $a should _NEVER_ be used as variable name, even not in
>>> examples, except when in sorting context?
>>
>> Yes, using $a outside of a sort subroutine is now bad form. It's not
>> wrong, just bad practice. It wasn't always a bad practice though,
>
> Interesting. You mean, $a and $b got their special meaning later in the
> process of developing the perl language?
I don't know if sort was in perl 1.0. It's pretty old, though. But $a
and $b got "more special" with the introduction of lexical variables and
use strict (perl 5.0?) and "worse practice" as it became good practice
to always use strict and lexical variables.
I agree that $a should be changed to $s (or some other non-special
variable) in the FAQ.
hp
------------------------------
Date: Wed, 19 Mar 2008 06:10:56 -0700 (PDT)
From: Idgarad <idgarad@gmail.com>
Subject: Re: Hell of a time extracting bits from a vector
Message-Id: <57dbe3cd-4370-49bc-90d5-76666ee45391@b64g2000hsa.googlegroups.com>
On Mar 13, 9:40=A0am, Ben Morrow <b...@morrow.me.uk> wrote:
> Quoth Idgarad <idga...@gmail.com>:
>
>
>
> > Exactly what I was looking for with one exception, I don't want to
> > store the ASCII in the array but rather the actual integer value.
>
> > my @somearray =3D unpack '(a2)*', unpack 'B*', sha1( $data );
>
> > Works perfect but I tried changing the a2 to N or n but that fails
> > miserable. I figure I have to append an bin to int of some sort to the
> > front of the unpacks but so far I have been unsuccessful. Any
> > suggestions?
>
> The obvious way is to add
>
> =A0 =A0 map { oct "0b$_" }
>
> to the front; there may be a cleverer way with pack, but if you don't
> need speed that's nice and simple.
>
> Ben
Worked like a charm, thank ya!
------------------------------
Date: Wed, 19 Mar 2008 13:31:39 -0800
From: "Robbie Hatley" <see.my.signature@for.my.email.address>
Subject: Re: Is substr only way of getting nth character of string?
Message-Id: <sKSdnSVsRf685XzanZ2dnUVZ_q2hnZ2d@giganews.com>
Tad J McClellan wrote:
> my @Charset = split //, $Charset; # 2 diff variables with similar names...
Now that's cool! Looks to me like its using the empty string between
each character as a delimiter to chop the string into 1-character-long
substrings. I'd never have thought of that. Thanks!
--
Cheers,
Robbie Hatley
lonewolf aatt well dott com
www dott well dott com slant user slant lonewolf slant
------------------------------
Date: Wed, 19 Mar 2008 22:06:48 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: Is substr only way of getting nth character of string?
Message-Id: <x7skymbc7c.fsf@mail.sysarch.com>
>>>>> "RH" == Robbie Hatley <see.my.signature@for.my.email.address> writes:
RH> Tad J McClellan wrote:
>> my @Charset = split //, $Charset; # 2 diff variables with similar names...
RH> Now that's cool! Looks to me like its using the empty string between
RH> each character as a delimiter to chop the string into 1-character-long
RH> substrings. I'd never have thought of that. Thanks!
you can also do that with a grabbing regex:
my @chars = $charset =~ /(.)/gs ; # /s allows for . to match \n
and for several of your char sets you can directly generate them with
the range (..) operator:
my @lower = 'a' .. 'z' ;
my @upper = 'A' .. 'Z' ;
my @digits = '0' .. '9' ;
my $Symbols = "`~!@#$%^&*()-_=+[{]}\\|;:\'\",<.>/?"; # symbols (32)
use an alternate delimiter for that:
my $symbols = q{`~!@#$%^&*()-_=+[]{}\\|;:'",<.>/?}; # symbols (32)
note that i didn't escape {} since i rearranged them to nest
properly. the only char that must be escaped is \
you can also directly split (as shown above) or grab the symbols chars
into an array.
my @symbols = q{`~!@#$%^&*()-_=+[]{}\\|;:'",<.>/?} =~ /(.)/g ;
my $White = "\11\40"; # tab, space ( 2)
perl has escape codes for tab. and no one codes space as octal.
my @white = ( "\t", ' ' ) ;
my $Charset = $Lower.$Upper.$Digits.$Symbols.$White; # total: (96)
since i have all the chars in arrays now, you can combine them into one
array:
my @charset = ( @lower, @upper, @digits, @symbols, @white ) ;
and finally you can even put them together without the temp vars:
my @charset = ( 'a' .. 'z',
'A' .. 'Z',
'0' .. '9',
q{`~!@#$%^&*()-_=+[]{}\\|;:'",<.>/?} =~ /(.)/g,
"\t", ' '
) ;
as for getting random chars out of them here are some simple subs you
can use. i set up the data differently but you can change them to your
needs. this came from the test data generator of Sort::Maker on cpan.
my @alpha_digit = ( 'a' .. 'z', 'A' .. 'Z', '0' .. '9' ) ;
my @alpha = ( 'a' .. 'z', 'A' .. 'Z' ) ;
my @bytes = ( "\x00" .. "\xff" ) ;
sub rand_token {
rand_string( \@alpha_digit, @_ ) ;
}
sub rand_alpha {
rand_string( \@alpha, @_ ) ;
}
sub rand_bytes {
rand_string( \@bytes, @_ ) ;
}
sub rand_string {
my( $char_set, $min_len, $max_len ) = @_ ;
$min_len ||= 8 ;
$max_len ||= $min_len ;
my $length = $min_len + int rand( $max_len - $min_len + 1 ) ;
return join '', map $char_set->[rand @{$char_set}], 1 .. $length ;
}
uri
--
Uri Guttman ------ uri@stemsystems.com -------- http://www.sysarch.com --
----- Perl Code Review , Architecture, Development, Training, Support ------
--------- Free Perl Training --- http://perlhunter.com/college.html ---------
--------- Gourmet Hot Cocoa Mix ---- http://bestfriendscocoa.com ---------
------------------------------
Date: Wed, 19 Mar 2008 16:48:23 -0800
From: "Robbie Hatley" <see.my.signature@for.my.email.address>
Subject: Re: Is substr only way of getting nth character of string?
Message-Id: <D96dnUEwsbujO3zanZ2dnUVZ_j2dnZ2d@giganews.com>
Uri Guttman wrote:
> my @chars = $charset =~ /(.)/gs ; # /s allows for . to match \n
So that's basically the "m" operator, with the actual "m" elided?
I can see it's matching "any one character. But why the parentheses,
as we don't need backreferences? And i'm not seeing how that's going
to chop the string into characters... unless the "global" flag causes
the m//g operator to be run multiple times, returning a list.
> (elide alternate ways of generating arrays for lower, upper, etc.)
Thanks, but the only array I really need is the entire 96-character
character set. The reason is, I'm re-implimenting an existing
C++ encryption/decryption program in Perl, both for training myself
in Perl, and because it really should have been done in Perl to start
with.
This is based on the absurdly simple concept of "ROT13", with a few
twists. For one, it's ROT48, since I'm using a 96-character set
consisting of all 94 glphical characters on a std keyboard, plus
space and tab.
BUT, I start with a random permutation of that character set,
find the index of an incoming character, rotate the index by
48, and output. Since it's a cyclic abelian group of even order,
it's invertable, so ROT48(ROT48("One two three!")) == "One two three!"
HOWEVER, since there's 96! different keys, small encrypted messages
are nearly impossible to break.
(I'm also using a closely-related technique at work to encrypt
autorization keys for our software and firmware products.)
And if I use an array of permuted arrays, so that each character has
a differnet encoding scheme, I have a "one time pad", which even
the NSA can't break.
> my $White = "\11\40"; # tab, space ( 2)
>
> perl has escape codes for tab. and no one codes space as octal.
>
> my @white = ( "\t", ' ' ) ;
Yes, but I prefer octal. :-) (True, that only works with ASCII,
but this is an ASCII-only program by its vary nature.)
> since i have all the chars in arrays now, you can combine them into one
> array:
>
> my @charset = ( @lower, @upper, @digits, @symbols, @white ) ;
Yep, I could put everything in little arrays and join them like that...
or put them in strings, paste the strings together, and convert the
final string to an array. Either would work.
I think I like your arrays idea, so i'll go with that. I doubt I'll
need the small arrays after concatenating... but at least they'd be
available.
> and finally you can even put them together without the temp vars:
>
> my @charset = ( 'a' .. 'z',
> 'A' .. 'Z',
> '0' .. '9',
> q{`~!@#$%^&*()-_=+[]{}\\|;:'",<.>/?} =~ /(.)/g,
> "\t", ' '
> ) ;
I've read about the ".." operater in the Camel book, but I found
the description quite confusing. What exactly is that beast doing,
anyway? Just creating ranges of values?
> (elide random stuff)
Thanks for the tips.
--
Cheers,
Robbie Hatley
lonewolf aatt well dott com
www dott well dott com slant user slant lonewolf slant
------------------------------
Date: Thu, 20 Mar 2008 00:06:39 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: Is substr only way of getting nth character of string?
Message-Id: <x7fxum9s35.fsf@mail.sysarch.com>
>>>>> "RH" == Robbie Hatley <see.my.signature@for.my.email.address> writes:
RH> Uri Guttman wrote:
>> my @chars = $charset =~ /(.)/gs ; # /s allows for . to match \n
RH> So that's basically the "m" operator, with the actual "m" elided?
RH> I can see it's matching "any one character. But why the parentheses,
RH> as we don't need backreferences? And i'm not seeing how that's going
RH> to chop the string into characters... unless the "global" flag causes
RH> the m//g operator to be run multiple times, returning a list.
it is the // operator. m// is only needed if you use alternate
delimiters. read perlre on grabbing. in a list context (assigning to the
array) the /g modifier will return all the grabs. don't call grabs
backreferences - that is only when you do a \1 inside the regex which is
rare.
>> (elide alternate ways of generating arrays for lower, upper, etc.)
RH> Thanks, but the only array I really need is the entire 96-character
RH> character set. The reason is, I'm re-implimenting an existing
RH> C++ encryption/decryption program in Perl, both for training myself
RH> in Perl, and because it really should have been done in Perl to start
RH> with.
sure but i showed you ways to make the arrays with less code and
cleaner. typing in the alphabet is more error prone than just 'a' and 'z'.
RH> I've read about the ".." operater in the Camel book, but I found
RH> the description quite confusing. What exactly is that beast doing,
RH> anyway? Just creating ranges of values?
.. is really 2 different operators both called range and selected by
context. the list context .. is just a range of values from the left
(low) to the right (high). it works with integers or char strings (which
need to match a special pattern) by using magic autoincrement. again,
read the docs for more (perldoc perlop).
uri
--
Uri Guttman ------ uri@stemsystems.com -------- http://www.sysarch.com --
----- Perl Code Review , Architecture, Development, Training, Support ------
--------- Free Perl Training --- http://perlhunter.com/college.html ---------
--------- Gourmet Hot Cocoa Mix ---- http://bestfriendscocoa.com ---------
------------------------------
Date: Thu, 20 Mar 2008 00:41:13 +0000 (UTC)
From: Ben Bullock <benkasminbullock@gmail.com>
Subject: Re: Is substr only way of getting nth character of string?
Message-Id: <frsbr9$d6t$3@ml.accsnet.ne.jp>
On Thu, 20 Mar 2008 00:06:39 +0000, Uri Guttman wrote:
>>>>>> "RH" == Robbie Hatley <see.my.signature@for.my.email.address>
>>>>>> writes:
> RH> the only array I really need is the entire 96-character
> RH> character set.
my @x = map chr, 33..127;
> typing in the alphabet is more error prone than just 'a' and 'z'.
Well, typing the entire alphabet in one go certainly is error-prone if
you're six or seven years old. But eight year olds or above probably can
handle it.
------------------------------
Date: Thu, 20 Mar 2008 00:50:11 +0000 (UTC)
From: Ben Bullock <benkasminbullock@gmail.com>
Subject: Re: Is substr only way of getting nth character of string?
Message-Id: <frscc3$d6t$4@ml.accsnet.ne.jp>
On Thu, 20 Mar 2008 00:41:13 +0000, Ben Bullock wrote:
>> RH> the only array I really need is the entire 96-character RH>
>> character set.
>
> my @x = map chr, 33..127;
Sorry, I forgot you wanted tab and space:
my @x = map chr, 9,32..126;
Also included 127 by mistake.
Should have looked more carefully at http://www.asciitable.com/.
Sorry!
------------------------------
Date: Wed, 19 Mar 2008 11:05:30 -0700 (PDT)
From: Micha <michael.andrassy@gmail.com>
Subject: Re: problem starting perl script from cron environment - ps: don't know which terminal to select
Message-Id: <d2a0b390-7f52-4b7f-92eb-d07a6ebb9dba@s13g2000prd.googlegroups.com>
On 19 Mrz., 17:53, Maxwell Lol <nos...@com.invalid> wrote:
> Micha <michael.andra...@gmail.com> writes:
> > I have perl program which works just fine on the console, but started
> > in cron environment it prints "ps: don't know which terminal to
> > select" to stderr - btw I don't call ps explicitly at any point in my
> > scripts.
>
> Cron doesn't.
> perl doesn't.
> Perhaps your ksh startup file calls it.....
no it doesn't ;) - still wondering why, currently I'm using a
workaround without cron. But somehow that problem still bothers me.
------------------------------
Date: 19 Mar 2008 12:53:34 -0400
From: Maxwell Lol <nospam@com.invalid>
Subject: Re: problem starting perl script from cron environment - ps: don't know which terminal to select
Message-Id: <861w66irjl.fsf@localhost.localdomain>
Micha <michael.andrassy@gmail.com> writes:
> I have perl program which works just fine on the console, but started
> in cron environment it prints "ps: don't know which terminal to
> select" to stderr - btw I don't call ps explicitly at any point in my
> scripts.
Cron doesn't.
perl doesn't.
Perhaps your ksh startup file calls it.....
------------------------------
Date: Wed, 19 Mar 2008 21:54:40 +0100
From: Rodion <hitodenashi@alexandria.cc>
Subject: Re: Problem with loop control LAST exiting prematurely
Message-Id: <MPG.224b9bff898b21d09896b5@news.metronet.hr>
Jednom davno, ne znam vise kad, Peter J. Holzer duboko zamisljen/a rece:
> On 2008-03-18 15:40, Rodion <hitodenashi@alexandria.cc> wrote:
> > Jednom davno, ne znam vise kad, xhoster@gmail.com duboko zamisljen/a
> > rece:
> >
> >> Rodion <hitodenashi@alexandria.cc> wrote:
> >> > Jednom davno, ne znam vise kad, John W. Krahn duboko zamisljen/a rece:
> >> > > Couldn't you just write that as:
> >> > >
> >> > > $found = 1 if exists $cb{$cbName}{$data};
> >> >
> >> > Well, I have to thank you for putting me on the right track!
> >> >
> >> > There was a problem with some numeric data having prefixed zeroes while
> >> > some of the hash keys did not so there could be no match ( 0567 != 567).
>
> Try to canonicalize the data.
The problem was in my data which became clear when I ditched that ugly
sub with a more sensible:
$found = 1 if exists $cb{$cbName}{$data};
and added a few checks for the data.
> > switch ($test){
>
> Don't use switch. It is rather buggy and introduces problems which are
> hard to find.
That sucks. I depend on switch in this for the main part of the program.
Is it documented?
> > case 'numbers' {
> > if ($data==$k){
> > $found=1;
> > #last CODECHECK if ($found==1);
>
> $found is always 1 here (you just set it to one), so this is equivalent
> to "last CODECHECK;". However, that seems to be what you want.
Yes I wrote a lot of silly stuff in a hurry trying to see what is
happening :/
Thanks for the help :)
--
Professor: Now, be careful, Fry. And if you kill anyone, make sure
to eat their heart to gain their courage. Their rich tasty courage.
------------------------------
Date: Wed, 19 Mar 2008 22:08:35 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: Problem with loop control LAST exiting prematurely
Message-Id: <x7od9abc4d.fsf@mail.sysarch.com>
>>>>> "R" == Rodion <hitodenashi@alexandria.cc> writes:
>> Don't use switch. It is rather buggy and introduces problems which are
>> hard to find.
R> That sucks. I depend on switch in this for the main part of the program.
R> Is it documented?
no, switch sucks. perl 5.10 has a proper builtin called given/when. and
for simple string cases a dispatch table is much better. google for that
phrase in this group as it has been discussed many times.
uri
--
Uri Guttman ------ uri@stemsystems.com -------- http://www.sysarch.com --
----- Perl Code Review , Architecture, Development, Training, Support ------
--------- Free Perl Training --- http://perlhunter.com/college.html ---------
--------- Gourmet Hot Cocoa Mix ---- http://bestfriendscocoa.com ---------
------------------------------
Date: Wed, 19 Mar 2008 16:29:13 -0700
From: Brian Helterline <brian.helterline@hp.com>
Subject: Re: Problem with loop control LAST exiting prematurely
Message-Id: <frs7ka$lb$1@usenet01.boi.hp.com>
Lawrence Statton wrote:
> Brian Helterline <brian.helterline@hp.com> writes:
>> If you are doing the testing using numeric comparison, then they are equal.
>>
>> print "equal" if '0567' == '567';
>>
>> --
>> -brian
>
> Does not print "equal"
It does on my system:
C:\>perl -le "print 'equal' if '0567' == '567'"
equal
C:\>perl -v
This is perl, v5.8.8 built for MSWin32-x86-multi-thread
(with 33 registered patches, see perl -V for more detail)
------------------------------
Date: 19 Mar 2008 15:26:29 GMT
From: Mike <mikee@mikee.ath.cx>
Subject: segfault in perl
Message-Id: <47e130a5$0$26117$88260bb3@free.teranews.com>
I am testing a program that is not yet in production that after a
while the program will segfault. There is no core left behind when
the segfault happens. How can I get a core from the segfault or is
there another way to diagnose the situation?
Mike
Fedora Core 5
perl 5.8.8
--
Posted via a free Usenet account from http://www.teranews.com
------------------------------
Date: Wed, 19 Mar 2008 17:45:29 +0100
From: Joost Diepenmaat <joost@zeekat.nl>
Subject: Re: segfault in perl
Message-Id: <87prtqr7bq.fsf@zeekat.nl>
Mike <mikee@mikee.ath.cx> writes:
> I am testing a program that is not yet in production that after a
> while the program will segfault. There is no core left behind when
> the segfault happens. How can I get a core from the segfault
Assuming you're using bash or something similar to start the program,
type "help ulimit" and set the max core size to something larger than 0.
> or is
> there another way to diagnose the situation?
I like valgrind. http://valgrind.org/
example: valgrind myprogram.pl
Cheers,
Joost.
--
Joost Diepenmaat | blog: http://joost.zeekat.nl/ | work: http://zeekat.nl/
------------------------------
Date: 19 Mar 2008 16:49:35 GMT
From: xhoster@gmail.com
Subject: Re: segfault in perl
Message-Id: <20080319124937.495$Bg@newsreader.com>
Mike <mikee@mikee.ath.cx> wrote:
> I am testing a program that is not yet in production that after a
> while the program will segfault. There is no core left behind when
> the segfault happens. How can I get a core from the segfault or is
On my system I also don't get a core dumps by default. That is because
my default limit (tcsh) or ulimit (bash) for coredumpsize is 0. Could
that be your issue as well?
> there another way to diagnose the situation?
There are so many it is hard to know where to start without knowing more
about your code. Step through with the debugger; or strace the process and
see what is happening just before the seg fault. Or maybe something like
the below:
use Carp;
$SIG{SEGV}=sub {Carp::croak @_; };
(You probably need to set Environment variable PERL_SIGNALS to "unsafe"
in order to make this work)
Xho
--
-------------------- http://NewsReader.Com/ --------------------
The costs of publication of this article were defrayed in part by the
payment of page charges. This article must therefore be hereby marked
advertisement in accordance with 18 U.S.C. Section 1734 solely to indicate
this fact.
------------------------------
Date: 19 Mar 2008 16:09:26 GMT
From: Mike <mikee@mikee.ath.cx>
Subject: Re: segfault in perl
Message-Id: <47e13ab6$0$23520$88260bb3@free.teranews.com>
In article <87prtqr7bq.fsf@zeekat.nl>, Joost Diepenmaat wrote:
> Mike <mikee@mikee.ath.cx> writes:
>
>> I am testing a program that is not yet in production that after a
>> while the program will segfault. There is no core left behind when
>> the segfault happens. How can I get a core from the segfault
>
> Assuming you're using bash or something similar to start the program,
> type "help ulimit" and set the max core size to something larger than 0.
>
>> or is
>> there another way to diagnose the situation?
>
> I like valgrind. http://valgrind.org/
>
> example: valgrind myprogram.pl
>
> Cheers,
> Joost.
>
I didn't think about ulimit, thanks.
I'm running as a non-root user. I'll reset the core size and see what happens.
Mike
[recvmail@viper ~]$ ulimit
unlimited
[recvmail@viper ~]$ ulimit -a
core file size (blocks, -c) 0
data seg size (kbytes, -d) unlimited
max nice (-e) 0
file size (blocks, -f) unlimited
pending signals (-i) 16380
max locked memory (kbytes, -l) 32
max memory size (kbytes, -m) unlimited
open files (-n) 1024
pipe size (512 bytes, -p) 8
POSIX message queues (bytes, -q) 819200
max rt priority (-r) 0
stack size (kbytes, -s) 10240
cpu time (seconds, -t) unlimited
max user processes (-u) 16380
virtual memory (kbytes, -v) unlimited
file locks (-x) unlimited
[recvmail@viper ~]$
--
Posted via a free Usenet account from http://www.teranews.com
------------------------------
Date: 19 Mar 2008 16:12:31 GMT
From: Mike <mikee@mikee.ath.cx>
Subject: Re: segfault in perl
Message-Id: <47e13b6f$0$23520$88260bb3@free.teranews.com>
In article <20080319124937.495$Bg@newsreader.com>, xhoster@gmail.com wrote:
> <snip>
> strace the process and
> see what is happening just before the seg fault. Or maybe something like
> <snip>
Oh, strace(8) is a really good idea, thanks.
Mike
--
Posted via a free Usenet account from http://www.teranews.com
------------------------------
Date: Wed, 19 Mar 2008 16:41:19 -0700
From: dummy@phony.info
Subject: very strange bug (in perl?)
Message-Id: <0193u3934jdcnfsarhpv7pa610e0o5ni6a@4ax.com>
Please don't sneer and laugh, but I think I've found a bug in perl
itself.
I am trying to make, in my stumbling way, a database of homophones to
be the basis of a verifier similar to a spell checker, but for
homophones. I wrote this script as a crutch to help me with some logic.
It didn't work.
After many hours with and without the perl debugger I found the
proximate cause of my problem. But I'm at a loss to explain it.
Here is my source, showing the cure, followed by the output before and
after the fix.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ script before fix ~~~~~~~~~~
#!c:/strawberry/perl/bin/perl.exe
# perl 5.10.0 installed 3/3/2008
use strict; use warnings;
my %ow = (
'a' => [qw/a b c/],
'b' => [qw/a b c/],
'c' => [qw/a b c/],
'r' => [qw/r s t u/],
's' => [qw/r s t u/],
't' => [qw/r s t u/],
'u' => [qw/r s t u/],
'd' => [qw/d m o p/],
'm' => [qw/d m o p/],
'o' => [qw/d m o p/],
'p' => [qw/d m o p/],
'e' => [qw/e f l/],
'f' => [qw/e f l/],
'l' => [qw/e f l/],
'g' => [qw/g n q/],
'n' => [qw/g n q/],
'q' => [qw/g n q/]
);
my @in = () # works if i comment out this line and put 'my' below -+
# print "old\n"; |
# display(); |
INPUT: while (<>) { # |
my $q = $_; # |
chomp $q; # |
$q =~ s/^\s*//; # |
$q =~ s/\s*$//; # |
warn "line 31 :@{$ow{'a'}}:\n"; # |
@in = (); # put 'my' here <---------------------------------+
warn "line 33 :@{$ow{'a'}}:\n";
@in = split /\s+/, $q;
warn "line 35 :@{$ow{'a'}}:\n";
my $sw = 1;
PASS: {
next INPUT unless $sw;
$sw = 0;
SCAN: for my $i(@in) {
if(exists $ow{$i}) {
if(compare_arrays($ow{$i},\@in)){
next SCAN;
}
@in = @{&merge_arrays($ow{$i},\@in)};
$ow{$i} = \@in;
$sw = 1;
redo PASS;
}else{
$ow{$i} = \@in;
$sw =1;
next SCAN;
}#if
}#SCAN
}#PASS
}#INPUT
#print "\nnew\n";
#display();
sub display {
for my $k (sort keys %ow) {
print "$k => @{$ow{$k}}\n";
}
print "\n";
}
sub merge_arrays { # adapted from perlfaq
my ($aref, $bref) = @_;
my @u = ();
my %ct;
for my $e(@$aref, @$bref){$ct{$e}++}
for my $e(sort keys %ct) {push @u, $e}
return \@u;
}
sub compare_arrays { # sraight from perlfaq
my ($first, $second) = @_;
no warnings; # silence spurious -w undef complaints
return 0 unless @$first == @$second;
for (my $i = 0; $i < @$first; $i++) {
return 0 if $first->[$i] ne $second->[$i];
}
return 1;
}
~~~~~~~~~~~~~ output showing bug ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
C:\Documents and Settings\Me\My Documents\homophones>perl
practice.pl
a l
line 31 :a b c:
line 33 :a b c:
line 35 :a b c:
q u
line 31 :a b c e f l:
line 33 ::
line 35 :q u:
^Z
C:\Documents and Settings\Me\My Documents\homophones>
~~~~~~~~~~~~~~~~ output after changes indicated in source ~~~~~~~~
C:\Documents and Settings\Me\My Documents\homophones>perl
practice.pl
a l
line 31 :a b c:
line 33 :a b c:
line 35 :a b c:
q u
line 31 :a b c e f l:
line 33 :a b c e f l:
line 35 :a b c e f l:
^Z
C:\Documents and Settings\Me\My Documents\homophones>
------------------------------
Date: Thu, 20 Mar 2008 00:02:28 +0000 (UTC)
From: Ben Bullock <benkasminbullock@gmail.com>
Subject: Re: very strange bug (in perl?)
Message-Id: <frs9ik$d6t$2@ml.accsnet.ne.jp>
On Wed, 19 Mar 2008 16:41:19 -0700, dummy wrote:
> Please don't sneer and laugh, but I think I've found a bug in perl
> itself.
I am using Perl on linux:
ben ~ 525 $ perl --version
This is perl, v5.10.0 built for i686-linux
I changed only the top line of your program to "#!/usr/bin/perl" and the
output was as follows:
ben ~ 524 $ ./bug.pl
Semicolon seems to be missing at ./bug.pl line 25.
"my" variable $q masks earlier declaration in same scope at ./bug.pl line
28.
"my" variable $q masks earlier declaration in same scope at ./bug.pl line
29.
"my" variable $q masks earlier declaration in same scope at ./bug.pl line
30.
"my" variable @in masks earlier declaration in same scope at ./bug.pl
line 32.
"my" variable @in masks earlier declaration in same scope at ./bug.pl
line 34.
"my" variable $q masks earlier declaration in same scope at ./bug.pl line
34.
"my" variable %ow masks earlier declaration in same scope at ./bug.pl
line 61.
"state" variable @_ masks earlier declaration in same scope at ./bug.pl
line 77.
syntax error at ./bug.pl line 26, near ") # works if i comment out this
line and put 'my' below -+
# print "old\n"; |
# display(); |
INPUT"
syntax error at ./bug.pl line 56, near "}"
Can't use global @_ in "my" at ./bug.pl line 68, near "= @_"
syntax error at ./bug.pl line 74, near "}"
Can't use global @_ in "my" at ./bug.pl line 77, near "= @_"
BEGIN not safe after errors--compilation aborted at ./bug.pl line 78.
I think some people might be tempted to laugh.
------------------------------
Date: Thu, 20 Mar 2008 01:37:22 +0100
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: very strange bug (in perl?)
Message-Id: <64dpucF2b9udeU1@mid.individual.net>
Ben Bullock wrote:
> I changed only the top line of your program to "#!/usr/bin/perl" and the
> output was as follows:
>
> ben ~ 524 $ ./bug.pl
> Semicolon seems to be missing at ./bug.pl line 25.
> "my" variable $q masks earlier declaration in same scope at ./bug.pl line
> 28.
> "my" variable $q masks earlier declaration in same scope at ./bug.pl line
> 29.
> "my" variable $q masks earlier declaration in same scope at ./bug.pl line
> 30.
> "my" variable @in masks earlier declaration in same scope at ./bug.pl
> line 32.
> "my" variable @in masks earlier declaration in same scope at ./bug.pl
> line 34.
> "my" variable $q masks earlier declaration in same scope at ./bug.pl line
> 34.
> "my" variable %ow masks earlier declaration in same scope at ./bug.pl
> line 61.
> "state" variable @_ masks earlier declaration in same scope at ./bug.pl
> line 77.
> syntax error at ./bug.pl line 26, near ") # works if i comment out this
> line and put 'my' below -+
> # print "old\n"; |
> # display(); |
> INPUT"
> syntax error at ./bug.pl line 56, near "}"
> Can't use global @_ in "my" at ./bug.pl line 68, near "= @_"
> syntax error at ./bug.pl line 74, near "}"
> Can't use global @_ in "my" at ./bug.pl line 77, near "= @_"
> BEGIN not safe after errors--compilation aborted at ./bug.pl line 78.
>
> I think some people might be tempted to laugh.
That's not fair. By just adding the missing semicolon, as the first
error message mentions, the code compiles.
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
------------------------------
Date: Wed, 19 Mar 2008 19:14:42 -0500
From: Tad J McClellan <tadmc@seesig.invalid>
Subject: Re: XML Parsing in Perl
Message-Id: <slrnfu3b3i.ei9.tadmc@tadmc30.sbcglobal.net>
Deepan Perl XML Parser <deepan.17@gmail.com> wrote:
> This post is regarding XML parsing in perl.
It would have been helpful if you had shared what XML parsing
module you are using.
It would have been even more helpful if you had posted a short
and complete program *that we can run* that illustrates your problem.
Have you seen the Posting Guidelines that are posted here frequently?
> I have written a handler for capturing Char named
> characterData. when this handler is getting called up for parsing
> ""1667999478""
> which is available in $data it should be able
Does "available in $data" mean that that is the output of the
print statment in your code?
> to print "1667999478" replacing " with ", but it is only printing
> ".
That would be expected behavior with some XML parsing modules.
What XML parsing module you are using?
Many (all?) modules can call characterData() multiple times.
If there are 20 character data, then it may be called as many
as 20 times.
The usual approach is to collect the character data into a buffer,
then operate on the buffer from the appropriate end tag handler.
> Here is the code :
>
> sub characterData {
> my( $parseinst, $data ) = @_;
> print "$data";
perldoc -q vars
What's wrong with always quoting "$vars"?
> ------------------>>> here i should get "1667999478" instead of "
> }
>
> Please help me.
Pleading is counter-productive, it makes it *less* likely that
someone will actually help you.
Have you seen the Posting Guidelines that are posted here frequently?
--
Tad McClellan
email: perl -le "print scalar reverse qq/moc.noitatibaher\100cmdat/"
------------------------------
Date: Wed, 19 Mar 2008 23:51:59 +0000 (UTC)
From: Ben Bullock <benkasminbullock@gmail.com>
Subject: Re: XML Parsing in Perl
Message-Id: <frs8uv$d6t$1@ml.accsnet.ne.jp>
On Wed, 19 Mar 2008 05:04:12 -0700, Deepan Perl XML Parser wrote:
> This post is regarding XML parsing in perl.
>
> I have written a handler for capturing Char named
> characterData. when this handler is getting called up for parsing
> ""1667999478"" which is available in $data it should be able
> to print "1667999478" replacing " with ", but it is only printing
> ".
>
> Here is the code :
>
> sub characterData {
> my( $parseinst, $data ) = @_;
> print "$data";
> ------------------>>> here i should get "1667999478" instead of "
> }
#!/usr/bin/perl
use warnings;
use strict;
use XML::Parser;
my $parser = XML::Parser->new(Handlers => {Char =>\&handle_char});
my $text = "<tag>";
for my $i (1..10000) {$text .=
"XML::Parser Gotcha: Character Handler Is Often Called Multiple Times\n"}
$text .= "</tag>";
$parser->parse($text);
my $x;
sub handle_char
{
my ($ignore,$text) = @_;
$x++;
print "Text is \"$text\". I have now been called $x times.\n";
}
------------------------------
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 V11 Issue 1374
***************************************