[17327] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 4749 Volume: 9

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sat Oct 28 14:05:41 2000

Date: Sat, 28 Oct 2000 11:05:09 -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: <972756309-v9-i4749@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Sat, 28 Oct 2000     Volume: 9 Number: 4749

Today's topics:
        "unrequire foo;":: Is this possible? <bbrown@addtoit.com>
    Re: "unrequire foo;":: Is this possible? <jeffp@crusoe.net>
    Re: "unrequire foo;":: Is this possible? <bbrown@addtoit.com>
        [Perl] How to find the Perl FAQ <rootbeer&pfaq*finding*@redcat.com>
    Re: Arggh... this should be easy but I can't do it... (Tad McClellan)
    Re: Arggh... this should be easy but I can't do it... (Tad McClellan)
    Re: Bitreverse an integer (Anno Siegel)
    Re: Bitreverse an integer (Anno Siegel)
        Breaking a long word (Jimtaylor5)
    Re: Breaking a long word (Clay Irving)
    Re: Breaking a long word <james@NOSPAM.demon.co.uk>
    Re: debugging cgi scripts (Tad McClellan)
    Re: Detecting socket closure <uri@sysarch.com>
        encrypting and decrypting a string metamp@my-deja.com
    Re: encrypting and decrypting a string (Clay Irving)
    Re: How to protect perl program from pirates? (Tad McClellan)
    Re: How to protect perl program from pirates? <harrisr@bignet.net>
    Re: in an eval, redirect STDOUT to a variable <abe@ztreet.demon.nl>
    Re: in an eval, redirect STDOUT to a variable (Tom Christiansen)
        Installing HTML module 0149@my-deja.com
    Re: newbie--Sorting pairs by value <lr@hpl.hp.com>
        No such file or directory (NT) <diab.lito@usa.net>
    Re: No such file or directory (NT) <tony_curtis32@yahoo.com>
        Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)

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

Date: Sat, 28 Oct 2000 07:22:10 -0400
From: William Lewis Brown <bbrown@addtoit.com>
Subject: "unrequire foo;":: Is this possible?
Message-Id: <39FAB6E2.C96E9BA9@addtoit.com>

Hi,
	I have need for the ability to wipe out the definition of a Perl class from
Perl's runtime environment.  The operation would eliminate all symbols from
Perl's symbol table which begin with the name of the class, ex. "my::class::". 
I then intend to "re-require" the class.  The result, if the class definition
has changed since the first require, would be a new version of the class in
Perl's symbol table.  It is safe to assume that the class is defined in a single
module.
	Is this possible?
	If it is possible, has anyone already done it?
	If it is possible and it has not been done, could you please give me some
pointers that will start me off in the right direction.

	Thanks for your help.

						Bill  
-- 
William L. Brown
Email: bbrown@addtoit.com


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

Date: Sat, 28 Oct 2000 08:46:35 -0400
From: Jeff Pinyan <jeffp@crusoe.net>
Subject: Re: "unrequire foo;":: Is this possible?
Message-Id: <Pine.GSO.4.21.0010280845040.14811-100000@crusoe.crusoe.net>

[posted & mailed]

On Oct 28, William Lewis Brown said:

>	I have need for the ability to wipe out the definition of a Perl class from
>Perl's runtime environment.  The operation would eliminate all symbols from
>Perl's symbol table which begin with the name of the class, ex. "my::class::". 

Check out the Symbol module (comes with Perl).  It has a function for
deleting a namespace.

>I then intend to "re-require" the class.  The result, if the class definition
>has changed since the first require, would be a new version of the class in
>Perl's symbol table.  It is safe to assume that the class is defined in a single
>module.

You can do something spiffy like:

  delete $INC{"path/to/file.pl"};
  require "path/to/file.pl";

Or, you can just forget about require() and use do().  do() will let you
include the same file multiple times.

-- 
Jeff "japhy" Pinyan     japhy@pobox.com     http://www.pobox.com/~japhy/
PerlMonth - An Online Perl Magazine            http://www.perlmonth.com/
The Perl Archive - Articles, Forums, etc.    http://www.perlarchive.com/
CPAN - #1 Perl Resource  (my id:  PINYAN)        http://search.cpan.org/





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

Date: Sat, 28 Oct 2000 10:40:47 -0400
From: William Lewis Brown <bbrown@addtoit.com>
Subject: Re: "unrequire foo;":: Is this possible?
Message-Id: <39FAE56F.EDF7DBED@addtoit.com>

Hi Jeff,
	Thanks very much for your help Jeff.  You've hit the nail squarely on the
head.  I certainly would not have known where to look for this function without
your help, however, I think I'm going to have to upgrade to "Programming Perl
V3" from V2.  This function was not listed in V2.
	I mean it sincerely when I say that its the people who answer questions on the
