[17153] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 4565 Volume: 9

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Oct 9 21:05:34 2000

Date: Mon, 9 Oct 2000 18:05:14 -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: <971139913-v9-i4565@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Mon, 9 Oct 2000     Volume: 9 Number: 4565

Today's topics:
    Re: "each %hash" evaluated in scalar context? (Mark-Jason Dominus)
    Re: 2 questions iamnotananimal@my-deja.com
    Re: Checking for existence of file <bwalton@rochester.rr.com>
    Re: cookbook: nonforker - why so complex? <uri@sysarch.com>
    Re: creating a variable whose name is defined at runtim (Mark-Jason Dominus)
    Re: Critique/Comments: daemon() <cliff@rayman.com>
    Re: Critique/Comments: daemon() (Mark-Jason Dominus)
    Re: error in mapping array slice (Martien Verbruggen)
        How can I add 5 hours to the time my server reports? <ben.graves@virgin.net>
    Re: How can I add 5 hours to the time my server reports (Martien Verbruggen)
    Re: how to remove unprintable  chars with Perl script <krahnj@acm.org>
    Re: IRC::Net stuff... (Clinton A. Pierce)
    Re: Newbie -> ini file to hash table? <edmond.nolan@debitel.net>
    Re: Perl utilizing DBI - Would love assistance! <etienno@sympatico.ca>
    Re: re-start problem <peter.sundstrom@eds.com>
        reading into vars cputek1@my-deja.com
    Re: reading into vars (Clay Irving)
        silly UNIX question cchristophe@my-deja.com
    Re: silly UNIX question <harrisr@bignet.net>
    Re: silly UNIX question <Mike@Shehan.org>
        Stumped <zach@pagm.com>
    Re: Stumped (Clay Irving)
    Re: the fastest way to test String A included by String (Martien Verbruggen)
    Re: UltraNewbie: grepping weblog (Chris Fedde)
    Re: UltraNewbie: grepping weblog <jamesN0@5PAM.young.net>
    Re: Writing to log files (Mark-Jason Dominus)
        Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)

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

Date: Mon, 09 Oct 2000 23:34:15 GMT
From: mjd@plover.com (Mark-Jason Dominus)
Subject: Re: "each %hash" evaluated in scalar context?
Message-Id: <39e255f7.55f5$5c@news.op.net>
Keywords: Dreyfuss, Ecole, mummy, pituitary

