[13238] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 648 Volume: 9

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Aug 26 03:07:32 1999

Date: Thu, 26 Aug 1999 00:05:15 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Thu, 26 Aug 1999     Volume: 9 Number: 648

Today's topics:
        Beginner--where to find info about debugging report-wha <spinne1@mindspring.com>
    Re: Beginner--where to find info about debugging report (Abigail)
    Re: Converting a decimal number to hex (Larry Rosler)
    Re: Desperately searching for perl lint (T. Alex Beamish)
    Re: email address verification <webmaster@mendonet.com>
        grab random image --> post into browser (David Ford)
    Re: How to "unoverride" functions? (pgmr)
    Re: How to "unoverride" functions? (Abigail)
    Re: How to Detect that a Process is running already (Bill Moseley)
    Re: Jenda's gender [was: newbi: Registry Help under NT] (Iain Chalmers)
        Need to get number of days in a specific month (Need Help)
    Re: Need to get number of days in a specific month (elephant)
    Re: Need to get number of days in a specific month <rra@stanford.edu>
        passing hidden varible between scripts kidbunny@my-deja.com
    Re: Perl a Black Sheep? ***offtopic rant*** <ltl@rgsun40.viasystems.com>
        perl in bash functions (Eric Smith)
    Re: Programming Question.. List/Email functions (Abigail)
    Re: redirecting outputs (Larry Rosler)
    Re: redirecting outputs (elephant)
    Re: redirecting outputs (elephant)
    Re: SSN format (Larry Rosler)
    Re: Strange -e behaviour.. <davidj@zipworld.net>
    Re: The extent of double-quotish interpolation (elephant)
        Truncating Lines In File By Timestamp <webmaster@mendonet.com>
        Digest Administrivia (Last modified: 1 Jul 99) (Perl-Users-Digest Admin)

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

Date: Thu, 26 Aug 1999 01:08:59 +0000
From: Brien Campbell <spinne1@mindspring.com>
Subject: Beginner--where to find info about debugging report-what to do now?
Message-Id: <37C493AC.FE8@mindspring.com>

I am the person assigned to administer my school organization's student
UNIX account at UT-Knoxville.  A few weeks ago I knew nothing of HTML or
scripting.  I have spent day and night learning and am close to
completing our web site.  

On the web site I'm building, I've installed four scripts.  Two work,
two do not work.  I use a Mac and use Fetch to ftp the files up in
either text or raw data format.  I then use BetterTelnet to set the
permissions for the directories and files as instructed in the docs for
each script.  I've run the debugging program that comes on our server. 
We are running Perl5.003 and using cgiwrap.  Error messages include (all
brackets:[] are added by me for explanatory purposes):

"String found where operator expected at [location on our server] line
(Missing operator before [various info depending on line])"
"Bare word found where operator expected at [location on our server]
line
(Missing operator before [various info depending on line])"
"Number found where operator expected at [location on our server] line
(Missing operator before [various info depending on line])"
"Scalar found where operator expected at [location on our server] line
(Missing operator before [various info depending on line])"
"Literal @raw now requires backslash at [location on our server] line
[x], within string"
 
I've read several FAQs on the net and have not come up with a specific
listing of error messages and what to do about them for beginners. 
Maybe such a thing doesn't exist.  I'd really like to obtain such a
document if it exists.

I don't really want to learn how to program Perl or CGI just to run
programs at my web site.  Help, please!

Brien


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

Date: 26 Aug 1999 00:15:58 -0500
From: abigail@delanet.com (Abigail)
Subject: Re: Beginner--where to find info about debugging report-what to do now?
Message-Id: <slrn7s9je2.lhu.abigail@alexandra.delanet.com>

Brien Campbell (spinne1@mindspring.com) wrote on MMCLXXXVI September
MCMXCIII in <URL:news:37C493AC.FE8@mindspring.com>:
``  
`` I've read several FAQs on the net and have not come up with a specific
`` listing of error messages and what to do about them for beginners. 


You shouldn't be looking on the net. You should look on your very own
cozy harddisk. "man perldiag".

You should also upgrade to 5.005_03. 