Perl mailing list that make using Perl many times more attractive to use than
Perl without these good people.  So, please keep up the good work Jeff. :-)

					Bill

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Jeff Pinyan wrote:
> 
> [posted & mailed]
> 
> On Oct 28, William Lewis Brown said:
> 
> >       I have need for the ability to wipe out the definition of a Perl class from
> >Perl's runtime environment.  The operation would eliminate all symbols from
> >Perl's symbol table which begin with the name of the class, ex. "my::class::".
> 
> Check out the Symbol module (comes with Perl).  It has a function for
> deleting a namespace.
> 
> >I then intend to "re-require" the class.  The result, if the class definition
> >has changed since the first require, would be a new version of the class in
> >Perl's symbol table.  It is safe to assume that the class is defined in a single
> >module.
> 
> You can do something spiffy like:
> 
>   delete $INC{"path/to/file.pl"};
>   require "path/to/file.pl";
> 
> Or, you can just forget about require() and use do().  do() will let you
> include the same file multiple times.
> 
> --
> Jeff "japhy" Pinyan     japhy@pobox.com     http://www.pobox.com/~japhy/
> PerlMonth - An Online Perl Magazine            http://www.perlmonth.com/
> The Perl Archive - Articles, Forums, etc.    http://www.perlarchive.com/
> CPAN - #1 Perl Resource  (my id:  PINYAN)        http://search.cpan.org/

-- 
William L. Brown
Work:  603-465-2114
Fax:   603-465-2114
Cell:  617-803-9156
Email: bbrown@addtoit.com
Home:  603-465-2948


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

Date: Sat, 28 Oct 2000 10:21:58 GMT
From: Tom Phoenix <rootbeer&pfaq*finding*@redcat.com>
Subject: [Perl] How to find the Perl FAQ
Message-Id: <pfaqmessage972728645.18893@news.teleport.com>

Archive-name: perl-faq/finding-perl-faq
Posting-Frequency: weekly
Last-modified: 29 Apr 2000

[ That "Last-modified:" date above refers to this document, not to the
Perl FAQ itself! The last _major_ update of the Perl FAQ was in Summer
of 1998; of course, ongoing updates are made as needed. ]

For most people, this URL should be all you need in order to find Perl's
Frequently Asked Questions (and answers).

    http://www.cpan.org/doc/FAQs/

Please look over (but never overlook!) the FAQ and related docs before
posting anything to the comp.lang.perl.* family of newsgroups.

For an alternative way to get answers, check out the Perlfaq website.

    http://www.perlfaq.com/

# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # 

Beginning with Perl version 5.004, the Perl distribution itself includes
the Perl FAQ. If everything is pro-Perl-y installed on your system, the
FAQ will be stored alongside the rest of Perl's documentation, and one
of these commands (or your local equivalents) should let you read the FAQ.

    perldoc perlfaq
    man perlfaq

If a recent version of Perl is not properly installed on your system,
you should ask your system administrator or local expert to help. If you
find that a recent Perl distribution is lacking the FAQ or other important
documentation, be sure to complain to that distribution's author.

If you have a web connection, the first and foremost source for all things
Perl, including the FAQ, is the Comprehensive Perl Archive Network (CPAN).
CPAN also includes the Perl source code, pre-compiled binaries for many
platforms, and a large collection of freely usable modules, among its
560_986_526 bytes (give or take a little) of super-cool (give or take
a little) Perl resources.

    http://www.cpan.org/
    http://www.perl.com/CPAN/
    http://www.cpan.org/doc/FAQs/FAQ/html/
    http://www.perl.com/CPAN/doc/FAQs/FAQ/html/

You may wish or need to access CPAN via anonymous FTP. (Within CPAN,
you will find the FAQ in the /doc/FAQs/FAQ directory. If none of these
selected FTP sites is especially good for you, a full list of CPAN sites
is in the SITES file within CPAN.)

    California     ftp://ftp.cdrom.com/pub/perl/CPAN/
    Texas          ftp://ftp.metronet.com/pub/perl/
    South Africa   ftp://ftp.is.co.za/programming/perl/CPAN/
    Japan          ftp://ftp.dti.ad.jp/pub/lang/CPAN/
    Australia      ftp://cpan.topend.com.au/pub/CPAN/
    Netherlands    ftp://ftp.cs.ruu.nl/pub/PERL/CPAN/
    Switzerland    ftp://sunsite.cnlab-switch.ch/mirror/CPAN/
    Chile          ftp://ftp.ing.puc.cl/pub/unix/perl/CPAN/

If you have no connection to the Internet at all (so sad!) you may wish
to purchase one of the commercial Perl distributions on CD-Rom or other
media. Your local bookstore should be able to help you to find one.

# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # 

Comments and suggestions on the contents of this document
are always welcome. Please send them to the author at
<pfaq&finding*comments*@redcat.com>. Of course, comments on
the docs and FAQs mentioned here should go to their respective
maintainers.

Have fun with Perl!

-- 
Tom Phoenix       Perl Training and Hacking       Esperanto
Randal Schwartz Case:     http://www.rahul.net/jeffrey/ovs/


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

