[19550] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 1745 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Sep 14 09:05:27 2001

Date: Fri, 14 Sep 2001 06:05:08 -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: <1000472708-v10-i1745@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Fri, 14 Sep 2001     Volume: 10 Number: 1745

Today's topics:
    Re: Client Timeout (Ilja Tabachniks)
    Re: file output <Thomas@Baetzler.de>
    Re: Help needed using "CDONTS.NewMail" in Perl scripts  <Thomas@Baetzler.de>
        HELP: File corruption on opening. <andytolley@hotmail.com>
    Re: HELP: File corruption on opening. <Thomas@Baetzler.de>
        Hex registry key (Phil Hibbs)
    Re: Hex registry key <Thomas@Baetzler.de>
        How do I see the actual error in an "eval" section? (Sara)
    Re: How do I see the actual error in an "eval" section? <Thomas@Baetzler.de>
    Re: How to comment C++  code using a Perl Script <goldbb2@earthlink.net>
    Re: How to comment C++  code using a Perl Script <wuerz@yahoo.com>
    Re: How to comment C++  code using a Perl Script <wyzelli@yahoo.com>
        Lotus Notes <hg_zauner@gmx.de>
        max length of keys? <kkoch@kxsu.de>
    Re: max length of keys? <Thomas@Baetzler.de>
        passwd and perl (Alex)
    Re: passwd and perl <diablo@prometheus.humsoc.utas.edu.au>
    Re: passwd and perl <Thomas@Baetzler.de>
    Re: Perl (slurping) is TOO much fun <bart.lateur@skynet.be>
        perl error checking routine <spamfree@sorted2000.net>
    Re: perl error checking routine <Thomas@Baetzler.de>
    Re: Problems with format (perlform) and carriage return <goldbb2@earthlink.net>
    Re: recognize MS Windows with perl <bart.lateur@skynet.be>
    Re: Recommendations for a PERL editor <Thomas@Baetzler.de>
    Re: Source Code Bracket Matching Utility Needed (Sam Holden)
        Using the c preprocessor for non c purposes <bcaligari@fireforged.com>
    Re: Using the c preprocessor for non c purposes <noselasd@frisurf.no>
    Re: xml parser <bart.lateur@skynet.be>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: 14 Sep 2001 05:57:41 -0700
From: billy@arnis-bsl.com (Ilja Tabachniks)
Subject: Re: Client Timeout
Message-Id: <5d4a715a.0109140457.50135506@posting.google.com>

Andrew Paul Gorton <gortona@cs.man.ac.uk> wrote in message news:<3BA0D25A.29291580@cs.man.ac.uk>...
> Hi,
> 
> I have a client/server  running, but I need the client to end the
> connection, if the server takes too long.
> 
> I am using IO::Socket.  I have tried using the timeout function on the
> client side but it does not work.
> 
> How could you wrap the client side so it can timeout
> 
> use strict;
> use IO::Socket;
> my $host = shift || 'localhost';
> my $port = shift || 2025;
> my $sock = new IO::Socket::INET(
>                   PeerAddr => $host,
>                   PeerPort => $port,
>                   Proto    => 'tcp',
> 		  );
> $sock or die "no socket :$!";
> 
> print $sock "GET_DATA\n";
> print scalar <$sock>;



You could use alarm() to generate SIGALRM, which in turn
can caught by a signal handler.

There is a FAQ: "How do I timeout a slow event?",
please consult 'perldoc -q timeout'.

Also, 'perldoc -f alarm' contains a complete example.

AFAIK, perldoc perlipc (section "Signals") also had some
code example with alarm().

Hope this help,
Ilja.


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

Date: Fri, 14 Sep 2001 10:30:06 +0200
From: =?ISO-8859-1?Q?Thomas_B=E4tzler?= <Thomas@Baetzler.de>
Subject: Re: file output
Message-Id: <5rf3qt826et32limlkg7s193l3fpsrr1ip@4ax.com>

On Thu, 13 Sep 2001 12:39:10 -0700, "kyi" <kyi@psnw.com> wrote:
>So how do I make the output file the current date in, date +%x, format?
>Instead of my phonelog.txt.name.

Create a suitable filename on the fly when you open the file:

# date today
my ( $day, $month, $year ) = ( localtime time ) [ 3..5 ];
$month++;
$year += 1900;