In article <8rt5cn$ev3$1@nnrp1.deja.com>,  <cogswheel@my-deja.com> wrote:
>    while ($k = each %$href) {
>
>I've come to expect a list evaluated in scalar context to return
>the _last_ element of the list.  

#1. There is no such thing as a list evaluated in scalar context.

#2. In scalar context, each() does not produce a list.  (See #1.)
    It produces a key from the hash.

#3. As the manual says:

       Remember the following important rule: There is no rule
       that relates the behavior of an expression in list context
       to its behavior in scalar context, or vice versa.  It
       might do two totally different things.  

#4. You already know this.  Consider:

    ($sec, $min, $hour, $day, $mon, $year, $wday, $yday, $isdst) = localtime();

In scalar context, does localtime() return a flag saying whether or
not it is daylight savings time?  No, it does not.  It returns a
string like "Mon Oct  9 19:28:55 2000".

Also consider:

    ($name,$passwd,$uid,$gid,etc. etc. etc.) = getpwnam;

What does getpwnam() return in scalar context?  It returns the uid.

Also consider:

    ($sec, $min, $hour) = ("02:38:36" =~ /(\d+):(\d+):(\d+)/);
    
What does the =~ do in scalar context?  It returns the value 1, to
indicate a successful match.  It also sets the values of $1, $2, and
$3.  It does not return 36.

Also consider:

    @items = reverse 1, 2, 3, 4;

In scalar context, reverse does not return 4.  It returns "4321".

You can probably invent your own examples.  To invent your own
example, either pick a function at random from perlfunc and try it
out, or follow this pattern:

        sub example {   
          return wantarray ? ('fish', 'dog', 'carrot') : 119;
        }

>Is 'each' written to detect which context it's been called in, and
>return the key (because that's what one would ususally want)?  

Yes, that is exactly so.  Most Perl functions are written similarly.

>Or am I just missing something?

No, you're right on target.

Remember, the rule is: There is no rule.



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

Date: Tue, 10 Oct 2000 00:44:07 GMT
From: iamnotananimal@my-deja.com
Subject: Re: 2 questions
Message-Id: <8rtoom$ve0$1@nnrp1.deja.com>

In article <slrn8u4atg.gi9.clay@panix6.panix.com>,
  clay@panix.com (Clay Irving) wrote:
> On Mon, 09 Oct 2000 18:00:31 GMT, iamnotananimal@my-deja.com
> <iamnotananimal@my-deja.com> wrote:
>
> >The following is an extract from a script labeled out.pl - It
displays
> >all images from "pic.list" to a browser when run from cgi-bin. (all
> >images output together at once)
> >Q. Is there a command I can use to clear the screen before loading
the
> >images as sequential items; giving a slide-show in effect. The
commented
> >lines are just thoughts along this line.
>
> That's not a Perl-related question.
>
I thought print "Content-type: text/html\n\n"; was specific perl
notation used to display output to browser from a perl script.
I was after notation used to clear the screen that is specific to perl.
I take it there is none.

> >$INPUT_FILE = "/root/apache/Pics/pic.list";
> >open (INPUT_FILE);
> >@array = <INPUT_FILE>;
> >close (INPUT_FILE);
> >print "Content-type: text/html\n\n";
> >foreach (@array) {
> >print "<IMG SRC=http://localhost/cgi-bin/out.pl/$_>\n";
> >#print "content-clear: text/html" #this is not a real command
> >#sleep 3 #a pause between slides
> >  }
> >
> >2./ I read here in an earlier post a script to strip out all lines
from
> >a log-file containing a certain string of characters begining the
line
> >and rewrite the log-file. Could some kind soul re-post that example
as
> >I'm having no luck recreating it myself.
> >I would like to remove all the local machine server accesses lines
from
> >my logfile before processing with analog.
>
> Something like this?
>
>   #!/usr/local/bin/perl -w
>
>   $string_to_replace = "I want to replace this string ";
>   $input_string = "I want to replace this string at the beginning of
the line";
>   ($output_string = $input_string) =~ s/^$string_to_replace//;
>
>   print "$input_string\n";
>   print "$output_string\n";
>
> Result:
>
>   I want to replace this string at the beginning of the line
>   at the beginning of the line
>
I want to have the whole line removed (ignored) altogether based on
whether the line begins with "some string" - not just an applied string
translation. The method described requires that one knows beforehand
what the rest of the line will be - where it is not.

thanks for trying,
ianna


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


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

Date: Tue, 10 Oct 2000 00:59:09 GMT
From: Bob Walton <bwalton@rochester.rr.com>
Subject: Re: Checking for existence of file
Message-Id: <39E26AB9.45BAA53F@rochester.rr.com>

Geoff Soper wrote:
> 
> In article <7f1E5.294$lw3.32114@eagle.america.net>,
>    Garry Williams <garry@ifr.zvolve.net> wrote:
 ...
> > But another poster already pointed out the race condition that this
> 
> What is a 'race condition'?
A race condition is a set of events that can happen in a multi-tasking
operating system in which a non-atomistic series of events in one
process can be interrupted by an event in another process which
adversely affects the operation of the first process.  For example (the
one you gave), one could test for the existence of a file, then the
execution of your program could be suspended and program B starts
executing, writes to the file your program just tested to be
non-existent, and then your program resumes execution, opening the file
for writing and clobbering the file program B just wrote.  Most
frequently this of significant concern only when dealing with a program
or set of programs that responds to external events over which the user
has little or no control, such as web page CGI scripts.  Improper
protection against race conditions in such scenarios will generate the
"one in a million" data wipeouts that are totally baffling when viewed
from the vantage point of one program executing a series of steps.  In
such scenarios, file operations must be made atomistic (that is, they
must run to completion without interruption).  This is accomplished
through a process called locking.  See:

    perldoc -q lock

 ...
> Geoff Soper
> g.soper@soundhouse.co.uk
> Take a look at the Soundhouse page http://www.soundhouse.co.uk/
-- 
Bob Walton


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

Date: Mon, 09 Oct 2000 22:13:12 GMT
From: Uri Guttman <uri@sysarch.com>
Subject: Re: cookbook: nonforker - why so complex?
Message-Id: <x7bswt3bpj.fsf@home.sysarch.com>

>>>>> "MK" == Mark Knutsen <knutsenm@my-deja.com> writes:

  MK> I'm trying to understand the code for a multiplexing server without
  MK> forking, section 17.13 (p.628) of the Cookbook. It seems a bit overly
  MK> complicated to me in the sense that it moves complete client requests
  MK> from an input buffer to a separate hash:

  MK> Why not just handle($1) immediately above, and avoid the use of %ready
  MK> and Tie::RefHash completely? It can't be a timing issue; this is just
  MK> one big while() loop.

looks like a style and a design choice. there are many way to build
non-forking servers and this one likes to keep the reading and writing
loops separated. if you merged them it would be much trickier code as
you would have to overlap can_read and can_write requests. why don't you
try to hack it that way and see if you think the code looks better or is
easier to maintain. i doubt that you will succeed without mucho work.

uri

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


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

Date: Mon, 09 Oct 2000 20:42:00 GMT
From: mjd@plover.com (Mark-Jason Dominus)
Subject: Re: creating a variable whose name is defined at runtime?!?
Message-Id: <39e252e8.55bc$244@news.op.net>
Keywords: Lumpur, WV, gin, pamper

In article <3YnE5.35$7J6.170977792@news.frii.net>,
Chris Fedde <cfedde@u.i.sl3d.com> wrote:
>Perl makes it possible to create variables at run time. Here is
>one approach to doing that:
>
>    #!/usr/bin/perl -l
>    $var = 'test';
>    eval "\$$var = 37";
>    print "\$test = $test";

Aaack.  That is the only way to make the problems of dynamic variable
names even bigger than they already are.  If you really need to use
dynamic variable names (and you almost never do) then

        $$var = 37;

is perfectly sufficient.  It has the added benefit of *not* erasing
all your files when $var happens to contain "1; system('rm -rf /'); \$x"
(Your code *will* erase all the files.)

A while back there was a thread about 'top ten common Perl mistakes'
and I was tempted mention "overuse of 'eval'", but I didn't.  This is
a perfect example of that mistake.


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

Date: Mon, 09 Oct 2000 22:47:53 GMT
From: ___cliff rayman___ <cliff@rayman.com>
Subject: Re: Critique/Comments: daemon()
Message-Id: <39E249FA.D8CD2C4A@rayman.com>


>      for (; $paddr = accept(CLIENT,SERVER); close Client) {
not sure why you'd want to use a for loop this way. also, have you tested
this code with a strict pragma?  i don't see Client used anywhere else,
shouldn't this be CLIENT?
>          RXLOOP:
a label with goto's is ugly here IMHO.  a while loop with next statements
would be prettier and easier to follow.
>          /^DICT-QUERY/  && do
>           /^(DICT-QUERY:)([\w]+)/;
>           my $dump=Dumper($dict->{$2}); $dump=~s/\$VAR1 = / /g;
unless i am missing something, very possible, why not
if(/^DICT-QUERY: (\w+)/){
   my $dump=Dumper($dict->{$1}); $dump=~s/\$VAR1 = / /g;

-- 
_____cliff_rayman_____cliff_@_rayman_._com_____


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

Date: Mon, 09 Oct 2000 21:09:49 GMT
From: mjd@plover.com (Mark-Jason Dominus)
Subject: Re: Critique/Comments: daemon()
Message-Id: <39e2596d.565f$4a@news.op.net>
Keywords: Adelia, arachnid, hafnium, walkie


In article <39E249FA.D8CD2C4A@rayman.com>,
___cliff rayman___  <cliff@rayman.com> wrote:
>
>>      for (; $paddr = accept(CLIENT,SERVER); close Client) {
>not sure why you'd want to use a for loop this way. also, have you tested
>this code with a strict pragma?  i don't see Client used anywhere else,
>shouldn't this be CLIENT?

Yeah, the reason that the original poster didn't notice this is
because the second accept call automatically closes the socket that
was opened by the first call, and soforth.


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

Date: Mon, 09 Oct 2000 22:06:49 GMT
From: mgjv@tradingpost.com.au (Martien Verbruggen)
Subject: Re: error in mapping array slice
Message-Id: <slrn8u4gbf.2ce.mgjv@verbruggen.comdyn.com.au>

On Mon, 09 Oct 2000 04:06:15 -0700,
	John W. Krahn <krahnj@acm.org> wrote:
> Tk Soh wrote:
> > 
> > Ren Maddox wrote:
> > >
> > > If so, then this should do it (though I certainly don't promise that
> > > it is the *best* way):
> > >
> > > @this_array = ((undef) x 10, @that_array)[-10 .. -1];
> > 
> > Guess I just found the asnwer:
> > 
> > @this_array = map {defined $_? $_ : ''}
> >                   ((undef) x 10, @that_array)[-10 .. -1];
> > 
> 
> Why not just:
> @this_array = (('') x 10, @that_array)[-10 .. -1];

I was going to say that too, but it may be possible that he also wants
to change undef values in the original data. 

Martien
-- 
Martien Verbruggen              | 
Interactive Media Division      | Little girls, like butterflies, need
Commercial Dynamics Pty. Ltd.   | no excuse - Lazarus Long
NSW, Australia                  | 


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

Date: Mon, 9 Oct 2000 23:31:55 +0100
From: "Ben Graves" <ben.graves@virgin.net>
Subject: How can I add 5 hours to the time my server reports?
Message-Id: <xHrE5.25409$L12.529956@news2-win.server.ntlworld.com>

My server reports a time exactly 5 hours behind GMT.

How do I add five hours to the time it reports in a way that also changes
the date?

The script I use is;
$sydate = localtime(time);
($day, $month, $num, $time, $year) = split(/\s+/,$sydate);
print "Content-type: text/html\n\n";
print "$day $month $num $time $year\n";

and it returns;
Mon Oct 9 17:29:56 2000

I would like it to display the date in the following format;
Mon 5th September, 2000




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

Date: Mon, 09 Oct 2000 23:45:21 GMT
From: mgjv@tradingpost.com.au (Martien Verbruggen)
Subject: Re: How can I add 5 hours to the time my server reports?
Message-Id: <slrn8u4m47.2ce.mgjv@verbruggen.comdyn.com.au>

On Mon, 9 Oct 2000 23:31:55 +0100,
	Ben Graves <ben.graves@virgin.net> wrote:
> My server reports a time exactly 5 hours behind GMT.
> 
> How do I add five hours to the time it reports in a way that also changes
> the date?

That also changes the date? I'm not sure what you are asking. Are you
asking to display dates in GMT or UTC?

# perldoc -f gmtime

> The script I use is;
> $sydate = localtime(time);
> ($day, $month, $num, $time, $year) = split(/\s+/,$sydate);
> print "Content-type: text/html\n\n";
> print "$day $month $num $time $year\n";

Why do you use localtime in scalar context, and then split the result?
Do you know what localtime returns in a list context?

# perldoc -f localtime.

I think you should read some documentation. You do know about the
documentation, right? perldoc will get you there. If you've got
ActiveState's version of Perl, you get a bundle of HTM files with said
documentation.

> and it returns;
> Mon Oct 9 17:29:56 2000
> 
> I would like it to display the date in the following format;
> Mon 5th September, 2000

It's possibly easies to use the strftime function from the POSIX
package for this (it's actually documented in the gmtime and localtime
entires of perlfunc):

use POSIX qw(strftime);
my $now = strftime "%a %e %B, %Y", gmtime;

If you really want 5th, you'll have to write something yourself.
Again, see the gmtime and localtime documentation.

Martien
-- 
Martien Verbruggen              | 
Interactive Media Division      | The world is complex; sendmail.cf
Commercial Dynamics Pty. Ltd.   | reflects this.
NSW, Australia                  | 


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

Date: Mon, 09 Oct 2000 16:09:43 -0700
From: "John W. Krahn" <krahnj@acm.org>
Subject: Re: how to remove unprintable  chars with Perl script
Message-Id: <39E25037.EEDA60FB@acm.org>

This should work:

s/[:^print:]//g;

HTH

John


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

Date: Mon, 09 Oct 2000 23:14:18 GMT
From: clintp@geeksalad.org (Clinton A. Pierce)
Subject: Re: IRC::Net stuff...
Message-Id: <ejsE5.32815$hD4.7855051@news1.rdc1.mi.home.com>

[Posted and mailed]

In article <39E1FCD0.B8CB0BF4@camelot.de>,
	Blackmail <blackmail@camelot.de> writes:
> I'd like to implement a bot on a IRC channel. Since I'm not so good in
> Perl, I'd like to know how to make the bot "speak" to the public in a
> channel.
> I've already made it connect to the server, join a channel, but it can't
> speak...

Look at the irctest script that came with the Net::IRC module.
It implements both public and private speaking (well, they're really the 
same...).


-- 
    Clinton A. Pierce              Teach Yourself Perl in 24 Hours! 
  clintp@geeksalad.org         for details see http://www.geeksalad.org
"If you rush a Miracle Man, 
	you get rotten Miracles." --Miracle Max, The Princess Bride


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

Date: Tue, 10 Oct 2000 00:11:45 +0200
From: Edmond Nolan <edmond.nolan@debitel.net>
Subject: Re: Newbie -> ini file to hash table?
Message-Id: <39E242A1.54422D65@debitel.net>

OK, still don't get it, maybe it's perlthink or doublethink or
something,
anyway, thanks to all for the replies

Eddie

Gwyn Judd wrote:

> I was shocked! How could Edmond Nolan <edmond.nolan@debitel.net>
> say such a terrible thing:
> >Hi Gwyn,
> >
> >thanks for the reply, that's exactly what I was looking for!
>
> You're welcome
>
> --
> Gwyn Judd (print `echo 'tjla@guvfybir.qlaqaf.bet' | rot13`)
> "May the forces of evil become confused on the way to your house."
> -- George Carlin



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

Date: Mon, 09 Oct 2000 22:48:45 GMT
From: Etienne Laverdiere <etienno@sympatico.ca>
Subject: Re: Perl utilizing DBI - Would love assistance!
Message-Id: <39E24C42.16C54CDA@sympatico.ca>

Adam of RWS wrote:

> I'm an experienced programmer relatively new to CGI.  I have written a script in
> Perl.  The syntax of the script checks out.  I can't even get warnings from
> the -w switch.
> When I run the script at the command line a bunch of pretty looking HTML dumps
> out including a proper header.  The suggestions I've gotten from friends,
> coworkers, and books (Yes, I stooped that low) have led me to try the following:
>
> 1) check the header.
>     The header is immaculate.
>
> 2) flush STDOUT before doing anything else ($| = 1)
>     No result.
>
> 3) Redirect STDERR to see if I get any error messages.
>     I didn't expect this to work since I got no errors from the command line.
>     I was right, it didn't give me any errors.
>
> 4) check the server error log.
> What I got was a bunch of lines that say:
> /*my IP*/ - [/*date and time*/] "GET /*my URL*/ HTTP/1.1" 500 546
>
> I can't find any info on what the 546 means, and I can't imagine where else to
> go from here.
>
> Also, the script is in a directory that has other CGI files doing similar
> actions but aren't using the Perl DBI Module.  This script has the same rights
> as the other scripts, so I can't imagine why it won't run.
> I know the DBI Module is working because I don't get an error from the script
> that the DBI Module is not found. Not even when I run it from the command line.
>
> Any help would be massively appreciated!!!
>
> ---Adam
>
> ___
>   Adam Sroka
>   Real World Solutions, Inc.
>   http://www.RealWorldSolutions.net
>   mailto:Adam@RealWorldSolutions.net

Hi, could you post (me) some of you Perl code -- mostly your 20 first lines?
Impementing to DBI and CGI should be very easy in a *.pl page.

Regards,

Etienne



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

Date: Tue, 10 Oct 2000 11:19:28 +1300
From: "Peter Sundstrom" <peter.sundstrom@eds.com>
Subject: Re: re-start problem
Message-Id: <8rtgh2$76m$1@hermes.nz.eds.com>


Gwyn Judd <tjla@guvfybir.qlaqaf.bet> wrote in message
news:slrn8u4938.4h0.tjla@thislove.dyndns.org...
> I was shocked! How could theomats <ejw@windsor.igs.net>
> say such a terrible thing:
> >Hi,
> >Can someone volunteer to answer why my site "Bishops, A Chess Variant"
needs
> >to  be re-started quite often. My ISP has done all they can and the
original
> >programmer also has done what is needed to get the program (applet)
running.
> >The command I have been told to use is : perl5 bishops.cgi &
>
> You have a bug in line 17

The general rule of thumb for identifying errors in non specified code is to
check any line number that is prime ;-)




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

