[17867] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 27 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Jan 9 21:05:40 2001

Date: Tue, 9 Jan 2001 18:05:14 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <979092314-v10-i27@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Tue, 9 Jan 2001     Volume: 10 Number: 27

Today's topics:
    Re: ASCII to integer conversion <cliff@*MYLASTNAMEHERE*.nl>
    Re: ASCII to integer conversion <cliff@*MYLASTNAMEHERE*.nl>
    Re: ASCII to integer conversion <cliff@*MYLASTNAMEHERE*.nl>
    Re: ASCII to integer conversion <wyzelli@yahoo.com>
    Re: checking/deleting mail duplicates (David Efflandt)
        counting lines in a file lpj91100@my-deja.com
    Re: Extract the nth word from a line (Craig Berry)
    Re: Is $? set when using backticks to issue a system co <brannon@lnc.usc.edu>
    Re: Negating an RE within Perl <iboreham@my-deja.com>
        please help me!! davigre@my-deja.com
    Re: please help me!! <wyzelli@yahoo.com>
        Problem w/ hash of references to hashes (or maybe scopi (Weston Cann)
        system() method won't change directories! 2obvious@my-deja.com
    Re: trying to count words - not working (Craig Berry)
    Re: trying to count words - not working (Craig Berry)
    Re: trying to count words - not working (Craig Berry)
        Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)

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

Date: Wed, 10 Jan 2001 00:28:45 +0100
From: Clifford Pennock <cliff@*MYLASTNAMEHERE*.nl>
Subject: Re: ASCII to integer conversion
Message-Id: <93g7ju$8l8$2@news.news-service.com>

Greg Bacon wrote:
> 
> In article <Pine.LNX.4.21.0101081542410.9913-100000@bleys.cs.uchicago.edu>,
>     anm imroz choudhury  <aichoudh@cs.uchicago.edu> wrote:
> 
> : Is there a function in perl similar to the atoi() function in C that
> : takes a string containing numerals, and outputs the integer that the
> : string represents?  I'd appreciate any help with this, thanks in
> : advance.
> 
> You can do it both ways.  You have to provide the digits in the base
> and request a conversion.  Decimal conversion looks like
> 
>     $num =~ tr|0-9||dc;  # dc == decimal conversion
> 
> To convert a decimal number to a string, use
> 
>     $str =~ tr|0-9||cs;  # cs == convert to string
> 
> Here's an example program:
> 
>     #! /usr/bin/perl -w
> 
>     use strict;
> 
>     my $str = "12345";
> 
>     # apply decimal conversion to $num
>     my $num = $str;
>     $num =~ tr|0-9||dc;
> 
>     $num += 42;
> 
>     # now convert to string so we can print it out
>     $str = $num;
>     $str =~ tr|0-9||cs;
> 
>     print $str, "\n";
> 
> Hope this helps,
> Greg
> --
> Health is merely the slowest possible rate at which one can die.

Now this is what I call an answer, instead of "If you would know the
very basics of Perl, you'd know how silly the question is.".

Thanks Greg.


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

Date: Wed, 10 Jan 2001 00:24:06 +0100
From: Clifford Pennock <cliff@*MYLASTNAMEHERE*.nl>
Subject: Re: ASCII to integer conversion
Message-Id: <93g7bd$8l8$1@news.news-service.com>

"Jürgen Exner" wrote:
> 
> "Clifford Pennock" <cliff@*MYLASTNAMEHERE*.nl> wrote in message
> news:93epse$54e$1@news.news-service.com...
> > Abigail wrote:
> > >
> > > If you would know the very basics of Perl, you'd know how silly the
> > > question is.
> >
> > An why is this silly? I've just started programming in Perl and I have
> > encountered the exact same "problem" numerous times.
> >
> > For instance, suppose we have a string that contains an important value
> > we need for some other stuff. The only thing we know and can be certain
> > of, is that this value can be found directly *after* a fixed delimiter
> > (in this case a ","). Now everything directly following this number can
> > be literally anything, except numbers:
> >
> >     $a_string = "Random string with a value from somewhere,1234m/s";
> >     $a_number = substr( $a_string, index( $a_string, "," ) );
> >
> > Now we need to pass this number to another program:
> >
> >     `a_program $a_string`;
> >
> > See the problem?
> 
> Yes, I do see the problem. You are assuming that a_program would expect a
> number.