Date: Sat, 28 Oct 2000 10:22:13 -0400
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: Arggh... this should be easy but I can't do it...
Message-Id: <slrn8vlo8l.lbn.tadmc@magna.metronet.com>

On 28 Oct 2000 02:08:06 GMT, Tarael200 <tarael200@aol.com> wrote:

>See, your using $variable_in_two as a global variable. I think. :-)


Yes, $variable_in_two is a variable in package "main", which
is as close as you can get to "global" in Perl.



>Anyway use strict requires you to EXPLICITLY declare all variables you use in
                                                      ^^^^^^^^^^^^^
>your code that are of your own creation..


No it doesn't.


   perldoc strict
 ...
       `strict vars'
             This generates a compile-time error if you access a
             variable that wasn't declared via "our" or `use
             vars', localized via `my()', or wasn't fully
             qualified.


Note that very last bit.

The OP can just fully-qualify the variable's name, and "use strict"
will be happy without declaring or localizing.

That is, don't write

   $variable_in_two

write instead:

   $main::variable_in_two

or

   $::variable_in_two   (defaults to package main)



>Therefore, you need to throw something like this into one.pl
                ^^^^^^^

   s/need to/can/;  

Though I would probably favor:

   s/need to/should/;   # being explicit is good


>use vars qw($variable_in_two);
>
>... I put this after the use strict code, not sure if it's necessary, 


It isn't, as explained above.


>but
>that's where I usually stick them. Anyway, I tested that 
                                            ^^^^^^^^


A thinking programmer's approach. Very good!  :-)


>and that works.


Which is the ultimate test of "correctness" in practical terms  :-)


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


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

Date: Sat, 28 Oct 2000 10:41:09 -0400
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: Arggh... this should be easy but I can't do it...
Message-Id: <slrn8vlpc5.lbn.tadmc@magna.metronet.com>

On Sat, 28 Oct 2000 00:45:44 GMT, fallenang3l@my-deja.com 
   <fallenang3l@my-deja.com> wrote:

> Subject: Arggh... this should be easy but I can't do it...


Please put a subject in your Subject: header.

I would not normally have read your article, as I want to know
what an article is about *before* I decide to open it up and read it.

You lucked out and caught me on a lazy Saturday morning with
nothing else to do, so I relaxed my normal technique.

   Subject: variables in different files

or

   Subject: multifile programs

or something would have avoided your article being widely ignored...



>I've been staring at Programming Perl 3rd Edition and I can't solve my
>simple problem. 


That is an awfully big book.

You should have told us where you were looking. Maybe you weren't
looking at the best place.

pp 129-136 "Scoped Declarations" seems to me to be the most applicable.


>Let's say I have two files, one.pl and two.pl. The
>contents of one.pl are as follows:
>
>-------------------------
>#!/usr/local/bin/perl
>require "two.pl";
>print $variable_in_two;
>-------------------------
>
>The contents of two.pl are:
>
>-------------------------
>$variable_in_two = "I'm here.";
>1;
>-------------------------
>
>
>This works great until I put "use strict" in one.pl:

>Now I get an error. 


You should include the text of error messages when seeking help.

They often help the helper help.    :-)

I'll guess that this is the message (an "error message" isn't the
same thing as an "error" BTW):

   Global symbol "$variable_in_two" requires explicit package name at ...

Which, in fact, gives you the solution to your problem, namely use
an explicit package name:

   $main::variable_in_two


>I've tried using "our", and "my" on
>$variable_in_two in two.pl but it didn't work. 


our() and my() both give lexical scope, and therefore cannot
be made to work across _files_.

Because lexical scope does not extend across files.

The root "lex" means roughly "in a line". So the scope of a
lexical variable is in-a-line from the declaration to the
end of the enclosing block (or end of file if not in a block).



>I know it has something
>to do with packages and I've tried "package main" as a first line in
>two.pl but I didn't work either.


Without any package declarations, all variables default to
package main anyway, so declaring package main doesn't change
anything in your example.


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


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

Date: 28 Oct 2000 15:57:52 -0000
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Bitreverse an integer
Message-Id: <8tet20$am5$1@lublin.zrz.tu-berlin.de>

Bart Lateur  <bart.lateur@skynet.be> wrote in comp.lang.perl.misc:
>Anno Siegel wrote:
>
>>Your method 2 suffers from what I think is a bug in unpack:
>>"unpack 'v', $str" returns an undefined value when $str is 0 or 1
>>bytes long, so when the number of bits to invert is < 9, it fails.
>
>Oops.
>
>Here's one more:
>
>	sub bitreverse ($$) {
>	    my($n, $b) = @_;
>	    if($b>32) {
>	        require Carp;
>	        Carp::croak("Too many bits for bitreverse()");
>	    }
>	    return (unpack 'N', pack 'B32', 
>	      unpack 'b32', pack 'V', $n) >> (32-$b);
>	}

See my followup to Pete M. Wilson in this thread.