Date: Tue, 10 Oct 2000 00:25:31 GMT
From: cputek1@my-deja.com
Subject: reading into vars
Message-Id: <8rtnll$uhr$1@nnrp1.deja.com>

I have a temp file that I am using to store some data.
I need to be able to read that data and place it into multiple vars for
use in a different perl script. the temp file will only have three
lines.  I need to store each line into a separate var.
I tried the read command but it grabs all the lines...(don't think I'm
doing it right)

The problem is that the data is not a fixed length.  each line of data
can be as long as the user wants.

thanks for any help...
-cmf



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


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

Date: 10 Oct 2000 00:55:20 GMT
From: clay@panix.com (Clay Irving)
Subject: Re: reading into vars
Message-Id: <slrn8u4q7o.auv.clay@panix3.panix.com>

On Tue, 10 Oct 2000 00:25:31 GMT, cputek1@my-deja.com 
<cputek1@my-deja.com> wrote:

>I have a temp file that I am using to store some data.
>I need to be able to read that data and place it into multiple vars for
>use in a different perl script. the temp file will only have three
>lines.  I need to store each line into a separate var.
>I tried the read command but it grabs all the lines...(don't think I'm
>doing it right)
>
>The problem is that the data is not a fixed length.  each line of data
>can be as long as the user wants.

