[11497] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 5097 Volume: 8

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Mar 9 19:07:27 1999

Date: Tue, 9 Mar 99 16:00:19 -0800
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Tue, 9 Mar 1999     Volume: 8 Number: 5097

Today's topics:
        Adduser for NT? dragnovich@my-dejanews.com
    Re: Can't kill Perl script with CTRL-C <alfred@ascend.com>
    Re: cobol line seq. file - one very long line - <dphi@ix.netcom.com>
    Re: Combining Files <aqumsieh@matrox.com>
    Re: Combining Files fxia@my-dejanews.com
    Re: Counter problem... HEEELLP! <flanker@sonnet.ru>
    Re: Counter problem... HEEELLP! (Alex Iatskovski)
    Re: Days in Month array <cassell@mail.cor.epa.gov>
    Re: Days in Month array <jglascoe@giss.nasa.gov>
        FAQ 3.16: How can I make my Perl program run faster?   <perlfaq-suggestions@perl.com>
    Re: gethostbyname on entire subnet (Charles DeRykus)
    Re: Help on CGI!! <strovink@acm.org>
        Help: lstat() and -l problems (George Lindholm)
        How to change file dates in Win32 using PERL?? qvanegeren@frxsoft.com
    Re: Illiad!!!!!! <gellyfish@btinternet.com>
    Re: Improving code fxia@yahoo.com
    Re: Limit string length <aqumsieh@matrox.com>
        Missing CGI Environment Variables (John Casey)
        nntp posting with perl (Eric Smith)
    Re: Perl and a Here document fxia@my-dejanews.com
        Problems with Perl and tar (Steve Lamb)
        REGEXP: Problem matching string containing parens or br <apollock11@hotmail.com>
    Re: REGEXP: Problem matching string containing parens o <apollock11@hotmail.com>
        TECO *is* obfuscation (was does perl discourage obfusca <davidx.corcoran@intel.com>
        while <> not work for empty files vicuna@my-dejanews.com
        Special: Digest Administrivia (Last modified: 12 Dec 98 (Perl-Users-Digest Admin)

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

Date: Tue, 09 Mar 1999 22:46:43 GMT
From: dragnovich@my-dejanews.com
Subject: Adduser for NT?
Message-Id: <7c48ch$7ur$1@nnrp1.dejanews.com>

Hello I have an application that is programed in perl, one subroutine of it
is a modified adduser rutine from the Unix adduser command.

But when we try to run it on NT it dont works, well is there any routines for
NT to add users (Setup email account) creating a user with username,
password, Real name, account privilegies, etc...

and/or change users passwords from Perl for NT

is this posible or im dreaming ??

regards!
------------------------
Juan Carlos Lopez
QDesigns President & CEO
http://www.qdesigns.com

-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/       Search, Read, Discuss, or Start Your Own    


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

Date: Tue, 09 Mar 1999 18:30:01 -0500
From: Alfred von Campe <alfred@ascend.com>
Subject: Re: Can't kill Perl script with CTRL-C
Message-Id: <36E5AEF9.A5DDE079@ascend.com>

OK, as soon as I posted my message I realized what I was doing
wrong.  But I still can't get it to work.  My routine now looks
likes this:

     sub update_files()
     {
         my $dirs = $_[0];

         print "Updating \"converted\" files with clearmake\n";
         open(DIRS, $dirs) || die "$0: Can't open $dirs ($!)\n";
         while(<DIRS>)
         {
             # Ignore comments and blank lines
             chomp();
             s/#.*$//;
             next if (/^\s*$/);
             print "  Updating files in $_\n";
             $status = system("cd $_; /usr/atria/bin/clearmake all");
             die "$0: Received CTRL-C -- bye!\n" if (($status & 0x00ff) > 0);
         }
         close(DIRS);
         print "\n";
     }
 
If I hit CTRL-C while my script is in the system() call, the clearmake
does end right away, but the script doesn't die.  The status returned
from system() is almost always 0x8200 (and sometimes 0x8400).  According
to the Camel book, system() will return with the lower 8 bits set to
something if the process recevied a signal.  Any ideas what's going on?

Alfred
-- 
Alfred von Campe                      home phone: +1 978.448.6214
CAE Software Engineer                 work phone: +1 508.486.2006
Carrier Signaling & Management Group         fax: +1 508.486.2921
Ascend Communications, Inc.                email: alfred@ascend.com


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

Date: Tue, 09 Mar 1999 14:18:44 -0600
From: Dale Phillips <dphi@ix.netcom.com>
Subject: Re: cobol line seq. file - one very long line -
Message-Id: <36E58224.77AC8FA6@ix.netcom.com>

Thank you very much!

Do happen to know how to Zero pad a $var? 

printf "%10s",$var;

where var is only 3 digits but needs to be 10 with leading zeros?

Pardon me my Cobol is showing ;-)


Dan Sugalski wrote:
> 
> Dale Phillips <dp@lore.org> wrote:
> : I have a cobol line sequential file that I need
> : to parse up into record length of 57 each....
> 
> : This has got to be brain dead easy but I
> : can not seem to find anything that
> : counts x chars from slurped file and add \r start counter over ....
> 
>         use 5.005;
>         $/ = \57;
>         while(<>) {
>            # $_ is your record in here...
>         }
> 
>                                                 Dan

-- 
-dp-----------------
Dale Phillips
dphi@ix.netcom.com


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

Date: Tue, 09 Mar 1999 22:38:00 GMT
From: @l@ <aqumsieh@matrox.com>
Subject: Re: Combining Files
Message-Id: <7c47s7$7en$1@nnrp1.dejanews.com>

In article <36e31147.4434897@news.flash.net>,
  golfer@usa.net wrote:
> I am stumped!  I have 50 text tab delimited files that I am trying to
> combine into one file based upon the username variable.

<snip>

> mike	100
> larry	87
> joe	90	15	12
> pete	35	21
> sam	20	15

my (%hash, $name, $mark);
for my $file (@files) {
	open F, $file or die "Can't open $file: $!\n";
	while (<F>) {
		next if /^\s*$/;
		($name, $mark) = split;
		push @{$hash{$name}} => $mark;
	}
	close F, or warn "Can't close $file: $!\n";
}

open OUT, "> output" or die "Can't create output file: $!\n";
{
	local $" = "\t";
	for my $name (sort keys %hash) {
		print OUT "$name\t@{$hash{$name}}\n";
	}
}
close OUT or warn "Can't close output file: $!\n";


--Ala

-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/       Search, Read, Discuss, or Start Your Own    


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

Date: Tue, 09 Mar 1999 22:42:00 GMT
From: fxia@my-dejanews.com
Subject: Re: Combining Files
Message-Id: <7c483m$7is$1@nnrp1.dejanews.com>



Just use a hash, with keys as names, and values are arrays
of integers. For example:

my %counts;
open(FILE, "$myfile") || die "dead";
while (<FILE>) {
    if (/^(\w+)\s+(\d+)/) {
        my ($name, $count) = ($1, $2);
        push @{$counts{$name}}, $count;
    }
}
close(FILE);
 ...
# more files to read ...
 ...

# print
for my $k (keys %counts) {
    print FILE, $k, "\t", join("\t", @{$counts{$k}}), "\n";
}


In article <36e31147.4434897@news.flash.net>,
  golfer@usa.net wrote:
> I am stumped!  I have 50 text tab delimited files that I am trying to
> combine into one file based upon the username variable.
>
> File 1:
> mike	100
> joe	90
> pete	35
>
> File 2:
> larry	87
> joe	15
> sam	20
>
> File 3:
> sam	15
> joe	12
> pete	21
>
> etc,; what I need to do is combine these files into a single file
> resulting in (order is not important):
> mike	100
> larry	87
> joe	90	15	12
> pete	35	21
> sam	20	15
>
> I can do it if the names are present in all files but each file may or
> may not have that person's name.  I have looked at the FAQ's but
> didn't have any luck.  Any help is greatly appreciated.  Thanks...
>

-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/       Search, Read, Discuss, or Start Your Own    


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

Date: Wed, 10 Mar 1999 02:29:00 +0300
From: "Michael Yevdokimov" <flanker@sonnet.ru>
Subject: Re: Counter problem... HEEELLP!
Message-Id: <7c4aor$lel$1@bison.rosnet.ru>

As I told I need in script which doesn't use SSI possibilities! All images
have to be shown in <IMG SRC="counter.cgi"> HTML code...

Do u have any ideas?

--
Best wishes,

Michael Yevdokimov

Email: flanker@sonnet.ru
ICQ: 30874618
-------------------------------------------------
>> Developers Support Site <<
Web: http://developer.tsx.org
http://www.basicnet.sonnet.ru
-------------------------------------------------

Jay Glascoe ohxer b qnnayemhh <36E57DB2.20A1696F@giss.nasa.gov> ...
>[posted and mailed]
>
>Michael Yevdokimov wrote:
>>
>> I want to create a small image counter. I've already written some code
>> for it (see below). I have a problem with showing numbers' images.. I
>> understand that my FOR..LOOP construction overwrites the previous
>> output image...
>
>Yes, your program should spit out HTML with the
>images embedded in it.
>
>> $base1="../../count/imgs";
>> $base2="../../count";
>> %imgs=(
>>          "0", "0.gif",
>>          "1", "1.gif",
>
>[... snip ...]
>
>>          "9", "9.gif"
>> );
>
>my @images = ();
>$images[$_] = "$_.gif" foreach (0..9);
>
>> open (F1,"<$base2/temp.txt");
>
>open F1, "< bleah" or die "biz: $!";
>
>>   $cont=<F1>;
>
>chomp(my $count = <F1>);  # like an extra "u" would kill you  ;^)
>
>> close(F1);
>>
>> #For example our temp.txt has number 10000 inside
>>
>> $sl=length($cont);
>> binmode(STDOUT);
>>
>> print "Content-type:image/gif\n\n";
>> for ($i=0;$i<$sl;$i++) {
>>    $n=substr($cont,$i,1);
>>    open (IMG, "$base1/$imgs{$n}");
>>      binmode(IMG);
>>      print STDOUT <IMG>;
>>    close(IMG);
>> }
>
># here's a very basic web page:
>
>print "Content-type: text/html\n\n";
>foreach my $n (split '', $count) {
>    print qq {
> <img src="$base1/$images[$n]">
>    };
>}
>
>> Can anyone consult me how to make a normal sequence of images, i.e.
>> how to correct program's bug? ;-)
>
>let the browser access the gif files itself.
>It was designed to do that.
>
> Jay Glascoe
>--
>"Narf!"
>  --Pinky




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

Date: Tue, 09 Mar 1999 23:27:46 GMT
From: 74642.3600@NOSPAM.compuserve.com (Alex Iatskovski)
Subject: Re: Counter problem... HEEELLP!
Message-Id: <36f2adf7.45057765@news.brainlink.com>

On Wed, 10 Mar 1999 02:29:00 +0300, "Michael Yevdokimov"
<flanker@sonnet.ru> wrote:

>As I told I need in script which doesn't use SSI possibilities! All images
>have to be shown in <IMG SRC="counter.cgi"> HTML code...
>
>Do u have any ideas?

Sure! :) Go to 