Anno


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

Date: 28 Oct 2000 16:35:24 -0000
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Bitreverse an integer
Message-Id: <8tev8c$ap1$1@lublin.zrz.tu-berlin.de>

Pete M. Wilson <wilsonpm@drop.gamewood.net> wrote in comp.lang.perl.misc:

Please, in following up place your reply after the material you
are replying to.

>The principle is pretty straightforward:
>
>You can reverse an arbitrary 1/2^n bits of a bit string by masking the
>upper and lower halves, shifting appropriately and oring back
>together. This reverses groups of bits in parallel.
>
>So, use successive masks to reverse the upper and lower half of the
>string, every quarter, every eigth, etc.
>
>In C, it goes something like this:
>
>unsigned long x; // 32 bit unsigned integer
>
>x = ((x & 0xffff0000) >> 16)  |  ((x & 0x0000ffff) << 16);
>x = ((x & 0xff00ff00) >> 8) | (( x & 0x00ff00ff) << 8);
>x = ((x & 0xf0f0f0f0) >> 4) | ((x & 0x0f0f0f0f) << 4);
>x = ((x & 0xcccccccc) >> 2) | ((x & 0x33333333) << 2);
>x = ((x & 0xaaaaaaaa) >> 1) | (x & 0x55555555) << 1);
>
>// x is now bit reversed!
>
>So, in Perl, try this:
>$x = (($x & 0xffff0000) >> 16) | (($x & 0x0000ffff) << 16); 
>
>and so on for the remaining lines.

To fully comply with the specifications of a reversal of $size bits,
the 32-bit reversal must be followed by a 32 - $size right shift.

>(Warning: this is from memory!)

Your memory seems to be fine, and this method is indeed superior to
the ones proposed so far.  The mechanics, while not straightforward,
are easy enough to grasp, it doesn't need auxiliary tables, and it
outperforms the others.  I suppose this is also the algorithm Steffen
Beyer mentions.

The one possible drawback is that it relies on a fixed integer size
(of 32 bits).  Some of the other methods avoid this commitment and
would continue to work on a 64 bit machine.  Of course, these methods
would silently fail if asked to reverse 44 bits on a 32-bit architecture,
so there's a fly in that ointment too.

I have added this method ("Pete") and Bart Lateur's improved
pack/unpack-based routine ("Bart3") to the benchmarks I'm keeping
around.  Method "Sean" is Sean McAfee's basic bit-shifting algorithm.
Using this as a base, the relative performances are:

Sean   1.0
Bart1  1.2
Bart2  1.3
Anno1  1.4
Anno2  1.7
Bart3  1.7
Pete   2.3

Anno

Full benchmarks and code for the terminally interested:

Benchmark: timing 4096 iterations of Anno1, Anno2, Bart1, Bart2, Bart3, Pete, Sean...
     Anno1:  2 wallclock secs ( 1.36 usr +  0.00 sys =  1.36 CPU) @ 3011.76/s (n=4096)
     Anno2:  1 wallclock secs ( 1.09 usr +  0.00 sys =  1.09 CPU) @ 3757.80/s (n=4096)
     Bart1:  2 wallclock secs ( 1.51 usr +  0.00 sys =  1.51 CPU) @ 2712.58/s (n=4096)
     Bart2:  2 wallclock secs ( 1.48 usr +  0.00 sys =  1.48 CPU) @ 2767.57/s (n=4096)
     Bart3:  1 wallclock secs ( 1.07 usr +  0.00 sys =  1.07 CPU) @ 3828.04/s (n=4096)
      Pete:  1 wallclock secs ( 0.85 usr +  0.00 sys =  0.85 CPU) @ 4818.82/s (n=4096)
      Sean:  2 wallclock secs ( 1.86 usr +  0.00 sys =  1.86 CPU) @ 2202.15/s (n=4096)

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

#!/usr/bin/perl
use strict;
use warnings;

use Benchmark;

sub reverse_bits_6 ($$); # predeclare

goto bench;

for ( 0 .. 0 ) {
  my $len = int rand 18;
  my $num = int rand 2 ** $len;
  my %results;
  $results{ Bart1} = reverse_bits_0( $num, $len);
  $results{ Bart2} = reverse_bits_3( $num, $len);
  $results{ Bart3} = reverse_bits_6( $num, $len);
  $results{ Sean} =  reverse_bits_1( $num, $len);
  $results{ Anno1} =  reverse_bits_2( $num, $len);
  $results{ Anno2} =  reverse_bits_4( $num, $len);
  $results{ Pete} =  reverse_bits_5( $num, $len);
  my @undefs = grep { not defined eval}
    qw( $results{Bart1} $results{Bart2} $results{Anno1} $results{Anno2}
        $results{Sean} $results{Bart3} $results{Pete});
  print "undef: ", join( ', ', @undefs), "\n" if @undefs;
  print "len: $len\n";
  for ( sort keys %results) {
    printf "%-5s: %0${len}b -> %0${len}b\n", $_, $num, $results{ $_};
  }
  print "\n";
}
exit;

