[24086] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 6280 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Mar 19 14:10:36 2004

Date: Fri, 19 Mar 2004 11:10:09 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Fri, 19 Mar 2004     Volume: 10 Number: 6280

Today's topics:
        Perl upgraded = problem resurfacing (Grant)
    Re: Perl upgraded = problem resurfacing <roel-perl@st2x.net>
        Problem installing Net::DNS (John Oliver)
    Re: Problem installing Net::DNS <roel-perl@st2x.net>
        problem with pack and output to binary files (Mark Flynn)
    Re: problem with pack and output to binary files <roel-perl@st2x.net>
    Re: problem with pack and output to binary files <remorse@partners.org>
    Re: problem with pack and output to binary files <roel-perl@st2x.net>
    Re: Searching on the internet with regex <jwillmore@remove.adelphia.net>
    Re: Searching on the internet with regex (=?iso-8859-1?q?M=E5ns_Rullg=E5rd?=)
        Truncating several lines of text into one line and putt (v796)
    Re: Truncating several lines of text into one line and  <nobull@mail.com>
    Re: Truncating several lines of text into one line and  <ittyspam@yahoo.com>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: 19 Mar 2004 09:43:58 -0800
From: tonearm@email.com (Grant)
Subject: Perl upgraded = problem resurfacing
Message-Id: <d6cf0719.0403190943.53291a68@posting.google.com>

I have some XML::Simple code that parses an XML response I get via
HTTP after a post.  Sometimes the response would come back blank and
it would crash my program because XML::Simple would try and parse it. 
I changed my code like this:

if ($response) {
*XML::Simple processing*
}
else {
*processing*
}

and it fixed the problem.  Now that I've upgrade to Perl 5.8.2 it has
re-appeared.  Can anyone suggest any alterations to my code to keep a
blank response from being processed by XML::Simple?

I suppose I don't know that it is totally blank for sure, although the
above code did solve the problem before.  If the above code should
still be working to correctly route a blank response, can anyone
suggest code that would check the response for something specific that
should be there (like "<?xml") and decide what to do based on that?

By the way, I know next to nothing about Perl.  It took me a while to
get the above code written properly.

- Grant


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

Date: 19 Mar 2004 18:06:31 GMT
From: Roel van der Steen <roel-perl@st2x.net>
Subject: Re: Perl upgraded = problem resurfacing
Message-Id: <slrnc5mdl1.284.roel-perl@localhost.localdomain>

On Fri, 19 Mar 2004 at 17:43 GMT, Grant <tonearm@email.com> wrote:
> I suppose I don't know that it is totally blank for sure, although the
> If the above code should
> still be working to correctly route a blank response, can anyone
> suggest code that would check the response for something specific that
> should be there (like "<?xml") and decide what to do based on that?

What about (untested):

if ($response =~ /^<\?xml/ ) {
  # *XML::Simple processing*
}
else {
  # *processing*
}



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

Date: 19 Mar 2004 18:11:22 GMT
From: joliver@john-oliver.net (John Oliver)
Subject: Problem installing Net::DNS
Message-Id: <slrnc5mdtv.eoj.joliver@ns.sdsitehosting.net>

