[13115] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 525 Volume: 9

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sat Aug 14 14:07:29 1999

Date: Sat, 14 Aug 1999 11:05:07 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Sat, 14 Aug 1999     Volume: 9 Number: 525

Today's topics:
    Re: Error message: comma not allowed in filehandle line (Michael Fuhr)
        How to develope CGI scripts with ActivePerl for Windows <nati.m@t-online.de>
        How to view code as text in working cgi script <resource@ERASEjps.net>
    Re: Looking for a good Perl Book <cassell@mail.cor.epa.gov>
        New User Q: Shell script to Perl Equivalent <knewman@mcs.com>
    Re: New User Q: Shell script to Perl Equivalent <uri@sysarch.com>
        New User Q:Tricky multiline Join <knewman@mcs.com>
    Re: Perl/TK issues <eserte@cs.tu-berlin.de>
    Re: Sesssion ID (Ronald J Kimball)
    Re: Sesssion ID (Benjamin Franz)
    Re: Traversing of datastructure (Larry Rosler)
    Re: trim code <ghira@mistral.co.uk>
    Re: trim code <bwalton@rochester.rr.com>
        Weird DBI/DBD bug bradwolf@my-deja.com
        Digest Administrivia (Last modified: 1 Jul 99) (Perl-Users-Digest Admin)

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

Date: 14 Aug 1999 10:18:43 -0600
From: mfuhr@dimensional.com (Michael Fuhr)
Subject: Re: Error message: comma not allowed in filehandle line 15
Message-Id: <7p44t3$t5@flatland.dimensional.com>

neptune19@my-deja.com writes:

> I wrote a small Perl script and when run the following message appears:
> no comma allowed in filehandle in line 15
> The only line of code in my script that has a comma is this one:
> print header, start_html;
> which I believe is harmless
>
> Can anyone help?

It would be helpful if you had posted a small, complete example script
that reproduces the problem instead of just the one line.  From what
you posted, I'd guess you did this:

    use CGI;

where you meant this:

    use CGI qw(:standard);

If that's not the problem, please post the smallest possible script
that causes the error.

-- 
Michael Fuhr
http://www.fuhr.org/~mfuhr/


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

Date: Sat, 14 Aug 1999 19:39:29 +0200
From: "nati" <nati.m@t-online.de>
Subject: How to develope CGI scripts with ActivePerl for Windows?
Message-Id: <7p49fv$d4k$1@news02.btx.dtag.de>

Hi!

I appriciate help on simple question (or is it simple? :)

I want to write CGI scripts in Perl, so I have downloaded and installed
ActivePerl. Now I want to tryout scripts in Perl on my computer (mailing
lists and stuff). When I install them on server, they are working without
problems. But what do I have to do when I want that offline? Do I have to
simulate (and how) server on my computer, or ... Anyway, when somebody makes
webmastering and uses this, Paar of hints would be useful.

Dino




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

Date: Sat, 14 Aug 1999 10:32:23 -0700
From: Warren Bell <resource@ERASEjps.net>
Subject: How to view code as text in working cgi script
Message-Id: <37B5A827.5F8D74B7@ERASEjps.net>

How can I call a cgi program on the web to see it's code?  Is there a
way to do this? Any adjustments I can do to my browser?

Can you do this with Unix, I've got wget and lynx?


-- 
####### Remove ERASE to reply #######


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

Date: Sat, 14 Aug 1999 10:47:33 -0700
From: David Cassell <cassell@mail.cor.epa.gov>
Subject: Re: Looking for a good Perl Book
Message-Id: <37B5ABB5.F32A49DD@mail.cor.epa.gov>

Ala Qumsieh wrote:
[snip of Abigail]
> IMO, it's probably the size of the docs that scare people away. If you
> want to find more info on something, you have to figure out which pod
> it resides in. And that location is not necessarily obvious as your INIT
> example showed. Then you'll have to wade your way through the several
> screens of code to get to your target information.
> 
> I can see easily where this becomes a tiresome, and frustrating
> process. So how about creating even some more documetation ? :-)
> 
> Would it be a good solution if the docs were divided into 3 (or
> more/less) sections:
> 
> 1) docs for beginners where things are explained in easy terms with no
> assumptions regarding experience. Not everything has to be included
> there.

I thought this was already present.  Isn't it called the FAQ?
If the FAQ isn't explained well enough for a beginner, then we
need to fix it.  In the words of TomC, "Patches are welcome."