http://www.cgi-resources.com/Programs_and_Scripts/Perl/Access_Counters/Graphical/

and look for youself.

--Regards, Alex.


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

Date: Tue, 09 Mar 1999 14:18:43 -0800
From: "David L. Cassell" <cassell@mail.cor.epa.gov>
Subject: Re: Days in Month array
Message-Id: <36E59E43.58173F3F@mail.cor.epa.gov>

Errm, didn't you forget to check whether years ending in '00' are
leap years?  And please, let's not fork a child on 'whether the
year 2000 is a leap year'.  Ugh.  I've seen that way too many times
already.

Jay Glascoe wrote:
> 
> [posted and mailed]
> 
> "Charles R. Thompson" wrote:
> >
> > I'm trying to build a timeline of days and dates when given a
> > year. Leap years are messin with my code.
> >
> > How does one calculate if a given year is a leap year?
> >
> > CT
> 
> isn't it simply
> 
> print "leap year\n" if $year % 4 == 0;

David
-- 
David L. Cassell, OAO                   cassell@mail.cor.epa.gov
Senior computing specialist
mathematical statistician


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

Date: Tue, 09 Mar 1999 18:19:54 -0500
From: Jay Glascoe <jglascoe@giss.nasa.gov>
Subject: Re: Days in Month array
Message-Id: <36E5AC9A.D96C7F7A@giss.nasa.gov>