bench:
timethese( 1 << ( shift or 0), {
  Bart1 => 'my $l = int rand 32; reverse_bits_0( int rand 2**$l, $l)',
  Bart2 => 'my $l = int rand 32; reverse_bits_3( int rand 2**$l, $l)',
  Bart3 => 'my $l = int rand 32; reverse_bits_6( int rand 2**$l, $l)',
  Sean => 'my $l = int rand 32; reverse_bits_1( int rand 2**$l, $l)',
  Anno1 => 'my $l = int rand 32; reverse_bits_2( int rand 2**$l, $l)',
  Anno2 => 'my $l = int rand 32; reverse_bits_4( int rand 2**$l, $l)',
  Pete => 'my $l = int rand 32; reverse_bits_5( int rand 2**$l, $l)',
});


#############################################

sub reverse_bits_0 { # From: Bart Lateur <bart.lateur@skynet.be>
  my( $num, $size) = @_;
  unpack "v", pack "b$size", sprintf "%0${size}b", $num;
}  

sub reverse_bits_3 { # From: Bart Lateur <bart.lateur@skynet.be>
  my ( $num, $len) = @_;
  oct('0b' . unpack "b$len", pack 'v', $num);
}

sub reverse_bits_6 ($$) { # From: Bart Lateur <bart.lateur@skynet.be>
  my($n, $b) = @_;
  if($b>32) {
    require Carp;
    Carp::croak("Too many bits for bitreverse()");
  }
  return (unpack 'N', pack 'B32', 
    unpack 'b32', pack 'V', $n) >> (32-$b);
}

sub reverse_bits_1 { # From: mcafee@waits.facilities.med.umich.edu (Sean McAfee)
    my ($num, $size) = @_;
    my $result = 0;
    (($result <<= 1) |= $num & 1, $num) >>= 1 for 1 .. $size;
    $result;
}

sub reverse_bits_5 { # From: Steffen Beyer <sb@muccpu1.muc.sdm.de>
                     # From: wilsonpm@drop.gamewood.net (Pete M. Wilson)
  my ( $num, $size) = @_;
  my $result;
  $num = ( ( $num & 0xff00ff00) >>  8) | ( ( $num & 0x00ff00ff) <<  8);
  $num = ( ( $num & 0xf0f0f0f0) >>  4) | ( ( $num & 0x0f0f0f0f) <<  4);
  $num = ( ( $num & 0xcccccccc) >>  2) | ( ( $num & 0x33333333) <<  2);
  $num = ( ( $num & 0xaaaaaaaa) >>  1) | ( ( $num & 0x55555555) <<  1);
  $num >> ( 32 - $size);
}

BEGIN { my @reverse_table;
  for ( 0 .. 255 ) {
    $reverse_table[ $_] = reverse_bits_1( $_, 8);
  }
  my $byte_mask = 255;

  sub reverse_bits_2 { # Anno
    my ( $num, $size) = @_;
    my $result = 0;
    for ( 0 .. int(( $size - 1)/8 ) ) {
      $result <<= 8;
      $result |= $reverse_table[ $num & $byte_mask];
      $num >>= 8;
    }
    $result >>= ( 7 - ( ( $size - 1) % 8));
    print "Anno returning undef\n" unless defined $result;
    $result;
  }

  my $reverse_str = join '', map chr $reverse_table[ $_], 0 .. 255;
  $reverse_str = quotemeta( $reverse_str);
  eval <<EOSUB;
  sub reverse_bits_4 {
    my ( \$num, \$size) = \@_;
    local \$_ = '';
    vec( \$_, 0, 32) = \$num;
    tr //$reverse_str/c;
#   vec( reverse( \$_), 0, 32) >> ( 7 - ( ( \$size - 1) % 8));
    vec( reverse( \$_), 0, 32) >> ( 32 - \$size);
  }
EOSUB
  print "\n$@\n" if $@;
}


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

Date: 28 Oct 2000 13:28:58 GMT
From: jimtaylor5@aol.com (Jimtaylor5)
Subject: Breaking a long word
Message-Id: <20001028092858.27760.00000153@ng-ft1.aol.com>

I was wondering if anyone could help me in finding a solutionin using perl to
break a long URL off and print the remainder on another line or place it in
another variable, as long URL's warp my printout. Say I have a URL in a
variable 60 characters long, and I want to print that variable. How would I
make sure maximum 40 characters get printed on one line, and the rest on
another. I guess I'm asking how do I break a variable off at a certain number
of characters, and yet retain that broken off to print on another line. Or if
any of you guys would have a better way of doing it. Thanks guys in advance. 


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

Date: 28 Oct 2000 15:44:19 GMT
From: clay@panix.com (Clay Irving)
Subject: Re: Breaking a long word
Message-Id: <slrn8vlt2j.a15.clay@panix3.panix.com>