Abigail
-- 
sub _'_{$_'_=~s/$a/$_/}map{$$_=$Z++}Y,a..z,A..X;*{($_::_=sprintf+q=%X==>"$A$Y".
"$b$r$T$u")=~s~0~O~g;map+_::_,U=>T=>L=>$Z;$_::_}=*_;sub _{print+/.*::(.*)/s}
*_'_=*{chr($b*$e)};*__=*{chr(1<<$e)};
_::_(r(e(k(c(a(H(__(l(r(e(P(__(r(e(h(t(o(n(a(__(t(us(J())))))))))))))))))))))))


  -----------== Posted via Newsfeeds.Com, Uncensored Usenet News ==----------
   http://www.newsfeeds.com       The Largest Usenet Servers in the World!
------== Over 73,000 Newsgroups - Including  Dedicated  Binaries Servers ==-----


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

Date: Wed, 25 Aug 1999 21:08:22 -0700
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: Converting a decimal number to hex
Message-Id: <MPG.122e5d929f90ab9b989ea9@nntp.hpl.hp.com>

[Posted and a courtesy copy sent.]

In article <37c4aeee@news.ausmail.com> on Thu, 26 Aug 1999 13:05:24 
+1000, Andrew Pollock <apollock@bit.net.au> says...
> I need to convert a decimal number to hex (and store the string
> representation of the hex number in a variable).
> 
> I can go
> printf("%x", time)
> but that doesn't store it anywhere ...

perldoc -f sprintf

You might want to consider formats such as '%8.8x' or '%8.8X'.

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


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

Date: Thu, 26 Aug 1999 04:31:50 GMT
From: talexb@tabsoft.on.ca (T. Alex Beamish)
Subject: Re: Desperately searching for perl lint
Message-Id: <37c4c19f.281564252@news1.on.sympatico.ca>

On 25 Aug 1999 21:20:29 -0000, Jonathan Stowe
<gellyfish@gellyfish.com> wrote:

>On Wed, 25 Aug 1999 18:43:22 GMT T. Alex Beamish wrote:
>> On 24 Aug 1999 15:44:23 +0100, Jonathan Stowe
>> <gellyfish@gellyfish.com> wrote:
>> 
>>>the -w switch and 'use strict;'
>>>
>>>(and possibly the -c switch if you dont want to actually run the program)
>> 
>> I'm using both of those already. That's like using \W4 under the MS C
>> compiler. I'm trying to find a good lint for perl.
>
>I think then perhaps you should explain what this fabled linter is
>supposed to do in addition to those flags?
>
>Of course Abigail has already pointed out the B::Lint module - this will
>take options that allow varying degrees of pickiness - using the 'all'
>option would probably not be something anyone would want to do as it
>will complain about things that most people would consider idiomatic
>Perl.

Jonathan,

Here's one thing that pops to mind: telling me that a variable that
I've declared is not used. Great for cleaning up variables that were
used in a previous version of the code.

Another would be telling me that a variable is only used in a certain
smaller scope that one that it is declared in .. I'm a huge fan of
declaring variables used only where necessary. I cringe when I see
dozens of variables declared at the top of a module when they're only
used between lines 800 and 840.

[negotiate steps up to soap box]
It's not even a perl thing, it's a software development thing. The
lint I used from Gimpel software was great for a shake-and-bake
approach to code cleanup (MS C [yechh, gimme Borland any day] for the
IBM PC under DOS). If it compiled cleanly, linted cleanly and
everything behaved properly in the debugger, I could be confident that
it would work well in the field. Takes a little longer but quality
development does take longer.
[clamber down from the lofty heights of soap box]

Thank you all .. since the "perl -MO=Lint -Mstrict -w" that Abigail
suggested didn't work on the Linux platform I'm using, I will see if I
can write something myself.
T. Alex Beamish, Principal -- TAB Software
  Toronto, Ontario -- www.tabsoft.on.ca


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

Date: Wed, 25 Aug 1999 20:59:13 -0700
From: Jon Hollcraft <webmaster@mendonet.com>
Subject: Re: email address verification
Message-Id: <37C4BB91.2A5C@mendonet.com>

David Cassell wrote:
> 
> Jon Hollcraft wrote:
> [a bunch of code]
> 
> Jon, this does *not* verify e-mail addresses.  It does make a
> couple checks.  It does not catch a lot of improper addresses.
> It does reject some legal addresses.
> 
> I suppose you didn't read my earlier post in this thread.
> Check out better solutions mentioned therein.
> 
> HTH,
> David
> --
> David Cassell, OAO                     cassell@mail.cor.epa.gov
> Senior computing specialist
> mathematical statistician