Open your temp file:

  open TMP, "temp_file" or die "Can't open temp_file: $!\n";

Process each record (by default the records will be separated by newlines):

  while ($record = <TMP>) {

Process the line (I assume fields in the records are delimited by something?):
      
      print "I'm doing my stuff to $record...\n";

You're finished.

  }

Be nice. Close your filehandle:

  close TMP; 

-- 
Clay Irving <clay@panix.com>
Worlds may freeze and suns may perish, but there stirs something within us
now that can never die again. 
- H. G.  Wells 


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

Date: Mon, 09 Oct 2000 22:14:39 GMT
From: cchristophe@my-deja.com
Subject: silly UNIX question
Message-Id: <8rtg09$o78$1@nnrp1.deja.com>

Hu guys,

when I make a little script executable and run it, it does not work.
I have to type;
perl 'script name'

looks like my path variable is ok. And anyway why would it work by
typing:
perl 'script name'

hope the question is not too stupid...

Christophe


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


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

Date: Mon, 9 Oct 2000 19:42:43 -0400
From: "Randy Harris" <harrisr@bignet.net>
Subject: Re: silly UNIX question
Message-Id: <su4lufmqdnmkb8@corp.supernews.com>


<cchristophe@my-deja.com> wrote in message
news:8rtg09$o78$1@nnrp1.deja.com...
> Hu guys,
>
> when I make a little script executable and run it, it does not work.
> I have to type;
> perl 'script name'