On 28 Oct 2000 13:28:58 GMT, Jimtaylor5 <jimtaylor5@aol.com> wrote:

>I was wondering if anyone could help me in finding a solutionin using perl to
>break a long URL off and print the remainder on another line or place it in
>another variable, as long URL's warp my printout. Say I have a URL in a
>variable 60 characters long, and I want to print that variable. How would I
>make sure maximum 40 characters get printed on one line, and the rest on
>another. I guess I'm asking how do I break a variable off at a certain number
>of characters, and yet retain that broken off to print on another line. Or if
>any of you guys would have a better way of doing it. Thanks guys in advance. 

  perldoc -f split

or

  perldoc -f substr

or 

  perldoc -f unpack

-- 
Clay Irving <clay@panix.com>
A witty saying proves nothing. 
- Voltaire 


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

Date: Sat, 28 Oct 2000 17:47:12 +0100
From: James Taylor <james@NOSPAM.demon.co.uk>
Subject: Re: Breaking a long word
Message-Id: <ant281612339fNdQ@oakseed.demon.co.uk>

In article <20001028092858.27760.00000153@ng-ft1.aol.com>, Jimtaylor5
<URL:mailto:jimtaylor5@aol.com> wrote:
> a variable 60 characters long, and I want to print that variable.
> How would I make sure maximum 40 characters get printed on one line,
> and the rest on another.

If the variable containing your long URL was called $url then this
may do what you want:

print substr($url, 0, 40, ''), "\n" while $url;

At the end of which $url will be empty, but will have been printed
40 characters per line.

You should read up on substr to see why this works though.

-- 
James Taylor <james (at) oakseed demon co uk>
PGP key available ID: 3FBE1BF9
Fingerprint: F19D803624ED6FE8 370045159F66FD02



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

Date: Sat, 28 Oct 2000 10:44:59 -0400
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: debugging cgi scripts
Message-Id: <slrn8vlpjb.lbn.tadmc@magna.metronet.com>

On 28 Oct 2000 05:27:21 GMT, kmead@socrates.Berkeley.EDU 
  <kmead@socrates.Berkeley.EDU> wrote:

>I've just found out that I'm now in charge of a bunch of
>Perl CGI scripts. While I'm quite familiar with perl scripts


Then you should also be familiar with the copius standard
documentation that comes with perl, and how to access it?


>I'm less so with perl CGI scripts.


perldoc -q CGI


   "Where can I learn about CGI or Web programming in Perl?"

   "How can I get better error messages from a CGI program?"


>My question is, what is the best way to go about debugging
>CGI scripts? Is there a better solution than just putting
>in print statements? I'd love to be able to single-step in
>a debugger through some of these scripts.


What is stopping you?

You are surely using the CGI.pm module, and that let's you
run CGI programs from the command line, where you can slip
in a -d switch  :-)


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


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

Date: Sat, 28 Oct 2000 15:55:46 GMT
From: Uri Guttman <uri@sysarch.com>
Subject: Re: Detecting socket closure
Message-Id: <x74s1xklj1.fsf@home.sysarch.com>

>>>>> "M" == MNJP  <not.my.real.email@bellglobal.com> writes:

  M> That is not correct. If the socket is set to non-blocking mode (the way I
  M> prefer it) using fcntl(), then read and sysread will return 0 bytes until
  M> something is received.

  M> 0 means 0. Nothing read. It does not mean the socket got closed.

  M> if ($socket && sysread($socket, $in, X)) { do so and so } is usually good
  M> enough.

if you have the socket in non-blocking mode and test for reading with
select (or IO::Seelct or Event.pm, etc.) and you read 0 bytes, the
socket is closed. if ( $socket ) doesn't mean anything as that is just a
handle or a handle ref which is always true. it does not change if the
status of the socket changed, even if you close it. it is only false if
you never set it to begin with as with a failed socket connection.

usually good enough is not good enough when writing multitasking
servers. 

and don't post jeopardy style. put your comments AFTER edited parts of
the quoted letter.

uri

-- 
Uri Guttman  ---------  uri@sysarch.com  ----------  http://www.sysarch.com
SYStems ARCHitecture, Software Engineering, Perl, Internet, UNIX Consulting
The Perl Books Page  -----------  http://www.sysarch.com/cgi-bin/perl_books
The Best Search Engine on the Net  ----------  http://www.northernlight.com


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

Date: Sat, 28 Oct 2000 15:53:48 GMT
From: metamp@my-deja.com
Subject: encrypting and decrypting a string
Message-Id: <8tesqa$q0t$1@nnrp1.deja.com>

can anybody give me a tip how to simply encrypt a strng an derypt it
back to its original state


Sent via Deja.com http://www.deja.com/
Before you buy.


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

Date: 28 Oct 2000 16:16:50 GMT
From: clay@panix.com (Clay Irving)
Subject: Re: encrypting and decrypting a string
Message-Id: <slrn8vluvh.gpa.clay@panix3.panix.com>

