[19792] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 1987 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Oct 23 00:05:42 2001

Date: Mon, 22 Oct 2001 21:05:06 -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: <1003809906-v10-i1987@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Mon, 22 Oct 2001     Volume: 10 Number: 1987

Today's topics:
    Re: accessing class-level variables (Paul Faulstich)
    Re: accessing class-level variables <goldbb2@earthlink.net>
    Re: accessing class-level variables (Mark Jason Dominus)
    Re: alarm and put a timeout on a perl program an its sh <goldbb2@earthlink.net>
    Re: alarm and put a timeout on a perl program an its sh (Garry Williams)
    Re: Array of filehandles <goldbb2@earthlink.net>
    Re: Encrypt/Decrypt module <sstod@family-net.net>
    Re: Encrypt/Decrypt module (John J. Trammell)
    Re: Fork messes up parent file handle? (Mark Jason Dominus)
    Re: Greediness and Regular Expressions <goldbb2@earthlink.net>
        NEWBIE sending vars <"goodrow"@opencity. com>
    Re: NEWBIE sending vars (Logan Shaw)
    Re: perl algorithm <bwalton@rochester.rr.com>
        Perl Image::Magick ignores QUALITY directive. <BrianP@Die_Spammers_Fractasia.com>
    Re: Perl Vs. Java <tlav1@mediaone.net>
        Premature end of script header <mjojoz@nospamhotmail.com>
    Re: Premature end of script header <goldbb2@earthlink.net>
    Re: Premature end of script header <wyzelli@yahoo.com>
    Re: Skipping following lines if the same (Martien Verbruggen)
    Re: Skipping following lines if the same <goldbb2@earthlink.net>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: 22 Oct 2001 18:06:40 -0700
From: pfaulstich@llbean.com (Paul Faulstich)
Subject: Re: accessing class-level variables
Message-Id: <c9c77658.0110221706.2e7e31ce@posting.google.com>

mjd@plover.com (Mark Jason Dominus) wrote in message news:<3bd43c06.3276$21a@news.op.net>...
 
> You'll have to do something like that.  You have declared
> '%object_list' with 'my', which means it will be private to the file
> in which it is declared.  Only a method that follows the declaration
> 'my %object_list' will be able to access %object_list.

[detailed explanation follows...]

> I hope this was clear.

Yes, it was.  I prefer to write my modules to use strict so I kind of
balk a bit at the idea of no strict.  Can I stick with using strict
and replace the my %object_list with %Son::object_list and
%Daughter::object_list as that isn't equivalent to my?  I will test
this out at work tomorrow (no perl at home - keeps me from working too
much...)

> %{$packagename . '::object_list'}
and
> %{"$packagename\::object_list"}

are exactly the hints I needed!  Thanks!

Paul


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

Date: Mon, 22 Oct 2001 21:15:51 -0400
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: accessing class-level variables
Message-Id: <3BD4C4C7.5341D2C0@earthlink.net>

Paul Faulstich wrote:
> 
> I am running into problems accessing a child class's class-level
> variables from the parent class.  Essentially, I would like to have an
> inherited parent method refer to some variable and have it use the
> child's variable, not the parent's.

Is this an instance variable, or a class variable?
I'll assume that it's a class variable which you are talking about,
otherwise you probably wouldn't be asking, unless you were *really*
confused.

Anyway, the prefered way is to store in each instance [at object
creation time], a reference to the package/class variable.