No, not really. I'm just saying that sometimes you want "1234" instead
of "1234m/s".

> However, there are no numbers in a shell command line argument to begin
> with. If you type
>     a_program 1234
> at a command prompt, then this "1234" is a text, not a number. And it is

I agree, but that is not my point. Even as a string there could be a lot
of difference for another program between "1234", "1234m/s" or "1234
-whatever". Maybe the shell example was a bad example.

> passed to a_program as a text, not as a number. a_program is responsible for
> converting this text "1234" into the number "1234". And it is up to
> a_program what to do in case it finds non-digits in the argument.

Like I said, that was not the point I was trying to make.
 
> And this is exactly what happens here. In your example the substring
> $a_number contains the scalar value "1234m" and this is being passed to
> a_program.
> If you want to pass a number then you need a scalar which contains only
> digits to begin with.

And that was (imo) what the original poster was asking about. How to
convert a string to number-only. In C, the easy thing to do is to use
the atoi function. It saves you searching through the string. The
answers he got was that there was no need for it, while (again imo)
there sometimes is.

> > Now this of course can be easily fixed, the easiest
> > (afaik) being by just adding the line (which also would be the answer to
> > his question):
> >
> >     $a_number += 0;
> 
> Well, this is a rather odd way that works by chance because the numerical
> value of a scalar happens to be the value of the leading digits of the
> scalar (somewhat simplified).

Exactly. And that is exactly the behavior of the atoi() function.

> The correct way would be to extract exactly the number, i.e. dicsard the
> trailing "m" with e.g. chop or something similar, depending on your data.

Yes and that was the intention of the original poster's question. How to
do that. Or at least, that's how *I* interpreted his question.
 
> > But if you have a background in C (or almost any other programming
> > language), this is pretty weird stuff.
> 
> Don't quite agree. Even in C the substring function (regardless if you use
> the library function or do some weird pointer arithmetic of your own) would
> still yield a string "1234m" and if you pass it on to the next program it
> will still be a string.

Again, that is why one would use the atoi funtion, as in

  a_number = index( a_string, ',' );
  sprintf( shellcommand, "a_program %d", atoi( ++a_number ) );

So the question remains: what's the easy way to do that in Perl?


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

Date: Wed, 10 Jan 2001 00:57:42 +0100
From: Clifford Pennock <cliff@*MYLASTNAMEHERE*.nl>
Subject: Re: ASCII to integer conversion
Message-Id: <93g9a6$9rc$1@news.news-service.com>

My apologies for another post I made (which I cancelled BTW).

My bad. I *did* read your message and you read mine. The confusion
starts with my piece of code:

>    $a_string = "Random string with a value from somewhere,1234m/s";
>    $a_number = substr( $a_string, index( $a_string, "," ) );
>
>  Now we need to pass this number to another program:
>
>    `a_program $a_string`;

which of course should be

    $a_string = "Random string with a value from somewhere,1234m/s";
    $a_number = substr( $a_string, index( $a_string, "," ) + 1 );

    'a_program $a_number';
-------------------^

Hey, I still don't have a message debugger.