Make the first line of your script:
#!/usr/bin/perl -w

(Or wherever the perl executable is located)
This way Unix will know to execute the script as perl.
By default, it will attempt to execute it using your default shell,
which likely won't work for Perl.

HTH
Randy Harris

>
> looks like my path variable is ok. And anyway why would it work by
> typing:
> perl 'script name'
>
> hope the question is not too stupid...
>
> Christophe
>
>
> Sent via Deja.com http://www.deja.com/
> Before you buy.




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

Date: Mon, 09 Oct 2000 20:29:07 -0400
From: Michael Shehan <Mike@Shehan.org>
Subject: Re: silly UNIX question
Message-Id: <39E262D3.C5CF9B22@Shehan.org>


--------------4BF3DCB679C4EAA22D957C7F
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit

More than likely the problem is with your Unix path.  Not the
#!/usr/bin/perl, but the unix path in which the script resides.  When
you are in the directory that the script is in try typing this.

 ./scriptname

The ./ will have it try to run the executable that is located in the
current directory.  If you have know this and have tried it I
appologize.  I have seen people have this problem however.  If this
works for you then you know you will need to add this directory to your
path in your ".profile" file in your home directory.

You can also verify the location of the perl executable by typing "which
perl" on the unix command line.  This is the path the needs to be on the
first line of the perl script after the !#.  Good luck.

                                Mike......