package Parent;
my $some_class_var = "foo";
sub new {
   my $class = shift;
   bless {some_class_var => \$some_class_var}, $class;
}
sub printit {
    my $self = shift;
    print STDOUT ${$self->{some_class_var}}, "\n";
1;
__END__

package Child;
use base qw(Parent);
my $some_class_var = "bar";;
sub new {
   my $self = shift->SUPER::new(@_);
   $self->{some_class_var} = \$some_class_var;
}
1;
__END__

#!/bin/perl -w
use strict; use Parent; use Child;
my ($p, $c) = Parent->new, Child->new;
$p->printit;
$c->printit;
__END__

NB: This code is untested.

-- 
Klein bottle for rent - inquire within.


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

Date: Tue, 23 Oct 2001 03:32:30 GMT
From: mjd@plover.com (Mark Jason Dominus)
Subject: Re: accessing class-level variables
Message-Id: <3bd4e4cd.475f$66@news.op.net>

In article <c9c77658.0110221706.2e7e31ce@posting.google.com>,
Paul Faulstich <pfaulstich@llbean.com> wrote:
>> I hope this was clear.
>
>Yes, it was.  I prefer to write my modules to use strict so I kind of
>balk a bit at the idea of no strict.  

I agree it would be better to leave strict in place.  It was an error
on my part to leave it out of the examples.  I was concentrating on
'strict refs', and forgot about 'strict vars'.

>Can I stick with using strict and replace the my %object_list with
>%Son::object_list and %Daughter::object_list as that isn't equivalent
>to my?

Yes, that will work fine.   The example I showed will cause a  'strict
vars' failure:

        class Daughter;

        sub add_object {
          my ($self, $name, $object) = @_;
          $object_list{$name} = $object;       # 'strict vars' failure
        }

So instead, write:

        class Daughter;

        sub add_object {
          my ($self, $name, $object) = @_;
          $Daughter::object_list{$name} = $object;     
        }

Or, perhaps more conveniently:


        class Daughter;
        our %object_list;

        sub add_object {
          my ($self, $name, $object) = @_;
          $object_list{$name} = $object;     
        }

Or, under older Perls:

        class Daughter;
        use vars '%object_list';

        sub add_object {
          my ($self, $name, $object) = @_;
          $object_list{$name} = $object;     
        }

>are exactly the hints I needed!  Thanks!

Glad to be of service.

-- 
@P=split//,".URRUU\c8R";@d=split//,"\nrekcah xinU / lreP rehtona tsuJ";sub p{
@p{"r$p","u$p"}=(P,P);pipe"r$p","u$p";++$p;($q*=2)+=$f=!fork;map{$P=$P[$f^ord
($p{$_})&6];$p{$_}=/ ^$P/ix?$P:close$_}keys%p}p;p;p;p;p;map{$p{$_}=~/^[P.]/&&
close$_}%p;wait until$?;map{/^r/&&<$_>}%p;$_=$d[$q];sleep rand(2)if/\S/;print


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

Date: Mon, 22 Oct 2001 21:39:28 -0400
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: alarm and put a timeout on a perl program an its shell childs ?
Message-Id: <3BD4CA50.62B9F019@earthlink.net>

Gildas PERROT wrote:
> 
> Hi,
> 
> I want to put a timeout on a perl program and its shell child.

use IO::Select;
open( SHELL_COMMAND, "shell_cmd|" ) or die $!;
unless( IO::Select->can_read(1) ) {
    die "TIMEOUT!";
}
print while( sysread( SHELL_COMMAND, $_, 4096 ) );
close(SHELL_COMMAND);

-- 
Klein bottle for rent - inquire within.


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

Date: Tue, 23 Oct 2001 03:44:39 GMT
From: garry@ifr.zvolve.net (Garry Williams)
Subject: Re: alarm and put a timeout on a perl program an its shell childs ?
Message-Id: <slrn9t9pt7.pbd.garry@zfw.zvolve.net>

On Mon, 22 Oct 2001 21:39:28 -0400, Benjamin Goldberg
<goldbb2@earthlink.net> wrote:

> Gildas PERROT wrote:
>> 
>> I want to put a timeout on a perl program and its shell child.
> 
> use IO::Select;
> open( SHELL_COMMAND, "shell_cmd|" ) or die $!;
> unless( IO::Select->can_read(1) ) {
>     die "TIMEOUT!";
> }
> print while( sysread( SHELL_COMMAND, $_, 4096 ) );
> close(SHELL_COMMAND);