"David L. Cassell" wrote:
> 
> Errm, didn't you forget to check whether years ending in '00' are
> leap years?  And please, let's not fork a child on 'whether the
> year 2000 is a leap year'.  <snip>

hmph.  Sorry, I think this is right:

print "biz!\n" unless $year % 4 or not $year % 100 and $year % 400;

	Jay Glascoe
--  
http://www.giss.nasa.gov/cgi-bin/csci/change.pl


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

Date: 9 Mar 1999 15:45:22 -0700
From: Tom Christiansen <perlfaq-suggestions@perl.com>
Subject: FAQ 3.16: How can I make my Perl program run faster?  
Message-Id: <36e5a482@csnews>

(This excerpt from perlfaq3 - Programming Tools 
    ($Revision: 1.33 $, $Date: 1998/12/29 20:12:12 $)
part of the standard set of documentation included with every 
valid Perl distribution, like the one on your system.
See also http://language.perl.com/newdocs/pod/perlfaq3.html
if your negligent system adminstrator has been remiss in his duties.)

  How can I make my Perl program run faster?

    The best way to do this is to come up with a better algorithm.
    This can often make a dramatic difference. Chapter 8 in the Camel
    has some efficiency tips in it you might want to look at. Jon
    Bentley's book ``Programming Pearls'' (that's not a misspelling!)
    has some good tips on optimization, too. Advice on benchmarking
    boils down to: benchmark and profile to make sure you're
    optimizing the right part, look for better algorithms instead of
    microtuning your code, and when all else fails consider just
    buying faster hardware.

    A different approach is to autoload seldom-used Perl code. See
    the AutoSplit and AutoLoader modules in the standard distribution
    for that. Or you could locate the bottleneck and think about
    writing just that part in C, the way we used to take bottlenecks
    in C code and write them in assembler. Similar to rewriting in C
    is the use of modules that have critical sections written in C
    (for instance, the PDL module from CPAN).

    In some cases, it may be worth it to use the backend compiler to
    produce byte code (saving compilation time) or compile into C,
    which will certainly save compilation time and sometimes a small
    amount (but not much) execution time. See the question about
    compiling your Perl programs for more on the compiler--the wins
    aren't as obvious as you'd hope.

    If you're currently linking your perl executable to a shared
    *libc.so*, you can often gain a 10-25% performance benefit by
    rebuilding it to link with a static libc.a instead. This will
    make a bigger perl executable, but your Perl programs (and
    programmers) may thank you for it. See the INSTALL file in the
    source distribution for more information.

    Unsubstantiated reports allege that Perl interpreters that use
    sfio outperform those that don't (for IO intensive applications).
    To try this, see the INSTALL file in the source distribution,
    especially the ``Selecting File IO mechanisms'' section.

    The undump program was an old attempt to speed up your Perl
    program by storing the already-compiled form to disk. This is no
    longer a viable option, as it only worked on a few architectures,
    and wasn't a good solution anyway.

-- 
"If Dennis Ritchie were the man who developed Modula-2 then C would be long forgotten."
    --Tarjei Jensen


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

