logo       

Re: [Boston.pm] Regex warning: msg#00025

Subject: Re: [Boston.pm] Regex warning
On 3/11/06, Ben Tilly <btilly-Re5JQEeQqe8AvxtiuMwx3w@xxxxxxxxxxxxxxxx> wrote:
> On 3/11/06, Joel Gwynn <joelman-Re5JQEeQqe8AvxtiuMwx3w@xxxxxxxxxxxxxxxx> 
> wrote:
> > I know I've done this before, but I'm not sure what I'm doing
> > differently today.  I'm trying to capture a simple command-line option
> > like so:
> >
> > my $debug = 0;
> >
> > if(grep(/--debug=(\d+)/, @ARGV)){
> >     $debug = $1;
> >     print "debug: $debug\n"; # Error here
> > }
> >
> > But I keep getting "Use of uninitialized value in concatenation (.) or
> > string" when I try to do something with the debug variable.  How can
> > $1 not be initialized?  If it's matching, then it should have a value,
> > no?
>
> That looks like a bug to me.  But you can work around it as follows:

Correcting myself, I don't think it is a bug.  $1 is dynamically
scoped.  In your construct above, that means that when grep ends, $1
is cleaned up.

> while(grep(/--debug=(\d+)/, @ARGV)){
>     $debug = $1;
>     print "debug: $debug\n";
>     last;
> }

And I think this works because the inner part of the while loop
executes while the grep is still executing.  Which is a Perl
optimization to avoid generating a long temporary list in this
situation.

Cheers,
Ben


<Prev in Thread] Current Thread [Next in Thread>
Google Custom Search

Recently Viewed:
science.linguis...    culture.sf.lite...    video.mplayer.c...    yellowdog.gener...    ietf.rfc822/199...    emacs.help/2002...    redhat.release....    kernel.speakup/...    java.openejb.de...    debian.devel.gt...    xfree86.newbie/...    bug-tracking.ma...    pam/2003-05/msg...    games.devel.ope...    user-groups.lin...    music.pancham/2...    network.mq.deve...    web.html.genera...    arklinux.bugs/2...    linux.ecasound/...    qnx.openqnx.dev...    org.user-groups...    file-systems.sf...    trustix.contrib...   
Home | blog view | USPTO Patent Archive | advertise | OSDir is an inevitable website. super tiny logo

Free Magazines

Cisco News
Receive a free quarterly e-newsletter with exclusive articles on how Cisco IT uses its own products and solutions to enable the business.
subscribe

Systems Management News, the newspaper for IT systems administration and data center managers! Each issue of Systems Management News is chock-full of news and analysis to help you understand what's happening in your field.
subscribe

The Enterprise Newsweekly eWeek is the essential technology information source for builders of e-business.
subscribe

Oracle Magazine Oracle Magazine contains technology strategy articles, sample code, tips, Oracle and partner news, how to articles for developers and DBAs, and more. Oracle (NASDAQ: ORCL) is the world's largest enterprise software company.
subscribe

Total Telecom Total Telecom is "The Economist of the communications industry".
subscribe