This is a plan for a much simpler solution to the OP's problem, than I
posted in this thread.  Unfortunately, the code above will fail.
Here's the fix: 

  $ cat wait_for_input
  #!/usr/bin/perl
  use warnings;
  use strict;
  my $x = <>;
  print $x;
  $ cat try
  #!/usr/bin/perl
  use warnings;
  use strict;
  use IO::Select;

  my $timeout = 3;

  my $pid = open( SHELL_COMMAND, "./wait_for_input |" ) or die $!;

  my $s = IO::Select->new(\*SHELL_COMMAND);
  unless( $s->can_read(3) ) {
      kill TERM => $pid;
      die "TIMEOUT!";
  }

  print while <SHELL_COMMAND>;
  close(SHELL_COMMAND) or die $! ? "$!" : "status=$?";

  __END__

  $ perl ./try
  TIMEOUT! at ./try line 13.
  $ perl ./try
  hello
  hello
  $ 

The IO::Select::can_read() method is *not* a class method: 

  Can't use string ("IO::Select") as an ARRAY ref while "strict refs" in
  use at /usr/local/lib/perl5/5.6.1/sun4-solaris/IO/Select.pm line 103.

The kill() isn't strictly necessary.  The use of <FILEHANDLE> will be
fine in this case because no other kinds of I/O are being used, once
the pipe is known to be ready to read.  (See below.)  

The only drawback to this fine suggestion that I can see is that it
could be possible for *some* external commands to produce some data on
the pipe and then block for some reason.  Now the parent is hopelessly
blocked in it's read.  

This is a good reason to use the sysread(), as you suggest.  Then it
becomes necessary for the parent to de-block the lines from the pipe
and repeatedly call $s->can_read() when the parent determines that
more data are needed from the child.  

Cool solution.  

-- 
Garry Williams


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

Date: Mon, 22 Oct 2001 21:25:14 -0400
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: Array of filehandles
Message-Id: <3BD4C6FA.E7AA3523@earthlink.net>

Steven Work wrote:
> 
> I'm new to perl and have a (probably simple) question on creating an
> array of file handles. Basically, I'm about to write out to N number
> of separate files.
> 
>         # open files ahead of time
>         for ( $index = 0; $index < $maxfiles; )
>         {
>                 $fn = "$filename$index$filenameext";
>                 open (PPM, $fn) or die "Problem: $fn $!";
>                 $ppm[$index] = \PPM;

This is bad/wrong.  If you had used strict, you would realize that \PPM
is considering PPM to be a string, and taking a reference to that
string.

Replace this with:
    open( local(*PPM), $fn) or die ...;
    $ppm[$index] = \*PPM;

>                 $index++;
>         }

Actually, though, you might consider replacing the above loop with:
use IO::File;

my @ppm = map {
    IO::File->new("$filename$_$filenameext") or die ...;
} 0 .. $maxfiles-1;

> 
> later when I use
> 
>         print $ppm[$index] "P5\n# $line$x $y\n255\n$frame";
> 
> I get the following error.
>         String found where operator expected line 43, near "]  (line
> 43 is the print statement)

There's two problems with this: One, syntax -- perl expects for a
filehandle either a simple bareword or variable, or a block.  Two, due
to the way you initialized it, $ppm[$index] contains something like
\"PPM", which isn't a filehandle.  I gave code to fix 2, but to fix the
syntax you need to do:
    print { $ppm[$index] } "P5\n# $line$x $y\n255\n$frame";

> I've tried a few variations, such as:
> 
>         KPPM = ${$ppm[$index]}; # and KPPM = $ppm[$index];

This attempts to use KPPM as the name of an lvalue subroutine.
You probably mean *KPPM = $ppm[$index];

>         print KPPM "P5\n# $line$x $y\n255\n$frame";
> 
> I've tried direct allocation into a filehandle:
>         ...
>                 open ( PPM[$index], $fn) or die "Problem: $fn $!";
>         ...
>         print PPM[$index] "P5\n# $line$x $y\n255\n$frame";

This is just plain Wrong.

> 
> I suspect I need to allocate the filehandle directly into an array,
> but have not discovered the form this would take.