Martien Verbruggen wrote:
> 
> On Tue, 09 Jan 2001 18:57:47 +0100,
>         Clifford Pennock <cliff@*MYLASTNAMEHERE*.nl> wrote:
> > Martien Verbruggen wrote:
> >>
> >> On Tue, 09 Jan 2001 11:28:14 +0100,
> >>         Clifford Pennock <cliff@*MYLASTNAMEHERE*.nl> wrote:
> >> >
> >> > See the problem? Now this of course can be easily fixed, the easiest
> >> > (afaik) being by just adding the line (which also would be the answer to
> >> > his question):
> >> >
> >> >     $a_number += 0;
> >>
> >> Unfortunately, perl isn't quite _that_ smart. You'll have to extract the
> >> number yourself. Watch:
> >
> > Actually, it works perfectly. It would converts the scalar "1234m/s" to
> > the scalar "1234".
> 
> Quoting from my previous post, from the bit you cut, just below the
> bit you quoted:
> 
> >> Perl's automagical conversion from strings to numbers works very much
> >> like the strto*() functions in C, or the mentioned atoi() function.
> >> Your string is allowed to start with whitespace, but the first
> >> character has to be a numerical character (or + or -). In other words,
> >> it has to be part of a valid number. Everything after that first valid
> >> number is ignored. If your string starts with anything that isn't a
> >> number, it'll become 0. Note that Perl will always warn if your string
> >> isn't purely numerical.
> 
> I already said this, didn't I? As long as the first non-whitespace bit
> in a string is a number, Perl will convert it to one (although it will
> complain under -w). If it's not a number, it'll become 0 (and perl
> will complain under -w).
> 
> You did read the whole post, didn't you?
> 
> Martien
> --
> Martien Verbruggen              |
> Interactive Media Division      | In a world without fences, who needs
> Commercial Dynamics Pty. Ltd.   | Gates?
> NSW, Australia                  |


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

Date: Wed, 10 Jan 2001 10:49:51 +0930
From: "Wyzelli" <wyzelli@yahoo.com>
Subject: Re: ASCII to integer conversion
Message-Id: <zEO66.10$Mx3.8365@vic.nntp.telstra.net>

"Greg Bacon" <gbacon@HiWAAY.net> wrote in message
news:t5muolmbuntk31@corp.supernews.com...
> In article
<Pine.LNX.4.21.0101081542410.9913-100000@bleys.cs.uchicago.edu>,
>     anm imroz choudhury  <aichoudh@cs.uchicago.edu> wrote:
>
> : Is there a function in perl similar to the atoi() function in C that
> : takes a string containing numerals, and outputs the integer that the
> : string represents?  I'd appreciate any help with this, thanks in
> : advance.
>
> You can do it both ways.  You have to provide the digits in the base
> and request a conversion.  Decimal conversion looks like
>
>     $num =~ tr|0-9||dc;  # dc == decimal conversion

For the benefit of the uninitiated that simply deletes all non-digits
from the string (c being the complement of the search which is all
digits, and d being delete)

> To convert a decimal number to a string, use
>
>     $str =~ tr|0-9||cs;  # cs == convert to string

This simply takes any non digit in the string and converts it to a
single instance of itself (c being the complement of the all digit
search and s being squash)

So the first example will convert any string to only have digits but I
fail to see the value in the second since if the string is already only
digits, then it will remain 'as is' and if the string contains
'aaaa12345' then it becomes 'a12345'.

Am I missing something here?  (humour perhaps?)

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





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

Date: Wed, 10 Jan 2001 01:25:13 +0000 (UTC)
From: efflandt@xnet.com (David Efflandt)
Subject: Re: checking/deleting mail duplicates
Message-Id: <slrn95nefl.hp3.efflandt@efflandt.xnet.com>