cchristophe@my-deja.com wrote:

> Hu guys,
>
> when I make a little script executable and run it, it does not work.
> I have to type;
> perl 'script name'
>
> looks like my path variable is ok. And anyway why would it work by
> typing:
> perl 'script name'
>
> hope the question is not too stupid...
>
> Christophe
>
> Sent via Deja.com http://www.deja.com/
> Before you buy.

--------------4BF3DCB679C4EAA22D957C7F
Content-Type: text/html; charset=us-ascii
Content-Transfer-Encoding: 7bit

<!doctype html public "-//w3c//dtd html 4.0 transitional//en">
<html>
More than likely the problem is with your Unix path.&nbsp; Not the #!/usr/bin/perl,
but the unix path in which the script resides.&nbsp; When you are in the
directory that the script is in try typing this.
<p><b>./</b><i>scriptname</i><i></i>
<p>The ./ will have it try to run the executable that is located in the
current directory.&nbsp; If you have know this and have tried it I appologize.&nbsp;
I have seen people have this problem however.&nbsp; If this works for you
then you know you will need to add this directory to your path in your
".profile" file in your home directory.
<p>You can also verify the location of the perl executable by typing "which
perl" on the unix command line.&nbsp; This is the path the needs to be
on the first line of the perl script after the !#.&nbsp; Good luck.
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
Mike......
<p>cchristophe@my-deja.com wrote:
<blockquote TYPE=CITE>Hu guys,
<p>when I make a little script executable and run it, it does not work.
<br>I have to type;
<br>perl 'script name'
<p>looks like my path variable is ok. And anyway why would it work by
<br>typing:
<br>perl 'script name'
<p>hope the question is not too stupid...
<p>Christophe
<p>Sent via Deja.com <a href="http://www.deja.com/">http://www.deja.com/</a>
<br>Before you buy.</blockquote>
</html>

--------------4BF3DCB679C4EAA22D957C7F--



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

Date: Mon, 9 Oct 2000 16:14:23 -0700
From: "Zach Brown" <zach@pagm.com>
Subject: Stumped
Message-Id: <su4k8lbsebko26@news.supernews.com>

I am working with a group of developers on a fairly large product,  most of
the project is written in C++ including a very specialized com object, I now
have the task of incorporating the website into the product and, for
security reasons, I need the web page to use the com object, now some of it
can be done using vbscript / javascript in either asp pages or client side
processing but there are two instances so far where I need to access the com
object from a cgi script but I can't seem to find any information on how to
do that.  I am tottaly stumped so any help would be greatly appreciated.




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

Date: 9 Oct 2000 23:51:25 GMT
From: clay@panix.com (Clay Irving)
Subject: Re: Stumped
Message-Id: <slrn8u4mft.6dh.clay@panix3.panix.com>