On Sat, 28 Oct 2000 15:53:48 GMT, metamp@my-deja.com <metamp@my-deja.com> wrote:

>can anybody give me a tip how to simply encrypt a strng an derypt it
>back to its original state

On a command line, type this:

  perl -MCPAN -e shell

On the CPAN shell command line, type:

  i /Cyrpt/

Stand back and watch the screen scroll by:

[...]
  Module    CBC             (L/LD/LDS/Crypt-CBC-1.00.tar.gz)
  Module    CGI::EncryptForm (M/MA/MARAL/CGI-EncryptForm-1.02.tar.gz)
  Module    Client          (E/EE/EESTABROO/Crypt-HCE_SHA-0.60.tar.gz)
  Module    Crypt::Beowulf  (S/SI/SIFUKURT/Crypt-Beowulf-0.21.tar.gz)
  Module    Crypt::Blowfish (D/DP/DPARIS/Crypt-Blowfish-2.06.tar.gz)
  Module    Crypt::Blowfish_PP (M/MA/MATTBM/Crypt-Blowfish_PP-1.11.tar.gz)
  Module    Crypt::CBC      (L/LD/LDS/Crypt-CBC-1.25.tar.gz)
  Module    Crypt::CBCeasy  (M/MB/MBLAZ/Crypt-CBCeasy-0.21.tar.gz)
  Module    Crypt::Cracklib (D/DA/DANIEL/Crypt-Cracklib-0.01.tar.gz)
  Module    Crypt::DES      (D/DP/DPARIS/Crypt-DES-2.01.tar.gz)
  Module    Crypt::DES_PP   (G/GU/GUIDO/Crypt-DES_PP-1.00.tar.gz)
  Module    Crypt::ElGamal  (Contact Author Vipul Ved Prakash <mail@vipul.net>)
  Module    Crypt::GOST     (V/VI/VIPUL/Crypt-GOST-0.41.tar.gz)
  Module    Crypt::GPG      (A/AG/AGUL/Crypt-GPG-1.8.tar.gz)
  Module    Crypt::HCE_MD5  (E/EE/EESTABROO/Crypt-HCE_MD5-0.60.tar.gz)
  Module    Crypt::HCE_SHA  (E/EE/EESTABROO/Crypt-HCE_SHA-0.60.tar.gz)
  Module    Crypt::IDEA     (D/DP/DPARIS/Crypt-IDEA-1.01.tar.gz)
  Module    Crypt::Keys     (Contact Author Vipul Ved Prakash <mail@vipul.net>)
[...]

There are many modules for encryption/decryption.

-- 
Clay Irving <clay@panix.com>
Winny would spend all of his time practicing limbo.  He got pretty good.
He could go under a rug.  - Steven Wright 


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

Date: Sat, 28 Oct 2000 10:47:16 -0400
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: How to protect perl program from pirates?
Message-Id: <slrn8vlpnk.lbn.tadmc@magna.metronet.com>

On Sat, 28 Oct 2000 01:00:23 +0400, Paul Antonov <antonov@lib.bmstu.ru> wrote:

>I need to protect my perl program...


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

   "How can I hide the source for my Perl program?"


>How can I crypt... compile...or do something else to
>privent free reaching of source codes?


Put a license on it.


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


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

Date: Sat, 28 Oct 2000 12:34:37 -0400
From: "Randy Harris" <harrisr@bignet.net>
Subject: Re: How to protect perl program from pirates?
Message-Id: <svlvvsbgu2t05f@corp.supernews.com>

<mischief@velma.motion.net> wrote in message
news:svjttre2fl8r47@corp.supernews.com...
> Paul Antonov <antonov@lib.bmstu.ru> wrote:
> > I need to protect my perl program...
> > How can I crypt... compile...or do something else to
> > privent free reaching of source codes?
>
> I've been away from the group for a while, but I could almost swear
> this was a FAQ last I remembered.

Unquestionably, this is one of the questions most frequently asked on
CLPM.  The FAQ does little to answer it, yours is a much better
discussion of the matter.  Thanks

Randy Harris

[snip]




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

Date: Sat, 28 Oct 2000 15:07:23 +0200
From: Abe Timmerman <abe@ztreet.demon.nl>
Subject: Re: in an eval, redirect STDOUT to a variable
Message-Id: <vfjlvscte41q8n8j05b4a02auhk14mbdke@4ax.com>

On 27 Oct 2000 07:51:25 -0700, tchrist@perl.com (Tom Christiansen)
wrote:

> In article <8taruq$mgd$1@nnrp1.deja.com>,
> Dave Brondsema  <brondsem@my-deja.com> wrote:
> >I get:
> >Can't use an undefined value as filehandle reference at test.pl line
> >33.  (First line of sub).  I'm running windows if it makes any
> >difference.  What is the $self variable?
> 
> You probably aren't running with a recent enough version of
> Perl for filehandle autovivification.