my $file = sprintf "/whatever/%02d%02d%4d.ext", $day, $month, $year;

open( OUT, ">$file" ) or die "Cn't open '$file' for writing: $!\n";

HTH,
-- 
use strict;my($i,$t,@r)=(0,'5 -.@BHJPT4acd6e2hk2lmn2o4r2s3tuz',map{ord}
split//,unpack('u*','L#`T&)QD5#0`#!!`#%1D)#08`#P05!!(3``$$"``#"0L&``('.
'"`P<!`````0$`'));$t=~s/(\d)(.)/$2x$1/eg;map{$t.=substr$t,$i,1,''while
$_--;$i++}@r;print"$t\n";# Thomas@Baetzler.de - http://baetzler.de/perl


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

Date: Fri, 14 Sep 2001 10:35:12 +0200
From: =?ISO-8859-1?Q?Thomas_B=E4tzler?= <Thomas@Baetzler.de>
Subject: Re: Help needed using "CDONTS.NewMail" in Perl scripts (with Win32::OLE)?
Message-Id: <h5g3qt493uhaad9pjs6mhp3r221ug64e0s@4ax.com>

On Fri, 14 Sep 2001, "Batormaster666" <batormaster666@hotmail.com>
wrote:
>I've been trying to use the COM component CDONTS.NewMail in my Perl CGI
>script but keep getting errors.
[...]

Why don't you use MIME::Lite and Net::SMTP instead? They're much
easier to use and your code will be portable. I'd also wager some
money that your web server will be more stable if you refrain from
using stuff like OLE.

Just my $0.02 of course.
-- 
use strict;my($i,$t,@r)=(0,'5 -.@BHJPT4acd6e2hk2lmn2o4r2s3tuz',map{ord}
split//,unpack('u*','L#`T&)QD5#0`#!!`#%1D)#08`#P05!!(3``$$"``#"0L&``('.
'"`P<!`````0$`'));$t=~s/(\d)(.)/$2x$1/eg;map{$t.=substr$t,$i,1,''while
$_--;$i++}@r;print"$t\n";# Thomas@Baetzler.de - http://baetzler.de/perl


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

Date: Fri, 14 Sep 2001 12:08:59 +0100
From: "IICS" <andytolley@hotmail.com>
Subject: HELP: File corruption on opening.
Message-Id: <1000465869.25539.0.nnrp-08.c1ed7194@news.demon.co.uk>

Hi all,

Could anyone possibly shed some light on a little problem im having.

Im attempting to open a datafile (simple fixed width fields database file).
However as soon as its opened its getting corrupted.

im using the following lines of code to open the file

$dbname = "orders.dat";

sysopen(ORDERS,$dbname,2);

close(ORDERS);

Ive got the use Fcntl ':flock'; line at the start of my code so its picking
up on that ok.

Basically without doing any sort of reading or writing to the datafile it
corrupts the database.  It appears to chop each line into three parts.  The
first part of each line gets written to the start of the file, the middle
part of each line ends up in the middle of the file and the end parts get
mainly written to the end of the file.

Ive got code elsewhere in the script that opens another datafile and reads
it in fine, but as soon as my perl script touches the orders.dat file it
goes pear shaped.

Ive also tried to open the file using the standard open (ORDERS,
">$dbname"); line but the same problem occurs.  This is also happening if I
attempt to open it in read only mode.

Please help me before I remove what little remains of my hair and my sanity
finaly takes a leave of absence.

Andy.




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

Date: Fri, 14 Sep 2001 14:10:47 +0200
From: =?ISO-8859-1?Q?Thomas_B=E4tzler?= <Thomas@Baetzler.de>
Subject: Re: HELP: File corruption on opening.
Message-Id: <pls3qt8an01p8p27ef4u8eigcufeh5qpok@4ax.com>

On Fri, 14 Sep 2001, "IICS" <andytolley@hotmail.com> wrote:
>Im attempting to open a datafile (simple fixed width fields database file).
>However as soon as its opened its getting corrupted.
>
>im using the following lines of code to open the file
>
>$dbname = "orders.dat";
>
>sysopen(ORDERS,$dbname,2);

You really should use the symbolic constants exported by the Fnctl
module. Have you read perlopentut yet? Try "perldoc perlopentut" if
you haven't done so yet.