On Mon, 9 Oct 2000 16:14:23 -0700, Zach Brown <zach@pagm.com> wrote:

>I am working with a group of developers on a fairly large product,  most of
>the project is written in C++ including a very specialized com object, I now
>have the task of incorporating the website into the product and, for
>security reasons, I need the web page to use the com object, now some of it
>can be done using vbscript / javascript in either asp pages or client side
>processing but there are two instances so far where I need to access the com
>object from a cgi script but I can't seem to find any information on how to
>do that.  I am tottaly stumped so any help would be greatly appreciated.

I'm also stumped -- Is there a question about Perl somewhere in your message?

-- 
Clay Irving <clay@panix.com>
365.25 days of drinking low-calorie beer because it's less
filling:  1 lite year


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

Date: Mon, 09 Oct 2000 23:28:34 GMT
From: mgjv@tradingpost.com.au (Martien Verbruggen)
Subject: Re: the fastest way to test String A included by String B
Message-Id: <slrn8u4l4n.2ce.mgjv@verbruggen.comdyn.com.au>

On Mon, 9 Oct 2000 20:22:58 +0100,
	Makhno <mak@imakhno.freeserve.co.uk> wrote:
> >@A = ("apple", "banana", "cherry", "cocount", "pear", "peach", "mango");
> >@B = ("cherry", "banana", "pear");
> 
> This might do what you're after, if I understand you correctly.

I don't think you do :)

> sub A_in_B
> {
> my %hash;
> foreach (@A){$hash{$_}=0}

A faster way to do this is by using hash slices:
@hash{@A} = (0) x @A;

But if you're not interested in the values, 

@hash{@A} = ();

will do just as well.

> foreach (@B){$hash{$_}=0}

same here; But since it's the same hash:

$hash{$_} = 0 for (@B);

is slightly more readable.

You could have done it in one go with:

@hash{@A, @B} = ();

> my @c=%hash;

@c now alternately has keys and values of the hash you just created.

> return @c!=scalar(@A)+scalar(@B);
> }

That condition will return true every time that @A and @B are not the
same. That was _not_ the problem stated. Try

@A = qw(foo);
@B = qw(bar);

You'll end up with 

4 != 1 + 1

meaning that your sub will incorrectly return true. 

@A = qw(foo);
@B = qw(foo);

will incorrectly return false; An array that is identical is also a
subset.

@A = qw(foo bar);
@B = qw(foo);

will correctly return true, but that's a coincidence.

What you are, as said, testing for is that the two arrays are not
identical. And that's it. And that can be more efficiently done by
using the example in the FAQ:

# perldoc perlfaq4
[snip]
       How do I test whether two arrays or hashes are equal?
[snip]

Martien
-- 
Martien Verbruggen              | 
Interactive Media Division      | Failure is not an option. It comes
Commercial Dynamics Pty. Ltd.   | bundled with your Microsoft product.
NSW, Australia                  | 


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

Date: Mon, 09 Oct 2000 22:06:47 GMT
From: cfedde@u.i.sl3d.com (Chris Fedde)
Subject: Re: UltraNewbie: grepping weblog
Message-Id: <XjrE5.42$7J6.170565632@news.frii.net>

In article <8rt9j5$klr$1@news.panix.com>,
James Young  <jamesN0@5PAM.young.net> wrote:
>Hi guys - Still in the early stages of learning perl.  I'm trying to write a
>script to do the following:  
>
>Can anyone help give me a jump start?
>Thanks! --Jim
>===========================================
>#! /usr/bin/perl -w
>
>@langs = ('EN', 'SP', 'FR', 'TU', 'PR');
>
>@cats = (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12);
>

Let me apologize for the way I've rather liberaly edited your posting.  
The report you are looking for might look like:

	cat	lang	count
	---------------------
	1	EN	1234
	1	SP	4657
	...
	2	EN	7654
	...
	12	PR      1234

A data structure to represent this would be an array of hashes (eg.
$count[1]{PR} ) A brute force solution in perl might have the form:

    # Build the structure

    while (<>)
    {
	/cat=1/ and /lang=EN/ and $count[1]{PR}++;
	/cat=1/ and /lang=SP/ and $count[1]{SP}++;
	...
	/cat=5/ and /lang=SP/ and $count[1]{SP}++;
	...
	/cat=12/ and /lang=PR/ and $count[1]{SP}++;
    } 

    # Generate the report
    print "cat\tlang\tcount\n";
    print '-' x 21;
    for my $i (1..12)
    {
	for my $j (@langs)
	{
	    print "$i\t$j\t$count[$i]{$j}\n";
	} 
    } 