On Sun, 7 Jan 2001 02:44:49 +0100, matthias tarasiewicz <t@inode.at> wrote:
>i am searching for a script that checks for duplicates in your mailbox (unix
>mbox format // pine for example)
>
>the duplicates should then be deleted
>
>-- does anybod< know if there is a script that can do this or is there any
>other possibility for doing this?

Well this is not a Perl answer, but procmail in a .forward file can
automatically do this as e-mail is received.  An example of the recipe is
in 'man procmailex' (search for 'duplicate').

However, if you are using sendmail and it uses smrsh as a secure shell,
you may need to symlink the path to procmail into the directory where
smrsh looks for safe .forward programs (which on my system is /etc/smrsh):

cd /etc/smrsh
ln -s /usr/bin/procmail .

-- 
David Efflandt  efflandt@xnet.com  http://www.de-srv.com/
http://www.autox.chicago.il.us/  http://www.berniesfloral.net/
http://cgi-help.virtualave.net/  http://hammer.prohosting.com/~cgi-wiz/


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

Date: Tue, 09 Jan 2001 23:54:15 GMT
From: lpj91100@my-deja.com
Subject: counting lines in a file
Message-Id: <93g8b6$hk2$1@nnrp1.deja.com>

Hi,

Does anybody have a perl script that counts the
numbers of lines of a file, excluding blank lines
and commented lines?

Thanks in advance.



Sent via Deja.com
http://www.deja.com/


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

Date: Wed, 10 Jan 2001 01:32:07 -0000
From: cberry@cinenet.net (Craig Berry)
Subject: Re: Extract the nth word from a line
Message-Id: <t5nesnd377h9af@corp.supernews.com>

News (dpmurphy@emc.com) wrote:
: I would like to extract a word in a particular position in a line.
: For example, if $_ is the line "This is a Perl script", I might want to
: extract the word "Perl" and assign it to a variable.
: I would like to do this for a word in any position in the line.

A lot depends on your definition of "word".  If you'll take \w+ (a
sequence of 1 or more letters, digits, or underscores), then this does the
trick:

  $word = (m/\w+/g)[$pos];

where $pos is the zero-based index of the desired word.

-- 
   |   Craig Berry - http://www.cinenet.net/~cberry/
 --*--  "The hills are burning, and the wind is raging; and the clock
   |   strikes midnight in the Garden of Allah." - Don Henley


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

Date: Tue, 09 Jan 2001 23:37:06 GMT
From: Terrence Brannon <brannon@lnc.usc.edu>
Subject: Re: Is $? set when using backticks to issue a system command
Message-Id: <lby9wkmh5p.fsf@lnc.usc.edu>

bmetcalf@nortelnetworks.com (Brandon Metcalf) writes:

> brannon@lnc.usc.edu writes:
> 
>  > PerlFAQ Server <faq@denver.pm.org> writes:
>  > 
>  > >         $exit_status   = system("mail-users");
>  > >         $output_string = `ls`;
>  > 
>  > Can I still get return status of the process with $?
> 
> Obviously you don't know how to read the manual.  Hmm, let's look in the

you're right and you're wrong. I am going through perlmod right now. I
looked at the system manpage and unfortunately the info wasn't
there... one of these days I will have made it through all the docs,
but for now, I guess I have to suffer the abuse.

> perlvar man page.  Hey, what do you know...
> 
>      $?      The status returned by the last pipe close, backtick
>              (``) command, or system() operator.  Note that this
>              is the status word returned by the wait() system
>              call, so the exit value of the subprocess is
>              actually ($? >> 8).  Thus on many systems, $? & 255
> 
> Brandon

Thanks

-- 
Terrence Brannon
Carter's Compass...
    I know I'm on the right track when by deleting code I'm adding
    functionality.


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

Date: Tue, 09 Jan 2001 23:26:55 GMT
From: Ian Boreham <iboreham@my-deja.com>
Subject: Re: Negating an RE within Perl
Message-Id: <93g6nr$gct$1@nnrp1.deja.com>

In article <93g3qq$e68$1@nnrp1.deja.com>,
  Benjamin Clark <eblitzkrieg@hotmail.com> wrote:
> Hi,
>
> 	I wish to write an exclusion RE in terms of what I want *left*.
>
> Code (which is hardcoded, and I'd rather not change across the board):
> $string !~ $re;

I think I figured out what you wanted from the Subject, but the body was
confusing, so I'll make a few suggestions regarding your post as I go.

It would have been nice if you'd posted a mini-program so we could just
insert the appropriate regex. Hopefully the one I have knocked up is
appropriate. The easier you make it, the more people are likely to
respond.

> eg. a file containing:
> hello there - line 1
> ABC 123 - line 2
> final line - line 3
>
> and an exclude rule that is "^eg|^final" would return the ABC line.
> Problem is, I wish to write the exclude rule in the context of the
> string ABC. Can I do it without using pattern modifiers like s///c or
> changing the !~ to =~?

I tried really hard to understand what this meant. I think you wanted to
say that you want an exclude rule that expresses internally what is to
be included, rather than excluded (i.e. an include rule in disguise)?
Which "ABC"? The one in the data? "Context"?

> I have tried "^[^A][^B][^C]" (which unfortunately doesn't match only
> ABC, but also qBq and qqC) and "^[^(ABC)]" to no avail.

To negate a regex, you normally need to use a zero-width negative
lookahead assertion: (?!xyz).

Here is an example program that I think shows you what you want (my
regexes are the last two in the list):

---CODE---
#!/usr/bin/perl -w

use strict;
my @data = <DATA>;

foreach my $re (
		('^eg|^final', # Anything starting with eg or final
		 '^[^A][^B][^C]', # First not A, second not B...
		 '^[^(ABC)]', # First not (, A, B, C, )
		 '^(?!ABC)', # Doesn't start with ABC
		 '^(?!ABC$)')) # Isn't "ABC"
{
    print "\nTesting regex '$re':\n\n";
    foreach my $string (@data)
    {
	chomp $string;
	print "Checking '$string':";
	print (($string !~ /$re/)? "Retained\n": "Excluded\n");
    }
}

__DATA__
eg. a file containing:
hello there - line 1
ABC 123 - line 2
final line - line 3
ABC
qBq
qqC
---CODE---

The output this gives is:

---OUTPUT---

Testing regex '^eg|^final':

Checking 'eg. a file containing:':Excluded
Checking 'hello there - line 1':Retained
Checking 'ABC 123 - line 2':Retained
Checking 'final line - line 3':Excluded
Checking 'ABC':Retained
Checking 'qBq':Retained
Checking 'qqC':Retained

Testing regex '^[^A][^B][^C]':

Checking 'eg. a file containing:':Excluded
Checking 'hello there - line 1':Excluded
Checking 'ABC 123 - line 2':Retained
Checking 'final line - line 3':Excluded
Checking 'ABC':Retained
Checking 'qBq':Retained
Checking 'qqC':Retained

Testing regex '^[^(ABC)]':

Checking 'eg. a file containing:':Excluded
Checking 'hello there - line 1':Excluded
Checking 'ABC 123 - line 2':Retained
Checking 'final line - line 3':Excluded
Checking 'ABC':Retained
Checking 'qBq':Excluded
Checking 'qqC':Excluded

Testing regex '^(?!ABC)':

Checking 'eg. a file containing:':Excluded
Checking 'hello there - line 1':Excluded
Checking 'ABC 123 - line 2':Retained
Checking 'final line - line 3':Excluded
Checking 'ABC':Retained
Checking 'qBq':Excluded
Checking 'qqC':Excluded

Testing regex '^(?!ABC$)':

Checking 'eg. a file containing:':Excluded
Checking 'hello there - line 1':Excluded
Checking 'ABC 123 - line 2':Excluded
Checking 'final line - line 3':Excluded
Checking 'ABC':Retained
Checking 'qBq':Excluded
Checking 'qqC':Excluded

---OUTPUT---


Regards,


Ian



Sent via Deja.com
http://www.deja.com/


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

Date: Tue, 09 Jan 2001 22:55:58 GMT
From: davigre@my-deja.com
Subject: please help me!!
Message-Id: <93g4tt$f1l$1@nnrp1.deja.com>

Hi!

I think that the following question has been posted, but I am very
confused.

What is the difference between .pl and .cgi script extensions?

second question..

I am using W2000 (SP1), Personal Web Server 5.0 and ActivePerl for w32
( I also have a perl interpreter named
Indigo that comes with Apache server ).

I have a script that is named count.cgi, the author of this
script tells that to use this script, the following lines must be
included in the html
page where I want to put the counter:

<!--#include virtual="count.cgi" -->

          or

<!--#exec cgi="count.cgi" -->


I try this but nothing occurs, no errors, nothing.

I change the .cgi extension to .pl and put in the browser URL the
following line:

http://localhost/count.pl

and the script works!!!!


But I need to put the counter between several lines of html code.

What can I do to make work: <!--#exec cgi="count.cgi" -->  !!!!

thanks for any help.



the following is the 'count.cgi' code:

*******************************************************************
begin code:
*******************************************************************

#!perl


# count.cgi version 2
#
# Leif M. Wright
# leif@conservatives.net
# http://www.conservatives.net/atheist/scripts/
#
# #########################
# Count.cgi is a tiny, simple little counter. It does just what
# it says it does. It counts. You can use it to count as many
# files as you want.
#
# Version 2 improves over version 1 in that it only uses one data file
# to keep track of all your web pages. That datafile should be indicated
# in Unix directory form below. The file should be a blank text file,
set to
# read/write/execute (CHMOD 777) for everyone.

$Datafile = "count_data.txt";

# $DisplayType tells the script whether to display text or images.
# if you want images, leave it "images" if you want text, change it to
# "text" Be sure not to use capital letters.

$DisplayType = "text";

#  There's only one other variable to set. If you use images to count,
# you must tell the script where your image files are in this variable.
# This should be a URL, not a Unix directory.

$ImgDir = "http://dave/count/";

#
# To use the script, include the following in your html document:
#
# <!--#include virtual="count.cgi" -->
#    or
# <!--#exec cgi="count.cgi" -->
#
# The script will automatically count any page you add one of these
notations to.
# Two caveats:
#
#		1) The first person to hit a page will get a strange-
looking counter.
#		   This is due to a glitch, which I haven't had time to
work out yet.
#		   Subsequent visitors won't have this problem.
#		2) If you call the script from any other directory than
the one in which
#		   it is resident, you must indicate where the script
is in your calling tag.
#		   For instance, if I call the script from a level
higher than my root directory
#		   (which is
http://www.conservatives.net/atheist/scripts), I must code the location
# 		   of the script in the tag like this:
#			<!--#exec cgi="/atheist/scripts/count.cgi" -->
#		   This tells the browser that it must start at my root
domain (conservatives.net) and
#		   step itself up two directories from there before it
looks for the script.
#		   THIS IS NOT A QUIRK OF THIS SCRIPT, it is standard
html stuff, but I figured
#		   this would be a handy place to tell you about it.
#
# END CONFIGURATION -- YOU'RE READY TO USE THE SCRIPT
# ########################
#

read(STDIN, $input, $ENV{'CONTENT_LENGTH'});

	$input = $ENV{'QUERY_STRING'} if $ENV{'QUERY_STRING'};

        @pairs = split(/&/, $input);

		foreach $pair (@pairs) {
		($name, $value) = split(/=/, $pair);

		$value =~ tr/+/ /;
		$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex
($1))/eg;

	$INPUT{$name} = $value;
}



