[11897] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 5497 Volume: 8

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Apr 27 14:07:01 1999

Date: Tue, 27 Apr 99 11:00:22 -0700
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Tue, 27 Apr 1999     Volume: 8 Number: 5497

Today's topics:
    Re: "learning perl" does not seem to be written well (Bart Lateur)
    Re: "learning perl" does not seem to be written well <cassell@mail.cor.epa.gov>
    Re: "learning perl" does not seem to be written well <emschwar@rmi.net>
    Re: $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex( (Hans Maurer)
        CGI::Cookie (CPAN) <donny@impulsesoftware.com>
    Re: CGI::Cookie (CPAN) (Jason)
    Re: Eliminate elements from array with second array? (Larry Rosler)
    Re: Eliminate elements from array with second array? <aqumsieh@matrox.com>
    Re: FAQ not applicable (was: Eliminate elements from ar (Bart Lateur)
    Re: get current time in milliseconds <emschwar@rmi.net>
    Re: get current time in milliseconds cindycrawford@my-dejanews.com
        Help Please! System commands from Win98 Perl CGI <thecure1@mediaone.com>
    Re: How to access entire command line? <aqumsieh@matrox.com>
        how to read a huge file line by line without loading it jeposner@my-dejanews.com
    Re: Newbie q: shopping cart w/o using cookies <cassell@mail.cor.epa.gov>
        On the fly conversion <ashley@pcraft.com>
        Output from eval (Linda Littleton)
    Re: Perl RegEx question (Larry Rosler)
        Perl->database problem <ours@casema.net>
    Re: Postponing interpolation? (Bart Lateur)
    Re: Postponing interpolation? (Andrew Allen)
    Re: question from a newbie slash_ben@my-dejanews.com
        Remote version of File::Find (was: Simple Question) (John Moreno)
    Re: searching perl documentation <e.h.bogart@larc.nasa.gov>
    Re: Simple Question <cassell@mail.cor.epa.gov>
    Re: stupid single quote " wipes out REST OF TEXT (Tad McClellan)
    Re: stupid single quote " wipes out REST OF TEXT <cassell@mail.cor.epa.gov>
    Re: stupid single quote " wipes out REST OF TEXT <jeromeo@atrieva.com>
        Using Expect to run Top montereykent@my-dejanews.com
        Using string content as an a variable name aseet@dascom.com
    Re: Where do the spaces come from (Larry Rosler)
    Re: Where do the spaces come from (Bart Lateur)
    Re: Where do the spaces come from sstarre@my-dejanews.com
        Special: Digest Administrivia (Last modified: 12 Dec 98 (Perl-Users-Digest Admin)

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

Date: Tue, 27 Apr 1999 15:59:09 GMT
From: bart.lateur@skynet.be (Bart Lateur)
Subject: Re: "learning perl" does not seem to be written well
Message-Id: <3725dda0.269022@news.skynet.be>

Eric The Read wrote:

>> As to your comment about the =~
>> operator, it is introduced on page 11, is described as the "match
>> operator" in a paragraph of text and used in a simple code sample which
>> illustrates its use. 
>
>Yeah, but let's face it, the =~ operator is conceptually kinda weird.
>Even as an experienced programmer coming to Perl, it threw me for a loop
>the first time.  I couldn't really grok what it was doing-- if you have a 
>m/// on the rhs, then it's just a binding, but the exact same operator
>with a s/// or y/// operator changes the value of the lhs.

I call it the "apply" operator. The RHS does something; the LHS says
what it does it to, i.e. the object of the operation. The operation on
the right is applied to the variable on the left. In fact, it has
nothing to do with any actual matching. It's just that the operations it
currently supports are all kinda matching related. But any operation
that reads and (possibly) modifies one variable is a candidate.

	Bart.


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

Date: Tue, 27 Apr 1999 09:22:35 -0700
From: David Cassell <cassell@mail.cor.epa.gov>
To: bowman@montana.com
Subject: Re: "learning perl" does not seem to be written well
Message-Id: <3725E44B.A2C18DB6@mail.cor.epa.gov>

[courtesy cc e-mailed to poster]

bowman wrote:
> 
> Bob Trieger <sowmaster@juicepigs.com> wrote in message
> >
> > Make that 3 of us. The only experience I had was COBOL on an IBM
> > mainframe. I was feeling pretty stupid by the time I finished the first
> > chapter. Boy was I relieve when I started chapter 2.
> 
> 4.  Being an old systems hack, I always sneered at scripting languages. Perl
> makes C++ STL source read like a Stephen King novel in comparison.

Umm, creepy?  Scary?  Intimidating?  Hastily written and too much like
too many others you've seen?  That's not a nice thing to say about C++.
:-)

You may have seen too many *bad* Perl programs.  Well-written Perl
programs, like well-written C++ programs, are easy to read and follow.
But looking at a few JAPHs before you learn about s/// and perlvars 
can make your cerebrum explode.  I won't even mention the
Schwartzian transform...

> Think I'll cast a Snake before Perls.  At least I can see the markings on
> the python's back, whilst perls are just shiny little indigestible nuggets.

Each to his own.  If you really only see Perl as `one more scripting
language', then you're missing some of the highlights.  Python is a nice
language, but you have to do all the dirty work yourself.  I prefer
Perl's approach, even that introduces some arcana.

And I prefer to think of Perls as small, concentrated, things of beauty.
Layers of shimmering concretion, awaiting your study.  But not to
be mistaken for snakemeat.  :-)

David
-- 
David Cassell, OAO                            cassell@mail.cor.epa.gov
Senior Computing Specialist                      phone: (541) 754-4468
mathematical statistician                          fax: (541) 754-4716


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

Date: 27 Apr 1999 10:47:52 -0600
From: Eric The Read <emschwar@rmi.net>
Subject: Re: "learning perl" does not seem to be written well
Message-Id: <xkfaevum2mf.fsf@valdemar.col.hp.com>

bart.lateur@skynet.be (Bart Lateur) writes:
> Eric The Read wrote:
> >Yeah, but let's face it, the =~ operator is conceptually kinda weird.
> >Even as an experienced programmer coming to Perl, it threw me for a loop
> >the first time.  I couldn't really grok what it was doing-- if you have a 
> >m/// on the rhs, then it's just a binding, but the exact same operator
> >with a s/// or y/// operator changes the value of the lhs.
> 
> I call it the "apply" operator. The RHS does something; the LHS says
> what it does it to, i.e. the object of the operation. The operation on
> the right is applied to the variable on the left. In fact, it has
> nothing to do with any actual matching. It's just that the operations it
> currently supports are all kinda matching related. But any operation
> that reads and (possibly) modifies one variable is a candidate.

That makes a great deal of sense, and I wish I'd seen something like
this when I was teaching myself Perl.  But it's still an odd sort of
operator; I haven't seen its like before.  Don't get me wrong, it's a
really great idea, and it simplifies things immensely, but it's still a
little weird, even for someone who's familiar with programming.

But now there is perldoc, and it has some fairly useful documentation in
perlop about stuff like this.  Now we just need to know to read perldoc,
and all is answered. :)

-=Eric


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

Date: 27 Apr 1999 19:24:01 +0200
From: hans@nosports.red.roses.de (Hans Maurer)
Subject: Re: $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg;
Message-Id: <7g4rrh$g9d$1@anathema.red.roses.de>

Hija,

Benjamin Franz wrote:
> 	my ($tick) = @_;
> 	my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst,
> 		$month,$wkday);
> 	($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst)=gmtime($tick);
[...]
> 	if ($year < 95) {
> 		$year  = $year + 2000
> 	}
> 	if (($year > 94) && ($year < 1000)) {
> 		$year = $year + 1900;
> 	}

I see year-mangling stuff like this all the time.  As the perlfunc man page
says (backed up by any gmtime or localtime man page):
             Also, $year is the
             number of years since 1900, that is, $year is 123 in
             year 2023, not simply the last two digits of the
             year.
So, a simple  $year+=1900;  does the trick.  The code above will fail for
time stamps earlier than 01/01/1995.

Is there an issue on NT with gmtime that needs work-arounds like the one
above?

Just curious,
  Hans

-- 
Hans Maurer                                                hans@red.roses.de

 "Wenn man jemandem viel Gl|ck w|nscht, dann hat der's auch bitter nvtig"


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

Date: Tue, 27 Apr 1999 17:07:31 GMT
From: Donny Widjaja <donny@impulsesoftware.com>
Subject: CGI::Cookie (CPAN)
Message-Id: <3725EFC5.40BB474F@impulsesoftware.com>

Hi,

I try to fetch the expiration time from a cookie by using CGI::Cookie.
This is what I have done:

  $oneCookie = new CGI::Cookie;
  %cookies = fetch CGI::Cookie;
  foreach $name (keys %cookies) {
     $found = &checkCookie($name, $storeID, $orderNumber);
     if ($found) { 
       $oneCookie = $cookies{$name};
       last;
     }
  }

  $name = $oneCookie->name();
  $timeLeft = $oneCookie->expires();
  &dieHTML("$timeLeft, $name");

After running the above code, I can get the name, but not the expiration
time.  I changed it to domain(), but it does not return the domain name
either. In Netscape documentation examples
(http://www.netscape.com/newsref/std/cookie_spec.html), when the client
request a URL from a specific path, the browser only returns the name
and values of a cookie.

So, does anybody has another method to fetch the expiration time from
cookie?  It will be easier if you provide me some sample code. 

Thanks.


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

Date: 27 Apr 1999 17:26:17 GMT
From: robobob@blech.mindwell.com (Jason)
Subject: Re: CGI::Cookie (CPAN)
Message-Id: <slrn7ibspo.8ss.robobob@blech.mindwell.com>

On Tue, 27 Apr 1999 17:07:31 GMT, Donny Widjaja wrote:
>Hi,
>
>I try to fetch the expiration time from a cookie by using CGI::Cookie.
>This is what I have done:
>
>In Netscape documentation examples
>(http://www.netscape.com/newsref/std/cookie_spec.html), when the client
>request a URL from a specific path, the browser only returns the name
>and values of a cookie.
>
The browser doesnt tell the cookie when it expires, so the only way for you
to find out is to encode that information in the cookie itself, or store it
on the server when the cookie is set.

$expiration = time() + 3600; # one hour from now
$cookie = $cgi->cookie(-name => 'info:expires',
                       -value => "blah:$expiration", # exp in cookie
                       -expires => '+1h', # also one hour from now
                       -path => '/');
print $cgi->header('text/html',-cookie => $cookie);

-- 
        Jason Kohles -- jason@mediabang.com
        http://www.mediabang.com/

          "This is as bad as it can get, but don't bet on it."


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

Date: Tue, 27 Apr 1999 08:59:58 -0700
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: Eliminate elements from array with second array?
Message-Id: <MPG.118f7ed44b77b27d98994d@nntp.hpl.hp.com>

In article <7g2vce$dte$1@fcnews.fc.hp.com> on 27 Apr 1999 00:11:58 GMT, 
Andrew Allen <ada@fc.hp.com> says...
> Andrew Allen (ada@fc.hp.com) wrote:
> : @found=grep(!/(cgi-bin|messages|oldstuff|ppd|test|archives)/,@found);
> 
> whoops-- change that to !{/(...)/}

That syntax is invalid.

    !m{/(...)/}

> On the other hand, I'd like to chastise Tad and Larry for pointing her
> to a rather inapplicable FAQ-- a quick perusal of her code shows that
> she wanted to do regexp checking to a list, not set
> difference. Perhaps before being so curt about FAQ's on the newsgroup,
> you could make sure they actually _are_ FAQ's. Perhaps her initial
> question wasn't phrased 100% accurately (but she did post her source,
> and it's a difficult problem to accurately capture in a couple of
> sentences), but your answers were _way_ off.

You can add Abigail's three-letter answer to the list.  You are right -- 
this is not a FAQ.  I misread "eliminate elements from an array if they 
contain any of a list of strings from another array" as "if they are the 
same as any elements from another array", which is 'set difference' and 
a FAQ.

The original poster has now told us that your reading was correct.

-- 
(Just Another Larry) Rosler
Hewlett-Packard Company
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com


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

Date: Tue, 27 Apr 1999 11:44:03 -0400
From: Ala Qumsieh <aqumsieh@matrox.com>
Subject: Re: Eliminate elements from array with second array?
Message-Id: <x3yhfq2qda4.fsf@tigre.matrox.com>


lou@visca.com writes:

> My question concerns finding the best way to eliminate elements from
> an array if they contain any of a list of strings from another
> array. 

perldoc perlfaq4:

	How do I compute the difference of two arrays?  How do I
	compute the intersection of two arrays? 



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

Date: Tue, 27 Apr 1999 16:32:59 GMT
From: bart.lateur@skynet.be (Bart Lateur)
Subject: Re: FAQ not applicable (was: Eliminate elements from array with second array?)
Message-Id: <3728e4d4.2113349@news.skynet.be>

lou@visca.com wrote:

>@found = qw(/www/visca/index.html /www/visca/ballparkfrank.html
>/www/visca/admin.html) # long etc.
>
>...and my @skips was like this:
>
>@skips = qw(cgi-bin messages oldstuff ppd test archives)

>Andrew's code:
>
>my $re=join("|",@skips);
>@found=grep(!m{/($re)/}o,@found);
>
>...was exactly what I was looking for:

Only if you don't mind skipping things like "latest.html". (hint:
"latest" =~ /test/)

And you should take care to put backslashes in front of meta-characters.

My first idea is:

	my $re = join '|', map { quotemeta } @skip;
	@found = grep(!m{/\b($re)\b/}o,@found);

but that doesn't work right if any of the alternatives starts of ends
with a non-word char, and the associated "\b" should then be replaced
with "\B" (put it inside the map() block).

	Bart.


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

Date: 27 Apr 1999 10:31:40 -0600
From: Eric The Read <emschwar@rmi.net>
Subject: Re: get current time in milliseconds
Message-Id: <xkfd80qm3df.fsf@valdemar.col.hp.com>

wtang@cs.ualberta.ca (Wei Tang) writes:
> How can I get the current time in milliseconds since 1970 rather than in
> seconds? The time function in Perl is not enough.

Multiply by 1000.

-=Eric


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

Date: Tue, 27 Apr 1999 16:41:52 GMT
From: cindycrawford@my-dejanews.com
Subject: Re: get current time in milliseconds
Message-Id: <7g4pcf$1kq$1@nnrp1.dejanews.com>

you can find some clock scripts at http://cgi-shop.com
maybe one of them will do the job you need



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


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

Date: Tue, 27 Apr 1999 13:07:45 -0400
From: "TheCure1@mediaone.com" <thecure1@mediaone.com>
Subject: Help Please! System commands from Win98 Perl CGI
Message-Id: <3725EEE1.AA9062B3@mediaone.com>

I am developing a solution which must work in multiple platforms.
It is presently already working on Solaris UNIX and IBM AIX.
I need to also make it work on a Windows platform.
It is based on Perl CGI in the server.
The CGI must run a command in the server.
The Perl stuff is working fine as the CGI, its with the system command I
am having trouble...
 ...
I hit an obstacle which seems very simple and I wonder if the
Windows/CGI/Perl implementation prevents me from doing this. I am having
problems with both Folkweb server and PWS.
 ...
All I want to do is to run a command and get its output back to the Perl
script that is running it. This works when I run it from the command
line ("perl scriptname")
but not as a CGI with POST method...

I do system("command > outputfile") and then look at the outputfile in a
subsequent line or
$output=`command`; and then look at the $output variable.
My present experience is that this code seems not to want to execute
either case. At this point "command" can be ANYTHING. Please try "echo
HELLO" or "type
file" or ANYthing... At this point I just want any command to run and me
being able to get its output in the Perl script.
Has anyone been succesful running a simple DOS command and getting the
results back to the Perl CGI in Windows 98? (Again: It works when I do
it from the command line in DOS!).
THANK YOU




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

Date: Tue, 27 Apr 1999 11:39:00 -0400
From: Ala Qumsieh <aqumsieh@matrox.com>
Subject: Re: How to access entire command line?
Message-Id: <x3yiuaiqdik.fsf@tigre.matrox.com>


georgee1631@my-dejanews.com writes:

> Inside a perl script is there a system variable or something that I
> can use to access the entire command line that invoked the script.

Read what 'perlvar' has to say about @ARGV.



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

Date: Tue, 27 Apr 1999 17:10:24 GMT
From: jeposner@my-dejanews.com
Subject: how to read a huge file line by line without loading it into memory
Message-Id: <7g4r1r$3ej$1@nnrp1.dejanews.com>

I have two very large files (each greater than the amount of memory on my
box) -	I need to perform a two file match, but the only way I know in perl
is to load the files up into memory with Open.

How can I read from each file one line at a time, or even better a block of N
lines at a time?

Thanks in advance!!

Please reply to the group and to my email: posnerje@nortonrose.com

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


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

Date: Tue, 27 Apr 1999 09:44:44 -0700
From: David Cassell <cassell@mail.cor.epa.gov>
Subject: Re: Newbie q: shopping cart w/o using cookies
Message-Id: <3725E97C.B71647BC@mail.cor.epa.gov>

emytang wrote:
> 
> Hi,
> 
> I want to develop a shopping cart without using cookies. How can I
> store the user's info so as to remember what clients have been
> selected?

I believe this is a FAQ.. but not in this newsgroup.
Your problem [even if if you are programming in Perl] is actually
a CGI issue.  So you need to ask in one of the CGI newsgroups, such
as comp.infosystems.www.authoring.cgi .

> TIA

you're welcome
David
-- 
David Cassell, OAO                            cassell@mail.cor.epa.gov
Senior Computing Specialist                      phone: (541) 754-4468
mathematical statistician                          fax: (541) 754-4716


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

Date: Tue, 27 Apr 1999 11:29:31 -0600
From: "Ashley M. Kirchner" <ashley@pcraft.com>
Subject: On the fly conversion
Message-Id: <3725F3FB.5EFC6447@pcraft.com>



    I have a complete web site which is build using SSI's on all of its
pages.  What I'd like to do is build a perl script that once passed one
of these .shtml files, it'll do some tag stripping and present the same
page again, will less bells and whistles...

    Ok, that sounded cryptic...so, let me try to explain it better.

    All the pages on the Websmith contains SSI tags, some are including
an entire JS routine, and some are as simple as tagging each page with a
LAST_MODIFIED field.  I want to create a cgi (print.cgi) that will
convert these pages by stripping out some of the unnecessary tags and
make the page suitable for printing a hard copy.

    What I'd like to do is have an URL like
/cgi-bin/print.cgi?/services/info/faq.shtml, where the print.cgi script
will take that file faq.shml (it's a valid URL as well), strip out what
I don't need to be printed, and present that same page again, only this
time without some (or all) of the included tags, JS, yaddi yaddi
yadda...  A plain vanilla page, suitable for printing.

    I'm running Apache web server.


    Anyone care to give me some pointers, or help me out here?

    Thanks


    AMK4
    ashley@yeehaw.com



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

Date: Tue, 27 Apr 1999 13:28:22 -0400
From: xxx@psu.edu (Linda Littleton)
Subject: Output from eval
Message-Id: <xxx-2704991328220001@rose.cac.psu.edu>

When I run the following code (where eval is evaluating something with a
syntax error), an error message is getting printed to the screen. What I
want is to capture all of the messages so that I can then handle the
situation in a different way. How do I keep eval from writing out this
stuff?

  $calc = '5)8(';
  local ($ans) = eval $calc;
  print "Calc:   $calc\n";
  print "Error:  $@\n" if ($@);
  print "Answer: $ans\n";


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

Date: Tue, 27 Apr 1999 09:17:40 -0700
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: Perl RegEx question
Message-Id: <MPG.118f83014fd660dd98994f@nntp.hpl.hp.com>

In article <m3hfq26rca.fsf@moiraine.dimensional.com> on 27 Apr 1999 
09:00:37 -0600, Daniel Grisinger <dgris@moiraine.dimensional.com> 
says...
> my_addr_is-chrisdl@pagesz.net (chris losinger) writes:
> 
> > but, what i've found is that sometimes the messages come in with
> > 0x0a/0x0d pairs (DOS CR/LF) at the end of the lines, instead of just
> > 0x0a. this causes my little regex to fail and set $name to blank.
> > 
> > so, my question is, how can i handle these situations ?
> 
> Strip the CRs first.
> 
>     s/\r//g;

Which, as Abigail pointed out yesterday, perl should compile as the much 
more efficient equivalent:

      tr/\r//d;

But it doesn't.  Yet???

-- 
(Just Another Larry) Rosler
Hewlett-Packard Company
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com


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

Date: Tue, 27 Apr 1999 19:36:34 -0700
From: "Ours" <ours@casema.net>
Subject: Perl->database problem
Message-Id: <7g4sjj$j6s$1@news.casema.net>

Hi,

Does someone have a list of characters that cannot be sql-ed into an ACCESS
database directly?
I am trying to store some text into a memo-field but it seems to fail on the
following for sure:
',"!
is there a way to "prepare" my $text so that it can be used as I want it. I
definitly want to store caracters like this in the Memo-field.

As I tried to enter these chars in the base directly and successfuly, it
seems to be (and it's kinda logic) a perl->string->problem.

Anyone familiar with a regular expression that takes care of them all?

~ s/\'/\' /g; and this for all different special char's is not really what I
intent. One sub for all is, only I do not know how to accomplish this.

Thanks,

MW





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

Date: Tue, 27 Apr 1999 16:15:38 GMT
From: bart.lateur@skynet.be (Bart Lateur)
Subject: Re: Postponing interpolation?
Message-Id: <3726df2a.663603@news.skynet.be>

Anneke Treep wrote:

>Any suggestions so that I can:
>- put the letter-definition at the very end of my script;
>- use variables local to my while loop in the letter;
>Any elegant solution is acceptable - my main concern is the 
>maintainability for occasional perl users.

A general "template" mechanism would be a possible candidate. This means
that you have to create one sub ONCE that does the substitution in the
string you pass, using a HASH for the values. Actually, the code needed
is incredibly simple.

Example:

	sub interpolate {
		my($text,$hash) = @_; # text to interpolate, 
			# plus hash ref with values
		$text =~ s/\{(\w+|(\W))\}/$2 || $hash->{$1}/ge;
	        return $text;
	}

	my $sons = 3;
	print interpolate("I have {sons} son{s}.\n",
		{ sons => $sons, 's' =>  $sons==1?'':'s'});

n.b. in case you're wondering: the construct using \W in the regex
serves only to allow you to output literal "{" characters: just encode
it as "{{}". And yes, you may read the text itself from an external text
file.

	Bart.


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

Date: 27 Apr 1999 16:36:56 GMT
From: ada@fc.hp.com (Andrew Allen)
Subject: Re: Postponing interpolation?
Message-Id: <7g4p38$s6p$1@fcnews.fc.hp.com>

Anneke Treep (anneke@echelon.nl) wrote:
: Hi all,

: So I would prefer to replace the print statements with just 
: "letter();"
: and say *at the end of my script* something like:

: sub letter {
:     print "
: I have $sons son$s
: ..etc.
: ";

: But if I do so the variables $sons and $s need to be global,
<snip>

I can think of two things to do:

pass your variables as arguments to letter:

  letter($sons,$s);
  ...
  sub letter {
    my($sons,$s)=@_;
    print "I have $sons son$s";
  };

or pass back a string to eval (blech!):

  print eval letter();
  ...
  sub letter {
    return q{"I have $sons son$s"};
  }

or pass back the string and do the substitition yourself:

  my $letter=letter();
  $letter=~s/\$sons\b/$sons/g;
  $letter=~s/\$s\b/$s/g;

course, I'd keep all the "replacement items" in a hash, so you could:

  my $letter=letter();
  $letter=~s/\$(\w+)/exists $replace{$1}?$replace{$1}:$&/eg;

and if you're doing your own replacements, you may want to use
different delimiters (since '$' followed by a word can be
ambiguous). '%word%' is suggested somewhere...

Umm.. I guess that's more than two things. Good luck!

Andrew


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

Date: Tue, 27 Apr 1999 16:18:12 GMT
From: slash_ben@my-dejanews.com
Subject: Re: question from a newbie
Message-Id: <7g4nvv$a5$1@nnrp1.dejanews.com>

Thanks to all - especially to Mr. Johnson -- sorry about the vagueness, but
this is the first post that I've ever done.....now I know (I hope).. Thanks
again


In article <U9eV2.9271$mR1.430284@news1.rdc1.on.wave.home.com>,
  andrew-johnson@home.com wrote:
> In article <7g3iu7$vkp$1@nnrp1.dejanews.com>,
> !  slash_ben@my-dejanews.com <slash_ben@my-dejanews.com> wrote: how can
> !  I print just two lines and all the lines in between them in a file?
>
> finally, a question with all the necessary information to answer
> completely and unequivocally:
>
> 1) print your two lines
> 2) print all the lines in between them
>
> No offense, but how do we know if you want to print line 13, then
> line 32, then lines 14 to 31 ... or perhaps every line from line 13
> to 32, or maybe every line from one that contains 'foo' to one that
> contains 'bar' ... or maybe something else entirely?
>
> One piece of advice: You must learn to clearly define your problem
> statement --- doing so will take you more than halfway to a solution.
>
> Also, don't ignore the FAQ's that come with perl: Even with a vague
> description such as yours a quick grep of the FAQ's for questions
> containing 'between' brings up 10 hits, one of which is:
>
> perlfaq6.pod: How can I pull out lines between two patterns that
>               are themselves on different lines?
>
> If that is no help, please reformulate your question and post again
> (leaving 'newbie' out of the subject might net a better response).
>
> regards
> andrew
>
> --
> Andrew L. Johnson   http://members.home.com/andrew-johnson/
>       The generation of random numbers is too
>       important to be left to chance.
>
>

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


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

Date: Tue, 27 Apr 1999 13:47:07 -0400
From: planb@newsreaders.com (John Moreno)
Subject: Remote version of File::Find (was: Simple Question)
Message-Id: <1dqx9t2.h38520owm4r8N@roxboro0-0029.dyn.interpath.net>

David Cassell <cassell@mail.cor.epa.gov> wrote:

> John Moreno wrote:
> > 
> > Tad McClellan <tadmc@metronet.com> wrote:
-snip-
> > >    Got some particular protocol in mind?
> > 
> > telnet and ftp.
> 
> Well then, get ye to CPAN and check these modules
> Net::Telnet
> Net::FTP

I'm somewhat familiar with both -- but neither (to my inexperienced eye)
has as clean a way to do this as File::Find does for local documents.

find(\&wanted, 'thedir');

sub wanted {
  if (m/html/) {
    $/=undef;
    open (DOC, "+< $_") || die;
    $doc = <DOC>;

    #make my changes

    truncate(DOC, 0);

    print DOC $doc;
    close <DOC>;

  }
}

I don't see as how I can do it as simply with Net::Telnet or Net::FTP.


-- 
John Moreno


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

Date: Tue, 27 Apr 1999 13:07:09 -0400
From: Ed Bogart <e.h.bogart@larc.nasa.gov>
Subject: Re: searching perl documentation
Message-Id: <3725EEBD.F8C28705@larc.nasa.gov>

Brian Peisley wrote:
> 
> Eric Smith wrote:
> >
[snip]
> > What's better?
> 
> Try using perldoc instead it can do exactly what you're looking for and
> much more. If you haven't used it before, just type this at the command
> line:
> 
> perldoc perldoc
> 
> This will give you a brief description of what perldoc is and how to use
> it.
> 
> Hope this helps you out.
> 
> Brian Peisley
> bdp@mutagenic.org

Let me jump in here and ask a question that has been bugging me. I
started doing perl (SGI 02 running IRIX6.5 and version 5.004_04 built
for IP19-irix) about a month ago and have been doing OK. However,
perldoc doesn't seem to work the way it should. If I do 'perldoc -f
BuiltinFunction' it's fine. If I do a 'perldoc -h' or the above 'perldoc
perldoc' I get the help doc/pod whatever. When I try to get help with a
'PageName|ModuleName|ProgramName' I get the following (using the example
from what perldoc -h returns.)

physio% perldoc Term::Info
No documentation found for "Term::Info".
physio% perldoc Term/Info
No documentation found for "Term/Info".
physio% perldoc Term/Info
No documentation found for "info".

Am I doing this wrong or is there something wrong with the installation?

Ed


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

Date: Tue, 27 Apr 1999 09:40:19 -0700
From: David Cassell <cassell@mail.cor.epa.gov>
Subject: Re: Simple Question
Message-Id: <3725E873.5ECC463@mail.cor.epa.gov>

John Moreno wrote:
> 
> Tad McClellan <tadmc@metronet.com> wrote:
> 
> > John Moreno (planb@newsreaders.com) wrote:
> > : Jason Simms <ffchopin@worldnet.att.net> wrote:
> >
> > : > Shashank Tripathi <mkshanx@ust.hk> wrote in message
> > : > news:7g0ngo$620@ustsu10.ust.hk...
> > : > > Is there a way to scour through every file in a specified directory
> > : > > on my computer thru perl?
> > : >
> > : > Sure...  Use the File::Find module that comes standard with Perl.
> > : > Read the
> >
> > : How about doing the same thing on a remote computer?
> >
> >    Sure.
> >
> >    But we (actually you) would need to know what protocols the
> >    "remote computer" understands.
> >
> >    Got some particular protocol in mind?
> 
> telnet and ftp.

Well then, get ye to CPAN and check these modules
Net::Telnet
Net::FTP

David
-- 
David Cassell, OAO                            cassell@mail.cor.epa.gov
Senior Computing Specialist                      phone: (541) 754-4468
mathematical statistician                          fax: (541) 754-4716


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

Date: Tue, 27 Apr 1999 07:31:06 -0400
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: stupid single quote " wipes out REST OF TEXT
Message-Id: <q574g7.6v4.ln@magna.metronet.com>

NOSPAMcrstlblu@planet.eon.net wrote:
: On Tue, 27 Apr 1999 05:53:30 -0400, tadmc@metronet.com (Tad McClellan) wrote:
: >   The double quote is giving you HTML problems.

: 	it's a single quote, and it "POSSIBLY" might be entered into
: 	a textbox, on a form, by someone.... eg:

: 		I am 5'10" tall and etc

: 	there is only ONE quote in the text above,
: 	this would be entered into a textfield, on a form, and then
: 	saved to a DBM file - EVERYTHING works to that point!

: 	if i call a script which extracts this text from the DBM
: 	and prints it to the screen it prints PERFECTLY! however,
: 	if i feed that value into ANOTHER HIDDEN form field,
: 	and try to pass it to another script the NEXT SCRIPT
: 	drops everything AFTER THE SINGLE QUOTE when
: 	it prints it to the browser???
: >
: >   Have you looked very carefully at the HTML containing 
: >   your hidden field?

: 	yes it's a perfectly ordinary, functional, "CGI SCRIPT" which
: 	prints an ELEMENTARY html form to the browser perfectly


   That is not what I meant.

   Does the generated HTML (the one with the hidden field in it)
   look something like:

      <input ... value='5'10"'>
                       ^^^   ^
                       ^^^   ^

   If so, they look yet more carefully.

   If not then I dunno what your problem is, but it is not a Perl
   problem and so should be moved to another newsgroup.



--
    Tad McClellan                          SGML Consulting
    tadmc@metronet.com                     Perl programming
    Fort Worth, Texas


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

Date: Tue, 27 Apr 1999 10:13:46 -0700
From: David Cassell <cassell@mail.cor.epa.gov>
Subject: Re: stupid single quote " wipes out REST OF TEXT
Message-Id: <3725F04A.3EB2E3DA@mail.cor.epa.gov>

NOSPAMcrstlblu@planet.eon.net wrote:
> 
> I've got this mysterious problem with a crummy " quotation mark,
> in my flatfile dbm database, I have several lines of text which have a crummy
> quotation mark in them (5'10") to be exact,... the 5'10" appears right smack in
> the middle of the text,....

Tad already gave you the crucial information.  But I noticed this:

> strange, I've tried various things with the (=~tr/"//;), (=~tr/\"//;) and so on
> to no avail,... any suggestions?

You need to look up tr/// in the perlop manpage.  Use `man' or
`perldoc' or the html docs, or whatever you like.

The important point:
tr/"// does *not* delete those quotes for you!  It only counts them.
If you want to get rid of them, you need to do this:
 
   $varname =~ tr/"//d;

And backwhacking the " won't help either.  That's not how tr///
works.

> sorry to bother you

It's okay.  We wouldn't be answering questions in this ng if we
didn't want to help.  But your problem really is an HTML problem
dressed up in a llama's coat.

David
-- 
David Cassell, OAO                            cassell@mail.cor.epa.gov
Senior Computing Specialist                      phone: (541) 754-4468
mathematical statistician                          fax: (541) 754-4716


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

Date: Tue, 27 Apr 1999 10:04:29 -0700
From: Jerome O'Neil <jeromeo@atrieva.com>
Subject: Re: stupid single quote " wipes out REST OF TEXT
Message-Id: <3725EE1D.46B1C971@atrieva.com>

NOSPAMcrstlblu@planet.eon.net wrote:
> 
> On Tue, 27 Apr 1999 05:53:30 -0400, tadmc@metronet.com (Tad McClellan) wrote:
>                 I am 5'10" tall and etc
> 
>         there is only ONE quote in the text above,
>         this would be entered into a textfield, on a form, and then
>         saved to a DBM file - EVERYTHING works to that point!

So perl is not the problem.

> 
>         if i call a script which extracts this text from the DBM
>         and prints it to the screen it prints PERFECTLY!

So perl is still not the problem.

>         however,
>         if i feed that value into ANOTHER HIDDEN form field,
>         and try to pass it to another script the NEXT SCRIPT
>         drops everything AFTER THE SINGLE QUOTE when
>         it prints it to the browser???

Perl doesn't know if it's printing to a browser, a terminal, a printer,
or a teletype.  Your problem is an HTML problem.


> >
> >   Have you looked very carefully at the HTML containing
> >   your hidden field?
> 
>         yes it's a perfectly ordinary, functional, "CGI SCRIPT" which
>         prints an ELEMENTARY html form to the browser perfectly

Aparently it isn't printing perfect HTML, though, which is the problem. 

Also, I noticed that the e-mail I sent you bounced.  Your e-mail address
is crstlblu@planet.eon.net, yes?

-- 
Jerome O'Neil, Operations and Information Services
Atrieva Corporation, 600 University St., Ste. 911, Seattle, WA 98101
jeromeo@atrieva.com - Voice:206/749-2947 
The Atrieva Service: Safe and Easy Online Backup  http://www.atrieva.com


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

Date: Tue, 27 Apr 1999 16:45:16 GMT
From: montereykent@my-dejanews.com
Subject: Using Expect to run Top
Message-Id: <7g4piq$1pp$1@nnrp1.dejanews.com>

I wanted to run top from a cron job, capturing the output to a file.
I thought the expect module would allow me to do this.

Downloaded and did the typical perl installation of Expect.pm-1.07,
IO-Stty-.02 and IO-Tty-0.02:  perl Makefile.PL, make, make install

When I try to put "use Expect in my code I get:

"Can't locate Expect.pm in @INC at test_expect line 2".

What's up?

I next tried putting in the explicit path to the modules in my code, they are
there:

This code was based on chapter 15:13 of the Perl Cookbook "Controlling
Another Program with Expect".

#!/usr/local/bin/perl

use lib "/usr/freeware/lib/perl5/site_perll/Expect";
use lib "/usr/freeware/lib/perl5/site_perl/IO/Pty;
use lib "/usr/freeware/lib/perl5/site_perl/IO/Tty;
use lib "/usr/freeware/lib/perl5/site_perl/IO/Stty;

$command = Expect->spawn("/usr/sbin/top -D /tmp/top.dump") or print
                    "Can't spawn to : $!\n";

$command->log_stdout(0);
sleep(6);
print $command "D";
$command->hard_close();

When this runs I get:
"Can't call method "spawn" in empty package "Expect" at run_top7 line8.

Thank you for any assistance you can provide,
John Kent
Naval Research Laboratory
Monterey, CA



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


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

Date: Tue, 27 Apr 1999 17:41:08 GMT
From: aseet@dascom.com
Subject: Using string content as an a variable name
Message-Id: <7g4srj$567$1@nnrp1.dejanews.com>

Let's say I have file with a string "$shell_prompt" and I read it into a
variable called $str. Somewhere else, I have declared a global $shell_prompt
and gave it the value

$shell_prompt = "prompt>";

Is there a way for me to use the value of $str to access the $shell_prompt
variable so that when I do a

print STDOUT "<something which I don't know what, maybe..> $str"

I would get the output "prompt>" ???

Basically, the string "$shell_prompt" is in a file which is read into the $str
variable and I want the ability to specify variable names in the file.

Anyway help would be appreciated. Thanks
adrian

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


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

Date: Tue, 27 Apr 1999 09:06:27 -0700
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: Where do the spaces come from
Message-Id: <MPG.118f80583079d1b098994e@nntp.hpl.hp.com>

In article <P1gV2.3449$B55.276363@dfiatx1-snr1> on Tue, 27 Apr 1999 
10:09:52 GMT, John T. Drefke <jtdrefke@gte.net> says...
 ...
> print "@x";
> 
> Prints:
> aa
>  aa
>  aa

Just to wrap this up -- it's a FAQ!  perlfaq5:  "Why do I get weird 
spaces when I print an array of lines?"

-- 
(Just Another Larry) Rosler
Hewlett-Packard Company
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com


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

Date: Tue, 27 Apr 1999 16:37:21 GMT
From: bart.lateur@skynet.be (Bart Lateur)
Subject: Re: Where do the spaces come from
Message-Id: <3729e70d.2681932@news.skynet.be>

John T. Drefke wrote:

>I have a file called a.dat which contains:
>aa
>aa
>aa
>
>Perl code:
>open(f,"<a.dat");
>@x=<f>;
>print "@x";
>
>Prints:
>aa
> aa
> aa
>
>Where did the space in front of aa in lines 2 3 come from??

>From $" (which defaults to space). Try setting { $" = "#" } before
printing out your result!

If you would have used

	print @x;

instead, $, would have been used as filler between the array elements
instead of $" , and the default for that variable is the empty string.

	Bart.


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

Date: Tue, 27 Apr 1999 16:58:26 GMT
From: sstarre@my-dejanews.com
Subject: Re: Where do the spaces come from
Message-Id: <7g4qbe$2nq$1@nnrp1.dejanews.com>

As I said, I also tried

print @l;

Same result John, don't let this response confuse you- I did try your example
as well as the other.

In article <v114g7.7l4.ln@magna.metronet.com>,
  tadmc@metronet.com (Tad McClellan) wrote:
> [ quotes moved around into non-Jeopardy order ]
>
> sstarre@my-dejanews.com wrote:
> : In article <P1gV2.3449$B55.276363@dfiatx1-snr1>,
> :   "John T. Drefke" <jtdrefke@gte.net> wrote:
> : > I know how to get my program to work but I also like
> : > to understand what is really going on behind door number 1.
> : >
> : > Perl code:
> : > open(f,"<a.dat");
> : > @x=<f>;
> : > print "@x";
>
> : Perhaps it is something with your implementation, as I tried your example on
> : our unix system and I don't see any spaces:
>
>    But you didn't try his example.
>
>    His example interpolates an array into a string.
>
>    Your example doesn't.
>
> :  open F,'<./x';
> :  my @l=<F>;
> :  foreach (@l) {print;}
>
> --
>     Tad McClellan                          SGML Consulting
>     tadmc@metronet.com                     Perl programming
>     Fort Worth, Texas
>

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


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

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


Administrivia:

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

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

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

	subscribe perl-users
or:
	unsubscribe perl-users

to almanac@ruby.oce.orst.edu.  

To submit articles to comp.lang.perl.misc (and this Digest), send your
article to perl-users@ruby.oce.orst.edu.

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

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

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

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

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


------------------------------
End of Perl-Users Digest V8 Issue 5497
**************************************

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