[25288] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 7533 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sat Dec 18 18:05:49 2004

Date: Sat, 18 Dec 2004 15:05:10 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Sat, 18 Dec 2004     Volume: 10 Number: 7533

Today's topics:
    Re: [Q] $ARGV, <>, and command-line Perl <someone@example.com>
    Re: [Q] $ARGV, <>, and command-line Perl <jkrugman345@yahbitoo.com>
        Brian? [Was: FAQ 4.36: How can I expand variables in te (Anno Siegel)
    Re: Brian? [Was: FAQ 4.36: How can I expand variables i <nobull@mail.com>
    Re: Brian? [Was: FAQ 4.36: How can I expand variables i (Anno Siegel)
    Re: Brian? [Was: FAQ 4.36: How can I expand variables i <comdog@panix.com>
    Re: Brian? [Was: FAQ 4.36: How can I expand variables i (Anno Siegel)
    Re: Brian? [Was: FAQ 4.36: How can I expand variables i <dha@panix.com>
    Re: Brian? [Was: FAQ 4.36: How can I expand variables i <flavell@ph.gla.ac.uk>
    Re: Consecutive Numbers (Anno Siegel)
    Re: Consecutive Numbers <abigail@abigail.nl>
        Finding out if another copy of a CGI Perl scripts is ru <dlr93612@yahoo.com>
    Re: Need to spawn an FTP process thru PERL <tadmc@augustmail.com>
        Page can not be displayed... (Piet L.)
    Re: Page can not be displayed... <nobull@mail.com>
        Some Programing Needed (Murray J)
    Re: Some Programing Needed <1usa@llenroc.ude.invalid>
    Re: Some Programing Needed <sbryce@scottbryce.com>
    Re: Some Programing Needed <dha@panix.com>
    Re: Static Code Analysis Tools? <nobull@mail.com>
    Re: Static Code Analysis Tools? (Randal L. Schwartz)
        uninitialized value in substitution iterator (Aberrant)
    Re: uninitialized value in substitution iterator <noreply@gunnar.cc>
    Re: uninitialized value in substitution iterator public@aberrantairbrush.com
    Re: uninitialized value in substitution iterator <noreply@gunnar.cc>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Sat, 18 Dec 2004 16:16:36 GMT
From: "John W. Krahn" <someone@example.com>
Subject: Re: [Q] $ARGV, <>, and command-line Perl
Message-Id: <EJYwd.8934$dv1.6450@edtnps89>

bill wrote:
> In <cpskfc$m4q$1@sun3.bham.ac.uk> Brian McCauley <nobull@mail.com> writes:
> 
>>J Krugman wrote:
>>
>>> Is it possible to write a simple one-liner
>>>that cycles through all the lines of *each* of the files in named
>>>in @ARGV and prints the name of the file if at least one of its
>>>lines meets a condition?
> 
>>perl -ne 'print "$ARGV\n" if /whatever/ && !$seen{$ARGV}++'
> 
> Interesting topic.
> 
> I have two follow up questions regarding this:
> 
> 1. Is there a simple modification of this one-liner that would short
> circuit the unnecessary reading of lines when $seen{$ARGV} evaluates
> to true?

perl -ne'/whatever/&&print("$ARGV\n")&&close(ARGV)'


> 2. A related issue is the resetting of $. .  Suppose that I wanted
> to check for /whatever/ only within the first 10 lines of every
> file.

perl -ne'(1..10)&&/whatever/&&print("$ARGV\n")&&close(ARGV);eof&&close(ARGV)'



John
-- 
use Perl;
program
fulfillment


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

Date: Sat, 18 Dec 2004 19:05:51 +0000 (UTC)
From: J Krugman <jkrugman345@yahbitoo.com>
Subject: Re: [Q] $ARGV, <>, and command-line Perl
Message-Id: <cq1v2f$o52$1@reader2.panix.com>





As usual I've learned a huge deal from the responses I received to
my original post.  With Perl I'm in a perpetual state of rank
newbiehood, even though I've been programming in it for years.

Many thanks,

jill


-- 
To  s&e^n]d  me  m~a}i]l  r%e*m?o\v[e  bit from my a|d)d:r{e:s]s.



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

Date: 18 Dec 2004 10:31:28 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Brian? [Was: FAQ 4.36: How can I expand variables in text strings?]
Message-Id: <cq10u0$i77$1@mamenchi.zrz.TU-Berlin.DE>

brian d foy  <comdog@panix.com> wrote in comp.lang.perl.misc:

[snip, just piggy-backing]

Brian, I mailed you a few times, concerning TPR and a patch to the postfaq
script, but never heard back.  Got lost in a spam trap?

Anno


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

Date: Sat, 18 Dec 2004 10:54:43 +0000
From: Brian McCauley <nobull@mail.com>
Subject: Re: Brian? [Was: FAQ 4.36: How can I expand variables in text strings?]
Message-Id: <cq120p$o38$1@sun3.bham.ac.uk>


To the end of a long dialogue between two Brians, Anno Siegel appended:

> Brian, I mailed you a few times, concerning TPR and a patch to the postfaq
> script, but never heard back.  Got lost in a spam trap?

This bemused be until I looked at the attribution...

 > brian d foy  <comdog@panix.com> wrote in comp.lang.perl.misc:
 >
 > [snip, just piggy-backing]

Ah, you were talking to the other Brian.



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

Date: 18 Dec 2004 12:34:12 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Brian? [Was: FAQ 4.36: How can I expand variables in text strings?]
Message-Id: <cq1844$mgc$1@mamenchi.zrz.TU-Berlin.DE>

Brian McCauley  <nobull@mail.com> wrote in comp.lang.perl.misc:
> 
> To the end of a long dialogue between two Brians, Anno Siegel appended:
> 
> > Brian, I mailed you a few times, concerning TPR and a patch to the postfaq
> > script, but never heard back.  Got lost in a spam trap?
> 
> This bemused be until I looked at the attribution...
> 
>  > brian d foy  <comdog@panix.com> wrote in comp.lang.perl.misc:
>  >
>  > [snip, just piggy-backing]
> 
> Ah, you were talking to the other Brian.

Ah, sorry.  I didn't notice how ambiguous "Brian" is in this thread.

Anno


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

Date: Sat, 18 Dec 2004 08:56:06 -0600
From: brian d foy <comdog@panix.com>
Subject: Re: Brian? [Was: FAQ 4.36: How can I expand variables in text strings?]
Message-Id: <181220040856066256%comdog@panix.com>

In article <cq120p$o38$1@sun3.bham.ac.uk>, Brian McCauley
<nobull@mail.com> wrote:

> To the end of a long dialogue between two Brians, Anno Siegel appended:
> 
> > Brian, I mailed you a few times, concerning TPR and a patch to the postfaq
> > script, but never heard back.  Got lost in a spam trap?
> 
> This bemused be until I looked at the attribution...
> 
>  > brian d foy  <comdog@panix.com> wrote in comp.lang.perl.misc:
>  >
>  > [snip, just piggy-backing]
> 
> Ah, you were talking to the other Brian.

there is one brian and one Brian.  :)

yes, I got the patch that you sent and I'm actually working on
it right now.  As for the TPR thing, I got that too and it's
somewhere in the To Do list for today :)

-- 
brian d foy, comdog@panix.com
Subscribe to The Perl Review: http://www.theperlreview.com


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

Date: 18 Dec 2004 15:44:06 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Brian? [Was: FAQ 4.36: How can I expand variables in text strings?]
Message-Id: <cq1j86$sbd$1@mamenchi.zrz.TU-Berlin.DE>

brian d foy  <comdog@panix.com> wrote in comp.lang.perl.misc:
> In article <cq120p$o38$1@sun3.bham.ac.uk>, Brian McCauley
> <nobull@mail.com> wrote:
> 
> > To the end of a long dialogue between two Brians, Anno Siegel appended:
> > 
> > > Brian, I mailed you a few times, concerning TPR and a patch to the postfaq
> > > script, but never heard back.  Got lost in a spam trap?
> > 
> > This bemused be until I looked at the attribution...
> > 
> >  > brian d foy  <comdog@panix.com> wrote in comp.lang.perl.misc:
> >  >
> >  > [snip, just piggy-backing]
> > 
> > Ah, you were talking to the other Brian.
> 
> there is one brian and one Brian.  :)
> 
> yes, I got the patch that you sent and I'm actually working on
> it right now.  As for the TPR thing, I got that too and it's
> somewhere in the To Do list for today :)