Date: Tue, 9 Mar 1999 22:03:08 GMT
From: ced@bcstec.ca.boeing.com (Charles DeRykus)
Subject: Re: gethostbyname on entire subnet
Message-Id: <F8CL98.LMF@news.boeing.com>

In article <7c18cs$jk8$1@nnrp1.dejanews.com>,
 <florcsk@boulder.nist.gov> wrote:
>I'm writing a few little utilities that allow lookups to be done via input
>from an html form. This data is passed to a perl script where the lookup is
>done with gethostbyaddr and gethostbyname calls.
>
>There are 4 things I'd like to do: 1) Enter an IP address, returns host name.
>2) Enter FQDN, returns IP address. 3) Enter a subnet, return IP addresses
>that resolve and their corresponding host names. 4) Enter a domain, return
>the hosts that exist on that domain and their corresponding IP addresses.
>
>The first 3 were easy. The 3rd was done with a loop basically calling
>gethostbyaddr 255 times. However, I'm stuck as to how to do the 4th. Can
>gethostbyname be used for this or some module? I'd like to be able to type in
>"somewhere.com" and back will come:
>www.somewhere.com (192.168.x.x)
>news.somewhere.com (192.168.x.x)
>gateway.somewhere.com (210.43.x.1)

Look for Net::DNS (author: Michael Fuhr) on CPAN 
This module provides a method to pull a whole zone
although servers can be configured to refuse zone 
transfers except from selected hosts. 

Here's a quick example of pulling a zone. You'll have
to tweak the output a bit: 


 use Net::DNS;

 my $resolver = new Net::DNS::Resolver;
 my $domain   = 'somewhere.com';
 my $query = $resolver->query($domain, "NS");
 if ($query) {
     foreach $rr ($query->answer) {
       next unless $rr->type eq "NS";
       $resolver->nameservers($rr->nsdname);
       last;
     }
 } else {
     print "query failed: ", $resolver->errorstring, "\n";
 }

 my @zone = $resolver->axfr($domain);
 foreach $rr (@zone) {   #  tweak output here 
     $rr->print;
 }



hth,
--
Charles DeRykus


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

Date: Tue, 09 Mar 1999 17:59:01 -0500
From: Eric Strovink <strovink@acm.org>
To: Yu Fang <yfang@gte.com>
Subject: Re: Help on CGI!!
Message-Id: <36E5A7B5.EB3BEE02@acm.org>

Oddly, I don't have problems with Netscape at all in this
situation, only with IE4.x.  Netscape paints what I send it,
when I send it.  So the problem, for me, isn't at the server
side at all -- it's in IE4.x.  Before you use my "solutions," you
should confirm that you are in the same situation (traffic
IS getting to the browser, just not being displayed).

Two things seem to convince IE4.x to behave:

1. Send </body> when you want something to print. :-(
2. Send lots of spaces to force text out.

The first alternative does work on IE4.x and Netscape 4.x,
but it shouldn't.  Believe it or not, you can send more stuff
after </body>, and it still comes out OK.  But this alternative
is way too bizarre to count on, and probably won't work
for some browsers.

The second alternative also works, and it shouldn't either.
But it appears to.  At least it's legal (2nd through Nth spaces
are NOOPs in HTML).  I use about
100 spaces, and it does seem to force things out reliably,
albeit at the expense of some bandwidth.

Let me know if you come across any better methods.

Thanks,

Eric

Yu Fang wrote:

> My dear friends:
>
> This question may not be related to this site. I don't know what place
> to turn to. Sorry to bother.
>
> I have a CGI script (in perl) which writes back the page piece by piece
> every couple of seconds. I want the browser shows the page piece by
> piece too - not waiting until the whole page is finished.
>
> The following script works on http://www.telcoip.com/cgi-bin/temp2.cgi
> but not on my Sun Web Server (sorry the server is behind a firewall). Do
> I need to do something special to configure my web server?
>
> Thanks.
> --
> #!/bbn/bin/perl
>
> # test script
>
> $|=1;
>
> print STDOUT "Content-type:text/html\n\n";
> $now = localtime time;
> print STDOUT "$now : First Try. Will try again in 5 seconds. Please
> wait. <p>\n";
>
> $allsec = time;
> $allsecb = ($allsec + 5);
>
> while ($allsecb > $allsec) {
> $allsec = time;
> }
>
> $now = localtime time;
>
> print STDOUT "Total seconds since 1970: $allsec <p>\n";
> print STDOUT "$now : Still Trying. Will try again in 5 seconds. Please
> wait. <p>\n";
>
> $allsec = time;
> $allsecb = ($allsec + 5);
>
> while ($allsecb > $allsec) {
> $allsec = time;
> }
>
> $now = localtime time;
>
> print STDOUT "Total seconds since 1970: $allsec <p>\n";
> print STDOUT "$now : Still Trying. Will try again in 5 seconds. Please
> wait. <p>\n";
>
> exit;
>
> --
> Frank Yu Fang
>
> GTE Internetworking
> 40 Sylvan Road
> Waltham, MA 02451-1128



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

Date: 9 Mar 1999 15:34:02 -0800
From: lindholm@ucs.ubc.ca (George Lindholm)
Subject: Help: lstat() and -l problems
Message-Id: <7c4b5a$cjm@greve.ucs.ubc.ca>