Of course the formatting of the output needs some work.  You might
also want to consider using a code generator to create the set of inner
match patterns:

    for my $i (1..12)
    {
	for my $j (@langs)
	{
	    print "/cat=$i/ and /lang=$j/ and \$count[$i]{$j}++;\n";
	} 
    } 

If you are fealing especially clever you can actualy generate this code in
on the fly at runtime but that's probably more than you want to try just now.

Good luck

chris
-- 
    This space intentionally left blank


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

Date: 9 Oct 2000 22:55:04 GMT
From: James Young <jamesN0@5PAM.young.net>
Subject: Re: UltraNewbie: grepping weblog
Message-Id: <8rtic8$n2d$1@news.panix.com>

Chris Fedde <cfedde@u.i.sl3d.com> wrote:

> In article <8rt9j5$klr$1@news.panix.com>,
> James Young  <jamesN0@5PAM.young.net> wrote:
>>Hi guys - Still in the early stages of learning perl.  I'm trying to write a
>>script to do the following:  
>>
>>Can anyone help give me a jump start?
>>Thanks! --Jim
>>===========================================
>>#! /usr/bin/perl -w
>>
>>@langs = ('EN', 'SP', 'FR', 'TU', 'PR');
>>
>>@cats = (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12);
>>

> Let me apologize for the way I've rather liberaly edited your posting.  
> The report you are looking for might look like:

>         cat     lang    count
>         ---------------------
>         1       EN      1234
>         1       SP      4657
>         ...
>         2       EN      7654
>         ...
>         12      PR      1234


> Of course the formatting of the output needs some work.  You might
> also want to consider using a code generator to create the set of inner
> match patterns:

>     for my $i (1..12)
>     {
>         for my $j (@langs)
>         {
>             print "/cat=$i/ and /lang=$j/ and \$count[$i]{$j}++;\n";
>         } 
>     } 
> chris

Thanks alot!  This is what I have now - based on what you have given me:

#! /usr/bin/perl -w

@langs = ('EN', 'SP', 'FR', 'TU', 'PR', 'PO', 'IT', 'GE', 'DU', 'SE', 'HU',
'DE', 'IS');

#@cats = (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12);

    for my $i (1..12)
    {
        for my $j (@langs)
        {
            print "/cat=$i/ and /lang=$j/ and $count[$i]{$j}++;\n";
        }
    }



    # Generate the report
    print "cat\tlang\tcount\n";
    print '-' x 21;
    for my $i (1..12)
    {
        for my $j (@langs)
        {
            print "$i\t$j\t$count[$i]{$j}\n";
        }
    }


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

I am getting an error though - 
Use of uninitialized value at ./category3.pl line 11.
/cat=8/ and /lang=HU/ and ++;

(for each instance), as well as:

Use of uninitialized value at ./category3.pl line 24.
1       DE
(also for each instance)  

I though I had defined $i and $j by :
    for my $i (1..12)
    {
        for my $j (@langs)

Thanks again for any more help - Looking through perl books now...
Jim


======================
James Young
james at young dot net


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

Date: Mon, 09 Oct 2000 21:03:44 GMT
From: mjd@plover.com (Mark-Jason Dominus)
Subject: Re: Writing to log files
Message-Id: <39e25800.5646$37c@news.op.net>
Keywords: intrigue, oxygen, retrograde, sinh


In article <HEqE5.40$7J6.170565632@news.frii.net>,
Chris Fedde <cfedde@u.i.sl3d.com> wrote:
>Your description makes it sounds like you are getting hit by some
>kind of buffering problem. 

That's what it sounds like to me also.

I wanted to add the suggestion that the original poster could read

        http://www.plover.com/~mjd/perl/FAQs/Buffering.html

paying particular attention to the section labeled

"My output is coming out in the wrong order!"

That might be suggestive.


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

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


Administrivia:

The Perl-Users Digest is a retransmission of the USENET newsgroup
comp.lang.perl.misc.  For subscription or unsubscription requests, send
the single line:

	subscribe perl-users
or:
	unsubscribe perl-users

to almanac@ruby.oce.orst.edu.  

| NOTE: The mail to news gateway, and thus the ability to submit articles
| through this service to the newsgroup, has been removed. I do not have
| time to individually vet each article to make sure that someone isn't
| abusing the service, and I no longer have any desire to waste my time
| dealing with the campus admins when some fool complains to them about an
| article that has come through the gateway instead of complaining
| to the source.

To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.

To request back copies (available for a week or so), send your request
to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
where x is the volume number and y is the issue number.

For other requests pertaining to the digest, send mail to
perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
sending perl questions to the -request address, I don't have time to
answer them even if I did know the answer.


------------------------------
End of Perl-Users Digest V9 Issue 4565
**************************************


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