What is it exactly you're trying to do?

Questions, questions...
-- 
use strict;my($i,$t,@r)=(0,'5 -.@BHJPT4acd6e2hk2lmn2o4r2s3tuz',map{ord}
split//,unpack('u*','L#`T&)QD5#0`#!!`#%1D)#08`#P05!!(3``$$"``#"0L&``('.
'"`P<!`````0$`'));$t=~s/(\d)(.)/$2x$1/eg;map{$t.=substr$t,$i,1,''while
$_--;$i++}@r;print"$t\n";# Thomas@Baetzler.de - http://baetzler.de/perl


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

Date: 14 Sep 2001 01:55:38 -0700
From: phil@snark.freeserve.co.uk (Phil Hibbs)
Subject: Hex registry key
Message-Id: <979ae699.0109140055.775fd534@posting.google.com>

I have a registry key like this:

[HKEY_LOCAL_MACHINE\System\CurrentControlSet\Services\Foo]
"Bar"=hex:01,00,00,00

How do I detect whether this key is set to this exact value?

Here's my current code:

sub Reg_Get
{
    local($MASTERKEY, $KEY, $VARIABLE) = @_;
    local $VALUE = "";
    if ( NTRegOpenKeyEx ( $MASTERKEY, $KEY, &NULL, &KEY_ALL_ACCESS,
$hkey ) )
    {
        if ( ! NTRegQueryValueEx ( $hkey, $VARIABLE, &NULL, &REG_SZ,
$VALUE ) )
        {
            $VALUE = "";
        }
        NTRegCloseKey( $hkey );
    }
    return $VALUE;
}

$FooBar=Reg_Get(&HKEY_LOCAL_MACHINE,
'System\CurrentControlSet\Services\Foo',
'Bar', __FALSE__);
print " Foo/Bar flag is set\n" if $FooBar == "\x01\x00\x00\x00";

It prints the message regardless of what the value is set to. What am
I doing wrong (other than trying to use Perl 5.001 on Win32)? I don't
have a choice of Perl version, I have to work with 5.001 for this.

Phil Hibbs.


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

Date: Fri, 14 Sep 2001 11:39:40 +0200
From: =?ISO-8859-1?Q?Thomas_B=E4tzler?= <Thomas@Baetzler.de>
Subject: Re: Hex registry key
Message-Id: <2dj3qt0u4pr2gqmo991sk3phpbloldc0oh@4ax.com>

On 14 Sep 2001, phil@snark.freeserve.co.uk (Phil Hibbs) wrote:

>Here's my current code:
>
>sub Reg_Get
>{
>    local($MASTERKEY, $KEY, $VARIABLE) = @_;
>    local $VALUE = "";

See perlfaq7: "What's the difference between dynamic and lexical
(static) scoping? Between local() and my()?"

You almost certainly want to use "my" here.

my($MASTERKEY, $KEY, $VARIABLE) = @_;
my $VALUE;

You might also consider using small caps for variable names - most
people I know seem to reserve uppercase for constants.

>        if ( ! NTRegQueryValueEx ( $hkey, $VARIABLE, &NULL, &REG_SZ,
>$VALUE ) )
>        {
>            $VALUE = "";

You should set this to undef - there may well be a valid key that
contains an empty string.

>print " Foo/Bar flag is set\n" if $FooBar == "\x01\x00\x00\x00";

>It prints the message regardless of what the value is set to. What am
>I doing wrong (other than trying to use Perl 5.001 on Win32)? I don't
>have a choice of Perl version, I have to work with 5.001 for this.

The comparison will always be true since it's 0 == 0 - your RHS is a
character string, not a number. Either use "eq" to compare the
strings, or convert the binary representation to a number, perhaps
using unpack.

And box their ears to get upgraded to 5.6.1. I betcha they don't run
their Windows without current service packs, either.

HTH,
-- 
use strict;my($i,$t,@r)=(0,'5 -.@BHJPT4acd6e2hk2lmn2o4r2s3tuz',map{ord}
split//,unpack('u*','L#`T&)QD5#0`#!!`#%1D)#08`#P05!!(3``$$"``#"0L&``('.
'"`P<!`````0$`'));$t=~s/(\d)(.)/$2x$1/eg;map{$t.=substr$t,$i,1,''while
$_--;$i++}@r;print"$t\n";# Thomas@Baetzler.de - http://baetzler.de/perl


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

Date: 14 Sep 2001 05:20:30 -0700
From: genericax@hotmail.com (Sara)
Subject: How do I see the actual error in an "eval" section?
Message-Id: <776e0325.0109140420.328c055b@posting.google.com>

I recently had an oracle query error that was inside an eval, and the
only info I could get back from perl was there was some "eval Error".
How do I see what the error was? Oddly, $@ was empty. Usually I can
find the error there but I guess Oracle errors don't make it to $@?

In this case I pulled it into pdb and traced it to the prepare
statement, then rewrote the section ABOVE the eval, inserting the
Oracle query and prepare, then finally detected the actual error.


If you can point me to more info to read that would be great!

  tuxy> perldoc eval
  No documentation found for "eval".
  tuxy> perldoc perleval
  No documentation found for "perleval".

perldoc perlfunc had some useful info including mysterious @DB:: var,
which I don't think would apply as I'm not "using DB";. Maybe there is
a @DBI??


  DB<2> x @DB
  empty array
  DB<3> x @DB::args
  empty array
  DB<4> x @DBI
  empty array
  DB<5> 

Thanks!


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

Date: Fri, 14 Sep 2001 14:40:55 +0200
From: =?ISO-8859-1?Q?Thomas_B=E4tzler?= <Thomas@Baetzler.de>
Subject: Re: How do I see the actual error in an "eval" section?
Message-Id: <hiu3qtksbopiukg34ib2gn3e5dh3pdtu09@4ax.com>

On 14 Sep 2001 05:20:30 -0700, genericax@hotmail.com (Sara) wrote:
>  tuxy> perldoc eval

Try perldoc perldoc :-)