I'm getting a strange error message when I try to combine lstat() and
-l with perl5.005.02/solaris. When I run this script:

#!/usr/local/bin/perl

open(FH, '/etc/motd');
($dev) = lstat(FH);
if (-l _) {
  print "symlink\n";
}

I get:

The stat preceding -l _ wasn't an lstat at /tmp/b.pl line 5.

Am I missing something here? Thanks

   George
-- 
George.Lindholm@ubc.ca       ITServices, UBC

phone:    604.822.4375       For information about Ballroom dance music:
fax:      604.822.5116       http://www.interchange.ubc.ca/lindholm


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

Date: Tue, 09 Mar 1999 21:59:30 GMT
From: qvanegeren@frxsoft.com
Subject: How to change file dates in Win32 using PERL??
Message-Id: <7c45js$5ab$1@nnrp1.dejanews.com>

I need to change the date of an executable file on a Windows NT machine.  Is
this possible to do through PERL?  I've used PERL for quite awhile, but have
just been tasked with changing the dates of some of the executables we
include in our distributions.  I know that using the AdminMisc module gives
me the ability to pull the modified date of files, but it doesn't seem to let
me CHANGE the modified date on these files.

Any help would be greatly appreciated.  Thanks in advance...

Quenten Van Egeren
(qvanegeren@frxsoft.com)

-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/       Search, Read, Discuss, or Start Your Own    


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

Date: 9 Mar 1999 22:48:03 -0000
From: Jonathan Stowe <gellyfish@btinternet.com>
Subject: Re: Illiad!!!!!!
Message-Id: <7c48f4$na$1@gellyfish.btinternet.com>

On 8 Mar 1999 20:08:37 GMT I R A Aggie wrote:
> For your viewing pleasure:
> <http://www.userfriendly.org/cartoons/archives/99mar/19990308.html>.
> 
> Amusing, I guess...don't tell Randal...
> 

But why is the llama all punctured up ?

/J\
-- 
Jonathan Stowe <jns@btinternet.com>
Some of your questions answered:
<URL:http://www.btinternet.com/~gellyfish/resources/wwwfaq.htm>
Hastings: <URL:http://www.newhoo.com/Regional/UK/England/East_Sussex/Hastings>


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

Date: Tue, 09 Mar 1999 22:16:37 GMT
From: fxia@yahoo.com
Subject: Re: Improving code
Message-Id: <7c46js$6ch$1@nnrp1.dejanews.com>

Personally I found CGI.pm table creation is a little bit clumsy.
So I wrote something of my own. Basically, one can think of
the table as a hash, and the rows is a ref to an array of hash,
and each row has a ref to an array of hash for cells. This makes
table construction cleaner, since the "structure" of the table
is more visible and comprehensible.

For example, a table can be:

my @cells;
push @cells,
    { value => 'Blah1', href => 'Blah1', rowspan => 3 },
    { value => 'Blah2', href => 'Blah2' };

my @rows;
push @rows,
    { align => 'center',
      cells => \@cells };

my $table = { align => 'center',
              border => 0,
              rows => \@rows };

my $table_str = generate_table_html($table);

The routine &generate_table is like this:

sub generate_table_html {
    my $table = shift;
    my $s = "<table";
    for my $attr (keys %{$table}) {
        next if ($attr eq "rows");
        $s .= attr_pair($attr, $table->{$attr});
    }
    $s .= ">\n";
    my $rows = $table->{rows};
    foreach my $r (@{$rows}) {
        $s .= "<tr";
        for my $attr (keys %{$r}) {
            next if ($attr eq "cells");
            $s .= attr_pair($attr, $r->{$attr});
        }
        $s .= ">";
        my $cells = $r->{cells};
        foreach my $c (@{$cells}) {
            $s .= "<td";
            for my $attr (keys %{$c}) {
                next if ($attr eq "value");
                next if ($attr eq "href");
                next if ($attr eq "font");
                $s .= attr_pair($attr, $c->{$attr});
            }
            $s .= ">";
            if ($c->{value}) {
                $value = $c->{value};
                if ($c->{href}) {
                    $value =~ /^(\s*)(\S(.+\S)*)(\s*)$/;
                    my ($ls, $core, $rs) = ($1, $2, $4);
                    $ls =~ s/\ /\&nbsp\;/g if $ls;
                    $rs =~ s/\ /\&nbsp\;/g if $rs;
                    if ($c->{font}) {
                        $s .= $ls . a({-href=>$c->{href}},
                                      mk_font($c->{value}, $c->{font})) . $rs;
                    } else {
                        $s .= $ls . a({-href=>$c->{href}}, $core) . $rs;
                    }
                } else {
                    if ($c->{font}) {
                        $s .= mk_font($c->{value}, $c->{font});
                    } else {
                        $s .= $c->{value};
                    }
                }
            } else {
                $s .= "&nbsp;";
            }
            $s .= "</td>";
        }
        $s .= "</tr>\n";
    }
    $s .= "</table>\n";
    return $s;
}

sub mk_font {
    my $value = shift;
    my $dec = shift;
    return "<font " . $dec . ">" . $value . "</font>";
}

sub attr_pair {
    my $attr = shift;
    my $value = shift;
    if ($value =~ /^\d+$/) {
        return " " . $attr . "=" . $value;
    } else {
        return " " . $attr . '=\'' . $value . '\'';
    }
}