David, I do appreciate your comments and understand what you are
expressing.  I would like to humbly point out that I labeled the sub
*validate* and not *verify* , both in the sub name and in the find it
line in my code.

My criteria is speed and security.  For my purposses with this program,
the trade off is allowing 200 million addresses in quickly with out any
funny business characters, while disallowing 10K or whaterever there
might be, of addresses which the filter disallows.  To load a 5K module
to catch all the others just isn't indicated.  It does sound pretty
provocative thought, and I will take a look at it; perhaps for another
application.

So that's my excuse, and I'm stickin' to it ;-)  Jon


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

Date: 25 Aug 1999 23:20:22 PDT
From: david_lee_ford@my-Deja.com (David Ford)
Subject: grab random image --> post into browser
Message-Id: <david_lee_ford-2508992319320001@ts010d16.lax-ca.concentric.net>

Hello,

I am totally new at this, and am hoping to find the answer here.

I need a CGI script that will grab a random image from a directory and
post it into a preset location on a WWW page.  I need for the image to
refresh and randomize upon every page reload.  The trick is that it has to
work the same in Netscape and Explorer.  A friend of mine came up with
what we thought would be a working script until we ran into the following
problem:

When the "reload" button is hit in Explorer, the entire contents of the
page reload (along with the image file).  This is what we want.  By
contrast, however, Netscape only "reloads" the cached version of the page
(in other words, neither the page or the image are RE-loaded at all --
only the cache contents are "reloaded").  This is not acceptable.  I need
for Netscape to perform a full reload of the page (and to obtain a
fresh/random image) upon hitting the "reload" button.  What is the
solution here?

I have heard that due to Netscape's tendency to "see" this CGI script as
an image (and thus load it into cache), my best solution for this problem
is Javascript instead of a CGI script.  Supposedly (in this case),
Javascript would "force" a reload in every browser.  Is this true?

Thank you for any help which you could offer.

David Ford
Costa Mesa, California


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

Date: Thu, 26 Aug 1999 06:26:24 GMT
From: a@b.com (pgmr)
Subject: Re: How to "unoverride" functions?
Message-Id: <B43BCC86733D1FAA.42EB123752F3566F.9F429464E304C6B4@lp.airnews.net>

You lost me with your jeopardy comments, however when you stated you
had answered my question, I went back and took a look at your reply
once again.  My apologies.  I missed that line before and thought you
were a newbie who was trying to be helpful, but had misunderstood or
were some netkook - as there are plenty about.

Again, thanks for the answer.


On 25 Aug 1999 17:48:32 -0500, abigail@delanet.com (Abigail) wrote:

>
>I would have pointed out the error in your statement if you hadn't
>insisted on posting jeopardy style, as I did tell you what you need
>to do. However, Jeopardist won't get an answer for me - they seek
>questions.
>
>
>
>Abigail



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

Date: 26 Aug 1999 01:47:39 -0500
From: abigail@delanet.com (Abigail)
Subject: Re: How to "unoverride" functions?
Message-Id: <slrn7s9opv.lhu.abigail@alexandra.delanet.com>

pgmr (a@b.com) wrote on MMCLXXXVI September MCMXCIII in
<URL:news:B43BCC86733D1FAA.42EB123752F3566F.9F429464E304C6B4@lp.airnews.net>:
~~ You lost me with your jeopardy comments, however when you stated you

You put replies before what you reply to. Most people don't think
nor read backwards. What you do is utterly confusing. Please stop
that irritating behaviour.

~~ had answered my question, I went back and took a look at your reply
~~ once again.  My apologies.  I missed that line before and thought you
~~ were a newbie who was trying to be helpful, but had misunderstood or

Thinking that I'm a newbie. That's cute. You must be new here.

~~ were some netkook - as there are plenty about.



Abigail
-- 
perl -we 'print split /(?=(.*))/s => "Just another Perl Hacker\n";'


  -----------== Posted via Newsfeeds.Com, Uncensored Usenet News ==----------
   http://www.newsfeeds.com       The Largest Usenet Servers in the World!