You want "perldoc -f eval". Now, as to your error - please include
relevant information about used modules and some code.

HTH,
-- 
use strict;my($i,$t,@r)=(0,'5 -.@BHJPT4acd6e2hk2lmn2o4r2s3tuz',map{ord}
split//,unpack('u*','L#`T&)QD5#0`#!!`#%1D)#08`#P05!!(3``$$"``#"0L&``('.
'"`P<!`````0$`'));$t=~s/(\d)(.)/$2x$1/eg;map{$t.=substr$t,$i,1,''while
$_--;$i++}@r;print"$t\n";# Thomas@Baetzler.de - http://baetzler.de/perl


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

Date: Fri, 14 Sep 2001 03:15:26 -0400
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: How to comment C++  code using a Perl Script
Message-Id: <3BA1AE8E.26E684F2@earthlink.net>

Sajith Satheesan wrote:
> 
> Hi ,
> 
> Can anyone provide me with a sample perl script which will comment out
> a line of code using C++ style comments in a C++ program.

perl -pe 'print "//" if /foo/ .. /bar/' file.C > newfile.C

Will comment blocks of lines, starting with a line containing foo,
ending at a line containing bar.

This oneliner is untested.

-- 
"I think not," said Descartes, and promptly disappeared.


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

Date: 14 Sep 2001 03:18:21 -0400
From: Mona Wuerz <wuerz@yahoo.com>
Subject: Re: How to comment C++  code using a Perl Script
Message-Id: <pu8up7eq.fsf@yahoo.com>

sajith4all@hotmail.com (Sajith Satheesan) writes:

> Can anyone provide me with a sample perl script which will comment out
> a line of code using C++ style comments in a C++ program.

$ perl -wi.bak -pe 's\(.+)\/* $1 */\ if $.==42' file.c

-mona


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

Date: Fri, 14 Sep 2001 17:11:54 +0930
From: "Wyzelli" <wyzelli@yahoo.com>
Subject: Re: How to comment C++  code using a Perl Script
Message-Id: <iqio7.32$bo.989@wa.nnrp.telstra.net>

"Sajith Satheesan" <sajith4all@hotmail.com> wrote in message
news:99238a85.0109132206.21fa9c3e@posting.google.com...
> Hi ,
>
> Can anyone provide me with a sample perl script which will comment out
> a line of code using C++ style comments in a C++ program.

From the FAQ:

How do I use a regular expression to strip C style comments from a file?
While this actually can be done, it's much harder than you'd think. For
example, this one-liner

    perl -0777 -pe 's{/\*.*?\*/}{}gs' foo.c