Running make test
PERL_DL_NONLAZY=1 /usr/local/bin/perl "-MExtUtils::Command::MM" "-e"
"test_harness(0, 'blib/lib', 'blib/arch')" t/*.t
t/00-load................ok
t/00-pod.................skipped
        all skipped: Test::Pod v0.95 required for testing POD
t/00-version.............ok
t/01-resolver-env........ok
t/01-resolver-file.......ok
        7/8 skipped: Could not read configuration file
t/01-resolver-opt........ok
t/01-resolver............ok
t/02-header..............ok
t/03-question............ok
t/04-packet..............ok
t/05-rr-txt..............ok
t/05-rr-unknown..........ok
t/05-rr..................ok
t/06-update-safe-push....ok
t/06-update..............ok
t/07-misc................ok
t/08-online..............ok
t/09-tkey................ok
t/10-recurse.............ok 2/8Server [198.41.0.4] did not give answers
at /root/.cpan/build/Net-DNS-0.46/blib/lib/Net/DNS/Resolver/Recurse.pm
line 73.
#     Failed test (t/10-recurse.t at line 29)
#     Failed test (t/10-recurse.t at line 35)
Can't call method "answer" on an undefined value at t/10-recurse.t line
36.
# Looks like you planned 8 tests but only ran 5.
# Looks like your test died just after 5.
t/10-recurse.............dubious
        Test returned status 255 (wstat 65280, 0xff00)
DIED. FAILED tests 4-8
        Failed 5/8 tests, 37.50% okay
Failed Test    Stat Wstat Total Fail  Failed  List of Failed
-------------------------------------------------------------------------------
t/10-recurse.t  255 65280     8    8 100.00%  4-8
1 test and 7 subtests skipped.
Failed 1/19 test scripts, 94.74% okay. 5/766 subtests failed, 99.35%
okay.
make: *** [test_dynamic] Error 2
  /usr/bin/make test -- NOT OK
Running make install
  make test had returned bad status, won't install without force

cpan> quit
Lockfile removed.
[root@smtp1 root]# dig @198.41.0.4 version.named txt chaos

; <<>> DiG 9.1.3 <<>> @198.41.0.4 version.named txt chaos
;; global options:  printcmd
;; connection timed out; no servers could be reached
[root@smtp1 root]# nmap -sS 198.41.0.4

Starting nmap V. 2.54BETA22 ( www.insecure.org/nmap/ )
Interesting ports on a.root-servers.net (198.41.0.4):
(The 1541 ports scanned but not shown below are in state: filtered)
Port       State       Service
53/tcp     open        domain


Nmap run completed -- 1 IP address (1 host up) scanned in 197 seconds
[root@smtp1 root]# ping 198.41.0.4
PING 198.41.0.4 (198.41.0.4) from 63.197.115.98 : 56(84) bytes of data.
64 bytes from 198.41.0.4: icmp_seq=0 ttl=238 time=75.350 msec
64 bytes from 198.41.0.4: icmp_seq=1 ttl=238 time=69.978 msec
64 bytes from 198.41.0.4: icmp_seq=2 ttl=238 time=69.973 msec
64 bytes from 198.41.0.4: icmp_seq=3 ttl=238 time=69.968 msec
64 bytes from 198.41.0.4: icmp_seq=4 ttl=238 time=69.962 msec

--- 198.41.0.4 ping statistics ---
5 packets transmitted, 5 packets received, 0% packet loss
round-trip min/avg/max/mdev = 69.962/71.046/75.350/2.158 ms
[root@smtp1 root]# ping www.yahoo.com
PING www.yahoo.akadns.net (66.94.230.39) from 63.197.115.98 : 56(84)
bytes of data.


There is a resolv.conf file, and it does work.  This host is not behind
a firewall.  I've asked the admin at that location to double-check the
router for ACLs, but I really doubt that's the case.

-- 
* John Oliver                              http://www.john-oliver.net/ *
* California gun owners - protect your rights and join the CRPA today! *
* http://www.crpa.org/         Free 3 month trial membership available *
* San Diego shooters come to http://groups.yahoo.com/group/sdshooting/ *


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

Date: 19 Mar 2004 18:38:11 GMT
From: Roel van der Steen <roel-perl@st2x.net>
Subject: Re: Problem installing Net::DNS
Message-Id: <slrnc5mfgc.284.roel-perl@localhost.localdomain>

On Fri, 19 Mar 2004 at 18:11 GMT, John Oliver <joliver@john-oliver.net> wrote:
<lots of dumped screen data snipped>
>
> There is a resolv.conf file, and it does work.  This host is not behind
> a firewall.  I've asked the admin at that location to double-check the
> router for ACLs, but I really doubt that's the case.
> 

Just installed Net::DNS on my system without problems. Maybe you can
add the line

  $res->debug(1);

to t/10-recurse.t, just after the object creator, and run this
particular test again from the build dir. (Your source tree is 
probably in ~/.cpan/build/Net-DNS-0.46 .)


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

Date: 19 Mar 2004 08:31:03 -0800
From: triflynn@earthlink.net (Mark Flynn)
Subject: problem with pack and output to binary files
Message-Id: <1840605b.0403190831.686f6ab1@posting.google.com>

I'm hoping someone can reply letting me know what I fool I am for
missing such an obvious error. This one is driving me nuts.

I'm using pack with the n format string to write big-endian 4 byte
binary data to a file. Sounds pretty simple. Here's the code.

#!Perl
use strict;

#Example of bug in print to binary file

my $begin =	0x100;
my $end =	0x130;

my $i;

my $file = "bug_test.pl";

open FILE, $file;
binmode FILE, ":raw" ;

for ($i = $begin; $i <= $end; $i++) {
	print FILE pack("n", $i);
}


And here's a hex dump of the output, parsed into 4 byte chunks.

01 00
01 01
01 02
01 03
01 04
01 05
01 06
01 07
01 08
01 09
01 0D 0A   <Extra byte inserted here!
01 0B
01 0C
01 0D
01 0E
01 0F
01 10

What I find is that for the number 0x010A (266), and only that number,
an extra byte is generated, with value 0x0D (13). This happens to be
an ASCII CR, but why there would be a CR inserted into the output is
beyond me. What's going on?

In case it matters, I'm using ActiveState Perl v5.6.1 on WinNT.

Any help would be greatly appreciated. Thanks.

Mark Flynn
mflynn at aurora-sys dot com


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

Date: 19 Mar 2004 17:11:40 GMT
From: Roel van der Steen <roel-perl@st2x.net>
Subject: Re: problem with pack and output to binary files
Message-Id: <slrnc5mae6.284.roel-perl@localhost.localdomain>

On Fri, 19 Mar 2004 at 16:31 GMT, Mark Flynn <triflynn@earthlink.net> wrote:
> I'm hoping someone can reply letting me know what I fool I am for
> missing such an obvious error. This one is driving me nuts.
> 
> I'm using pack with the n format string to write big-endian 4 byte
> binary data to a file. Sounds pretty simple. Here's the code.
> 
> #!Perl
> use strict;

use warnings would have warned you about the typo below. (Use
cut and paste to include your code in the message.)

> 
> #Example of bug in print to binary file
> 
> my $begin =	0x100;
> my $end =	0x130;
> 
> my $i;
> 
> my $file = "bug_test.pl";
             ^           ^
Use single quotes when no interpolation is required. Why do you misuse
the extension .pl for a file that contains binary data?

> 
> open FILE, $file;
             ^
I assume you mean to open the handle for writing: open FILE, ">$file";

> binmode FILE, ":raw" ;
                ^^^^^^
                (not needed)
> 
> for ($i = $begin; $i <= $end; $i++) {
> 	print FILE pack("n", $i);
> }
> 
> 
> And here's a hex dump of the output, parsed into 4 byte chunks.
> 
> 01 00
> 01 01
> 01 02
> 01 03
> 01 04
> 01 05
> 01 06
> 01 07
> 01 08
> 01 09
> 01 0D 0A   <Extra byte inserted here!
> 01 0B
> 01 0C
> 01 0D
> 01 0E
> 01 0F
> 01 10
> 
> What I find is that for the number 0x010A (266), and only that number,
> an extra byte is generated, with value 0x0D (13). This happens to be
> an ASCII CR, but why there would be a CR inserted into the output is
> beyond me. What's going on?

Are you really, absolutely, positively sure that this is not caused by
your dumper application? On my Windows box this works just fine. The
file size should be 98 bytes (31 hex = 49 decimal, times 2).

The Windows C open library strips and adds CR characters as it reads and
writes. It occurs to me as if a bug in your dumper program adds the
extra CR -- not Perl.

My recommendation: find another hexdump.exe on the net and look what's
_really_ in the file.


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

Date: Fri, 19 Mar 2004 13:15:32 -0500
From: Richard Morse <remorse@partners.org>
Subject: Re: problem with pack and output to binary files
Message-Id: <remorse-242298.13152919032004@plato.harvard.edu>

In article <slrnc5mae6.284.roel-perl@localhost.localdomain>,
 Roel van der Steen <roel-perl@st2x.net> wrote:

> On Fri, 19 Mar 2004 at 16:31 GMT, Mark Flynn <triflynn@earthlink.net> wrote:
> 
> > binmode FILE, ":raw" ;
>                 ^^^^^^
>                 (not needed)

Ummmm.... I disagree.  He does need the binmode, otherwise he'll see 
exactly the problem that he's seeing -- '\n' is being turned into '\r\n'.

Ricky


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

Date: 19 Mar 2004 18:40:15 GMT
From: Roel van der Steen <roel-perl@st2x.net>
Subject: Re: problem with pack and output to binary files
Message-Id: <slrnc5mfk8.284.roel-perl@localhost.localdomain>

On Fri, 19 Mar 2004 at 18:15 GMT, Richard Morse <remorse@partners.org> wrote:
> In article <slrnc5mae6.284.roel-perl@localhost.localdomain>,
>  Roel van der Steen <roel-perl@st2x.net> wrote:
> 
>> On Fri, 19 Mar 2004 at 16:31 GMT, Mark Flynn <triflynn@earthlink.net> wrote:
>> 
>> > binmode FILE, ":raw" ;
>>                 ^^^^^^
>>                 (not needed)
> 
> Ummmm.... I disagree.  He does need the binmode, otherwise he'll see 
> exactly the problem that he's seeing -- '\n' is being turned into '\r\n'.
> 
> Ricky

Yes, but ":raw" is the default for binmode. So the one-argument form
"binmode FILE;" would have been sufficient. Never mind. ;)


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

Date: Fri, 19 Mar 2004 09:51:04 -0500
From: James Willmore <jwillmore@remove.adelphia.net>
Subject: Re: Searching on the internet with regex
Message-Id: <pan.2004.03.19.14.51.02.300620@remove.adelphia.net>

On Thu, 18 Mar 2004 04:55:26 -0800, stef wrote:

> Does anybody know an internet search engine that allows search-queries
> with regular expressions as in perl?

I can't say I've heard of any.  However ironic this is ... have you tried
searching for one :-)

There is a valid reason for not wanting to have metacharacters being used
in a search engine that faces the Internet, but there are also ways of
using them properly and safely.  It's just that the mass majority of
people, IMHO, don't want/need anything more than a '*' in their search :-)

Just my $0.02 (I think I've given about $0.10 this week :-) ).

-- 
Jim

Copyright notice: all code written by the author in this post is
 released under the GPL. http://www.gnu.org/licenses/gpl.txt 
for more information.

a fortune quote ...
The moon is a planet just like the Earth, only it is even deader.




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

Date: Fri, 19 Mar 2004 16:11:39 +0100
From: mru@kth.se (=?iso-8859-1?q?M=E5ns_Rullg=E5rd?=)
Subject: Re: Searching on the internet with regex
Message-Id: <yw1xznacc1n8.fsf@kth.se>

James Willmore <jwillmore@remove.adelphia.net> writes:

> On Thu, 18 Mar 2004 04:55:26 -0800, stef wrote:
>
>> Does anybody know an internet search engine that allows search-queries
>> with regular expressions as in perl?
>
> I can't say I've heard of any.  However ironic this is ... have you tried
> searching for one :-)
>
> There is a valid reason for not wanting to have metacharacters being used
> in a search engine that faces the Internet, but there are also ways of
> using them properly and safely.  It's just that the mass majority of
> people, IMHO, don't want/need anything more than a '*' in their search :-)

There's also the aspect of speed of the search engine.  Matching
regular expressions against vast amounts of text is not something that
is easily optimized.

-- 
Måns Rullgård
mru@kth.se


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

Date: 19 Mar 2004 09:06:46 -0800
From: vicky7909@rediffmail.com (v796)
Subject: Truncating several lines of text into one line and putting in scalar
Message-Id: <49f90fb9.0403190906.1aa31227@posting.google.com>

Hi,

I have text across several lines in a scalar like this:

ddd
 .
<blank line>
<blank line>
Hello there how are you?
continues
text
more etext
text ends

The above text is in a scalar variable. I need to get the text (split
by newlines) into a scalar like this
$text = "ddd . Hello there how are you? continues text more etext text
ends";

Notice that the first letter of every line is preceded by one space in
$text. Also all the blank lines are deleted. And now it is like it was
originally in one line i.e. without newlines '\n'.

How can this be done?

Thanks,
v796


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

Date: 19 Mar 2004 17:43:35 +0000
From: Brian McCauley <nobull@mail.com>
Subject: Re: Truncating several lines of text into one line and putting in scalar
Message-Id: <u9ad2chgvs.fsf@wcl-l.bham.ac.uk>

vicky7909@rediffmail.com (v796) writes:

> I have text across several lines in a scalar like this:
> 
> ddd
> .
> <blank line>
> <blank line>
> Hello there how are you?
> continues
> text
> more etext
> text ends
> 
> The above text is in a scalar variable. I need to get the text (split
> by newlines) into a scalar like this
> $text = "ddd . Hello there how are you? continues text more etext text
> ends";

I think you are asking how to replace every occurance of one or more
newlines with a space.

tr/\n/ /s;

This, of course, assumes that you've correctly stated the question and
there are no other characters you want to worry about (e.g. "\r").  It
also assumes that "blank line" means "empty line" not "line consisting
entirely of whitespace".

Maybe you would prefer the canonical canonicalisation of whitespace:

s/(\s+)/ /g;

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


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

Date: Fri, 19 Mar 2004 12:23:20 -0500
From: Paul Lalli <ittyspam@yahoo.com>
Subject: Re: Truncating several lines of text into one line and putting in scalar
Message-Id: <20040319122241.U21521@dishwasher.cs.rpi.edu>

On Fri, 19 Mar 2004, v796 wrote:

> Hi,
>
> I have text across several lines in a scalar like this:
>
> ddd
> .
> <blank line>
> <blank line>
> Hello there how are you?
> continues
> text
> more etext
> text ends
>
> The above text is in a scalar variable. I need to get the text (split
> by newlines) into a scalar like this
> $text = "ddd . Hello there how are you? continues text more etext text
> ends";
>
> Notice that the first letter of every line is preceded by one space in
> $text. Also all the blank lines are deleted. And now it is like it was
> originally in one line i.e. without newlines '\n'.
>
> How can this be done?
>


As someone here said recently in another post...

What have you tried so far?
What didn't work?
When is the homework assignment due?

Paul Lalli


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

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


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