$referer = $ENV{'HTTP_REFERER'};

$pageuri = $ENV{'DOCUMENT_URI'};
$counternm = $ENV{'DOCUMENT_NAME'};




#begin count
open (CNT,"$Datafile") || die "Can't open $Datafile\n";



@CounterFile = <CNT>;
close (CNT);


open (CNTER,">$Datafile") || die "Can't open $Datafile\n";
			flock (CNTER,2);

	foreach $CounterFile (@CounterFile)
		{ #begin foreach
		($CounterName,$Otherstuff) = split(/=/,$CounterFile);

		if ($CounterName eq $pageuri)

			{ #begin second if
			$count = $Otherstuff;
			chop($count);


    		$count++;


			$Success = 1;


			print CNTER "$pageuri\=$count\n";


			} # end second if
			else
			{
			print CNTER "$CounterFile";
			next;}


}
close (CNTER);

&newname unless $Success;

&GenerateCounter;

sub newname
{
open(THEFILE,">>$Datafile") || die "Can't open $Datafile\n";
$ToPrint = "$pageuri" . "\=" . "1";
print THEFILE "$ToPrint\n";
$count = 1;
&GenerateCounter;
}



sub GenerateCounter
{

if ($DisplayType eq 'text')
{
print "Content-type: text/html\n\n";
print "$count\n";
exit;
}

$CountLength = length($count);

 for ($i = 0; $i < $CountLength; $i++)
    {


$A = chop($count);

unshift(@countlist, $A);

    }

print "Content-type: text/html\n\n ";

foreach $countlist (@countlist)
{

$CountImage = "$ImgDir" . "$countlist" . ".gif";
print "<img src=$CountImage>";

}

}