Perhaps a step-zero tutorial, or at least pointers to some
good step-zero tutorials, would be a welcome addition.  There's
already a good list of web tutorials at perl.com, although I
have seen a good one which isn't listed there.

[snip]
> Plus of course the FAQs. Everything should reside in different
> directories, to make life simpler. Also, maybe a sort of graphical
> perldoc might help. It shouldn't be too hard writing one in
> Perl/Tk. Or maybe something like that already exists.

See the perlman program from Advanced Perl Programming.  With
a few minor additions, it would be a rival to Tkman.  It does
use Tk.

Or maybe ActiveState could fix the scrolling problems with
some components of perldoc, so beginners in win32 could actually
use perldoc -q all the time...

> No. Uninstalling IE from windows is almost impossible (or made very
> hard for a purpose). And assembling a car is an almost impossible feat
> for me to accomplish as well.

Hey, if Ed Felten can do it, then surely you can to.  :-)

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


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

Date: Sat, 14 Aug 1999 03:15:08 -0500
From: Kevin Newman <knewman@mcs.com>
Subject: New User Q: Shell script to Perl Equivalent
Message-Id: <37B5258C.601CEA55@mcs.com>

Hi All,

What is the perl equivalent of the following shell statement

executable <<EOD
command1
command2
  .
  .
EOD


thanks,


kevin newman






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

Date: 14 Aug 1999 13:39:28 -0400
From: Uri Guttman <uri@sysarch.com>
Subject: Re: New User Q: Shell script to Perl Equivalent
Message-Id: <x7emh645yn.fsf@home.sysarch.com>

>>>>> "KN" == Kevin Newman <knewman@mcs.com> writes:

  KN> What is the perl equivalent of the following shell statement

  KN> executable <<EOD
  KN> command1
  KN> command2
  KN> EOD

just use system and here docs:

	system( <<EOD ) ;
command1
command2
EOD

uri

-- 
Uri Guttman  -----------------  SYStems ARCHitecture and Software Engineering
uri@sysarch.com  ---------------------------  Perl, Internet, UNIX Consulting
Have Perl, Will Travel  -----------------------------  http://www.sysarch.com
The Best Search Engine on the Net -------------  http://www.northernlight.com
"F**king Windows 98", said the general in South Park before shooting Bill.


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

Date: Sat, 14 Aug 1999 11:38:20 -0500
From: Kevin Newman <knewman@mcs.com>
Subject: New User Q:Tricky multiline Join
Message-Id: <37B59B7C.5486FE29@mcs.com>

Hi All,

How can I  join multilple lines with one line repeated?  This may be
better explained in an example.   The pattern is as follows:

123 string string string
Keyword  -> 162 string string string

124  string string string
  Keyword -> 163  string string string
<whitespace> 164  string string string
<whitespace> 165 string string string

The pattern I would like to end up with is

123 string string string  Keyword  -> 162 string string string

124  string string string Keyword -> 163  string string string
124  string string string Keyword -> 164  string string string
124  string string string Keyword ->  165  string string string


What I started off with is:

while ($line = <>) {
            if ($line =~ m/\+[0-9]+/) {
                 $line =~ s/\n//;
}
print $line;
}

This works okay for patterns of  the first type, but how can I modify
this the multiple line case?

Thanks,

kevin newman







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

Date: 14 Aug 1999 17:05:28 +0200
From: Slaven Rezic <eserte@cs.tu-berlin.de>
Subject: Re: Perl/TK issues
Message-Id: <87r9l62yiv.fsf@cabulja.herceg.de>

elflord@news.newsguy.com (Donovan Rebbechi) writes:

