[19872] in Perl-Users-Digest
Perl-Users Digest, Issue: 2067 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sun Nov 4 21:10:55 2001
Date: Sun, 4 Nov 2001 18:10:11 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <1004926211-v10-i2067@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Sun, 4 Nov 2001 Volume: 10 Number: 2067
Today's topics:
Re: Perl-Bug? It crashes while accessing hash value!!! <echang@netstorm.net>
Re: reading flat-file db and replacing a word <wwonko@rdwarf.com>
Re: Sending Content Type in email <Juha.Laiho@iki.fi>
Re: Sending Content Type in email (Glenn White)
Re: Serial Port control under Win32::SerialPort <ned@bike-nomad.com>
Re: Software error with -T using sendmail (Garry Williams)
Re: Split output into multiple pages? <nospam_kingony@yahoo.com>
Re: Tainting with Tad <was Taint problem with BEGIN blo <whataman@home.com>
Re: Tainting with Tad <was Taint problem with BEGIN blo <whataman@home.com>
Re: Untainting globally with regular expression? (Tad McClellan)
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Mon, 05 Nov 2001 00:52:58 GMT
From: "E.Chang" <echang@netstorm.net>
Subject: Re: Perl-Bug? It crashes while accessing hash value!!!
Message-Id: <Xns914FCB429144Eechangnetstormnet@207.106.93.86>
"Markus Dehmann" <markus.cl@gmx.de> wrote in
news:9s49eg$10kt6b$1@ID-101658.news.dfncis.de:
[snip]
> Before the certain value is accessed and contains errors, I work
> with a reference to $self->{'SEP'}. The reference is called
> $hashRef
>
> foreach ( @{$ {$hashRef}{$key}} ){
> my ($num1, $num2) = split (';', $_);
> ...
> # Later:
> $_ = 'I'; # Causes the error later
> print; # print an I
> }
>
> So, it seems, $_ = 'I' has inserted the char 'I' into the array
> that is stored in the hash. And so, the perl interpreter crashed
> when accessing this element later becauseit is not properly
> inserted and allocated.
>
> But why did $_ = 'I' insert the char into the array????
In a foreach loop, the interating variable (in this case $_) is
"aliased" to each value in the array that you interate over. That
means that it is a synonym for the actual value, not a copy. For
example
@arr = (1, 2, 3);
foreach (@arr) {
$_ *= 2;
}
print "@arr\n";
will print 2 4 6.
--
EBC
------------------------------
Date: Mon, 5 Nov 2001 00:40:24 +0000 (UTC)
From: Louis Erickson <wwonko@rdwarf.com>
Subject: Re: reading flat-file db and replacing a word
Message-Id: <9s4n5o$anc$1@holly.rdwarf.com>
Tad McClellan <tadmc@augustmail.com> wrote:
: Louis Erickson <wwonko@rdwarf.com> wrote:
:>Carsten Menke <bootsy52@gmx.net> wrote:
:>: On Sun, 04 Nov 2001 02:19:44 +0100, Tad McClellan wrote:
:>I would handle this by reading the records, one line at a time, and
:>writing out updated records, or skipping a record to be deleted.
: In case other readers don't recognize it, the above is "ripping
: through the file with -i and a while <> loop".
Actually, I wouldn't have used -i, and would have used a set of
renames at the end. Adding the extra command line switch always
seems less clear to me, so I wind up doing it explicitly in code.
:>I hate to say this, but what you're describing here is a database.
:>This is what databases do, and someone ELSE has written and debugged
:>and tested that whole big mess of code so you don't have to. A
:>good database handles all the problems of multiple people making
:>changes to the data at once, and keeping the data consistent
:>when errors happen.
:>
:>I do understand that saying, "We need a database!" is a big step,
:>and kind of scary for a lot of people, but it is the right answer.
: Right.
:>You will also be faster that way, and be able to handle any
:>amount of load and many unforseen things, which this code will
:>be much harder to maintain. Perl's DBI lets you access many
:>databases, such as MySql, ODBC, Sybase, and others.
: ^^^^^
: ^^^^^
: Note that that particular DB does not provide all that has been
: described here.
Eek. Really? I'd been told that the newer versions of it had
resolved those issues, if you used the right type of database.
I know that it formerly didn't, and thought they'd addressed
that. Considering that it lacks those things, the number of
people which use it for critical things surprises me a lot.
: PostgreSQL is free and does have the "ACID" database properties,
: I'd look into using that.
I am going to retrain my brain to think of PostgresSQL first.
I have only heard good things about it.
I actually use Borland's InterBase, which they have recently
made open source. It is a fine system, and you can buy
support (for a LOT of money!) if your management seems to
feel they must pay for a database and get good support from
people on the 'net, for free.
So, there are a lot of tools out there for databases.
The problem becomes using a database; you trade the ease of
understanding and development of flat files for the complexity
of SQL and a database, but you gain concurrency, and transactions
and some other very useful things.
------------------------------
Date: 4 Nov 2001 07:25:16 GMT
From: Juha Laiho <Juha.Laiho@iki.fi>
Subject: Re: Sending Content Type in email
Message-Id: <9s2qgs$uco$1@ichaos.ichaos-int>
spam.killer@home.com_nospam (Glenn White) said:
>I've created a Perl program that runs on NT that uses sendmail to email
>text that contains mono-spaced tables.
Ok.
>The people using the MS products usually have their mail readers set to
>display something like Times font.
Too bad. Can't help that.
>$mail{'Content-type'} = 'text/plain; charset="iso-8859-1"';
>$mail{'Content-type'} = 'text/plain; charset="US-ASCII"';
Ok. These specify that the content is text, with different character
encodings. The recipient is still free to choose the font used, and
will bear the responsibility to check that the font will support the
character set.
>I can see the content type listed in the email header, but the mail
>programs will not display it as a mono-type font.
Because for plain text it's up to the recipient to choose the font s/he
likes. The sender is not to control that (and in some cases, like when
using text-only terminals, it can't be controlled by the recipient,
either).
So, not a Perl question. Proposed solution would be to add a note to
the beginning of the message that for sake of readability the recipient
should switch to fixed-width font. The other solution would be to put
the layout-critical content to a non-plaintext attachment (in some format
that supports tables and other layout primitives). HTML and PDF come to
mind. HTML tables might even be somewhat readable on a text-only terminals.
--
Wolf a.k.a. Juha Laiho Espoo, Finland
(GC 3.0) GIT d- s+: a C++ UH++++$ UL++++$ P++@ L+++ E(-) W+$@ N++ !K w !O
!M V PS(+) PE Y+ PGP(+) t- 5 !X R !tv b+ !DI D G e+ h--- r+++ y+++
"...cancel my subscription to the resurrection!" (Jim Morrison)
------------------------------
Date: Mon, 05 Nov 2001 00:28:41 GMT
From: spam.killer@home.com_nospam (Glenn White)
Subject: Re: Sending Content Type in email
Message-Id: <Xns914FA7943A022ccruizermydejacom@24.0.0.25>
spam.killer@home.com_nospam (Glenn White) wrote in
<Xns914EB018994A7ccruizermydejacom@24.0.0.25>:
>I've created a Perl program that runs on NT that uses sendmail to email
>text that contains mono-spaced tables.
<-- snip -->
Thanks for the info. The change request is actually a case of scope creep
and was not in the original specs. I will heed Tassilo's suggestions:
Either they can do it or submit it as a new request to create a
"multipart/alternative email ." Otherwise, the best suggestion is, "But
don't do it and instead leave the font used as a choice for the recipient."
Thanks for the suggestions.
------------------------------
Date: Sun, 04 Nov 2001 18:07:28 -0800
From: Ned Konz <ned@bike-nomad.com>
Subject: Re: Serial Port control under Win32::SerialPort
Message-Id: <tubst5lu81nbd6@corp.supernews.com>
David wrote:
> I can't seem to figure out how to
The following info is from the manpage of Device::SerialPort (which should
be similar or identical to Win32::SerialPort but I don't use Windows much)
under "Operating Methods". Does the Win32::SerialPort manpage not have
these?
> 1) Set RTS high/low
(set no handshaking when you open the port first)
$PortObj->rts_active(Yes); # return status of ioctl call
# return undef on failure
> 2) Detect CD high/low
$ModemStatus = $PortObj->modemlines;
if ($ModemStatus & $PortObj->MS_RLSD_ON) { print "carrier detected"; }
> 3) Capture raw binary data (i.e. 0x01, 0x00, etc.)
($count_in, $string_in) = $PortObj->read($InBytes);
warn "read unsuccessful\n" unless ($count_in == $InBytes);
> Can this be done with Perl?? I looked at Win32API::CommPort and these
> lower level functions look like the right thing, but I still can't
> figure out the afterfore mentioned things.
>
> What sort issues do I have to worry about if I want to do the same
> under Linux?
Use Device::SerialPort instead of Win32::SerialPort.
Here's a little tidbit that might help:
# Lets serial port programs written for either Windows or Unix
# work on the other kind of system without modification.
# By Ned Konz, ned@bike-nomad.com, http://bike-nomad.com
# This script must have only LF line endings to work cross-platform.
# usage:
# perl -MAnySerialPort myProgram.pl
#
# This will map port names between Linux and Windows; if your system doesn't
# use the same mappings, you can call
# Device::SerialPort::mapPorts
# or
# Win32::SerialPort::mapPorts
# to change it:
# Device::SerialPort->mapPorts('COM1:' => '/dev/magicSerial0',
# 'COM2' => '/dev/magicSerial1');
use strict;
package AnySerialPort;
use vars '@ISA';
BEGIN {
my %portMap;
my $oldNew;
my $onWindows = 0;
if ($^O eq 'MSWin32') # running on Win32
{
$onWindows = 1;
eval "use Win32::SerialPort";
*main::Device::SerialPort:: = *main::Win32::SerialPort::;
$oldNew = \&Win32::SerialPort::new;
$INC{'Device/SerialPort.pm'} = $INC{'Win32/SerialPort.pm'};
%portMap = ('/dev/ttyS0' => 'COM1:',
'/dev/ttyS1' => 'COM2:',
'/dev/ttyS2' => 'COM3:',
'/dev/ttyS3' => 'COM4:',
);
}
else # running on Unix
{
eval "use Device::SerialPort";
*main::Win32::SerialPort:: = *main::Device::SerialPort::;
$oldNew = \&Device::SerialPort::new;
$INC{'Win32/SerialPort.pm'} = $INC{'Device/SerialPort.pm'};
%portMap = ('COM1:'=> '/dev/ttyS0',
'COM2:'=> '/dev/ttyS1',
'COM3:'=> '/dev/ttyS2',
'COM4:'=> '/dev/ttyS3',
);
}
die "$@\n" if $@;
@ISA = 'Device::SerialPort';
# Hook the constructor so we can map the port names
# and class if needed
*main::Device::SerialPort::new = sub {
my $class = shift;
my $portName = shift;
if ($onWindows != ($class eq 'Win32::SerialPort'))
{
$portName = $portMap{$portName} || $portName;
$class = $onWindows ? 'Win32::SerialPort' : 'Device::SerialPort';
}
$oldNew->($class, $portName, @_);
};
# Gets and/or modifies the port mapping
# Returns a hash
sub Device::SerialPort::mapPorts
{
my $self = shift;
%portMap = (%portMap, @_);
}
}
1;
------------------------------
Date: Mon, 05 Nov 2001 00:25:47 GMT
From: garry@ifr.zvolve.net (Garry Williams)
Subject: Re: Software error with -T using sendmail
Message-Id: <slrn9ubn4b.32d.garry@zfw.zvolve.net>
On Sun, 04 Nov 2001 22:00:33 GMT, spamfree <spamfree@go-away.net> wrote:
> I wish to enable taint but get software error opening sendmail.
> Do I need to untaint path?
> If so, how to do that.
>
> #!/usr/bin/perl -Tw
> #<code cut>
> open (MAIL, "|/usr/sbin/sendmail -t") || &ErrorMessage;
> # Insecure $ENV{PATH} while running with -T switch ?
Read the perlsec manual page.
Set the PATH environment variable to an appropriate value *before*
using system():
$ENV{PATH} = "/usr/bin";
--
Garry Williams
------------------------------
Date: Sun, 04 Nov 2001 23:22:35 GMT
From: "Aaron Dancygier" <nospam_kingony@yahoo.com>
Subject: Re: Split output into multiple pages?
Message-Id: <%4kF7.37115$XA5.8309028@typhoon.nyc.rr.com>
Are you developing on unix?
1)If you are run a wc -l on the file to get the number of line. An even
better way around the wc -l is to include the number of lines in the file as
part of the filename.
2)Set a page length constant to what ever you want. ($page_length = 25)
3)Calculate the number of pages. $maxpages = int($num_lines / $page_length)
+ (($num_lines % $page_length) ? 1 : 0);
4)For calculating the page interval links you could predefine an array or
better yet just take the log of the number of pages.
$lastinterval = int(log10($num_lines));
for ( 0 .. $lastinterval)
{
link_interval(10 ** $_);
## where link_interval creates self referential link with a page
number. You'd get page intervals 10**0, 10**1, 10**2, ... 10**n( 1, 10, 100,
...)
}
5) You could store the entire file in an array and calculate what offset to
start printing at.
6) You could do a linear go through of the file and start printing at the
correct line.
7) You could use a combination of head and tail to print out slices of the
file.
"Andrew Cady" <please@no.spam> wrote in message
news:87vggqq389.fsf@homer.cghm...
> ccking@consultant.com (Charles King) writes:
>
> > Have a problem with a script which prints designated fields from
> > *all records* in a flat file database. The problem is how to split
> > what gets printed into multiple pages with links at the bottom to
> > the other pages.
>
> [...]
>
> > while (<DATABASE>)
> > {
> > $row = $_;
> > chop $row;
> > @stuff = split (/\|/, $row);
> > &table_row; # prints designated fields in the record
>
> $row shouldn't be global. Nor @stuff. Pass the values to print to
> table_row.
>
> > $count++;
> > }
> > close (DATABASE);
> > $count--;
>
> Why $count-- ? Start the count at 0. Unless it's a global you're
> using in table_row, in which case don't do that.
>
> > &table_footer;
> > }
> >
> > print "$footertemplate";
> >
> > ____________________________________________________________________
> >
> > The following code works well to split the pages in a Search script.
> > I'm hoping it could be adapted, or maybe there's a much simpler way?
>
> [snip unreadable cludge]
>
> I remember this code. Still trying to get that monstrosity to work,
> huh? I think you should give up and try to write something on your
> own from scratch... or find something better to start from at least.
>
> Anyway, the basic idea is this:
>
> sub PAGERECS { 30 };
>
> my $i = 0;
> while (<DATABASE>) {
> chomp;
> print_header() if ($i % PAGERECS == 0);
> print_row(split /\|/);
> print_footer() if (++$i % PAGERECS == 0);
> }
> print_footer() unless ($i % PAGERECS == 0); # print unless we just did
>
> That's to split into pages, but print ALL RECORDS, which is what you
> said you wanted, although it seems like it might make more sense to
> print only a portion of the records, which is just as easy:
>
> my ($from, $to) = (30, 60); # print records [30,60[
>
> my $i = 0;
> while (<DATABASE>) {
> ++$i;
> next unless $i >= $from;
> last unless $i < $to;
>
> # do whatever...
> }
------------------------------
Date: Mon, 05 Nov 2001 00:40:37 GMT
From: "What A Man !" <whataman@home.com>
Subject: Re: Tainting with Tad <was Taint problem with BEGIN block>
Message-Id: <3BE5E01C.B02D1F54@home.com>
[from same person as dennis100@webtv.net]
Tad McClellan wrote:
>
> [ something really funky has happened to your formatting,
> your post is barely readable to me.
> ]
Sorry. I'll reply from my PC addy this time so that I can quote better.
> >> > BEGIN {
> > $ENV{PATH} = "/usr/bin:/bin:/usr/local/bin";
> >> Why are you not ending the BEGIN block right here?
>
> Messing with %ENV is the only thing requiring you to have a
> BEGIN block at all. You do not need a BEGIN block for anything
> else that you are doing. (as far as I can see, and my immediate
> record doesn't provide encouragement that I'm right here either.)
>
I thought you meant something was wrong with the syntax; but you're just
saying that that all of that coding doesn't need to be in a BEGIN block,
except for the first line that begins with $ENV. Thanks. I obviously
don't understand BEGIN blocks like I thought. From his response, I think
Martien also perceived my ignorance in that area.
> >> my $stats = stat("$dir/$f") or die "Can't stat: $!";
> >> if ( $stats->mtime < $age ) {
>
> >I'm using File::stat, in
> >case you didn't notice.
>
> Doh! No, I didn't notice.
>
> I owe you an apology.
>
Apology accepted. Thanks.
> That'll teach me to dip down to the bottom of the
> scorings. We would have both been better off if
> I had never read it.
> )
I wouldn't be better off. You helped me improve my coding and explained
things that I didn't understand. I appreciate it and hope that also
makes you feel a little better about it.
Regards,
--Dennis
------------------------------
Date: Mon, 05 Nov 2001 00:43:02 GMT
From: "What A Man !" <whataman@home.com>
Subject: Re: Tainting with Tad <was Taint problem with BEGIN block>
Message-Id: <3BE5E0AC.FCC6AE7E@home.com>
Martien Verbruggen wrote:
>
> >> system("rm", "-r", "$dir/$f");
> >> };
> >> };
> >> 1;
>
> Also, this 1 is unnecessary, unless it is the last bit of the module. A
> BEGIN block doesn't need to return a true value, unless it's used by
> something. A module needs to return a true value, which I suspect you're
> trying to do here. You should however not do that in a BEGIN block.
>
> You did read up what a BEGIN block is, right? In perlsub and perlmod,
> for example.
>
> Martien
> --
Thanks, Martien. I didn't know that.
--Dennis
------------------------------
Date: Sun, 04 Nov 2001 23:25:18 GMT
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Untainting globally with regular expression?
Message-Id: <slrn9ubgq0.3ea.tadmc@tadmc26.august.net>
spamfree <spamfree@go-away.net> wrote:
>
>"Tad McClellan" <tadmc@augustmail.com> wrote in message
>news:slrn9u7upt.g7m.tadmc@tadmc26.august.net...
>> spamfree <spamfree@go-away.net> wrote:
>> >I want to throw in some code which untaints input from all params in one
>> >foul swoop...
>> Possibly. It depends on what characters are allowed in each
>> variable and what you are going to do with each variable.
>>
>> Of course if you don't happen to be doing anything "dangerous"
>> with a variable, you don't need to untaint it at all.
>>
>Its users input I'm worried about!
"validating data" does not require taint checking.
You only need taint checking if you are going to do "something
dangerous" with the input.
>> You should laboriously untaint each variable, since they should
>> probably have different patterns.
>> my %var; # all "variables" are colleced here as hash keys
>Is my %var; a special variable?
No, choose whatever name you like.
>> Or, better yet, use a HoH to associate each pattern with the
>> scalar that it is to be applied to (untested):
>>
>> my %var = (
>> firstname => { value => 'wherever the value comes from',
>> untaint => qr/[\w .,-]+/
>> },
>I don't fully understand the line: untaint => qr/[\w .,-]+/
>what does qr mean?
Quote a Regex;
perldoc -f qr
>and whats a HoH?
Hash of Hashes.
perldoc perllol
perldoc perldsc
%var's keys are "variable names" its values are references to
another level of hash. Each "inner" hash has 2 key/values
one holds the actual value, the other holds a pattern that
can be used to untaint that value.
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
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 2067
***************************************