In article <36e1d912.2338397@news.supernews.com>,
  alany@2021.com wrote:
> I previously posted some code without actually testing it and asked
> for help in improving it.  Hence the muffled sounds coming from my
> direction (foot in mouth).  Basically, I got too big fer ma britches,
> thinking I understood it well enough to fire it off w/o testing it.
>
> I have since made it work, but it seems clumsy to me.  Here is a test
> program that I was able to produce the results I wanted (yes, I
> actually tested it this time *blush*).  You can look at
> http://alany.office2office.com/cgi-bin/alany/tst
> to see what it looks like.
>
> My biggest concern is in creating the table tag.  I'm using CGI.pm
> throughout my script, but here I've been forced to manually print the
> table tag instead of using CGI::table.  It doesn't seem to matter one
> way or the other, but it certainly looks screwy.
>
> Thanks for your time.
>
> begin perl
> ==========
> #!/u/alany/bin/perl -Tw
>
> use strict;
> use vars qw(%Inventory);
> use CGI::Pretty qw(:all -no_debug);
> use IO;
>
>   # Build a hash for the inventory
>   my $inventory = "./inventory.db";
>   my $INV = new IO::File "<$inventory";
>   die "Unable to open inventory file" if !$INV;
>
>   %Inventory = map {(split /\|/)[0], $_} <$INV>;
>
>   my $cart = "./user.cart";
>   my $CART = new IO::File "<$cart";
>   die "Unable to open $cart." if !$CART;
>
>   # Slurp the cart.
>   my @CartContents = <$CART>;
>
>   # Build array of information for existing items
>   my @items = sort map {
>     my ($itm, $qty) = (split /\|/);
>     my $item = $Inventory{$itm} || " Item $itm does not exist in
> inventory.";
>     chomp $item;
>     $item =~ /^$itm\|/ ? $item . "|$qty" : $item;
>   } @CartContents;
>
> print header, start_html, start_form, "<TABLE cellpadding=2 border=yes
> width=\"60%\">", th(['Item', 'Description', 'Quantity', 'Price',
> 'Subtotal']);
>
> foreach (@items) {
>   CASE: {
>     /not exist/ and do {
>       print Tr(td({colspan=>'5'}, "&nbsp;&nbsp;$_"));
>       last CASE;
>     };
>
>     my @item = split /\|/;
>     print Tr(td({-align=>'center', valign=>'center'}, $item[0]),
>              td({-align=>'left', valign=>'center'}, $item[5]),
>              td({-align=>'center', valign=>'center'},
>                 textfield(-maxLength=>'4', -name=>'quantity',
> -size=>'4',
>                           -value=>$item[-1])
>                ),
>              td({-align=>'right', valign=>'center'},
>                 [$item[6], sprintf('%.2f', $item[6] * $item[-1])]
>                )
>             );
>   }
> }
>
> print "<\TABLE>";
>
> print table(Tr(td(submit(-name=>'action', -value=>'Submit Changes')),
>                td(reset('Undo any changes since last load'))));
>
> print end_form, end_html;
>
> --
> Alan Young                                            Technical Support
> http://members.xoom.com/AlanYoung                 2021.Interactive, LLC
> If your happy and you know it, clunk your chains!   http://www.2021.com
>
> 865 I just walk right through the door...
>
>

-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/       Search, Read, Discuss, or Start Your Own    


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

Date: Tue, 09 Mar 1999 22:43:43 GMT
From: @l@ <aqumsieh@matrox.com>
Subject: Re: Limit string length
Message-Id: <7c486t$7qk$1@nnrp1.dejanews.com>

In article <xTKE2.5701$ZF1.11057@newsr2.twcny.rr.com>,
  "Dan Burke" <dbws@----nospam----hotmail.com> wrote:
> What is the best way to take a string and chop off the end of it, if it is
> over a certain length?

perldoc -f substr

--Ala

-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/       Search, Read, Discuss, or Start Your Own    


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

Date: Tue, 09 Mar 1999 22:35:50 GMT
From: jcasey@workingventures.ca (John Casey)
Subject: Missing CGI Environment Variables
Message-Id: <36e5a187.115824476@wv-proxy>

I just finished a Web Server course. During the course we looked a
Perl 5 script that returned the extra path information using the
PATH_INFO environment variable. We were using IIS40 for the course. 

I later tried using the same script with Omnicron HTTPd/Perl5.
PATH_INFO and HTTP_REFERER do not work, but others do. Almost all of
my path type information does not work. 

Could this be because I am on an intranet (I dunno), an Omnicron HTTPd
limitation (doubt it) or something I did wrong(more than likely)?

Server_Software, Server_Name, Gateway_Interface, Query_String all work
fine

The reason I am so interested in PATH_INFO/HTTP_REFERER is I want to
be able to set up several domain names that point to my server. When a
request comes in for one of the domains a Perl script on the server
root will look at the PATH_INFO determine what domain name was
requested and go to the index.html in the appropriate sub directory. I
know I can use IP and nonIP virtual servers but I don't want to mess
with extra Ips and/or DNS yet. In theory do you think this may work,
or am I just totally out to lunch..