********************************************************************



Sent via Deja.com
http://www.deja.com/


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

Date: Wed, 10 Jan 2001 10:13:15 +0930
From: "Wyzelli" <wyzelli@yahoo.com>
Subject: Re: please help me!!
Message-Id: <e6O66.8$Mx3.8106@vic.nntp.telstra.net>

<davigre@my-deja.com> wrote in message
news:93g4tt$f1l$1@nnrp1.deja.com...
> Hi!
>
> I think that the following question has been posted, but I am very
> confused.
>
> What is the difference between .pl and .cgi script extensions?

Nothing except for the fact that the server will be configured to
recognise one or the other.  Generally Windows servers are configured
for .pl and *nix servers for .cgi but that is far from common.

You need to name your scripts to suit whatever your server is configured
to work with.

> second question..
>
> I am using W2000 (SP1), Personal Web Server 5.0 and ActivePerl for w32
> ( I also have a perl interpreter named
> Indigo that comes with Apache server ).
>
> I have a script that is named count.cgi, the author of this
> script tells that to use this script, the following lines must be
> included in the html
> page where I want to put the counter:
>
> <!--#include virtual="count.cgi" -->
>
>           or
>
> <!--#exec cgi="count.cgi" -->
>
>
> I try this but nothing occurs, no errors, nothing.
>
> I change the .cgi extension to .pl and put in the browser URL the
> following line:
>
> http://localhost/count.pl
>
> and the script works!!!!
>

How about changing the line to be <!--#include virtual="count.pl" -->
and rename your script .pl and see what happens.

Wyzelli
--
($a,$b,$w,$t)=(' bottle',' of beer',' on the wall','Take one down, pass
it around');
for(reverse(1..100)){$s=($_!=1)?'s':'';$c.="$_$a$s$b$w\n$_$a$s$b\n$t\n";
$_--;$s=($_!=1)?'s':'';$c.="$_$a$s$b$w\n\n";}print"$c*hic*";





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

Date: Wed, 10 Jan 2001 00:39:53 GMT
From: iowa_song88.remove_eights_and_this@hotmail.com (Weston Cann)
Subject: Problem w/ hash of references to hashes (or maybe scoping?)
Message-Id: <iowa_song88.remove_eights_and_this-0901011743140001@140.salt-lake-city-03-04rs.ut.dial-access.att.net>

I'm trying to create a hash of references to hashes, but I seem to be 
having some difficulty.

Our "key" players in this drama are the following hashes:

%answerKeys
%fileHash

I have a function that builds %answerKeys with the proper keys and values,
and then tries to do this:

$fileHash{$filename} = \%answerKeys;

But then, when I try to get stuff back out by doing something like this:

$fileHash{$filename}->{$label}

I get nothing. Nothing at all. Pure variable undefinedness.

The only two things I can think of are that 1) I'm doing the
referencing/dereferencing wrong or 2) I have a scoping problem
so that the data I think I'm referencing is actually getting 
scrapped before I look at it.

Ideas? (Entire mess of code follows....)

---Weston


#!/usr/bin/perl

$filename = $ARGV[0];
$label    = $ARGV[1];

print "\nfetchKey: |$filename| |$label|\n\n";
$str = &fetchKeyFromFile($filename,$label);
print "\nFetched Key: \n",$str,"End Fetched Key\n\n";
exit;

%fileHash;