And to add to that, it won't work on Win32 with the current emulation of
fork().

From perlfork.pod:

    Forking pipe open() not yet implemented
        The `open(FOO, "|-")' and `open(BAR, "-|")' constructs are not
        yet implemented. This limitation can be easily worked around in
        new code by creating a pipe explicitly.

-- 
Good luck,
Abe

##
perl -Mstrict -wle 'sub Just{&$_}sub another{&$_}sub Perl{&$_}sub hacker{&$_}$_=sub{(split /::/,(caller $^W)[3])[-$^W].$"};print@{[Just,another,Perl,hacker]}'


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

Date: 28 Oct 2000 09:53:42 -0700
From: tchrist@perl.com (Tom Christiansen)
Subject: Re: in an eval, redirect STDOUT to a variable
Message-Id: <39faf686$1@cs.colorado.edu>

In article <vfjlvscte41q8n8j05b4a02auhk14mbdke@4ax.com>,
Abe Timmerman  <abe@ztreet.demon.nl> wrote:
>And to add to that, it won't work on Win32 with the current emulation of
>fork().

Which serves to remind us of that unnameless evil reminiscent of some 
Biblical scourge sent to punish sloth and gluttony--to remind us, in fact,
how this insidious abomination of avarice incarnate proves that one need no
longer first die before suffering the tempestuous fires of Hell.

While I imagine that there might somewhere exist people who could care less
about this vexing issue, it would be a grave error to count me amongst them,
as I shall not condemn the upright man to eternal torture over the sins which
his weak neighbor, completely unbeknownst to him, may have committed.

--tom


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

Date: Sat, 28 Oct 2000 14:08:59 GMT
From: 0149@my-deja.com
Subject: Installing HTML module
Message-Id: <8temlo$ldm$1@nnrp1.deja.com>

I downloaded the HTML module 0.6 from cpan.org. How do I install it?
(There is no Makefile.PL)

Thanks in advance


Sent via Deja.com http://www.deja.com/
Before you buy.


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

Date: Sat, 28 Oct 2000 00:07:24 -0700
From: Larry Rosler <lr@hpl.hp.com>
Subject: Re: newbie--Sorting pairs by value
Message-Id: <MPG.14641b0581f4d05198ae7a@nntp.hpl.hp.com>

In article <39FA2212.53EB39E8@lmumail.lmu.edu>, pmosinsk@lmumail.lmu.edu 
says...

 ...


> Say I have the following data in the form key,value:
> 	apple,10
>        	banana,30
>        	cake,20
>        	drinks,20
>        	eggs,50
> This data is stored in an array and/or hash.

Storing associated data in a simple array makes little sense.  That's 
what an 'associative array' (aka hash) is for.

> I want to sort the pairs ascending by the number value.
> I tried reversing key/values in the hash, but then obviously you can't
> have two hash keys of the same "name". I just can't picture the
> necessary algorithm. Any suggestions?

Yes.  Look at the section in the FAQ on hashes before posting a 
question about them.

perlfaq4: "How do I sort a hash (optionally by value instead of key)"

-- 
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com


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

Date: Sat, 28 Oct 2000 15:24:43 GMT
From: Mario <diab.lito@usa.net>
Subject: No such file or directory (NT)
Message-Id: <8ter3m$ooj$1@nnrp1.deja.com>

I wrote a script using flat files.It was running properly on a Unix
server.Now I had to install it on an NT machine.

It gives me the "No such file or directory" error even if the files are
in the same directory of the script opening it.

I am opening the files in this way:
open (DB, "nome.dbf")|| die "error";

Is the server working bad or does NT requires something different to
specify the path?

Thanks anyone,
Mario


Sent via Deja.com http://www.deja.com/
Before you buy.


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

Date: 28 Oct 2000 10:49:39 -0500
From: Tony Curtis <tony_curtis32@yahoo.com>
Subject: Re: No such file or directory (NT)
Message-Id: <874s1xrmng.fsf@limey.hpcc.uh.edu>

>> On Sat, 28 Oct 2000 15:24:43 GMT,
>> Mario <diab.lito@usa.net> said:

> I wrote a script using flat files.It was running
> properly on a Unix server.Now I had to install it on an
> NT machine.

> It gives me the "No such file or directory" error even
> if the files are in the same directory of the script
> opening it.

> I am opening the files in this way: open (DB,
> "nome.dbf")|| die "error";

Put $! into the die message, then you can see what's
actually happening.

(Is this really a CGI question by any chance?)

hth
t
-- 
Eih bennek, eih blavek.


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

Date: 16 Sep 99 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 16 Sep 99)
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: The mail to news gateway, and thus the ability to submit articles
| through this service to the newsgroup, has been removed. I do not have
| time to individually vet each article to make sure that someone isn't
| abusing the service, and I no longer have any desire to waste my time
| dealing with the campus admins when some fool complains to them about an
| article that has come through the gateway instead of complaining
| to the source.

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 V9 Issue 4749
**************************************


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