open( $ppm[$index], $fn );

But this only works with perl5.6 and greater, not with perl5.0

-- 
Klein bottle for rent - inquire within.


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

Date: Mon, 22 Oct 2001 21:52:07 -0500
From: steve <sstod@family-net.net>
Subject: Re: Encrypt/Decrypt module
Message-Id: <3BD4DB57.4F2C972E@family-net.net>

I've had good results with Crypt::RC4, and it's easy to use.  I've also
tried Crypt::TripleDES, but that one is sensitive to the string length.

Steve Stoddard

Anand Ramamurthy wrote:

> Which is the simplest and easy to use module for encrypt and decrypt
> of text strings? Any sample code is also welcome.



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

Date: Mon, 22 Oct 2001 20:36:53 -0500
From: trammell@haqq.hypersloth.invalid (John J. Trammell)
Subject: Re: Encrypt/Decrypt module
Message-Id: <slrn9t9idl.g00.trammell@haqq.hypersloth.net>

On 22 Oct 2001 16:54:52 -0700, Anand Ramamurthy wrote:
> Which is the simplest and easy to use module for encrypt and decrypt
> of text strings? Any sample code is also welcome.

Module Crypt::CBC is a no-brainer.  Sample code is available in
its documentation.

-- 
ERR_NOSIG: sigfile out of commission while removing 'all your base'
           references.


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

Date: Tue, 23 Oct 2001 03:17:50 GMT
From: mjd@plover.com (Mark Jason Dominus)
Subject: Re: Fork messes up parent file handle?
Message-Id: <3bd4e15d.4701$49@news.op.net>

In article <3BD45F1C.AD56528@brighton.ac.uk>,
John English  <je@brighton.ac.uk> wrote:
>Thanks. This is presumably the root cause of the problem, but I'm
>still baffled because the child doesn't access the file handle at
>all. 

It may be a bug in Perl.  Other folks have reported problems that may
be similar, but unfortunately nobody's been able to pin it down well
enough to fix it.
-- 
@P=split//,".URRUU\c8R";@d=split//,"\nrekcah xinU / lreP rehtona tsuJ";sub p{
@p{"r$p","u$p"}=(P,P);pipe"r$p","u$p";++$p;($q*=2)+=$f=!fork;map{$P=$P[$f^ord
($p{$_})&6];$p{$_}=/ ^$P/ix?$P:close$_}keys%p}p;p;p;p;p;map{$p{$_}=~/^[P.]/&&
close$_}%p;wait until$?;map{/^r/&&<$_>}%p;$_=$d[$q];sleep rand(2)if/\S/;print


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

Date: Mon, 22 Oct 2001 21:47:56 -0400
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: Greediness and Regular Expressions
Message-Id: <3BD4CC4C.4695B34F@earthlink.net>

Syrag wrote:
> 
> I have a problem where I need to match 1 to 4 characters at the end of
> a string that string that might be 1 to 8 characters long.
> 
> So I might have any of the following and want to match upto 4
> characters at the end of the line.
> 
> stuff: 6837 abcd1234  #want 1234
> stuff: 6837 1234  #want 1234
> stuff: 6837 34  #want 34

Well, obviously since you don't want the space, you mean that you want
to match up to 4 non-whitespace characters at the end of the line.

[snip]
> (note, the part I want to match could be anything
> aphanumeric, 1234 is just used above)

Ahh, even more specific -- not just not whitespace, but must be
alphanumeric.

> Is there any way to match this?  Or, is there any way to change the
> greediness to be right to left or get around this?  I am sure there is
> something silly I am missing somewhere.

print m/(\w{1,4})$/, "\n";

-- 
Klein bottle for rent - inquire within.


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

Date: Mon, 22 Oct 2001 23:31:05 -0400
From: Jason Goodrow <"goodrow"@opencity. com>
Subject: NEWBIE sending vars
Message-Id: <9r2nth$cb4$1@news.panix.com>

I want to send a variable to another script
The command line seems wrong (to this newbie)
although this worked