sub fetchKeyFromFile
{
        my($filename,$label) = @_;

        #if there's not a fileHash entry for this filename already, we make one
        if(!defined($fileHash{$filename}))
        {

                open(_FILE,"$filename") 
                   || die("Error: can't open $filename --  $!");

                my $line;
                my $label;
                my %answerKeys;

                #we check each line of the file -- at first, until we
                #find a key label line, delimited by #@ key ref
                while(!defined($label) && ($line = <_FILE>))
                {
                        if($line =~ m/^###@\s*(.*?)$/)
                        { $label = $1; }
                }

                #then we read in, line by line, adding each line to the
                #key (lines with # but not #@ are comment lines).
                #when we can't read anymore, we are done.
                while($line = <_FILE>)
                {
                        if($line =~ m/^###@\s*(.*?)$/)
                        { 
                                $label = $1; 
                        }
                        elsif($line =~ m/^#/)
                        { 
                                #don't do anything; this is a comment line
                        }
                        else
                        { 
                                $answerKeys{$label} .= $line; 
                        }
                }

                close(_FILE);

                $fileHash{$filename} = \%answerKeys;
        }

        return $fileHash{$filename}->{$label};
}


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

Date: Wed, 10 Jan 2001 01:53:36 GMT
From: 2obvious@my-deja.com
Subject: system() method won't change directories!
Message-Id: <93gfau$n2c$1@nnrp1.deja.com>

I'm a Windows 98 user who is trying to use the system() method to get
into my c:\program files directory.  But I don't seem to be able to get
out of the c:\perl\bin directory.

system("cd.."); doesn't change directories.  Nor does
system("cd\progra~1");

I know that the directory hasn't changed, because if I include
system("dir >file.txt"); after either of the lines above, the contents
of file.txt are always from the c:\perl\bin directory.

Help!


Sent via Deja.com
http://www.deja.com/


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

Date: Wed, 10 Jan 2001 01:19:07 -0000
From: cberry@cinenet.net (Craig Berry)
Subject: Re: trying to count words - not working
Message-Id: <t5ne4bo8unv866@corp.supernews.com>

Joe Schaefer (joe+usenet@sunstarsys.com) wrote:
: cberry@cinenet.net (Craig Berry) writes:
: 
: > This is my prefered solution in terms of elegance of expression.  Others
: > object that it needlessly builds and throws away an intermediate list; 
: 
: [...]
: 
: >   $leftcnt = 0; $leftcnt++ while $body =~ m/<left>/g;
: > 
: > is good enough.
: 
: Where do you see a list? I see m//g in the scalar context 
: provided by while().

I meant in the

  $count = () = $str =~ m/.../g;

alternative, as quoted in my message.

-- 
   |   Craig Berry - http://www.cinenet.net/~cberry/
 --*--  "The hills are burning, and the wind is raging; and the clock
   |   strikes midnight in the Garden of Allah." - Don Henley


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

Date: Wed, 10 Jan 2001 01:21:16 -0000
From: cberry@cinenet.net (Craig Berry)
Subject: Re: trying to count words - not working
Message-Id: <t5ne8cdt4acsc4@corp.supernews.com>

Martien Verbruggen (mgjv@tradingpost.com.au) wrote:
: > Bart?
: 
: Ack.... sorry, Craig. And sorry, Craig. Don't know how that happened.

Forgot to oil the neurons...happens to everybody, some days.  And as for
calling me 'Bart', at least it's not 'Greg'. :)

-- 
   |   Craig Berry - http://www.cinenet.net/~cberry/
 --*--  "The hills are burning, and the wind is raging; and the clock
   |   strikes midnight in the Garden of Allah." - Don Henley


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

Date: Wed, 10 Jan 2001 01:19:49 -0000
From: cberry@cinenet.net (Craig Berry)
Subject: Re: trying to count words - not working
Message-Id: <t5ne5lajpe7c81@corp.supernews.com>

Rick Delaney (rick.delaney@home.com) wrote:
: Martien Verbruggen wrote:
: >         Joe Schaefer <joe+usenet@sunstarsys.com> wrote:
: > > cberry@cinenet.net (Craig Berry) writes:
: > 
: > I think Bart was talking about the code that Ala submitted,
: 
: Bart?

For values of Bart approaching Craig. :)

-- 
   |   Craig Berry - http://www.cinenet.net/~cberry/
 --*--  "The hills are burning, and the wind is raging; and the clock
   |   strikes midnight in the Garden of Allah." - Don Henley


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

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 V10 Issue 27
*************************************


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