John Casey
Applications Support Specialist
Working Ventures Canadian Fund Inc.




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

Date: 9 Mar 1999 22:23:55 GMT
From: eric@fruitcom.com (Eric Smith)
Subject: nntp posting with perl
Message-Id: <slrn7eb8nq.t3.eric@plum.fruitcom.com>

Hi all

Its real fun be able to slurp the contents out of an newsgroup fom the
commandline with perl and send it to a pager or filter or whatever.  How do
I achieve the reverse, i.e. to post to a newsgroup from the command line
with perl?

A nice little script for a dummy that writes code far too slowly to roll is
own would be great.

Thanx

-- 
Eric Smith
<eric@fruitcom.com>


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

Date: Tue, 09 Mar 1999 23:12:43 GMT
From: fxia@my-dejanews.com
Subject: Re: Perl and a Here document
Message-Id: <7c49t2$9f0$1@nnrp1.dejanews.com>



Programming Perl, page 43-44.

In article <7c40mb$ro$1@nnrp1.dejanews.com>,
  kstinson@hotmail.com wrote:
> How can I mimic the "here document" facility in the korn shell using perl?
> For Instance I have the following script that I would like duplicate in perl:
>
> #/bin/ksh
>
> DOC_tool <<!
> surf
> 3160
> q
> !
>
> This script is specific to an application on our RS6000. This script calls
> the DOC_tool command.  Then at the DOC_tool prompt it enters surf then at the
> next prompt it enters 3160 then there is output to the screen that I capture
> for processing.  Then it enters q to quit.  I use a perl program to process
> the output of this script.  I would like to just have perl do everything
> instead of relying on a script to always be there, etc.
>
> thanks,
> Kevin
>
> -----------== Posted via Deja News, The Discussion Network ==----------
> http://www.dejanews.com/       Search, Read, Discuss, or Start Your Own
>

-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/       Search, Read, Discuss, or Start Your Own    


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

Date: 9 Mar 1999 14:59:18 +0800
From: morpheus@no-spam.calweb.com (Steve Lamb)
Subject: Problems with Perl and tar
Message-Id: <slrn7eb9u4.be9.morpheus@teleute.rpglink.com>

    I've been working on a script that does some interesting things with tar
for backups.  One of the things we wanted to do was to have tar create a
file, export it to the console, pipe it to tee, then have the tee send it to
another tar to extract (mirroring the mount) as well as create a tar for
backup elsewhere.

    From the command line, it works fine.  Inside perl, however, the console
gets spew from tar at some point.  Here is the command:

