[19155] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 1350 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sat Jul 21 21:05:26 2001

Date: Sat, 21 Jul 2001 18:05:07 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <995763907-v10-i1350@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Sat, 21 Jul 2001     Volume: 10 Number: 1350

Today's topics:
        ANNOUNCE: XML::Records 0.10 (Eric Bohlman)
        Appending to string in array <greenbd@u.washington.edu>
    Re: Appending to string in array (Tad McClellan)
    Re: Collin hates subject lines. <krahnj@acm.org>
        FAQ: When I tried to run my script, I got this message. <faq@denver.pm.org>
        PASCAL > PERL <cvule@eunet.yu>
    Re: PASCAL > PERL <krahnj@acm.org>
    Re: PASCAL > PERL (Eric Bohlman)
    Re: PASCAL > PERL <krahnj@acm.org>
    Re: perl and Informix <ahamm.NO$PAM@sanderson.NO$PAM.net.au>
        POSIX' sprintf doesn't regard locale? <arifsaha@yahoo.com>
    Re: Repetitive if statements <greenbd@u.washington.edu>
    Re: splitting an array on an empty line <goldbb2@earthlink.net>
        UDP Client/Server Tutorial (Christian Klauss)
    Re: web interface to c program running on different ser <goldbb2@earthlink.net>
        what is the defer form "my" to "local"? <no@mail.addr>
    Re: Who can help me about the confused (..) operator? <no@mail.addr>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: 21 Jul 2001 21:55:08 GMT
From: ebohlman@omsdev.com (Eric Bohlman)
Subject: ANNOUNCE: XML::Records 0.10
Message-Id: <tlk18a6164iab6@corp.supernews.com>

Version 0.10 of XML::Records is now available on CPAN.  It allows you to
pull "records" out of XML documents and turn them into Perl data
structures (similar to Grant McLean's XML::Simple, but without having to
read the entire document into memory), create simple tree structures (same
as XML::Parser::EasyTree) from them, or generate PerlSAX events from them,
allowing you to build DOM, XPath or similar structures from selected parts
of a document.  Since it's now a subclass of XML::TokeParser, it allows 
you to read token-by-token as well as record-by-record.





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

Date: Sat, 21 Jul 2001 16:30:11 -0700
From: "Brian D. Green" <greenbd@u.washington.edu>
Subject: Appending to string in array
Message-Id: <Pine.A41.4.33.0107211615190.145464-100000@dante59.u.washington.edu>

Hello again,

I'm now trying to write a script for my legislative simulation that allows
users to add themselves as co-sponsors to a bill. It should read from the
flat-file database where the bill information is stored, go to the line
for the appropriate bill, and append their username and a pipe to the end
of it. Here's what I've tried doing, but it just prints a lengthy error
message into my data file instead of the username.

#!/usr/local/bin/perl -w
use CGI qw/:standard/;
use CGI::Carp qw(fatalsToBrowser);
print header;

$number = param('number');
$billtype = param('billtype');
$netid = $ENV{'REMOTE_USER'};

open (ADD_ME, ">>$billtype.out");
@data = <ADD_ME>;

foreach $line (@data) {
	if ($line =~ /^$number\|/) {
	$added = "$line";
	$line = "";
	print "$added$netid|";
	}
}
close (ADD_ME);

What am I doing wrong, and how should I correct it? Thanks for your help!

Sincerely,
Brian Green			http://students.washington.edu/greenbd/

O-----------------------------------------------------------------------O
|"I am not ashamed of the gospel, because it is the power of God for the|
|  salvation of everyone who believes: first for the Jew, then for the  |
|    Gentile."					 --Romans 1:16, NIV     |
O-----------------------------------------------------------------------O



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

Date: Sat, 21 Jul 2001 19:31:00 -0400
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Appending to string in array
Message-Id: <slrn9lk45k.6db.tadmc@tadmc26.august.net>