------== Over 73,000 Newsgroups - Including  Dedicated  Binaries Servers ==-----


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

Date: Wed, 25 Aug 1999 21:23:30 -0700
From: moseley@best.com (Bill Moseley)
Subject: Re: How to Detect that a Process is running already
Message-Id: <MPG.122e6119a12279f9896d7@nntp1.ba.best.com>

John Nolt (baghera@mindspring.net) seems to say...
> Hi,
> 
> I'm hoping that this is a simple question.
> 
> I want to create a CGI that runs a perl script. However, if that perl
> script is already running, I want to pop up a message that says
> something to the effect of "I'm sorry, the script is already running.
> Try again later."

Sounds like what you really want it to make sure only one person can use 
the CGI script at a time??

perldoc -f flock
and check the FAQ on lock files.

perlipc does talk about sending kill 0 to a process to check if it's 
alive.  But it doesn't sound like that's what you want.

-- 
Bill Moseley mailto:moseley@best.com
pls note the one line sig, not counting this one.


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

Date: Wed, 25 Aug 1999 21:16:09 -0700
From: bigiain@mightymedia.com.au (Iain Chalmers)
Subject: Re: Jenda's gender [was: newbi: Registry Help under NT]
Message-Id: <bigiain-2508992116090001@dhcp-135.goop.org>

In article <MPG.122f5a09aa928d3f989c80@news-server>,
elephant@squirrelgroup.com (elephant) wrote:

> ( I guess I'll have to go back to dreaming about Abigail *8^)

bwah ha ha ha ha!!!

big


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

Date: Wed, 25 Aug 1999 09:26:53 GMT
From: needhelp@help.com (Need Help)
Subject: Need to get number of days in a specific month
Message-Id: <37c3b6a5.89153780@news.isdn.net.il>

Hi,

How can I get the number of days in a specific month?
Lets say I need to know how many days are going to be in February
2005.

Thanks


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

Date: Thu, 26 Aug 1999 15:57:10 +1000
From: elephant@squirrelgroup.com (elephant)
Subject: Re: Need to get number of days in a specific month
Message-Id: <MPG.122f823eaa303e95989c85@news-server>

Need Help writes ..
>How can I get the number of days in a specific month?
>Lets say I need to know how many days are going to be in February
>2005.

February being the only one that changes you really want to know whether 
the year in question is a leap year or not

search back (about two weeks ago - from memory) there was a reasonable 
sized discussion of leap years here in this newsgroup

-- 
 jason - elephant@squirrelgroup.com -


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

Date: 25 Aug 1999 23:25:58 -0700
From: Russ Allbery <rra@stanford.edu>
Subject: Re: Need to get number of days in a specific month
Message-Id: <ylyaez83d5.fsf@windlord.stanford.edu>

Need Help <needhelp@help.com> writes:

> How can I get the number of days in a specific month?  Lets say I need
> to know how many days are going to be in February 2005.

# Takes the number of the month (range 1-12) and the year, returns the
# number of days in that month.  There are lots of very good, clear, and
# boring ways of solving this problem that would be maintainable and
# suitable for production code, like a table of month numbers and the
# days in each month, with February handled specially.  This isn't one of
# them.
sub days_in_month {
    my ($month, $year) = @_;
    30 + ($month + ($month > 7)) % 2 - ($month == 2)
     * (2 - ($year % 4 == 0 && ($year % 100 != 0 || $year % 400 == 0)));
}

-- 
#!/usr/bin/perl -- Russ Allbery, Just Another Perl Hacker
$^=q;@!>~|{>krw>yn{u<$$<[~||<Juukn{=,<S~|}<Jwx}qn{<Yn{u<Qjltn{ > 0gFzD gD,
 00Fz, 0,,( 0hF 0g)F/=, 0> "L$/GEIFewe{,$/ 0C$~> "@=,m,|,(e 0.), 01,pnn,y{
rw} >;,$0=q,$,,($_=$^)=~y,$/ C-~><@=\n\r,-~$:-u/ #y,d,s,(\$.),$1,gee,print


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

Date: Thu, 26 Aug 1999 05:34:04 GMT
From: kidbunny@my-deja.com
Subject: passing hidden varible between scripts
Message-Id: <7q2jkc$37p$1@nnrp1.deja.com>

Is it possible for a first cgi script (written in
PERL), that generates a HTML form to pass along a
hidden varible (so it's not shown in the
navigation bar) to the second cgi script when the
form is posted?

Something like...

print "<form method=post
action=%%/cgi-bin/secondscript.cgi%%>";
print "<input type=%%hidden%% name=%%notseen%%
value=%%,$secertid,%%";
print "<input type=submit name=%%callnextcgi%%
value=%%go%%>";


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


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

Date: 26 Aug 1999 04:26:02 GMT
From: lt lindley <ltl@rgsun40.viasystems.com>
Subject: Re: Perl a Black Sheep? ***offtopic rant***
Message-Id: <7q2fkq$593$1@rguxd.viasystems.com>

Eric Bohlman <ebohlman@netcom.com> wrote:
:>Ala Qumsieh (aqumsieh@matrox.com) wrote:
:>: There is a problem with some of the "older" programmers. They learnt C
:>: (or some other useful language), and are comfortable with it although
:>: programming simple things with it (like opening files, and
:>: manipulating their contents) can be a real pain in the ass. They

:>I'd be willing to bet that a big part of the problem is that someone 
:>who's learned how to jump through hoops and bang his head against the 
:>wall in order to accomplish relatively simple tasks isn't going to be 
:>very comfortable learning that there's a way to accomplish those tasks 
:>with far less effort.  It makes him feel like all his effort was worthless.

[snip parable]

Ha!  If the geezers were any good at what they learned, they now
embrace Perl and use its strengths where they are appropriate.  Hell,
those old geezers implemented and continue to enhance Perl in that
"pain in the ass" language you (Ala) denigrate.

Don't presume to understand your elders.  Your life experience is not
yet rich enough to appreciate all of the factors that go into their
prejudices (and won't be until you have the same prejudices :-).
There are perfectly valid reasons why they are concerned about a
"free lunch" from Perl.  It is true that Perl takes care of many
details and makes things easy.  But masking complexity does not
eliminate it.  Most of the time you will be right and the
complexities of the lower level languages are not worth the trouble.
The trick is having the knowledge (experience?) to know when it does
matter.

You were both writing about your interpretation of what may have
motivated some people whose behavior did not fit your world model.
You then tried to rationalize and generalize their behavior.  This is
a normal kind of short hand calculus people go through to get a
handle on the world (I may even be guilty of it now :-).  And as
applied to the fairly obvious and already commented upon conflicing
interests of the "counsellor" who was the original subject of this
thread, I shouldn't have gone off about it; but, you struck a nerve
with me, however unintentionally.  Old and stubborn does not equal
stupid (necessarily :-).  I suppose that I am on my way to
curmodgeonhood.  I'm certainly on my way to old.

Maybe I'll just do a ":q" now.   Nope.  I reread both your posts
and mine is no more offensive than yours.

-- 
// Lee.Lindley   /// Programmer shortage?  What programmer shortage?
// @bigfoot.com  ///  Only *cheap* programmers are in short supply.
////////////////////    50 cent beers are in short supply too.


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

Date: 26 Aug 1999 06:48:39 GMT
From: eric@fruitcom.com (Eric Smith)
Subject: perl in bash functions
Message-Id: <slrn7s9oq6.978.eric@plum.fruitcom.com>

Hi

May one use perl code in a bash function and pass the command line args of
the function to the perl "script"?

-- 
Eric Smith
eric@fruitcom.com
www.fruitcom.com


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

Date: 26 Aug 1999 01:24:54 -0500
From: abigail@delanet.com (Abigail)
Subject: Re: Programming Question.. List/Email functions
Message-Id: <slrn7s9nfb.lhu.abigail@alexandra.delanet.com>

Delarock (netdevilx@aol.com) wrote on MMCLXXXVI September MCMXCIII in
<URL:news:19990825224816.08941.00004558@ng-bg1.aol.com>:
?? I'm using Perl 4.0.

And the original 7th edition of Unix, lava lamps, and UUCP for your mail
and news?

?? How do you put a variable (or a list of variables) into a perl email syntax?
?? (open MAIL, print MAIL, close MAIL)

Perl email syntax? Hmmm, that must be new in perl4.0.

?? Any help with these commands would be appreciated.

I'd suggest you upgrade, and then figure out what question you want to ask.



Abigail
-- 
perl5.004 -wMMath::BigInt -e'$^V=Math::BigInt->new(qq]$^F$^W783$[$%9889$^F47]
 .qq]$|88768$^W596577669$%$^W5$^F3364$[$^W$^F$|838747$[8889739$%$|$^F673$%$^W]
 .qq]98$^F76777$=56]);$^U=substr($]=>$|=>5)*(q.25..($^W=@^V))=>do{print+chr$^V
%$^U;$^V/=$^U}while$^V!=$^W'


  -----------== Posted via Newsfeeds.Com, Uncensored Usenet News ==----------
   http://www.newsfeeds.com       The Largest Usenet Servers in the World!
------== Over 73,000 Newsgroups - Including  Dedicated  Binaries Servers ==-----


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

Date: Wed, 25 Aug 1999 21:29:14 -0700
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: redirecting outputs
Message-Id: <MPG.122e627649813cb1989eab@nntp.hpl.hp.com>

In article <Pine.BSF.4.10.9908252000060.24651-
100000@soda.CSUA.Berkeley.EDU> on Wed, 25 Aug 1999 20:06:51 -0700, Dan 
Schneider <dcs@NOSPAM.csua.berkeley.edu> says...
> I can't seem to solve this problem: I want STDERR to be redirected into
> STDOUT, so that if I do a piped "open" on a Unix program, its STDERR will
> also be piped and not output to the terminal.  I can do this using the
> shell's 2>&1 thingie but I would like a way to have Perl do this if
> possible.

perlfaq5: "How do I dup() a filehandle in Perl?"

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


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

Date: Thu, 26 Aug 1999 15:11:40 +1000
From: elephant@squirrelgroup.com (elephant)
Subject: Re: redirecting outputs
Message-Id: <MPG.122f7793bf99a593989c83@news-server>

Dan Schneider writes ..
>I can't seem to solve this problem: I want STDERR to be redirected into
>STDOUT, so that if I do a piped "open" on a Unix program, its STDERR will
>also be piped and not output to the terminal.  I can do this using the
>shell's 2>&1 thingie but I would like a way to have Perl do this if
>possible.

it's a puzzle how you can know what to do in the shell but not in Perl 
 .. this question is usually asked the other way around

all you're doing with the 2 >&1 thing is using the shell's behaviour of 
assigning the STDERR handle to '2' and the STDOUT handle to '1' .. in 
Perl you just use the named handles themselves

  open( STDERR, '>&STDOUT') || die "Bad STDERR redirect: $!\n";

-- 
 jason - elephant@squirrelgroup.com -


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

Date: Thu, 26 Aug 1999 15:15:17 +1000
From: elephant@squirrelgroup.com (elephant)
Subject: Re: redirecting outputs
Message-Id: <MPG.122f787332a861e6989c84@news-server>

Larry Rosler writes ..
>In article <Pine.BSF.4.10.9908252000060.24651-
>100000@soda.CSUA.Berkeley.EDU> on Wed, 25 Aug 1999 20:06:51 -0700, Dan 
>Schneider <dcs@NOSPAM.csua.berkeley.edu> says...
>> I can't seem to solve this problem: I want STDERR to be redirected into
>> STDOUT, so that if I do a piped "open" on a Unix program, its STDERR will
>> also be piped and not output to the terminal.  I can do this using the
>> shell's 2>&1 thingie but I would like a way to have Perl do this if
>> possible.
>
>perlfaq5: "How do I dup() a filehandle in Perl?"

even better .. couldn't find it under 'redirect' and that little 'dup' 
word had escaped from my brain

-- 
 jason - elephant@squirrelgroup.com -


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

Date: Wed, 25 Aug 1999 21:23:29 -0700
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: SSN format
Message-Id: <MPG.122e611428cecdd3989eaa@nntp.hpl.hp.com>

In article <slrn7s9f18.lhu.abigail@alexandra.delanet.com> on 25 Aug 1999 
23:00:53 -0500, Abigail <abigail@delanet.com> says...
> Blair Chesnut (blair_chesnut@ncsu.edu) wrote on MMCLXXXV September
> MCMXCIII in <URL:news:7q1k32$pvj$1@uni00nw.unity.ncsu.edu>:
> || What's an "efficient" way to format an integer into an SSN string?
> || For example, 12345 -> "000-01-2345".
> 
> That's depends what you find "efficient". If you don't mind a bit
> of preprocessing, and the use of some memory, a lookup table
> is the fastest.
> 
>     my @table = map {my $a = $_; map {"$_-$a"} '0000' .. '9999'}
>                 map {my $a = $_; map {"$_-$a"}   '00' ..   '99'}
>                                                 '000' ..  '999';
> 
>     print $table [12345];

I assume you tested that before posting it.  :-0

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


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

Date: Thu, 26 Aug 1999 14:15:30 +1000
From: "David James" <davidj@zipworld.net>
Subject: Re: Strange -e behaviour..
Message-Id: <7q2erd$sfu$1@the-fly.zip.com.au>

[cc'd to original poster]

Hi,

Alex Krohn <alex@krohn.org> wrote in message
news:37c4a863.548911933@news.supernews.com...
<snip>
> hits:~$ perl -MCGI -e "print $CGI::VERSION"
> hits:~$

Most likely your shell thinks the $ is part of a shell variable. If you
escape the $:

perl -MCGI -e "print \$CGI::VERSION"

this should work.

Hope this helps,

David




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

Date: Thu, 26 Aug 1999 14:55:39 +1000
From: elephant@squirrelgroup.com (elephant)
Subject: Re: The extent of double-quotish interpolation
Message-Id: <MPG.122f73d427cbb620989c82@news-server>

Alan Curry writes ..
>In article <7q1ns6$7qf$1@charm.magnus.acs.ohio-state.edu>,
>Ilya Zakharevich <ilya@math.ohio-state.edu> wrote:
>>[A complimentary Cc of this posting was sent to Alan Curry
>><pacman@defiant.cqc.com>],
>>who wrote in article <KKYw3.24595$x04.1456615@typ11.nn.bcandid.com>:
>>> print "$i";
>>> print "$a[0]";
>>> print "@a";
>>> print "$i+1";
>>> print "$a[$i+1]";
>>> print "$a[$i+1]+1";
>>> print "$f->()+1";
>>
>>I would think that this one is the only one which might be
>>hard-to-predict, all the rest is straightforward: arrays and scalars
>>constructed using $, blocks, [], {}, ->[] and ->{} are interpolated if
>>no whitespace between the tokens intervene.
>
>Let me add a couple more fun ones:
>
>my %h=(foo=>'bar', bar=>'baz');
>my $s='foo';
>
>print "$h{'foo'}";
>print "$h{$s}";
>print "$h{$h{$s}}";
>print "$h{\"$h{$s}\"}";

so far - the only one that got me was the "$f->()+1" .. but that was 
mainly because I was stupid .. seeing what was produced made sense 
instantly

>Anybody else surprised by the last one?

nope

>I'm trying to get at some clear, unambiguous documentation of what gets
>interpolated and what doesn't. The starting points are easy to define. easy
>to spot. It's either a $ or a @ followed by either an symbol name or a {.
>But the ending point of an interpolation is really hard to pin down with such
>a simple rule.

in string context it's important NOT to think of the subscript operator 
(as well as the hash element operator) like an operator (it's not in 
perlop for a reason) .. it's just part of the variable .. there's no $a 
variable that you're evaluating with the [] operator

this can be seen with this code

  #!/usr/bin/perl -w
  use strict;

  my $a = 'xyz';
  print "$a[3]";		# nope - compile time error
  print "${a}[3]";		# also no go
  print "$a"."[3]";		# finally
  __END__

with that in mind .. I think I may have your rule for you: the variables 
in a string are interpolated .. but no operators are evaluated - UNLESS 
- the interpolation of another variable demands a value from an operator

I'll go through each non-simple example with the above rule in mind 
(comments after the example)

  print "$i+1";

the $i is interpolated .. but the + operator is not evaluated because no 
other variable interpolation requires it

  print "$a[$i+1]";

the $i is interpolated .. then the $a[1+1] is interpolated .. that 
second interpolation requires the + operator to be evaluated (can't have 
a string array index) so it is .. then $a[2] is interpolated

  print "$a[$i+1]+1";

same as above .. except once $a[2] is interpolated no other operations 
are done as in "$i+1"

  print "$f->()+1";

the only one that threw initially (before I made up the rule) .. you get 
so used to references being the value of the thing they reference rather 
than a value all their own .. so anyway .. $f is interpolated .. the -> 
operator is not evaluated because $f has a string value so no further 
operations need to be done in order for print to work

  print "$r->[1]";

this example clearly shows that my rule needs a slight ammendment .. 
with my rule this should print "ARRAY(0xblah)->[1]" .. because the 
operator is the '->' .. but clearly Perl is being clever here and binds 
tightly to the [] operators hence this is treated just as if it was 
$a[1] .. possibly inconsistent - but not if you use your imagination

the rule should probably be adjusted to say that in a string Perl will 
try everything it can to evaluate an array index or hash key .. but 
performs no other operator evaluations unless that evaluation is needed 
for an index/key .. shrug

  print "$a[$f->()+1]+1";

back to the rule .. $a[blah] needs to be interpolated so blah is 
evaluated in a non-string context giving $a[4+1] .. then $a[5] .. then 
50 .. the + operator is not evaluated for reasons already mentioned

  print "@a[2..$f->()]";

same as above .. except it's the .. operator instead of the + operator

my %h=(foo=>'bar', bar=>'baz');
my $s='foo';

  print "$h{'foo'}";

QED

  print "$h{$s}";

QED

  print "$h{$h{$s}}";

again .. meets the rule perfectly .. $h{something} needs interpolation 
 .. so something is interpolated - $h{$s} needs inerpolation so $s is 
done .. then it backs out

  print "$h{\"$h{$s}\"}";

you were surprised by this ? .. because there are extra double quotes ? 
 .. what did you want to be printed $h{"bar"} ?? .. it's still possible 
to interpolata that further .. hence the 'baz' output

>perlop just says this:
>
>       For constructs that do interpolation, variables beginning
>       with "$" or "@" are interpolated
>
>"$a[2..$f->()]" is not just a "variable beginning with $ or @". It's a
>complex expression (involving a function call!). Being inside brackets must
>give it special status. But perlop doesn't say anything about that. I want to
>know exactly how the interpreter decides where to stop interpolating. A
>regexp that takes a string like q{$a[2..$f->()]junk} and returns the portion
>before the "junk" would be ideal :)

you're right there .. the doco seems to be quite sparse on this topic

-- 
 jason - elephant@squirrelgroup.com -


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

Date: Wed, 25 Aug 1999 23:27:57 -0700
From: Jon Hollcraft <webmaster@mendonet.com>
Subject: Truncating Lines In File By Timestamp
Message-Id: <37C4DE6D.5A3E@mendonet.com>

Boulders on the path.  I need to truncate or tail a logfile using a time
stamp as
a means to determine when that particular line was written.  If it is
older than
a certain number of days, the line should be whacked.

This either appends, doubles, or wipes; but not truncate.  Any
suggestions will be
sincerely appreciated.   TIA  Jon

A sample logfile line:
935646781 - 204.149.026.229 - 375MebxykillY - Wednesday, August 25, 1999
at 22:53:01

	{
	$time=time;
	$posttime=($time - $passtimeout);  #Current epoch time minus config
default 60 secs
	$keeptime=($keepkeys * 86400);  #Number of days to keep log data 30
	$culltime=($posttime - $keeptime);
	open(KEYS,"+< $keys") || die print "Cannot Open Keys For Update: $!\n";
	flock(KEYS, 2);
	@loglines=<KEYS>;
	$loglines[$x]="printf(KEYS / -
/,$sendtime,$envremadd1,$logkey,$fuldate)"; 
	foreach $logline(@loglines)
		{
		chomp($logline);
		unless($sendtime < $culltime)  #unless too old, print to logline
			{
			print KEYS "$logline\n";
			}
		}
	close(KEYS);
	}


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

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


Administrivia:

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

	subscribe perl-users
or:
	unsubscribe perl-users

to almanac@ruby.oce.orst.edu.  

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

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

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

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

The "mini-FAQ", which is an updated version of the Meta-FAQ, is
available by requesting "send perl-users mini-faq" from
almanac@ruby.oce.orst.edu. 

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


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


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