#!/usr/perl5

use strict;

my $out = 2;
`./other $out`;

Any info?

Thanks

goodrow@panix.com



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

Date: 22 Oct 2001 22:47:39 -0500
From: logan@cs.utexas.edu (Logan Shaw)
Subject: Re: NEWBIE sending vars
Message-Id: <9r2p8r$24g$1@charity.cs.utexas.edu>

In article <9r2nth$cb4$1@news.panix.com>,
Jason Goodrow  <goodrow@opencity.com> wrote:
>I want to send a variable to another script
>The command line seems wrong (to this newbie)
>although this worked
>
>#!/usr/perl5

That's a unique place for perl to live.

>use strict;
>
>my $out = 2;

good so far.

>`./other $out`;

You're using backticks, which run a command and then return its
output as a value.  Then you're throwing away that output.
Usually it's better to just use system() instead, like this:

    system ("./other", $out);

Alternatively, you can do this:

    system ("./other $out");

but the first form is preferred because it passes each
argument separately instead of all together in one string.  If
$out is "2", that doesn't matter, but it does matter if $out
is "a b c" (i.e. if it contains spaces, among other things).

  - Logan
-- 
"In order to be prepared to hope in what does not deceive,
 we must first lose hope in everything that deceives."

                                          Georges Bernanos


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

Date: Tue, 23 Oct 2001 02:15:59 GMT
From: Bob Walton <bwalton@rochester.rr.com>
Subject: Re: perl algorithm
Message-Id: <3BD4D2FB.4C3DF70E@rochester.rr.com>

"F. Xavier Noria" wrote:
> 
> On Mon, 22 Oct 2001 01:33:35 GMT, Bob Walton <bwalton@rochester.rr.com> wrote:
> 
> : while(<DATA>){
>       #...
>   }
> 
> Is there any benefit using DATA that way instead of a standard
> filehandle to a file on disk with the data to process? If so, which is
> the usual way to accomplish that? Would one wrap the original script
> in a shell script or whatever that copies it on top of the data file
> and then calls it?
> 
> -- fxn

I use the DATA filehandle for the convenience of Usenet folks who might
want to copy/paste the code and try it.  That makes one clean copy/paste
for a complete executable example (something I'd like to see more of on
clpm -- it shows folks you care about their time and effort), rather
than having to fuss around with multiple files.  It would never be done
that way in a "real" program.  Usually, the DATA is deleted to leave <>
and process arguments and/or STDIN, or it is replaced by an open
filehandle.  Or the user can just add an open for the DATA filehandle.
-- 
Bob Walton


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

Date: Tue, 23 Oct 2001 02:39:33 GMT
From: "Brian P. Barnes" <BrianP@Die_Spammers_Fractasia.com>
Subject: Perl Image::Magick ignores QUALITY directive.
Message-Id: <3BD4D905.31FD12DA@Die_Spammers_Fractasia.com>

Hi,

I am upgrading an old tool to make it faster and easier on the images. I
used to use Image Magick's convert.exe repeatedly to resize, rotate,
annotate and thumbnail each pic. Now, I use Perl Magick $Image->Read and
do everything in memory with no file re-reads from disk and no disk
writes until all the processing is done.

I used to use "convert.exe -quality $quality -compress JPEG $infile
$outfile" in a system command and the quality was honored.

Now I use
$err = $image->Read("$infile");  # Read the Fully Qualified Path.
$err = $image->Set(compression => "JPEG");
$err = $image->Set(quality => $quality);
$err = $image->write(compression => "JPEG",  quality => $quality,
filename => "$outfile");

After each read, set and write command, I check for an error:
if("$err")  {
   warn "$err";
   $ec = 1;  # Flag error.
}

The quality value I try to use is somewhere in the 93 to 99 range (from
convert.exe documentation). I tried adding explicit SET commands in
addition to set the compression and quality in the write command.

I have tried setting the quality before the compression type. I have
tried setting them both together. No luck. The quality level is ignored
in every case.