system("/bin/sh -c 'tar cpsf - $files | tee /backup/$locmount.tar | tar xpvf
- -C /backup/local/$locmount > /backup/$locmount.cat'");

    We've tried it with exec, with and without the /bin/sh -c, backticks,
everything, and it still spews to the console.  Even tried redirecting
STDERR to no avail.  Does anyone have any clues as to how to get this to work?


-- 
             Steve C. Lamb             | Opinions expressed by me are not my
    http://www.calweb.com/~morpheus    | employer's.  They hired me for my
             ICQ: 5107343              | skills and labor, not my opinions!
---------------------------------------+-------------------------------------


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

Date: Tue, 9 Mar 1999 14:29:32 -0800
From: "Alvin Pollock" <apollock11@hotmail.com>
Subject: REGEXP: Problem matching string containing parens or brackets
Message-Id: <7c46iu$r15$1@agate.berkeley.edu>

I have been programming perl for many years and have never run
into this problem before (or I have but never noticed it, a VERY
frightening thought!). My script opens a file and attempts to match
strings which may contain regexp metacharacters. Strings containing
brackets or parentheses (and probably other metacharacters as well)
fail the match. I tried deleting just one of the brackets and compilation
failed with a message about unmatched [] in regexp. I've tried both
Unix and Windows and the program fails on both platforms. I've tried
to reproduce the problem in a very simple perl program for posting to
this newsgroup but I can't, the matches succeed and the little script
works as it should. What am I doing wrong.

Here is the text file for the working test scriptlet:

This line <word id="0">[contains</word> a lone left bracket
This line <word id="1"> [contains]</word> a pair of brackets
This line <word id="2">(contains a</word> lone right parenthesis
This line <word id="3"> text (contains) 6</word> both parentheses

Here is the test scriptlet itself (this works!):

#!/usr/local/bin/perl

undef $/;
$Line = <>;
&PrintIt ($Line);

sub PrintIt {
    my $line = shift;
    $line =~ s/<word\s+([^>]*)>/<string $1>/gi;
    $line =~ s/<\/word>/<\/string>/g;
    while ($line =~ /(<string[^>]*>[\w\W]*?<\/string>)/gi) {
        print "$1\n";
    }
}

This is the output:

<string id="0">[contains</string>
<string id="1"> [contains]</string>
<string id="2">(contains a</string>
<string id="3"> text (contains) 6</string>

Now my complete program is too large to post here but a sample
of the data file is here:

<c02>
<did>
<container type="box">6</container>
<container type="volume">40-46</container>
<unittitle><unitdate>(Sep. 1943-Jan. 1944).</unitdate></unittitle>
</did>
</c02>
<c02>
<did>
<container type="box">7</container>
<container type="volume">47- [54</container>
<unittitle><unitdate>(Jan. 1944-Mar. 1945).</unitdate></unittitle>
</did>
</c02>

$/ is set to "<c0" and each record is sent through a few different
subroutines. Here is the first part of the subroutine which fails.
The failure occurs in the "while" loop:

sub EncodeType6 {
    my $component = shift;
    my ($end, $cnum, $containerflag);
    if ($SeriesFlag) {
        $component =~ /^(\d)/ && ($CNum = $1);
    }
    $component =~ /^(\d)/ && ($cnum = $1);
    my $titlespan = &EditSpannames ($cnum, 3);
    $component =~ s/<did>/<drow>/i;
    if ($component =~ /<\/c0/i) {
        $component =~ s/\n?<\/c0/<\/dentry><\/drow><\/c0/i;
    } else {
        $component =~ s/\n?<c0/<\/dentry><\/drow>\n<c0/i;
    }
    $component =~ s/<\/did>//i;
    my $comp = $component;

#### program fails on the next line

    while ($component =~ /\n?(<container([^>]*)>[\w\W]*?<\/container>)/gi) {
        my $atts = $2;
        my $container = $1;
        my $rest = $';

      etc...

This is the error message generated:

/<container type="volume">47- [54</container>/: unmatched [] in regexp at
c:\perl\myprogs\mktable\mktable.pl line 642, <INFILE> chunk 9.

I've seen some talk of this in this newsgroup and at first thought it was
a problem on the windows version of perl but, as I said, I'm getting the
same
error on Unix.

Thanks for any help!

Alvin Pollock
apollock11@hotmail.com






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

Date: Tue, 9 Mar 1999 15:56:08 -0800
From: "Alvin Pollock" <apollock11@hotmail.com>
Subject: Re: REGEXP: Problem matching string containing parens or brackets
Message-Id: <7c4bl9$qq$1@agate.berkeley.edu>

I forgot to mention that I did try several techniques suggested
in different places, including first using the substitution
$line =~ s/(\W)/\\$1/g; but when I did this, although the
program ran to completion, the match failed in *every*
case, even for strings which did not contain these meta
characters.

Regardless of the solution I very much want to *understand*
this problem, especially why the small test scriptlet works
but my complete program does not.

Alvin Pollock
apollock11@hotmail.com




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

Date: Tue, 09 Mar 1999 07:29:20 -0800
From: David Corcoran <davidx.corcoran@intel.com>
Subject: TECO *is* obfuscation (was does perl discourage obfuscated code)
Message-Id: <36E53E50.9E5B93B4@intel.com>

> On 28 Feb 1999 00:01:11 -0800, Russ Allbery <rra@stanford.edu> wrote:
>
> + Actually, among all of the languages that I know, the one that takes the
> + prise for the most generally unreadable language (and it's not even
> + *close*) is FORTRAN,

Not by a long shot, the worst I've seen (actually used) is TECO:

 .uB 0j <:fshooey$louie$;> qBj

or how bout vi macros :-)



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

Date: Tue, 09 Mar 1999 23:42:54 GMT
From: vicuna@my-dejanews.com
Subject: while <> not work for empty files
Message-Id: <7c4blt$b0d$1@nnrp1.dejanews.com>

Wasted again,

Caper: add to top of file.
Hitch: File is empty.
Problem: Doesn't work

Stole from Perl Book of Cooking (but no llama recipes):

local $^I   = '.orig';
local @ARGV = glob("*.c");

while (<>) {
    if ($. == 1) {
        print "I am on top of file\n";
   }
  print;
} continue {close ARGV if eof}

but if file exist yet empty, no line numbers.  No line numbers, no line at top
of file.  Near as can groklet, while never whiles, yet I while away time
perlplexing.  For too long reasons must use above.  Empty file feels sad with
no topping.  Glimmerings?

V

-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/       Search, Read, Discuss, or Start Your Own    


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

Date: 12 Dec 98 21:33:47 GMT (Last modified)
From: Perl-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Special: Digest Administrivia (Last modified: 12 Dec 98)
Message-Id: <null>


Administrivia:

Well, after 6 months, here's the answer to the quiz: what do we do about
comp.lang.perl.moderated. Answer: nothing. 

]From: Russ Allbery <rra@stanford.edu>
]Date: 21 Sep 1998 19:53:43 -0700
]Subject: comp.lang.perl.moderated available via e-mail
]
]It is possible to subscribe to comp.lang.perl.moderated as a mailing list.
]To do so, send mail to majordomo@eyrie.org with "subscribe clpm" in the
]body.  Majordomo will then send you instructions on how to confirm your
]subscription.  This is provided as a general service for those people who
]cannot receive the newsgroup for whatever reason or who just prefer to
]receive messages via e-mail.

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.misc (and this Digest), send your
article to perl-users@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.

The Meta-FAQ, an article containing information about the FAQ, is
available by requesting "send perl-users meta-faq". The real FAQ, as it
appeared last in the newsgroup, can be retrieved with the request "send
perl-users FAQ". Due to their sizes, neither the Meta-FAQ nor the FAQ
are included in the digest.

The "mini-FAQ", which is an updated version of the Meta-FAQ, is
available by requesting "send perl-users mini-faq". It appears twice
weekly in the group, but is not distributed in the digest.

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 V8 Issue 5097
**************************************

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