Very well, and sorry for seeming impatient. I mailed from an account
I hadn't been using before.  It did work in tests, but you know how
it is...

Anno


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

Date: Sat, 18 Dec 2004 21:38:45 +0000 (UTC)
From: "David H. Adler" <dha@panix.com>
Subject: Re: Brian? [Was: FAQ 4.36: How can I expand variables in text strings?]
Message-Id: <slrncs98r5.2vj.dha@panix2.panix.com>

On 2004-12-18, Alan J. Flavell <flavell@ph.gla.ac.uk> wrote:
> On Sat, 18 Dec 2004, Anno Siegel wrote:
>
>> Ah, sorry.  I didn't notice how ambiguous "Brian" is in this thread.
>
> Only standing at the beginning of a sentence!  There'd be no
> mistaking brian anywhere else   ;-) SCNR.

The style guide makes no such exception for the beginning of sentences.

dha, sergeant-at-arms

-- 
David H. Adler - <dha@panix.com> - http://www.panix.com/~dha/
"You're on dry land! Squeaky Whale can't save you now!"
	- Stephen Cole


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

Date: Sat, 18 Dec 2004 16:25:36 +0000
From: "Alan J. Flavell" <flavell@ph.gla.ac.uk>
Subject: Re: Brian? [Was: FAQ 4.36: How can I expand variables in text strings?]
Message-Id: <Pine.LNX.4.61.0412181624520.21045@ppepc56.ph.gla.ac.uk>