Am I doing something wrong? Any ideas greatly appreciated,

    Brian


D:\scan\models\felicia\rot>perl -V
Summary of my perl5 (revision 5 version 6 subversion 0) configuration:
  Platform:
    osname=MSWin32, osvers=4.0, archname=MSWin32-x86-multi-thread
    uname=''
    config_args='undef'
    hint=recommended, useposix=true, d_sigaction=undef
    usethreads=undef use5005threads=undef useithreads=define
usemultiplicity=define
    useperlio=undef d_sfio=undef uselargefiles=undef
    use64bitint=undef use64bitall=undef uselongdouble=undef
usesocks=undef
  Compiler:
    cc='cl', optimize='-O1 -MD -DNDEBUG', gccversion=
    cppflags='-DWIN32'
    ccflags ='-O1 -MD -DNDEBUG -DWIN32 -D_CONSOLE -DNO_STRICT
-DHAVE_DES_FCRYPT  -DPERL_IMPLICIT_CONTEXT
-DPERL_IMPLICIT_SYS -DPERL_MSVCRT_READFIX'
    stdchar='char', d_stdstdio=define, usevfork=false
    intsize=4, longsize=4, ptrsize=4, doublesize=8
    d_longlong=undef, longlongsize=8, d_longdbl=define, longdblsize=10
    ivtype='long', ivsize=4, nvtype='double', nvsize=8, Off_t='off_t',
lseeksize=4
    alignbytes=8, usemymalloc=n, prototype=define
  Linker and Libraries:
    ld='link', ldflags ='-nologo -nodefaultlib -release
-libpath:"C:\Perl\lib\CORE"  -machine:x86'
    libpth="C:\Perl\lib\CORE"
    libs=  oldnames.lib kernel32.lib user32.lib gdi32.lib winspool.lib
comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib
netapi32.lib uuid.lib
wsock32.lib mpr.lib winmm.lib  version.lib odbc32.lib odbccp32.lib
msvcrt.lib
    libc=msvcrt.lib, so=dll, useshrplib=yes, libperl=perl56.lib
  Dynamic Linking:
    dlsrc=dl_win32.xs, dlext=dll, d_dlsymun=undef, ccdlflags=' '
    cccdlflags=' ', lddlflags='-dll -nologo -nodefaultlib -release
-libpath:"C:\Perl\lib\CORE"  -machine:x86'


Characteristics of this binary (from libperl):
  Compile-time options: MULTIPLICITY USE_ITHREADS PERL_IMPLICIT_CONTEXT
PERL_IMPLICIT_SYS
  Locally applied patches:
        ActivePerl Build 623
  Built under MSWin32
  Compiled at Dec 15 2000 16:27:07
  @INC:
    C:/perl/lib
    C:/perl/site/lib




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

Date: Tue, 23 Oct 2001 01:09:11 GMT
From: ted <tlav1@mediaone.net>
Subject: Re: Perl Vs. Java
Message-Id: <3BD4ED57.7578F377@mediaone.net>

Java crashes browsers MUCH better hat Perl. : )

ted



Peter Hickman wrote:

> "Krishna Kumar" <krishna.kumar@rhii.com> wrote in message
> news:PO$b#qyWBHA.169@hqp_news_nt1.corp.rhalf.com...
> > Folks at my work are talking about using Java as a standard instead of
> Perl.
>
> I know that this is unproven but when people start to talk of Java I think
> of
> Ars Digita and the place I used to work at. 'Lets do it in Java' seems to be
> the
> nail in the coffin of many a project and in some cases entire companies.
>
> What is it that Java can do they these people are saying that Perl cannot?
> Without knowing Java you can still assess this claimed deficiency, and then
> ask even
> if Perl cannot do it is it a problem?
>
> I've seen some very well paid Java programmers but I have yet to witness a
> successful project. I would question the motives of these people.
>
> But then I'm a cynic!



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

Date: Tue, 23 Oct 2001 11:33:59 +0800
From: "Terence Smith" <mjojoz@nospamhotmail.com>
Subject: Premature end of script header
Message-Id: <9r2oe7$7tv$1@violet.singnet.com.sg>