> 
> I am wondering if anyone has written a substantial ( say over 1000 lines ) 
> perl-Tk program. I am interested in seeing the code for some larger 
> perl-Tk programs ( because I'm wondering if perl-Tk is suitable 
> for sizeable programs -- but then I'd rather die than use Tcl ... )
> 
> I am currently coding something which is about 1000 lines at this 
> stage, and the naming conventions make it difficult to write 
> clean code ( eg in tcl, you have a naming scheme that reflects 
> the widget heirarchy, in perl you don't. )

IMHO this is no advantage. You have a lot of rewrite if you decide to
put an additional frame layer or move a widget subset to another
frame. It's also difficult to modularize a set of widgets. That's why
you often see the use of variables in widget names in tcl programs:

	set w .something
	toplevel $w
	label $w.l

> My reason for wanting to build the widget heirarchy into variables is
> because passing widgets to subroutines is very tedious otherwise,
> and you also run out of names for all those widgets (-; My current
> attempt at an answer has been to use anonymous hashrefs to build 
> a data structure mirroring the structure of a  widget tree. This 
> helps, but is still a tad cumbersome.

It's not necessary to assign every widget to a variable. You can
create and pack a widget in one statement. Mostly container widgets
(toplevel, frame) need to be assigned to a variable. And you can
always do:

	{
	   my $w = $top->Toplevel;
	   $w->Label->pack;
	   ...
	}

and use $w for other container widgets as well.

> 
> I am posting to ask if other people have written long perl-Tk 
> programs ( I'd be interested to see how others have handled this if 
> they have ) and also to seek advice about what to keep in mind 
> when building a (moderately) complex GUI with perl/Tk. I've looked 
> at all the ORA books that talk about perl-Tk (panther, 
> ram, learning perl/Tk ) but they tend to stick 
> with  very simple examples.
> 

If you want a really long perl/Tk program, look at
http://pub.cs.tu-berlin.de/src/BBBike/ for something like
BBBike-x.xx.tar.gz. It's over 30000 lines of code.

Regards,
	Slaven

-- 
use Tk;$c=tkinit->Canvas(-he,20)->grid;$x=5;map{s/\n//g;map{$c->create('line'=>
map{$a=-43+ord;($x+($a>>3)*2=>5+($a&7)*2)}split//)}split/!/;$x+=12}split/_/=>'K
PI1_+09IPK_K;-OA1_+K!;A__1;Q!7G_1+QK_3CLPI90,_+K!;A_+1!KQ!.N_K+1Q!.F_1+KN.Q__1+
KN._K+1Q!.F_1+KN.Q_+1Q__+1!KQ!.N_1;Q!7G_K3,09Q_+1!K.Q_K+1Q!.F_1+KN.Q_';MainLoop


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

Date: Sat, 14 Aug 1999 12:44:24 -0400
From: rjk@linguist.dartmouth.edu (Ronald J Kimball)
Subject: Re: Sesssion ID
Message-Id: <1dwj1t8.166n1uip4vgioN@p162.tc2.state.ma.tiac.com>

Benjamin Franz <snowhare@long-lake.nihongo.org> wrote:

> In article <37b56416@cs.colorado.edu>,
> Tom Christiansen  <tchrist@mox.perl.com> wrote:
> >:It looks to me like you improved it partly by cheating.  :)  Why is it that
> >:every function except yours takes four lines to get to gmtime(), including
> >:extra variables and a shift, while your function only uses one line, hmm?
> >
> >Good catch!
> 
> <sarcasm>
>  I will remember to complain next time I see benchmarks where the
>  benchmarker failed to rewrite submitted code fragments to optimize 
>  them better than the original submitter did.
> </sarcasm>

Hey, you don't have to if you don't want to.  If you're not interested
in fair Benchmarks, I bet you could find a great job in Benchmarking
Microsoft and Linux operating systems...  ;)

-- 
 _ / '  _      /       - aka -
( /)//)//)(//)/(   Ronald J Kimball      rjk@linguist.dartmouth.edu
    /                                http://www.tiac.net/users/chipmunk/
        "It's funny 'cause it's true ... and vice versa."


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

Date: Sat, 14 Aug 1999 18:04:37 GMT
From: snowhare@long-lake.nihongo.org (Benjamin Franz)
Subject: Re: Sesssion ID
Message-Id: <Vcit3.76$7e.9186@typhoon01.swbell.net>

In article <x7iu6i4awr.fsf@home.sysarch.com>,
Uri Guttman  <uri@sysarch.com> wrote:
>so the padding thread started here. and no one cared about the context
>after that. that is what sometimes happens with long threads. it became
>about padding vars and not about creating a cookie date.
>
>  BF> The purpose of the routine is to return a date for use in a
>  BF> Netscape cookie. As is obvious in the original code. Everyone else
>  BF> seems to have lost sight of that goal in favor of worrying about
>  BF> how to pad a list of numbers to 2 digits. Which *wasn't* the goal
>  BF> - merely a sub-task. Which is also why complaints about
>  BF> 'scalablity' etc are badly mis-placed. The routine doesn't need to
>  BF> scale to long lists of numbers. It will *never* need to.
>
>so why did you write benchmarks comapring a set of padding tricks to one
>that sprintf'ed the cookie?

Because y'all annoyed me by nitpicking at something that works
fine for what it is supposed to do. And by the way, the scalability
argument is *also* bogus even for list processing. See the benchmarks
below. My method is within 10% of the speed of the fastest proposed
alternative. It scales fine.

> is that fair either? you could have just
>stated that earlier or stopped defending your method. anyone would have
>agreed sprintf is the right solution for the date problem. you didn't
>even use it correctly in your original code so you learned something
>from this.

What learn? I've known about printf and variants since, oh, 1984. 
It doesn't mean it is always the best tool. Since you all seem so 
hot on padding lists, fine. Here is the benchmark reorganized to 
reflect list padding. Before someone tries to complain that
'uri1' is artificially slow since the list copy isn't necessary
for it to preserve the test data - the test data setup is factored
out of the normalized results by the 'empty' routine. Allowing 'uri1'
to 'skip' part of that setup would in fact give it an unfair
advantage since the 'empty' time would then not reflect the actual
setup time for 'uri1'. Notice that 'benjamin3' which uses an
'if' *combined* with the regex approach of 'uri2' is substantially
faster than 'uri2' alone is.

Benchmark: timing 1000 iterations of benjamin, benjamin2, benjamin3, 
           empty, fl_aggie, tomc, uri1, uri2...
  benjamin:  7 wallclock secs ( 7.02 usr +  0.00 sys =  7.02 CPU)
 benjamin2:  8 wallclock secs ( 6.96 usr +  0.01 sys =  6.97 CPU)
 benjamin3:  9 wallclock secs ( 8.41 usr +  0.00 sys =  8.41 CPU)
     empty:  0 wallclock secs ( 0.85 usr +  0.00 sys =  0.85 CPU)
  fl_aggie:  7 wallclock secs ( 6.42 usr +  0.00 sys =  6.42 CPU)
      tomc:  7 wallclock secs ( 6.48 usr +  0.00 sys =  6.48 CPU)
      uri1:  7 wallclock secs ( 7.14 usr +  0.00 sys =  7.14 CPU)
      uri2: 12 wallclock secs (11.84 usr +  0.00 sys = 11.84 CPU)

The normalized (with 'empty' subtracted) times are:

                            X factor
-------------------------------------               
 benjamin:  6.17 CPU         1.00
benjamin2:  6.11 CPU         0.99
benjamin3:  7.56 CPU         1.22
 fl_aggie:  5.57 CPU         0.90
     tomc:  5.63 CPU         0.91
     uri1:  6.29 CPU         1.01
     uri2: 10.99 CPU         1.78

#!/usr/bin/perl -w
use strict;
use Benchmark;
my $list = [map { int(rand(32)) } (0..1000)];

my $tick = time;
timethese(1000,{
       'benjamin' => sub { benjamin($list) },
      'benjamin2' => sub { benjamin2($list) },
      'benjamin3' => sub { benjamin3($list) },
          'empty' => sub { empty($list) },
       'fl_aggie' => sub { fl_aggie($list) },
           'tomc' => sub { tomc($list) },
           'uri1' => sub { uri1($list) },
           'uri2' => sub { uri2($list) },
    });

sub empty {
	my $list_ref = pop;
	my @list     = @$list;
}

sub benjamin {
	my $list_ref = pop;
	my @list     = @$list;
	for (@list) {
		$_ = "0$_" if (length($_) < 2);
	}			
}
sub benjamin2 {
	my $list_ref = pop;
	my @list     = @$list;
	for (@list) {
		$_ = "0$_" if (2 > length);
	}			
}
sub benjamin3 {
	my $list_ref = pop;
	my @list     = @$list;
	for (@list) {
		s/^/0/ if (2 > length);
	}			
}
sub fl_aggie {
	my $list_ref = pop;
	my @list     = @$list;
	foreach (@list) {
		$_ = sprintf('%02d',$_);
	}
}
sub tomc {
	my $list_ref = pop;
	my @list     = @$list;
	foreach my $value (@list) {
		$value = sprintf('%02d',$value);
    } 
}
sub uri1 {
	my $list_ref    = pop;
	my @list        = @$list;
    my @padded_list = map { sprintf("%02d", $_) } @$list;
}
sub uri2 {
	my $list_ref = pop;
	my @list     = @$list;
    s/^(\d)$/0$1/ for @list;
}


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

Date: Sat, 14 Aug 1999 09:02:05 -0700
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: Traversing of datastructure
Message-Id: <MPG.121f32d67f931030989e5b@nntp.hpl.hp.com>

In article <37B45C2F.4E1DF36B@cisco.REMOVETHIS.com> on Fri, 13 Aug 1999 
10:55:59 -0700, Makarand Kulkarni <makkulka@cisco.REMOVETHIS.com> 
says...
> > Hi, I have a datastructure which I want to traverse. Example:
> > 
> > $self->{os}             = 'solaris';
> > $self->{osVersion}      = '7';
> > $self->{nodeImportant}  = 5;
> > $self->{heartbeat}      = 300;
> > 
> > I want to traverse the '$self'-object and get a key and value pair as
> > if it were a traditional hash (I can not substitute it with a
> > traditional hash). Pseudo code and the wished for results:
> > 
> >   foreach $key (keys $self) {
> >       print "$key = $self->{$key}\n";
> >   }

The argument to 'keys' must be a hash, not a reference to a hash.  So 
use 'keys %$self'.

> Use each() like this -
>     while (($key,$value) = each %self) {
>         print "$key=$value\n";
>     }

The argument to 'each' must be a hash, but there is no hash named 
'%self'.  So use 'each %$self'.
 
-- 
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com


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

Date: 14 Aug 99 16:42:25 +0000
From: "Adam Atkinson" <ghira@mistral.co.uk>
Subject: Re: trim code
Message-Id: <318.895T1261T10023542ghira@mistral.co.uk>

On 14-Aug-99 15:31:45, Jimtaylor5 said:

>This works, but I'm trying to find a simpler way of matching and incrementing
>sales, hits, whatever, in each month, without all this embarassingly ugly
>code.

Use a hash.

-- 
Adam Atkinson (ghira@mistral.co.uk)



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

Date: Sat, 14 Aug 1999 12:28:18 -0400
From: Bob Walton <bwalton@rochester.rr.com>
Subject: Re: trim code
Message-Id: <37B59922.AD238B94@rochester.rr.com>

Jimtaylor5 wrote:

> Newbe question!
> This works, but I'm trying to find a simpler way of matching and incrementing
> sales, hits, whatever, in each month, without all this embarassingly ugly code.
> I've tried and failed. Does anyone know of a better way. The $mon_it variable
> being the current month, and the month variables holding the numbers. Help me
> or shoot me and put me out of my misery :)
>
>  foreach $month ($line1) {

Jim, it's not real clear what you are trying to do here.  Ordinarily, one would
have an array inside the parens above, and $month would be referenced to the
elements of the array one at a time.  Your code above is probably not what you
really want.

>
>   if ($mon_it =~ Jan) {

It is typical to use delimiters on patterns, like /Jan/, for example.  Leaving them
out does work in your case, but will stop working as soon as the patterns get a bit
more complicated.

>
>     $jan++;
>   }
>   elsif ($mon_it =~ Feb) {
>     $feb++;
>   }
>   elsif ($mon_it =~ Mar) {
>     $mar++;
>   }
>  ..etc.
>  }
>

I suggest something like:

@lines=('blahJanblah','blahMarblah');
for $line (@lines){
 $count{$1}++ if $line=~/(Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)/
}
for $month (sort keys %count){
 print "$month has $count{$month} hits\n";
}

This assumes that you have an array of lines coming in in array @lines, and that
each line might contain one occurrence of a month abbreviation anywhere in it.  The
for (or foreach, if you like extra typing) goes through the lines one at a time.
If the line in question has a month abbreviation in it, a hash element with a key
of the name of that month is incremented.  Later, the months that had occurrences
are printed out in alphabetical order along with the number of counts.  Hope this
helps.



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

Date: Sat, 14 Aug 1999 17:39:36 GMT
From: bradwolf@my-deja.com
Subject: Weird DBI/DBD bug
Message-Id: <7p49kn$uv2$1@nnrp1.deja.com>

Hi,

I'm running (at work):
RedHat Linux 6.0
Oracle 8.0.5
Perl 5.005_03
DBI 1.13
Oracle DBD 0.9 (or something)

I get this weird bug when trying to use the connect-> command.
If I specify the database to connect to, it doesn't work.

But if I set the ENV ORACLE_SID on the line before it, it does work.

I have the same stuff on RedHat Linux 5.1 and it works normally.

Has anyone encountered this? Does anyone know why it happens?

Any help would be appreciated.

Thanks,

bradwolf


Sent via Deja.com http://www.deja.com/
Share what you know. Learn what you don't.


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

Date: 1 Jul 99 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 1 Jul 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.  

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" from
almanac@ruby.oce.orst.edu. The real FAQ, as it appeared last in the
newsgroup, can be retrieved with the request "send perl-users FAQ" from
almanac@ruby.oce.orst.edu. 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" from
almanac@ruby.oce.orst.edu. 

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


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