Brian D. Green <greenbd@u.washington.edu> wrote:

>It should read from the
>flat-file database where the bill information is stored, go to the line
>for the appropriate bill, and append their username and a pipe to the end
                               ^^^^^^
>of it. 


   perldoc -q append

      "How do I change one line in a file/delete a line in a
       file/insert a line in the middle of a file/append to the
       beginning of a file?"


You should check the Perl FAQs *before* posting to the
Perl newsgroup.


>Here's what I've tried doing, but it just prints a lengthy error
>message into my data file instead of the username.
         ^^^^^^^^^^^^^^^^^

I do not see how anything gets into a file...


>open (ADD_ME, ">>$billtype.out");


You should always, yes *always*, check the return value from open():

   open (ADD_ME, ">>$billtype.out") or die "could not open '$billtype.out' $!";


>@data = <ADD_ME>;


You have opened ADD_ME for writing, not reading!


>What am I doing wrong, 


Ignoring the hundreds of previous times that this problem has
surfaced.


>and how should I correct it? 


As the FAQ suggests, with the -i switch or the $^I variable.


>Thanks for your help!

You're welcome.


-- 
    Tad McClellan                          SGML consulting
    tadmc@augustmail.com                   Perl programming
    Fort Worth, Texas


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

Date: Sat, 21 Jul 2001 22:28:53 GMT
From: "John W. Krahn" <krahnj@acm.org>
Subject: Re: Collin hates subject lines.
Message-Id: <3B5A0226.678B60EE@acm.org>