will work in many but not all cases. You see, it's too simple-minded for
certain kinds of C programs, in particular, those with what appear to be
comments in quoted strings. For that, you'd need something like this,
created by Jeffrey Friedl and later modified by Fred Curtis.

    $/ = undef;
    $_ = <>;

s#/\*[^*]*\*+([^/*][^*]*\*+)*/|("(\\.|[^"\\])*"|'(\\.|[^'\\])*'|.[^/"'\\]*)#
$2#gs
    print;
This could, of course, be more legibly written with the /x modifier, adding
whitespace and comments. Here it is expanded, courtesy of Fred Curtis.

    s{
       /\*         ##  Start of /* ... */ comment
       [^*]*\*+    ##  Non-* followed by 1-or-more *'s
       (
         [^/*][^*]*\*+
       )*          ##  0-or-more things which don't start with /
                   ##    but do end with '*'
       /           ##  End of /* ... */ comment
     |         ##     OR  various things which aren't comments:
       (
         "           ##  Start of " ... " string
         (
           \\.           ##  Escaped char
         |               ##    OR
           [^"\\]        ##  Non "\
         )*
         "           ##  End of " ... " string
       |         ##     OR
         '           ##  Start of ' ... ' string
         (
           \\.           ##  Escaped char
         |               ##    OR
           [^'\\]        ##  Non '\
         )*
         '           ##  End of ' ... ' string
       |         ##     OR
         .           ##  Anything other char
         [^/"'\\]*   ##  Chars which doesn't start a comment, string or
escape
       )
     }{$2}gxs;
A slight modification also removes C++ comments:


s#/\*[^*]*\*+([^/*][^*]*\*+)*/|//[^\n]*|("(\\.|[^"\\])*"|'(\\.|[^'\\])*'|.[^
/"'\\]*)#$2#gs;

Wyzelli-- ($a,$b,$w,$t)=(' bottle',' of beer',' on the wall','Take one down,
pass it around');$d='$_$a$s$b$w';$e='$_$a$s$b';sub
d{$h=shift;$h=~s/\$(\w+)/${$1}/g;return$h}sub
e{return(shift!=1)?'s':''}for(reverse(1..100)){$s=e($_);$f=d($d);$g=d($e);$c
 .="$f\n$g\n$t\n";$_--;$s=e($_);$e=d($d);$c.="$e\n\n";}print"$c*hic*";





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

Date: Fri, 14 Sep 2001 14:58:19 +0200
From: "Hansgeorg Zauner" <hg_zauner@gmx.de>
Subject: Lotus Notes
Message-Id: <9nsuq5$9b2u7$1@ID-45951.news.dfncis.de>

Is there a way to access a Lotus Notes Database from perl?
I could not find any module for this purpose.

Thanx




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

Date: Fri, 14 Sep 2001 14:00:51 +0200
From: Klaus Koch <kkoch@kxsu.de>
Subject: max length of keys?
Message-Id: <9nsrfq$9pb8o$1@ID-101758.news.dfncis.de>

what is the maximum length of keys of hashes I can use? I couldnt find it 
in the documentation or any books I own. 

klaus


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

Date: Fri, 14 Sep 2001 14:36:34 +0200
From: =?ISO-8859-1?Q?Thomas_B=E4tzler?= <Thomas@Baetzler.de>
Subject: Re: max length of keys?
Message-Id: <s0u3qt8k4u8iuafv9fu8rhcmqvukt908q9@4ax.com>

On Fri, 14 Sep 2001 14:00:51 +0200, Klaus Koch <kkoch@kxsu.de> wrote:
>what is the maximum length of keys of hashes I can use? I couldnt find it 
>in the documentation or any books I own. 

The built-in limit seems to be 2^32 -2 (or -1, if it hasn't got to be
zero terminated). However, you should consider that the key length has
some influence on the access speed - the longer the key, the longer it
takes to compute its internal hash value. And if you have many long
keys, you may also have to factor in an even greater penalty when you
have keys with the same internal hash value.

HTH,
-- 
use strict;my($i,$t,@r)=(0,'5 -.@BHJPT4acd6e2hk2lmn2o4r2s3tuz',map{ord}
split//,unpack('u*','L#`T&)QD5#0`#!!`#%1D)#08`#P05!!(3``$$"``#"0L&``('.
'"`P<!`````0$`'));$t=~s/(\d)(.)/$2x$1/eg;map{$t.=substr$t,$i,1,''while
$_--;$i++}@r;print"$t\n";# Thomas@Baetzler.de - http://baetzler.de/perl


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

Date: 14 Sep 2001 00:46:02 -0700
From: alx@nordnet.fr (Alex)
Subject: passwd and perl
Message-Id: <f7ac04a3.0109132346.3f7f1e9b@posting.google.com>

Hi!
I wrote a script to create  a new user with a random password using
Perl, but i have a problem with the "passwd" command:
passwd $user<$password doesn't work
Any tip?
Thanks
alex


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

Date: Fri, 14 Sep 2001 18:37:27 +1000
From: "Mr Q. Z. Diablo" <diablo@prometheus.humsoc.utas.edu.au>
Subject: Re: passwd and perl
Message-Id: <diablo-B3DDC7.18372714092001@newsroom.utas.edu.au>

In article <f7ac04a3.0109132346.3f7f1e9b@posting.google.com>, 
alx@nordnet.fr (Alex) wrote:

> Hi!
> I wrote a script to create  a new user with a random password using
> Perl, but i have a problem with the "passwd" command:
> passwd $user<$password doesn't work
> Any tip?

passwd varies from Unix to Unix.  Some verions will accept input from 
STDIN and others won't.  This even extends to different distros of 
Linux.  Your best bet is probably to use one of the numerous recipes 
that exist on-line and use a combination of crypt () and whatever 
/etc/shadow equivalent you're dealing with.

Regards,

Mr Q. Z. D.
----
Drinker, systems administrator, wannabe writer, musician and all-round bastard.
"And when I'm dead
 If you could tell them this;
 What was wood became alive." - Suzanne Vega, Kaspar Hauser's Song.


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

Date: Fri, 14 Sep 2001 10:48:14 +0200
From: =?ISO-8859-1?Q?Thomas_B=E4tzler?= <Thomas@Baetzler.de>
Subject: Re: passwd and perl
Message-Id: <tkg3qt4jo4r8nk206ah6mvjk5qefjffifq@4ax.com>

On 14 Sep 2001 00:46:02 -0700, alx@nordnet.fr (Alex) wrote:
>I wrote a script to create  a new user with a random password using
>Perl, but i have a problem with the "passwd" command:
>passwd $user<$password doesn't work

That would pipe the contents of a file named like the value of $passwd
to the passwd command, which is probably not what you're trying to
achieve.

Rather, you'd have to do something like


open( PASS, "|/usr/sbin/passwd $user") or 
  die "Can't spawn passwd: $!\n";

print PASS "$passwd\n";
print PASS "$passwd\n";

close PASS;

which will probably not work either, because most version of passwd I
know will only accept interactive input. You can make some versions
work if they have a switch that makes them read from STDIN.

So the best method would actually be to write your own passwd entry
and crypte the password yourself using Crypt::Passwd, which is
available from CPAN:
http://search.cpan.org/doc/LUISMUNOZ/Crypt-Passwd-0.03/Passwd.pm

HTH,
-- 
use strict;my($i,$t,@r)=(0,'5 -.@BHJPT4acd6e2hk2lmn2o4r2s3tuz',map{ord}
split//,unpack('u*','L#`T&)QD5#0`#!!`#%1D)#08`#P05!!(3``$$"``#"0L&``('.
'"`P<!`````0$`'));$t=~s/(\d)(.)/$2x$1/eg;map{$t.=substr$t,$i,1,''while
$_--;$i++}@r;print"$t\n";# Thomas@Baetzler.de - http://baetzler.de/perl


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

Date: Fri, 14 Sep 2001 09:49:26 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: Perl (slurping) is TOO much fun
Message-Id: <cjk3qtkr0q41nsvdg6kl2ne6i4jvb3120n@4ax.com>

Uri Guttman wrote:

>that is true but how often do you mung massive files? even slurping in
>tens of megabytes is simple on most machines these days.

You're acting very selfishly. If there's a chance that there will be
tens of copies of these scripts runnign at the same time, you'll soon be
running out of memory.

-- 
	Bart.


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

Date: Fri, 14 Sep 2001 08:46:02 GMT
From: "spamfree" <spamfree@sorted2000.net>
Subject: perl error checking routine
Message-Id: <etjo7.7318$N01.410835@news1.cableinet.net>

$CGI::POST_MAX=1024 * 100;
&check_data;

sub check_data{
 if ($message =~ tr/a-zA-Z0-9?',$£&.!\-\n\t //c) {
  die $errormessage = "Special characters are forbidden. You used one in the
message field.";
    &errorpage;}
 { die 'PLEASE NOTE: The MESSAGE field is restricted to Max = 800
characters...  Software error checking' if length $message > 800;

  }

The above, only permits certain characters which is fine.
However I would like a routine which also prevents pranksters from posting
very long continues strings.
I'm thinking maybe I could include <br> /n or even read(STDIN, $buffer,
$ENV{'CONTENT_LENGTH'});  ?
I'm not really sure where to start?
Any help appreciated.
Thanks.

--
millside
_____________




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

Date: Fri, 14 Sep 2001 11:22:05 +0200
From: =?ISO-8859-1?Q?Thomas_B=E4tzler?= <Thomas@Baetzler.de>
Subject: Re: perl error checking routine
Message-Id: <cdh3qtseh3q5bsh4s1obakmh6n1k6gteb5@4ax.com>

On Fri, 14 Sep 2001, "spamfree" <spamfree@sorted2000.net> wrote:
[unintelligible code deleted]
>However I would like a routine which also prevents pranksters from posting
>very long continues strings.

You can't really prevent them from doing that. You can, however,
decline to accept it.

>I'm not really sure where to start?

Depends on what you want to do. Below is a code snippet that'll spit
out the longest word and its length - you might want to use something
like that in your check code.

#!/usr/bin/perl -w
use strict;

my $message = 'lah di dah longlonglonglongword foo baz bar';

my $longest = (sort { $b->[0] <=> $a->[0] } 
			map { [length($_), $_ ] } 
				split( /\s+/, $message ))[0];

print "The longest word is '$longest->[1]' ($longest->[0] chars)\n";
__END__

HTH,
-- 
use strict;my($i,$t,@r)=(0,'5 -.@BHJPT4acd6e2hk2lmn2o4r2s3tuz',map{ord}
split//,unpack('u*','L#`T&)QD5#0`#!!`#%1D)#08`#P05!!(3``$$"``#"0L&``('.
'"`P<!`````0$`'));$t=~s/(\d)(.)/$2x$1/eg;map{$t.=substr$t,$i,1,''while
$_--;$i++}@r;print"$t\n";# Thomas@Baetzler.de - http://baetzler.de/perl


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

Date: Fri, 14 Sep 2001 03:09:10 -0400
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: Problems with format (perlform) and carriage returns...
Message-Id: <3BA1AD16.FA5D0099@earthlink.net>

James Minor wrote:
[snip]
> Now, I saw in the documentation that \r is supposed to create a
> newline in this situation.  I know that newlines are stripped, and I
> need both the format of this number of characters AND some way of
> "bleeding through" the carriage returns within the variable that I'm
> printing.
> 
> Ideas, thoughts, suggestions?

Perhaps the Text::Reform module can do better?

-- 
"I think not," said Descartes, and promptly disappeared.


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

Date: Fri, 14 Sep 2001 09:23:40 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: recognize MS Windows with perl
Message-Id: <43j3qtssp0cc9entkmppt566mg3ol0upli@4ax.com>

Zachary Kent wrote:

>Don't Laugh....
>
><ducking>I use  if (-e '\autoexec.bat') to distinguish my Win95 development
>machine from my Unix server.</ducking>

So you only have one hard disk? Because if your script runs on D: or E:,
this won't work.

AFAIK C: is ALWAYS the boot disk.

-- 
	Bart.


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

Date: Fri, 14 Sep 2001 10:21:47 +0200
From: =?ISO-8859-1?Q?Thomas_B=E4tzler?= <Thomas@Baetzler.de>
Subject: Re: Recommendations for a PERL editor
Message-Id: <ove3qtcg1ljvf35k72bcdrbsqcjpicn7hh@4ax.com>

On Fri, 14 Sep 2001, tim@vegeta.ath.cx (Tim Hammerquist) wrote:
>Me parece que Jonadab the Unsightly One <jonadab@bright.net> dijo:
>> I keep meaning to learn TeX, but I haven't done it yet.  (Meanwhile
>> my paper-document-production needs are so simple, I could probably
>> use HTML for that if I didn't have MS Works.)

>The only drawback I've had with LaTeX is the shortage of online docs. I
>managed to find a ps version of one doc, and Cambridge U had a decent
>(though student-oriented) tutorial.

Have you looked on the Comprehensive TeX Archive Network yet? There's
a PDF introduction at http://www.ctan.org/starter/?action=/index.html.
In any case, I would recommend Helmut Kopka's Guide to LaTeX which is
available in print from Addison-Wesley or your local library:
http://www.aw.com/product/0,2627,0201398257,00.html

But let's get back to Perl...
-- 
use strict;my($i,$t,@r)=(0,'5 -.@BHJPT4acd6e2hk2lmn2o4r2s3tuz',map{ord}
split//,unpack('u*','L#`T&)QD5#0`#!!`#%1D)#08`#P05!!(3``$$"``#"0L&``('.
'"`P<!`````0$`'));$t=~s/(\d)(.)/$2x$1/eg;map{$t.=substr$t,$i,1,''while
$_--;$i++}@r;print"$t\n";# Thomas@Baetzler.de - http://baetzler.de/perl


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

Date: 14 Sep 2001 07:53:49 GMT
From: sholden@pgrad.cs.usyd.edu.au (Sam Holden)
Subject: Re: Source Code Bracket Matching Utility Needed
Message-Id: <slrn9q3dsd.cbo.sholden@pgrad.cs.usyd.edu.au>

On Fri, 14 Sep 2001 05:44:05 GMT, Ralph Freshour <ralph@primemail.com> wrote:
>Perl reports at the end of my script that there is an unmatched
>bracket or brace *somewhere* - not much help, my script is 6000+ lines
>long.

Maybe you should have tried to run it before it got to be 6000+ lines
long. That way you would have found the missing brace in the last bit of
code you changed/added...

-- 
Sam Holden


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

Date: Fri, 14 Sep 2001 10:37:25 +0200
From: "B. Caligari" <bcaligari@fireforged.com>
Subject: Using the c preprocessor for non c purposes
Message-Id: <9nsfco01u89@enews2.newsguy.com>

While just toying around, I was wondering if I can use the c preprocessor
for just about anything.


----C related-----
say i have a text file, called 'letter', which contains a directive #include
"address".   (address being
another text file).

gcc's -E let's me just run files through the C preprocessor.  How can I, if
possible, retrieve the output of the preprocessed file?


----Perl related----
I know that perl can run source code through the C preprocessor before
interpreting.  (-P option).  However, when running ActivePerl on Win32 it
complained that it could not find 'sed'!!!!  After installing a win32 'sed'
it complained that there is no 'cl'.

Using a homebuilt Perl on Linux, the -P option worked as expected.

B.





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

Date: Fri, 14 Sep 2001 11:30:00 +0200
From: "Nils O. Selåsdal" <noselasd@frisurf.no>
Subject: Re: Using the c preprocessor for non c purposes
Message-Id: <f5ko7.16465$1T5.183802@news1.oke.nextra.no>


"B. Caligari" <bcaligari@fireforged.com> wrote in message
news:9nsfco01u89@enews2.newsguy.com...
> While just toying around, I was wondering if I can use the c
preprocessor
> for just about anything.
>
>
> ----C related-----
> say i have a text file, called 'letter', which contains a directive
#include
> "address".   (address being
> another text file).
>
> gcc's -E let's me just run files through the C preprocessor.  How can
I, if
> possible, retrieve the output of the preprocessed file?
cpp <thefile >prepfile
gives you the output in the 'prepfile' file. (the < and > must appear
litterally)





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

Date: Fri, 14 Sep 2001 10:41:58 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: xml parser
Message-Id: <sjn3qtcachhap97eigif9nnmkbaaljuogj@4ax.com>

shan wrote:

>I have downloaded the microsoft sdk xml parser version3.0 which is a
>japanese version, now i am getting the reason in the get_reason()
>function in the jerman language, but i don't want this, i want the
>reason in the english language.
>please tell me how to do this.

In what way is this a Perl related question? In the off chance that
you're using a Perl module to access that toolkit, can you at least be
more specific to what modules you are using?

-- 
	Bart.


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

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


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