On Sat, 18 Dec 2004, Anno Siegel wrote:

> Ah, sorry.  I didn't notice how ambiguous "Brian" is in this thread.

Only standing at the beginning of a sentence!  There'd be no
mistaking brian anywhere else   ;-) SCNR.


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

Date: 18 Dec 2004 13:24:42 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Consecutive Numbers
Message-Id: <cq1b2q$o4u$1@mamenchi.zrz.TU-Berlin.DE>

Matija Papec  <perl@my-header.org> wrote in comp.lang.perl.misc:
> X-Ftn-To: Anno Siegel 
> 
> >> sub is_arithmetic_sequence2 {
> >>     my $delta = shift;
> >>     while ( @_ > 1 ) {
> >>         (shift) + $delta == $_[ 0] or return 0;
> >
> >This is arguably wrong.  The Perl interpreter is free to evaluate
> >subexpressions in any order, so there is no guarantee that shift()
> >has happened before $_[ 0] is evaluated.  The result of the expression
> >is undefined, even though there was probably never a Perl interpreter
> >that did it the other way 'round.
> 
> Ah, so I'm living on the edge? Are there some other common cases where it
> comes to undefined results?

It happens every time an expression has a subexpression that has a
side-effect on other parts of the expression.  The problem is by no
means limited to Perl, though Perl may have more operations with
side-effects than other languages.  The scalar-modifying ++, --, +=,
*= and their ilk are candidates, as are the array-modifying operations
shift, unshift, pop, push and splice.  There are many more.

They can be used freely in any expression as long as the modified
object doesn't appear again in the same expression.  When it does,
there is no way of telling whether it is going to be used in its
original state or after modification.

Only a few languages (Lisp) commit themselves to a defined order of
evaluation of expressions.  Others wisely reserve the freedom of
changing the evaluation order at random.  This is wise because small
changes in the parsing technique (for sake of efficiency) may change
the order of evaluation in hard-to-predict ways.

Btw, the problem is worse in languages that have macro capabilities,
like C.  A macro can hide the fact that a subexpression appears more
than once.  The standard example is

    #define SQUARE( x, y) ((x)*(x))
    int i = 1;
    printf( "%d is not 4\n", SQUARE( ++i));

That looks entirely innocent, yet it prints "6 is not 4".

Anno


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

Date: 18 Dec 2004 22:04:26 GMT
From: Abigail <abigail@abigail.nl>
Subject: Re: Consecutive Numbers
Message-Id: <slrncs9aba.fj.abigail@alexandra.abigail.nl>

Anno Siegel (anno4000@lublin.zrz.tu-berlin.de) wrote on MMMMCXXVII
September MCMXCIII in <URL:news:cq1b2q$o4u$1@mamenchi.zrz.TU-Berlin.DE>:
??  Matija Papec  <perl@my-header.org> wrote in comp.lang.perl.misc:
?? > X-Ftn-To: Anno Siegel 
?? > 
?? > >> sub is_arithmetic_sequence2 {
?? > >>     my $delta = shift;
?? > >>     while ( @_ > 1 ) {
?? > >>         (shift) + $delta == $_[ 0] or return 0;
?? > >
?? > >This is arguably wrong.  The Perl interpreter is free to evaluate
?? > >subexpressions in any order, so there is no guarantee that shift()
?? > >has happened before $_[ 0] is evaluated.  The result of the expression
?? > >is undefined, even though there was probably never a Perl interpreter
?? > >that did it the other way 'round.
?? > 
?? > Ah, so I'm living on the edge? Are there some other common cases where it
?? > comes to undefined results?
??  
??  It happens every time an expression has a subexpression that has a
??  side-effect on other parts of the expression.  The problem is by no
??  means limited to Perl, though Perl may have more operations with
??  side-effects than other languages.  The scalar-modifying ++, --, +=,
??  *= and their ilk are candidates, as are the array-modifying operations
??  shift, unshift, pop, push and splice.  There are many more.
??  
??  They can be used freely in any expression as long as the modified
??  object doesn't appear again in the same expression.  When it does,
??  there is no way of telling whether it is going to be used in its
??  original state or after modification.
??  
??  Only a few languages (Lisp) commit themselves to a defined order of
??  evaluation of expressions.  Others wisely reserve the freedom of
??  changing the evaluation order at random.  This is wise because small
??  changes in the parsing technique (for sake of efficiency) may change
??  the order of evaluation in hard-to-predict ways.
??  
??  Btw, the problem is worse in languages that have macro capabilities,
??  like C.  A macro can hide the fact that a subexpression appears more
??  than once.  The standard example is
??  
??      #define SQUARE( x, y) ((x)*(x))
??      int i = 1;
??      printf( "%d is not 4\n", SQUARE( ++i));
??  
??  That looks entirely innocent, yet it prints "6 is not 4".


Well, the latter is bad because it has a side-effect - not because the
order of evaluation isn't fully defined. If you replace '++ i' in the
expression above with a function call that adds 1 to i and then returns
it, the order of evaluation is fully defined - but it will still print 6.



Abigail
-- 
   my $qr =  qr/^.+?(;).+?\1|;Just another Perl Hacker;|;.+$/;
      $qr =~  s/$qr//g;
print $qr, "\n";


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

Date: 18 Dec 2004 15:00:23 -0800
From: "Lisa" <dlr93612@yahoo.com>
Subject: Finding out if another copy of a CGI Perl scripts is running?
Message-Id: <1103410823.017720.48130@z14g2000cwz.googlegroups.com>

How would one go about finding out if another copy of a CGI Perl
scripts is running?

I want to set up a script to run as a cron job, starting about once a
minute, however, the first thing I want to do when the script starts is
to check and see if the last incarnation is still (highly unlikly but
could happen on very busy days) running and shut down if it is, so that
there is only one version of the script proccessing data.

Lisa



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

Date: Sat, 18 Dec 2004 05:43:42 -0600
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: Need to spawn an FTP process thru PERL
Message-Id: <slrncs85ve.2rg.tadmc@magna.augustmail.com>

A. Sinan Unur <1usa@llenroc.ude.invalid> wrote:
> "William Hymen" <t18_pilot@hotmail.spam.com> wrote in 
> news:oJLwd.2780$Z47.115@newsread2.news.atl.earthlink.net:
> 
> [ Top-posting fixed. Don't do that. ]


He was asked to stop that over a year ago, 
which explains why I did not see his post in this thread.


-- 
    Tad McClellan                          SGML consulting
    tadmc@augustmail.com                   Perl programming
    Fort Worth, Texas


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

Date: 18 Dec 2004 03:26:14 -0800
From: PietLaroy@hotmail.com (Piet L.)
Subject: Page can not be displayed...
Message-Id: <c47f81f6.0412180326.185c4e9b@posting.google.com>

Piet L. wrote:

>> Hey,
>> I'm working with IIS (Windows 2000).
>> I've create a virtual directory usr-cgi met link naar e:\cgi
>> It works all well when I run simple scripts, but with the following
script
>> I get a "Page can not be displayed" error.

 >> I know the script is working, because when I try it in DOS
 >> e:\cgi\finaal> perl orders.cgi
 >>
 >> I get the right output
 >>
 >> Problem is the http://localhost/usr-cgi/finaal/orders.cgi

>Most web server software will direct STDOUT from CGI scripts to a log
>file somewhere.  I've hardly ever used IIS but I think I'd remeber if
it
>were an exception.  Have you tried looking for such a log.

Yes I deed, the only thing I've learned is that the file ib20 was
created/changed at the moment I tried the link.
It is in c:\winnt\temp

That's all I know


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

Date: Sat, 18 Dec 2004 10:20:21 +0000
From: Brian McCauley <nobull@mail.com>
Subject: Re: Page can not be displayed...
Message-Id: <cq100c$n3v$1@sun3.bham.ac.uk>



Piet L. wrote:

> Hey,
> I'm working with IIS (Windows 2000).
> I've create a virtual directory usr-cgi met link naar e:\cgi
> It works all well when I run simple scripts, but with the following script
> I get a "Page can not be displayed" error.

 > I know the script is working, because when I try it in DOS
 > e:\cgi\finaal> perl orders.cgi
 >
 > I get the right output
 >
 > Problem is the http://localhost/usr-cgi/finaal/orders.cgi

Most web server software will direct STDOUT from CGI scripts to a log 
file somewhere.  I've hardly ever used IIS but I think I'd remeber if it 
were an exception.  Have you tried looking for such a log.



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

Date: 18 Dec 2004 10:15:21 -0800
From: murrayscs@sasktel.net (Murray J)
Subject: Some Programing Needed
Message-Id: <71f844a7.0412181015.168e5170@posting.google.com>

I am not sure if this is the proper group for this, however, I am sure
someone will redirect me if necessary.

I have an HTML page which is an image map with a 4 X 4 grid of 'hot
spots', linking to other HTML pages, each of which contains a large
(3200px X 2560px) image.  I would like to capture the co-ordinates of
the mouse at the instant  when it is clicked on the first image, 
apply some mathematics based on which 'hot spot' was clicked, and come
up with a new set of co-ordinates.  When the destination page is
opened, I would like the viewport to be at those new co-ordinates on
the 3200px X 2560px image on the page.

I suspect this will require some programing in languages I know
nothing about, and haven't the time to learn at the moment.

If anyone is interested in this project for the challenge and/or cash,
please give me a shout at bigmur77@hotmail.com .

Thanks,
Murray


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

Date: 18 Dec 2004 18:23:07 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: Some Programing Needed
Message-Id: <Xns95C38828F7FA0asu1cornelledu@132.236.56.8>

murrayscs@sasktel.net (Murray J) wrote in 
news:71f844a7.0412181015.168e5170@posting.google.com:

> I am not sure if this is the proper group for this, 

It is not.

> If anyone is interested in this project 

http://jobs.perl.org/

Sinan


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

Date: Sat, 18 Dec 2004 12:09:49 -0700
From: Scott Bryce <sbryce@scottbryce.com>
Subject: Re: Some Programing Needed
Message-Id: <vdSdnYG3RaPuHVncRVn-tg@comcast.com>

Murray J wrote:
> I am not sure if this is the proper group for this, however, I am sure
> someone will redirect me if necessary.

<snip>

> If anyone is interested in this project for the challenge and/or cash,
> please give me a shout at bigmur77@hotmail.com .

Try at alt.comp.perlcgi.freelance



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

Date: Sat, 18 Dec 2004 21:41:56 +0000 (UTC)
From: "David H. Adler" <dha@panix.com>
Subject: Re: Some Programing Needed
Message-Id: <slrncs9914.2vj.dha@panix2.panix.com>

On 2004-12-18, Murray J <murrayscs@sasktel.net> wrote:
> I am not sure if this is the proper group for this, however, I am sure
> someone will redirect me if necessary.

We live to serve. :-)

You have posted a job posting or a resume in a technical group.

Longstanding Usenet tradition dictates that such postings go into
groups with names that contain "jobs", like "misc.jobs.offered", not
technical discussion groups like the ones to which you posted.

Had you read and understood the Usenet user manual posted frequently to
"news.announce.newusers", you might have already known this. :)  (If
n.a.n is quieter than it should be, the relevent FAQs are available at
http://www.faqs.org/faqs/by-newsgroup/news/news.announce.newusers.html)
Another good source of information on how Usenet functions is
news.newusers.questions (information from which is also available at
http://www.geocities.com/nnqweb/).

Please do not explain your posting by saying "but I saw other job
postings here".  Just because one person jumps off a bridge, doesn't
mean everyone does.  Those postings are also in error, and I've
probably already notified them as well.

If you have questions about this policy, take it up with the news
administrators in the newsgroup news.admin.misc.

http://jobs.perl.org may be of more use to you

Yours for a better usenet,

dha

-- 
David H. Adler - <dha@panix.com> - http://www.panix.com/~dha/
I'm not a tramp... I'm an Episcopalian!
	- subbes


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

Date: Sat, 18 Dec 2004 10:40:19 +0000
From: Brian McCauley <nobull@mail.com>
Subject: Re: Static Code Analysis Tools?
Message-Id: <cq115p$nlj$1@sun3.bham.ac.uk>



Randal L. Schwartz wrote:

>>>>>>"Brian" == Brian McCauley <nobull@mail.com> writes:
> 
> 
> Brian> Beacuse Perl is not strongly typed
> 
> Well, for some definitions of "strongly typed". 

OK sorry for my sloppy teminiology.  I, of course, meant that you cannot 
in general know the type of an object at compile time.

 > Some would loudly disagree with you, for example.

Such loud disagreements always remind me of a passage from "Surely 
You're Joking Mr Feynman".

I was able to find this passage quoted on the net in the following 
"Letter to Professor Feynman".  It starts in the last paragraph of the 
3rd page (which is numbered page 442).

http://www.thoughtsandvisions.com/feynlet.pdf

Read and enjoy!



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

Date: 18 Dec 2004 06:26:20 -0800
From: merlyn@stonehenge.com (Randal L. Schwartz)
Subject: Re: Static Code Analysis Tools?
Message-Id: <1103380424.7af3bca412af397496cf127713669851@teranews>

>>>>> "Brian" == Brian McCauley <nobull@mail.com> writes:

Brian> OK sorry for my sloppy teminiology.  I, of course, meant that you
Brian> cannot in general know the type of an object at compile time.

For some meaning of "type".  You can certainly know whether it's
a scalar, array, hash, filehandle, dirhandle, or subroutine, because
the syntax enforces that.  $a is definitely a scalar.  @a is definitely
an array.

But no, you cannot determine user-defined type of a scalar until
runtime, true.  But even within that, you have strong typing.
You can't accidentally call a Foo method on a Bar object.  It doesn't
work.

So, Perl is strongly typed, but some is compile-time determined
(built-in types), and others are runtime determed (user-defined types).

-- 
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!


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

Date: 18 Dec 2004 13:02:46 -0800
From: public@aberrantairbrush.com (Aberrant)
Subject: uninitialized value in substitution iterator
Message-Id: <ca4f057d.0412181302.7f1fa36@posting.google.com>

What I'm trying to do is take %%variable%% in a file and replace it
with data returned by the subroutine substitute(). The code I have
looks like this:

$data =~ s/%%([^%]*)%%/&substitute($1)/ge;

And it does exactly what I want, but it also fills up my error log
with this:

"Use of uninitialized value in substitution iterator"

Can someone shed some light on this? How can I get around the warning?
Or rather, why is it being generated and how can I do what I want and
make perl happy? Thanks,

Abe


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

Date: Sat, 18 Dec 2004 22:56:48 +0100
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: uninitialized value in substitution iterator
Message-Id: <32jndvF3nbvd5U1@individual.net>

Aberrant wrote:
> What I'm trying to do is take %%variable%% in a file and replace it
> with data returned by the subroutine substitute(). The code I have
> looks like this:
> 
> $data =~ s/%%([^%]*)%%/&substitute($1)/ge;
-------------------------^
redundant

> And it does exactly what I want, but it also fills up my error log
> with this:
> 
> "Use of uninitialized value in substitution iterator"
> 
> Can someone shed some light on this?

The file probably includes variables that are unknown by the 
substitute() function. You can for instance do something like this:

     sub substitute {
         my $key = shift;
         my %vars = (
             var1 => 'aaa',
             var2 => 'bbb',
             ...
         );

         if ( $vars{$key} ) {
             $vars{$key};
         } else {
             warn "Unknown template variable: $key";
             "%%$key%%";
         }
     }

-- 
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl


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

Date: 18 Dec 2004 14:15:16 -0800
From: public@aberrantairbrush.com
Subject: Re: uninitialized value in substitution iterator
Message-Id: <1103408116.879730.71970@c13g2000cwb.googlegroups.com>

Gunnar Hjalmarsson wrote:
> > $data =~ s/%%([^%]*)%%/&substitute($1)/ge;
> -------------------------^
> redundant

What's redundant, the ampersand? Depending on how the text is displayed
the caret is pointing to parentheses.

> The file probably includes variables that are unknown by the
> substitute() function. You can for instance do something like this:

Thanks, that was the problem! I had this:

sub substitute
{
my $var = shift;
if (exists($subs->{$var}) && $subs->{$var} eq "readPage") {
return readPage($var);
} elsif (ref($subs->{$var}) eq "CODE") {
return &{$subs->{$var}};
} else {
return $subs->{$var};
}
}

and I changed it to this (last few lines changed):

sub substitute
{
my $var = shift;
if (exists($subs->{$var}) && $subs->{$var} eq "readPage") {
return readPage($var);
} elsif (ref($subs->{$var}) eq "CODE") {
return &{$subs->{$var}};
} elsif (exists($subs->{$var})) {
return $subs->{$var};
} else {
return "";
}
}


No more warnings, I never realized I was returning undef to s/// like
that.



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

Date: Sat, 18 Dec 2004 23:28:53 +0100
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: uninitialized value in substitution iterator
Message-Id: <32jpamF3laab5U1@individual.net>

public@aberrantairbrush.com wrote:
> Gunnar Hjalmarsson wrote:
>> 
>>> $data =~ s/%%([^%]*)%%/&substitute($1)/ge;
>> ------------------------^
>> redundant
> 
> What's redundant, the ampersand?

Yes, provided that you are using Perl 5. (It does have special meanings, 
see "perldoc perlsub".)

-- 
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl


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

Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 6 Apr 01)
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: due to the current flood of worm email banging on ruby, the smtp
server on ruby has been shut off until further notice. 

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


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