Collin E Borrlewyn wrote:
> 
> "John W. Krahn" <krahnj@acm.org> wrote in message
> news:3B59342E.1944EAC4@acm.org...
> > Collin E Borrlewyn wrote:
> > >
> > > I'm writing a signup script for part of a larger message board.
> Everything
> > > else works, but I've been having trouble with preferences. I've tracked
> the
> > > problem down to the following subroutine. (I don't know if the
> indentation
> > > will hold.)
> > >
> > > sub update_info(){
> 
> >                  ^^
> > You're saying you don't want to accept any arguments so @_ will be empty
> > (depending on how you call the sub.)
> 
> Forgive my ignorance, but I don't follow.
> 
> > sub update_info {
> >     my ( $id, $field, $value ) = @_;
> 
> Is there a good reason to do this? Apart from (perhaps) readability, I am
> unaware of an advantage.

I can't count the number of times I've gone back to code I've written
months or years ago (before I knew better) and tried to figure out WTF
the code was doing. Descriptive variable names and limiting the scope of
variables is very important in maintaining code over a long period of
time.

> >     use Fcntl ':flock'; # import LOCK_* constants
> >     open DATA,"< $userdir/$id" or return 0;
> >     flock DATA, LOCK_EX unless $^O =~ /Win/;
> >     my ( $data, @sig ) = <DATA>;
> >     close DATA;
> >
> >     $data =~ s/$field\*(\S+)/$field*$value/;
> 
> That's very nice, but it wont work for my purposes. First, it wont let me
> update the signature, which is stored with no label.

Your original post didn't update the signature but it's easy enough to
do:

sub update_info {
    my ( $id, $field, $value, @newsig ) = @_;
 ...
@sig = @newsig if @newsig;

> Second, it doesn't let
> people use spaces in their names. s/$field\*([^\t]+)/$field*$value/ would
> fix the second but not the first problem.
> 
> I was more interested in why it wasn't working than how to make it work. I
> can make it work by doing it differently, but the fact that this didn't work
> when it should have is annoying me.

You can do it any way you want, I was just offering some suggestions.
:-)



John
-- 
use Perl;
program
fulfillment


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

Date: Sun, 22 Jul 2001 00:17:02 GMT
From: PerlFAQ Server <faq@denver.pm.org>
Subject: FAQ: When I tried to run my script, I got this message. What does it
Message-Id: <2Yo67.13$T3.170720256@news.frii.net>

This message is one of several periodic postings to comp.lang.perl.misc
intended to make it easier for perl programmers to find answers to
common questions. The core of this message represents an excerpt
from the documentation provided with every Standard Distribution of
Perl.

+
  When I tried to run my script, I got this message. What does it
mean?

    A complete list of Perl's error messages and warnings with explanatory
    text can be found in the perldiag manpage. You can also use the splain
    program (distributed with Perl) to explain the error messages:

        perl program 2>diag.out
        splain [-v] [-p] diag.out

    or change your program to explain the messages for you:

        use diagnostics;

    or

        use diagnostics -verbose;

- 

Documents such as this have been called "Answers to Frequently
Asked Questions" or FAQ for short.  They represent an important
part of the Usenet tradition.  They serve to reduce the volume of
redundant traffic on a news group by providing quality answers to
questions that keep coming up.

If you are some how irritated by seeing these postings you are free
to ignore them or add the sender to your killfile.  If you find
errors or other problems with these postings please send corrections
or comments to the posting email address or to the maintainers as
directed in the perlfaq manual page.

Answers to questions about LOTS of stuff, mostly not related to
Perl, can be found by pointing your news client to

    news:news.answers

or to the many thousands of other useful Usenet news groups.

Note that the FAQ text posted by this server may have been modified
from that distributed in the stable Perl release.  It may have been
edited to reflect the additions, changes and corrections provided
by respondents, reviewers, and critics to previous postings of
these FAQ. Complete text of these FAQ are available on request.

The perlfaq manual page contains the following copyright notice.

  AUTHOR AND COPYRIGHT

    Copyright (c) 1997-1999 Tom Christiansen and Nathan
    Torkington.  All rights reserved.

This posting is provided in the hope that it will be useful but
does not represent a commitment or contract of any kind on the part
of the contributers, authors or their agents.

                                                           03.31
-- 
    This space intentionally left blank


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

Date: Sun, 22 Jul 2001 00:45:04 +0200
From: "Ciric Vukasin" <cvule@eunet.yu>
Subject: PASCAL > PERL
Message-Id: <9jd0h1$i1g$1@news.eunet.yu>

How to convert this code into PERL ?

b:=(((pom XOR 197) XOR 247 ) XOR 231);
b:=b+2*i+7;
pom:=b mod 10;
Res:=Res+Chr(Ord('0')+pom)

Thanks in adv.




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

Date: Sat, 21 Jul 2001 23:50:15 GMT
From: "John W. Krahn" <krahnj@acm.org>
Subject: Re: PASCAL > PERL
Message-Id: <3B5A158B.D9806AAF@acm.org>

Ciric Vukasin wrote:
> 
> How to convert this code into PERL ?
> 
> b:=(((pom XOR 197) XOR 247 ) XOR 231);

$b = ((( $pom ^ 197 ) ^ 247 ) ^ 231 );

> b:=b+2*i+7;

$b += 2 * $i + 7;

> pom:=b mod 10;

$pom = $b % 10;

> Res:=Res+Chr(Ord('0')+pom)

Sorry, don't know what Chr() and Ord() do in Pascal but I'll take a
guess that they're the same as Perl's chr() and ord().

$Res += chr( ord( '0' ) + $pom );



John
-- 
use Perl;
program
fulfillment


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

Date: 21 Jul 2001 23:55:04 GMT
From: ebohlman@omsdev.com (Eric Bohlman)
Subject: Re: PASCAL > PERL
Message-Id: <9jd4oo$let$6@bob.news.rcn.net>

Ciric Vukasin <cvule@eunet.yu> wrote:
> How to convert this code into PERL ?

> b:=(((pom XOR 197) XOR 247 ) XOR 231);

In Perl, assignment is '=', exclusive or is '^' and scalar (simple number 
or string) variables start with '$'.  So you want:

$b = ((($pom^197)^247)^231);

> b:=b+2*i+7;

You should be able to convert this yourself now, but read up on the "+=" 
operator in the perlop manpage to see a more Perlish way of doing such 
assignments.

> pom:=b mod 10;

In Perl, the modulus operator is '%'.

> Res:=Res+Chr(Ord('0')+pom)

In perl, the chr() and ord() functions are written in all lower case (case 
is significant in Perl identifiers) but otherwise work as they do in 
Pascal.



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

Date: Sat, 21 Jul 2001 23:56:42 GMT
From: "John W. Krahn" <krahnj@acm.org>
Subject: Re: PASCAL > PERL
Message-Id: <3B5A170F.C6C7FA53@acm.org>

"John W. Krahn" wrote:
> 
> Ciric Vukasin wrote:
> >
> > How to convert this code into PERL ?
> >
> > b:=(((pom XOR 197) XOR 247 ) XOR 231);
> 
> $b = ((( $pom ^ 197 ) ^ 247 ) ^ 231 );
> 
> > b:=b+2*i+7;
> 
> $b += 2 * $i + 7;
> 
> > pom:=b mod 10;
> 
> $pom = $b % 10;
> 
> > Res:=Res+Chr(Ord('0')+pom)
> 
> Sorry, don't know what Chr() and Ord() do in Pascal but I'll take a
> guess that they're the same as Perl's chr() and ord().
> 
> $Res += chr( ord( '0' ) + $pom );

Maybe that should be:

$Res .= chr( ord( '0' ) + $pom );



John
-- 
use Perl;
program
fulfillment


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

Date: Sat, 21 Jul 2001 23:52:56 GMT
From: "Andrew Hamm" <ahamm.NO$PAM@sanderson.NO$PAM.net.au>
Subject: Re: perl and Informix
Message-Id: <3b1ecf8a@news.iprimus.com.au>

John Imrie <07950232225@one2one.net> wrote in message
<3B175677.44F915A8@one2one.net>...
>
>This link
http://aspn.activestate.com/ASPN/Downloads/ActivePerl/PPM/Packages
>will give you a list of all the other precompiled packages you can get with
ppm
>
>See the Active State ppm documentation for more info
>
I haven't PPM'd on windowz without a C compiler, and i haven't a chance to
test it. What happens with modules that require C compiling? Or are ppm
deliveries pre-compiled? What do you do if you want to put down a module
from CPAN that can't be found from ActiveState in a pre-compiled condition?
Surely you need a C compiler then. I'm not aware of DBD::Informix being
available in a pre-compiled form, but then again, I haven't really gone
looking for it;-)

--
"Dis act ain't about lafter - it's about comedy" - Andrew Dice Clay





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

Date: Sat, 21 Jul 2001 18:59:42 -0500
From: S P Arif Sahari Wibowo <arifsaha@yahoo.com>
Subject: POSIX' sprintf doesn't regard locale?
Message-Id: <Pine.GSO.4.10.10107211855320.19976-100000@bluestem.prairienet.org>

Apparently the perllocale documentation is wrong. Although it said that
printf and sprintf will obey the LC_NUMERIC locale information, and that
print and internal conversions between numeric and string formats don't
get affected, the reality is reverse.

print & internal conversion obey locale information
printf and sprintf DON'T obey locale information

Here is the code from perllocale documentation:
-------------------------------------------------------------------------
use strict;
use POSIX qw(locale_h strtod);
use locale;

setlocale(LC_NUMERIC, 'de_DE@euro');
my($n) = 5/2;   # Assign numeric 2.5 to $n
my($a) = " $n"; # Locale-independent conversion to string
print "half five is $a (locale independent)\n";
print "half five is $n (locale independent)\n"; # Locale-independent
output
printf "half five is %g (locale dependent)\n", $n; # Locale-dependent
output
print "DECIMAL POINT IS COMMA\n"
    if $n == (strtod("2,5"))[0]; # Locale-dependent conversion
-------------------------------------------------------------------------

This is the output I got:

-------------------------------------------------------------------------
half five is  2,5 (locale independent)
half five is 2,5 (locale independent)
half five is 2.5 (locale dependent)
DECIMAL POINT IS COMMA
-------------------------------------------------------------------------

As you can see, it actually give result different from what the perllocale
said it would, except for the last output from strtod.

My systems are several Athlon machines running i386 Red Hat Linux 7.0 and
7.1, all running perl 5.6.0. The POSIX unit is part of the perl 5.6.0
distribution.

How to get printf and sprintf to regard locale?

Thanks.

-- 
                                   S P Arif Sahari Wibowo
  _____  _____  _____  _____ 
 /____  /____/ /____/ /____          arifsaha@yahoo.com
_____/ /      /    / _____/       http://www.arifsaha.com/



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

Date: Sat, 21 Jul 2001 16:06:48 -0700
From: "Brian D. Green" <greenbd@u.washington.edu>
Subject: Re: Repetitive if statements
Message-Id: <Pine.A41.4.33.0107211603260.145464-100000@dante59.u.washington.edu>

On Sat, 21 Jul 2001, Godzilla! wrote:

> Alexis Machin wrote:
>
> > Godzilla! wrote:
>
(more snippage)

> > >Your method of tag resizing graphics changes the visual
> > >size of your graphics but not the file size. A browser
> > >will still load the full size bytes and produce a scaled
> > >downed visual graphic. This really slows down a browser.
> > >Avoid this. Make "real" thumbnails and full size images
> > >as needed, with a clickable link to a full size. Your
> > >visitors will appreciate this although no word of thanks
> > >will come your way. Don't use tag resizing, it's not good.
>
> > Utter rubbish.
>
> > Although you've guessed correctly that sending down large images
> > then down sizing them on the page is not a good idea....
>
> My oh my, will ya read yourself contradicting yourself in
> the same breath! Goodness, you do seem to enjoy flaunting
> your fatally flawed thinking!

For the record, Alexis was right. I specified the image sizes to improve
load time; the files are all less than 0.2K anyway. Thanks for
contributing, though.

Cheers,
Brian Green			http://students.washington.edu/greenbd/

O-----------------------------------------------------------------------O
|"I am not ashamed of the gospel, because it is the power of God for the|
|  salvation of everyone who believes: first for the Jew, then for the  |
|    Gentile."					 --Romans 1:16, NIV     |
O-----------------------------------------------------------------------O



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

Date: Sat, 21 Jul 2001 19:57:52 -0400
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: splitting an array on an empty line
Message-Id: <3B5A1700.E67E2C41@earthlink.net>

Another Newbe wrote:
> 
> Can this be done?
> 
> I store a message body in an array via the Mail::Internet module
> Is it possible to split after the firsth paragraph?

If you want to seperate the mime headers from the message, use this:
($header, $body) = split( /(?<=\n)\n/, $message, 2 );

If what you want is what you said, taking the message body itself and
splitting, then do one of these:

If you want to discard the blank line, then use this:
($paragraph1, $rest) = split( /(?<=\n)\n/, $message, 2 );

If you want the blank line to be part of the first paragraph:
($paragraph1, $rest) = split( /(?<=\n\n)/, $message, 2 );

If you want the blank line to be part of the "rest" section:
($paragraph1, $rest) = split( /(?<=\n)(?=\n)/, $message, 2 );

Most likely, you will want to either discard it or have it as part of
the first paragraph.

-- 
The longer a man is wrong, the surer he is that he's right.


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

Date: Sun, 22 Jul 2001 02:39:22 +0200
From: mandor@gfxspace.com (Christian Klauss)
Subject: UDP Client/Server Tutorial
Message-Id: <Xns90E61B32773Bmeinepostings@62.153.159.134>

Hi,

Can anyone point me to a tutorial or working framework
of a UDP client/server (bi-directional) system in Perl?

Thanks for your help

Christian Klauss


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

Date: Sat, 21 Jul 2001 20:36:14 -0400
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: web interface to c program running on different server
Message-Id: <3B5A1FFE.F79B5E@earthlink.net>

Lee wrote:
> 
> Hi there,
> 
> I wonder if anyone reading this could be kind enough to offer me some
> advice. There is a piece of software being developed in C for
> performing various scientific calculations on various types of data. I
> have been asked to investigate the ways in which this could be made
> into a web application - specifically, a portal. Reimplementing the
> program in another language is not one I wish to investigate, as I
> believe the software has gone through months of testing already.
> 
> I can think of a few solutions, but I would appreciate the insight and
> advice of those with more experience than myself. I am working on the
> premise that the software written in C will be running on server X and
> the software creating the interface and the portal will be on server Y
> (with a database on server Z).
[snip java servlets and "zope," whatever that is, and XML-RPC]
> Ideally, I'd like to have maybe 5 or 6 different implementation
> suggestions with an associated set of pros and cons for each, so I'd
> love to hear lots of suggestions!

It depends on what interfaces to the software already exist.

If it's a library type of interface (like for other C programs to call
it), then probably the best solution would be XS, which is a C-like
language which gets processed into C code, which then gets compiled; you
can call functions in ordinary libraries from XS code.  Inline::C is
another way of mixing C and perl code, and may be easier to use.