Hi all,

I need an advice from all of you about this perl program.

#!c:\perl_prog\bin\perl
push(@INC, "\cgi-bin");
require("cgi-lib.pl");
print &PrintHeader;
print "<html>\n";
print "<head><title> Environment Variables </title></head>\n";
print "<body>\n";

print <<"EOF";
<center>
<table border=2 cellpadding=10 cellspacing=10>
<th align=left><h3>Environment Variable</h3>
<th align=left><h3>Contents</h3><tr>
EOF
foreach $var (sort keys(%ENV))
{
  print "<td> $var <td> $ENV{$var}<tr>";
}
print <<"EOF"
</table>
</body>
</html>
EOF

When I try to run this program from my webbrowser always return error 500.
If I check on error log on my webserver state that "Premature end of script
header". Thank for any advice in advance.

Regards,
Franky




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

Date: Mon, 22 Oct 2001 23:50:41 -0400
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: Premature end of script header
Message-Id: <3BD4E911.F81A58B2@earthlink.net>

Terence Smith wrote:
> 
> Hi all,
> 
> I need an advice from all of you about this perl program.
> 
> #!c:\perl_prog\bin\perl
> push(@INC, "\cgi-bin");

"\cg" is control-g.  Try instead one of
	"\\cgi-bin"
	"/cgi-bin"
	'\cgi-bin'
	'/cgi-bin'

-- 
Klein bottle for rent - inquire within.


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

Date: Tue, 23 Oct 2001 13:34:57 +0930
From: "Wyzelli" <wyzelli@yahoo.com>
Subject: Re: Premature end of script header
Message-Id: <AS5B7.54$zX2.351@wa.nnrp.telstra.net>

"Terence Smith" <mjojoz@nospamhotmail.com> wrote in message
news:9r2oe7$7tv$1@violet.singnet.com.sg...
> Hi all,
>
> I need an advice from all of you about this perl program.
>
> #!c:\perl_prog\bin\perl

No -w
No 'use strict;'

If you insert
use CGI::Carp qw(fatalsToBrowser);
you should get some meaningful errors printed to your umm, well, browser...

> push(@INC, "\cgi-bin");
> require("cgi-lib.pl");

VERY obsolete.  Check out CGI.pm instead.

> print &PrintHeader;
> print "<html>\n";
> print "<head><title> Environment Variables </title></head>\n";
> print "<body>\n";
>
> print <<"EOF";
> <center>
> <table border=2 cellpadding=10 cellspacing=10>
> <th align=left><h3>Environment Variable</h3>
> <th align=left><h3>Contents</h3><tr>
> EOF
> foreach $var (sort keys(%ENV))

 foreach my $var (sort keys(%ENV))

> {
>   print "<td> $var <td> $ENV{$var}<tr>";
> }
> print <<"EOF"

Missing ; at end of previous line

> </table>
> </body>
> </html>
> EOF

Ensure there is a newline after that last EOF as well, of the 'here-doc' may
not work.

>
> When I try to run this program from my webbrowser always return error 500.
> If I check on error log on my webserver state that "Premature end of
script
> header". Thank for any advice in advance.

Any or all of the above could be causing your problem.