If there's an existing XML-RPC interface, then you can use one of the
Perl modules already written for doing remote procedure calls with XML
as the transfer format.  A search on CPAN should provide you with what
you need.  (Umm, if you meant XDR, not XML, there's probably that,
too... maybe.  XDR is sun's eXternal Data Representation, and is more
compact than XML, but not widely used.)

-- 
The longer a man is wrong, the surer he is that he's right.


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

Date: Sun, 22 Jul 2001 08:58:54 +0800
From: MMX166+2.1G HD <no@mail.addr>
Subject: what is the defer form "my" to "local"?
Message-Id: <vrbiltsu9cbhak4qo96lp0mu0g64qpthiu@4ax.com>

they all work like the C auto, but what's the deference?


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

Date: Sun, 22 Jul 2001 08:58:55 +0800
From: MMX166+2.1G HD <no@mail.addr>
Subject: Re: Who can help me about the confused (..) operator?
Message-Id: <aqfilt41eaak44prrn0pbcsctokq830bs6@4ax.com>

^_^ Thank you very much, Great explanation!

>The false value returned by the range operator is the empty string.  The true
>value returned is the sequence number (starting with 1).  The final sequence
>number has the string E0 appended to it -- it's still a numeric value (1e0 is 
>just 1) but can be parsed to tell if you've run off the end of the list.
>
what dos the "sequence number" mean? Is it the count number of
evaluation? and when will it return the final sequence number?

>If an operand is a numeric literal, the operand is implicitly compared to the
>variable $. (line input number).  This allows you to mimic the behavior 
>of Unix utilities such as sed and awk.
>	while( <FH> ) {
>		print if (1..10);
>	}

I found that the $. is equal to the sum of *total* lines. So, this
examples did nothing actually.

BTW: Is this "Perl Developer's Dictionary" written by you?

--
On Sat, 21 Jul 2001 02:24:51 GMT, in comp.lang.perl.misc
clintp@geeksalad.org (Clinton A. Pierce) wrote:

>In article <050glt41plvq4pa3s8t2f2h0m1l06pnua0@4ax.com>,
>	MMX166+2.1G HD <no@mail.addr> writes:
>> Terrible range operator (..) which in the scalar context...I had read
>> the perldoc many times, but I can't understand it at all. Can any
>> kindly angel help me about this operator (in the scalar context)?
>
>Not a really easy operator to get your head wrapped around.  Here's an
>explanation extracted from the Perl Developer's Dictionary:
>
>******



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

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.  

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


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