Wyzelli
--
#Modified from the original by Jim Menard
for(reverse(1..100)){$s=($_!=1)? 's':'';print"$_ bottle$s of beer on the
wall,\n";
print"$_ bottle$s of beer,\nTake one down, pass it around,\n";
$_--;$s=($_==1)?'':'s';print"$_ bottle$s of beer on the
wall\n\n";}print'*burp*';





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

Date: Tue, 23 Oct 2001 03:07:16 GMT
From: mgjv@tradingpost.com.au (Martien Verbruggen)
Subject: Re: Skipping following lines if the same
Message-Id: <slrn9t9nn3.1bv.mgjv@verbruggen.comdyn.com.au>

On Mon, 22 Oct 2001 20:43:59 -0400,
	Benjamin Goldberg <goldbb2@earthlink.net> wrote:
> Laird wrote:
>> 
>> Hi everyone,
>> 
>> I've got this array
>> 
>> aaa
>> aaa
>> bbbbb
>> cccc
>> cccc
>> c
>> ddd
>> ddd
>> fff
>> fff
>> fff
>> ffff
>> ffff
>> 
>> and would like to transform it into this
>> 
>> aaa
>> bbbbb
>> cccc
>> c
>> ddd
>> fff
>> ffff
>> 
>> skipping following lines if the same.
>> But only following lines.
> 
> [untested]:
> my %seen;
> while(<IN>) {
>     next if exists $seen{$_} && $seen{$_} == $. - 1;
>     print;
>     $seen{$_} = $.;
> }

But this will also transform 

aaa
bbb
aaa
bbb
ccc
aaa

into

aaa
bbb
ccc

The OP specifically states that that is not what they want to happen.
At least, I read the following:

>> skipping following lines if the same.
>> But only following lines.

as remove duplicate entries, but only if they follow each other
immediately.  Your code also needs a hash entry for each unique
element of the array, which is more than is needed if the OP's
original spec is followed more literally.

The OP doesn't specify whether they want a new array, or whether it
should be modified in-place, so I'll just assume they need a new array:

# 1) Using grep

my $last = ""; # Assuming there are no empty strings in the array
my @new_data = grep { $last ne $_ && ($last = $_) } @data;

# 2) Using map (unnecessarily ugly)

my $last = ""; # Assuming there are no empty strings in the array
my @new_data = map { $last ne $_ && ($last = $_) ? $_ : () } @data;

# 3) gentler on memory, since we don't need to build temporary lists:

my @new_data = ();
do { push @new_data, $_ unless @new_data && $new_data[-1] eq $_ } 
	for @data;

I'd probably prefer the last one. if you want to speed it up
marginally, you could prefill the first element of the array, and
avoid the test for @new_array:

my @new_data = @data[0];
do { push @new_data, $_ unless $new_data[-1] eq $_ } for @data;

Note that @data[0] is a slice, not an element. Both will work, but I
like to be explicit when assigning to arrays.

It is possible to do this in-place, but it's more complex, and
probably not necessary. Unless you're really tight on memory, you can
always do:

@data = one_of_the_above @data;

Martien
-- 
Martien Verbruggen              | 
                                | True seekers can always find
Trading Post Australia Pty Ltd  | something to believe in.
                                | 


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

Date: Mon, 22 Oct 2001 23:47:26 -0400
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: Skipping following lines if the same
Message-Id: <3BD4E84E.B7A7D026@earthlink.net>

Martien Verbruggen wrote:
> 
> On Mon, 22 Oct 2001 20:43:59 -0400,
>         Benjamin Goldberg <goldbb2@earthlink.net> wrote:
[snip]
> >> skipping following lines if the same.
> >> But only following lines.
> >
> > [untested]:
> > my %seen;
> > while(<IN>) {
> >     next if exists $seen{$_} && $seen{$_} == $. - 1;
> >     print;
> >     $seen{$_} = $.;
> > }
> 
> But this will also transform
> 
> aaa
> bbb
> aaa
> bbb
> ccc
> aaa
> 
> into
> 
> aaa
> bbb
> ccc

No it won't, due to the " && $seen{$_} == $. - 1" clause.

However it does have another [different] problem in that if a line is
repeated 3 or more times in a row, only every other one of the
duplicates will be skipped.

my %seen;
while(<IN>) {
    next if exists $seen{$_} && $seen{$_} == $. - 1;
    print;
} continue {
    $seen{$_} = $.;
}

You're absolutely right that this is more than is needed, though.

my $last;
while(<IN>) {
    next if defined $last && $last eq $_;
    print;
} continue {
    $last = $_;
}

Of course, it occurs to me that the unix program uniq should also be
able to do what the OP wants.

-- 
Klein bottle for rent - inquire within.


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

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


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