[29214] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 458 Volume: 11

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu May 24 21:14:25 2007

Date: Thu, 24 May 2007 18:14:19 -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, 24 May 2007     Volume: 11 Number: 458

Today's topics:
        perlre: why {n}?, {n,}?, {n,m}?   ? <socyl@987jk.com.invalid>
    Re: perlre: why {n}?, {n,}?, {n,m}?   ? <uri@stemsystems.com>
    Re: perlre: why {n}?, {n,}?, {n,m}?   ? (Greg Bacon)
    Re: perlre: why {n}?, {n,}?, {n,m}?   ? <ipozgaj@nospam.fly.srk.fer.hr>
    Re: perlre: why {n}?, {n,}?, {n,m}? ? <mritty@gmail.com>
    Re: perlre: why {n}?, {n,}?, {n,m}? ? <uri@stemsystems.com>
    Re: Running perl scripts on the fly jrosik@gmail.com
    Re: Running perl scripts on the fly jrosik@gmail.com
        sort? g4173c@motorola.com
    Re: sort? <nobull67@gmail.com>
    Re: sort? <nobull67@gmail.com>
    Re: sort? <mritty@gmail.com>
    Re: sort? (Greg Bacon)
    Re: sort? g4173c@motorola.com
    Re: sort? g4173c@motorola.com
    Re: sort? <mritty@gmail.com>
    Re: The Concepts and Confusions of Prefix, Infix, Postf <development-2006-8ecbb5cc8aREMOVETHIS@ANDTHATm-e-leypold.de>
        Why put a debug option in a production code perl script <cdalten@gmail.com>
    Re: Why put a debug option in a production code perl sc xhoster@gmail.com
    Re: Why put a debug option in a production code perl sc <uri@stemsystems.com>
    Re: Why put a debug option in a production code perl sc <cdalten@gmail.com>
    Re: Why put a debug option in a production code perl sc <veatchla@yahoo.com>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Thu, 24 May 2007 16:51:34 +0000 (UTC)
From: kj <socyl@987jk.com.invalid>
Subject: perlre: why {n}?, {n,}?, {n,m}?   ?
Message-Id: <f34fqm$q7g$1@reader2.panix.com>



In perlre the descriptions given for each item in the following
pairs are identical:

  {n}   and {n}?     Match exactly n times
  {n,}  and {n,}?    Match at least n times
  {n,m} and {n,m}?   Match at least n but not more than m times

I.e. it seems that in all the cases above the ? serves no purpose
other than to add superfluous complexity to a regular expression.

I don't get it.  Is there a reason for this?  (The only one I can
come up is that it may simplify the automatic construction of
regexps, but this hardly seems worth the cost of the added line
noise.)

kj

-- 
NOTE: In my address everything before the first period is backwards;
and the last period, and everything after it, should be discarded.


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

Date: Thu, 24 May 2007 17:10:42 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: perlre: why {n}?, {n,}?, {n,m}?   ?
Message-Id: <x78xbe2lm5.fsf@mail.sysarch.com>

>>>>> "k" == kj  <socyl@987jk.com.invalid> writes:

  k> In perlre the descriptions given for each item in the following
  k> pairs are identical:

the ? quantifier is non-greedy. it may have useful effects on some of these.

  k>   {n}   and {n}?     Match exactly n times

don't see how ? can change this match. probably there for syntactic consistancy

  k>   {n,}  and {n,}?    Match at least n times
  k>   {n,m} and {n,m}?   Match at least n but not more than m times

non-greedy makes sense with those two. with ? perl will try to match n times
and succeed and not go further. backtracking later one can still cause
more matching to occur up to the limit (none or m).

  k> I don't get it.  Is there a reason for this?  (The only one I can
  k> come up is that it may simplify the automatic construction of
  k> regexps, but this hardly seems worth the cost of the added line
  k> noise.)

you didn't analyze it enough to realize that ? can affect the latter two
quantifiers. only in the first one it is a no-op.

uri

-- 
Uri Guttman  ------  uri@stemsystems.com  -------- http://www.stemsystems.com
--Perl Consulting, Stem Development, Systems Architecture, Design and Coding-
Search or Offer Perl Jobs  ----------------------------  http://jobs.perl.org


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

Date: Thu, 24 May 2007 17:20:46 -0000
From: gbacon@hiwaay.net (Greg Bacon)
Subject: Re: perlre: why {n}?, {n,}?, {n,m}?   ?
Message-Id: <135bibego3i4e68@corp.supernews.com>

In article <f34fqm$q7g$1@reader2.panix.com>,
    kj  <socyl@987jk.com.invalid> wrote:

: In perlre the descriptions given for each item in the following
: pairs are identical:
: 
:   {n}   and {n}?     Match exactly n times
:   {n,}  and {n,}?    Match at least n times
:   {n,m} and {n,m}?   Match at least n but not more than m times
: 
: I.e. it seems that in all the cases above the ? serves no purpose
: other than to add superfluous complexity to a regular expression.
: 
: I don't get it.  Is there a reason for this?  (The only one I can
: come up is that it may simplify the automatic construction of
: regexps, but this hardly seems worth the cost of the added line
: noise.)

Note the following passage in the same manpage:

    By default, a quantified subpattern is "greedy", that
    is, it will match as many times as possible (given a
    particular starting location) while still allowing the
    rest of the pattern to match.  If you want it to match
    the minimum number of times possible, follow the
    quantifier with a "?".

For example:

    $ cat try
    #! /usr/bin/perl

    $_ = "aaaa";

    foreach my $pattern (qr/(a{2,3})/, qr/(a{2,3}?)/) {
      if (/$pattern/) {
        print "$pattern: \$1 = '$1' (length ", length($1), ")\n";
      }
      else {
        warn "$0: no match for $pattern!\n";
      }
    }

    $ ./try
    (?-xism:(a{2,3})): $1 = 'aaa' (length 3)
    (?-xism:(a{2,3}?)): $1 = 'aa' (length 2)

Note how the quantifier with the question mark is satisfied with a
shorter match.

Hope this helps,
Greg
-- 
Now let us retract the foreskin of misconception and apply the
wire brush of enlightenment. 
    -- Geoff Miller 


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

Date: Thu, 24 May 2007 17:20:45 +0000 (UTC)
From: Igor Pozgaj <ipozgaj@nospam.fly.srk.fer.hr>
Subject: Re: perlre: why {n}?, {n,}?, {n,m}?   ?
Message-Id: <f34hhd$nol$1@ss408.t-com.hr>

On Thu, 24 May 2007 16:51:34 +0000, kj wrote:

> In perlre the descriptions given for each item in the following
> pairs are identical:
> 
>   {n}   and {n}?     Match exactly n times
>   {n,}  and {n,}?    Match at least n times
>   {n,m} and {n,m}?   Match at least n but not more than m times
> 
> I.e. it seems that in all the cases above the ? serves no purpose
> other than to add superfluous complexity to a regular expression.
> 
> I don't get it.  Is there a reason for this?  (The only one I can
> come up is that it may simplify the automatic construction of
> regexps, but this hardly seems worth the cost of the added line
> noise.)

Yes, there is a reason. Perl regular expressions are by default "greedy".
That means Perl will match the biggest possible pattern from the given
input. ? character denotes non-greedy match (+?, *? etc).

For example:

warbird:~% echo "abcabc" | perl -lne 'print $& if /a.*c/'
abcabc
warbird:~% echo "abcabc" | perl -lne 'print $& if /a.*?c/'
abc

-- 
Igor Pozgaj | ipozgaj at fly.srk.fer.hr
ICQ: 126002505  | IRC: @thunder (#linux@IdolNet)
PGP: 0xEF36A092 | http://fly.srk.fer.hr/~ipozgaj
http://ipozgaj.blogspot.com (/atom.xml RSS feed)


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

Date: 24 May 2007 10:31:57 -0700
From: Paul Lalli <mritty@gmail.com>
Subject: Re: perlre: why {n}?, {n,}?, {n,m}? ?
Message-Id: <1180027917.428526.25320@o5g2000hsb.googlegroups.com>

On May 24, 1:10 pm, Uri Guttman <u...@stemsystems.com> wrote:
> >>>>> "k" == kj  <s...@987jk.com.invalid> writes:
>
>   k> In perlre the descriptions given for each item in the following
>   k> pairs are identical:
>
> the ? quantifier is non-greedy.

Just to be pedantic, the ? *quantifier* is in fact greedy.  That is,
the quantifier that means "0 or 1 of the previous token" will prefer
to match 1.  A separate and distinct use of the question-mark
character is to make a preceding quantifier non-greedy.  So the ?
quantifier, modified by a ? will match 0 or 1 of the previous token,
preferring to match 0.

"ab" =~ /(ab?)/
matches, and sets $1 to 'ab'
"ab" =~ /(ab??)/
matches, and sets $1 to 'a'

Paul Lalli



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

Date: Thu, 24 May 2007 19:43:04 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: perlre: why {n}?, {n,}?, {n,m}? ?
Message-Id: <x7k5uy0zzs.fsf@mail.sysarch.com>

>>>>> "PL" == Paul Lalli <mritty@gmail.com> writes:

  PL> On May 24, 1:10 pm, Uri Guttman <u...@stemsystems.com> wrote:
  >> >>>>> "k" == kj  <s...@987jk.com.invalid> writes:
  >> 
  k> In perlre the descriptions given for each item in the following
  k> pairs are identical:
  >> 
  >> the ? quantifier is non-greedy.

  PL> Just to be pedantic, the ? *quantifier* is in fact greedy.  That is,
  PL> the quantifier that means "0 or 1 of the previous token" will prefer
  PL> to match 1.  A separate and distinct use of the question-mark
  PL> character is to make a preceding quantifier non-greedy.  So the ?
  PL> quantifier, modified by a ? will match 0 or 1 of the previous token,
  PL> preferring to match 0.

well, i should have said ? modifier vs the ? quantifier which is 0 or 1
times. but it is obvious from the OP that it is the ? modifier in
question.

uri

-- 
Uri Guttman  ------  uri@stemsystems.com  -------- http://www.stemsystems.com
--Perl Consulting, Stem Development, Systems Architecture, Design and Coding-
Search or Offer Perl Jobs  ----------------------------  http://jobs.perl.org


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

Date: 24 May 2007 14:10:25 -0700
From: jrosik@gmail.com
Subject: Re: Running perl scripts on the fly
Message-Id: <1180041025.186087.103320@q69g2000hsb.googlegroups.com>

Jussi,

I have tried Zeus and the example of a macro running iSql.exe. I did
not figure out where to place the perl script. Actually I need two
windows - one with the text to process and another one with the perl
script. The "iSql.exe" macro example operates only with one window.

Jiri


JussiJ napsal:
> On Apr 15, 8:42 am, jro...@gmail.com wrote:
>
> > I would like to run perl scripts as in the following scenario:
> >
> > 1. I open a texteditor- for example Notepad, Wordpad, Word.
> > 2. I paste some text into this texteditor.
> > 3. I press a magic key - let's say I double press the Shift key.
> > 4. A magic window appears and I enter the following script:
> >   while (<>) {
> >     s/you/You/;
> >     print;
> >   }
> > 5. I execute the script.
>
> FWIW the Zeus IDE can be configured to do this.
>
> The "magic window" would be nothing more than a new or existing
> document window and the "magic key" would be any key bound to
> a Zeus macro.
>
> For example this macro script:
>
>     http://www.zeusedit.com/forum/viewtopic.php?t=220
>
> does something very similar for SQL scripts. It takes the text
> from the current document and sends it to iSql and captures the
> output.
>
> So all that is needed is the command line contained in the script
> is changed to run Perl instead of iSql.exe utility.
>
> > 6. Now there are two texteditorwindows - one with the source text
> > and another with the output text.
>
> In the case of Zeus you would be left with the original document
> window and a new tool output window containing the output generated
> by the perl script.
>
> > Is this possible?
>
> Yes.
>
> > One note: I have not saved any document during my scenario!
>
> Zeus will run the script whether the document is save or not saved.
>
> Jussi Jumppanen
> Author: Zeus for Windows IDE



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

Date: 24 May 2007 14:13:22 -0700
From: jrosik@gmail.com
Subject: Re: Running perl scripts on the fly
Message-Id: <1180041202.545744.304260@p77g2000hsh.googlegroups.com>

Sherm Pendley napsal:
> jrosik@gmail.com writes:
>
> > I am trying to accomplish the most simple way to filter text data
> > using perl script.
>
> 1. Buy a Mac.
> 2. Install PerlPad. <http://perl-pad.sourceforge.net/>
> 3. There is no step three. :-)
>
> sherm--

Sherm,

I think PerlPad is the right thing that does exactly what I need.
Unfortunately I use Windows.

Jiri



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

Date: 24 May 2007 10:02:53 -0700
From: g4173c@motorola.com
Subject: sort?
Message-Id: <1180026173.627588.321570@q75g2000hsh.googlegroups.com>

Greeting:

I have the following code to sort an array of dirs/files:

    @sorted = sort { -M $b <=> -M $a } @logfile;
    foreach $lastfilemod (@sorted) {
        $dir = (dirname $lastfilemod);
        if (! exists $srt{$dir} ) {
            push(@srtlist, $lastfilemod);
            $srt{$dir} = 1;
        }
    }

The @logfile looks like:

/dir/dir/file1
/dir/dir/file2
/dir/dir2/file1
 ...

What I was trying to do is have @sorted list the files by last
modified and then I could print out each file last modified in one per
directory. However the sort isn't working correctly and I'm not
getting the last file modified for some directories. Could anyone
point out what I'm doing wrong?

Thanks in advance for any help!

  Tom



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

Date: 24 May 2007 10:32:49 -0700
From: Brian McCauley <nobull67@gmail.com>
Subject: Re: sort?
Message-Id: <1180027969.414445.21070@u30g2000hsc.googlegroups.com>

On May 24, 6:02 pm, g41...@motorola.com wrote:
> Greeting:
>
> I have the following code to sort an array of dirs/files:
>
>     @sorted = sort { -M $b <=> -M $a } @logfile;
>     foreach $lastfilemod (@sorted) {
>         $dir = (dirname $lastfilemod);
>         if (! exists $srt{$dir} ) {
>             push(@srtlist, $lastfilemod);
>             $srt{$dir} = 1;
>         }
>     }
>
> The @logfile looks like:
>
> /dir/dir/file1
> /dir/dir/file2
> /dir/dir2/file1

Have you checked that the values of the entries in @logfile are
actually the _exact_ names of files that exist and that you have
permission to read the attributes of? Are you sure that, for example,
you don't have newline characters appended?

I'd to a transform and check -M worked.

my @sorted =
  map { $_->[0] }
  sort { $b->[1] <=> $a->[1] }
 @logfile;


> ...
>
> What I was trying to do is have @sorted list the files by last
> modified and then I could print out each file last modified in one per
> directory. However the sort isn't working correctly and I'm not
> getting the last file modified for some directories. Could anyone
> point out what I'm doing wrong?
>
> Thanks in advance for any help!
>
>   Tom




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

Date: 24 May 2007 10:37:07 -0700
From: Brian McCauley <nobull67@gmail.com>
Subject: Re: sort?
Message-Id: <1180028227.034644.34940@o5g2000hsb.googlegroups.com>

On May 24, 6:32 pm, Brian McCauley <nobul...@gmail.com> wrote:
> On May 24, 6:02 pm, g41...@motorola.com wrote:
>
>
>
> > Greeting:
>
> > I have the following code to sort an array of dirs/files:
>
> >     @sorted = sort { -M $b <=> -M $a } @logfile;
> >     foreach $lastfilemod (@sorted) {
> >         $dir = (dirname $lastfilemod);
> >         if (! exists $srt{$dir} ) {
> >             push(@srtlist, $lastfilemod);
> >             $srt{$dir} = 1;
> >         }
> >     }
>
> > The @logfile looks like:
>
> > /dir/dir/file1
> > /dir/dir/file2
> > /dir/dir2/file1
>
> Have you checked that the values of the entries in @logfile are
> actually the _exact_ names of files that exist and that you have
> permission to read the attributes of? Are you sure that, for example,
> you don't have newline characters appended?
>
> I'd to a transform and check -M worked.
>
> my @sorted =
>   map { $_->[0] }
>   sort { $b->[1] <=> $a->[1] }
>  @logfile;

Opps hit send before I finished typing...

# Untested
my @sorted =
  map { $_->[0] }
  sort { $b->[1] <=> $a->[1] }
  map {
    my $mod = -M;
    if ( defined $mod ) {
       [ $_, $mod ];
    else {
       warn "$_: $!\n";
       ();
    }
  } @logfile;




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

Date: 24 May 2007 10:39:29 -0700
From: Paul Lalli <mritty@gmail.com>
Subject: Re: sort?
Message-Id: <1180028369.287515.72410@q75g2000hsh.googlegroups.com>

On May 24, 1:02 pm, g41...@motorola.com wrote:
> Greeting:
>
> I have the following code to sort an array of dirs/files:
>
>     @sorted = sort { -M $b <=> -M $a } @logfile;
>     foreach $lastfilemod (@sorted) {
>         $dir = (dirname $lastfilemod);
>         if (! exists $srt{$dir} ) {
>             push(@srtlist, $lastfilemod);
>             $srt{$dir} = 1;
>         }
>     }
>
> The @logfile looks like:
>
> /dir/dir/file1
> /dir/dir/file2
> /dir/dir2/file1
> ...
>
> What I was trying to do is have @sorted list the files by last
> modified and then I could print out each file last modified in one per
> directory. However the sort isn't working correctly and I'm not
> getting the last file modified for some directories. Could anyone
> point out what I'm doing wrong?

I think you have your sort backwards, for one.  -M returns the number
of days since the file was modified.  You're sorting the resutls of -M
in descending numerical order.  That is, largest first.  So the file
with the LARGEST number of days since it was modified comes first.
The file with the largest number of days since modification is the
least recently modified, not most recently.

Once you get this working, I also rather strongly suggest you not use
the file-comparison operators in a sort subroutine. It's very
ineffient, as you're doing a stat() call on every file in your list
multiple times.  Instead, use a Schwartzian transform:

my @sorted = map { $_->[0] }
            sort { $a->[1] <=> $b->[1] }
             map { [ $_, -M $_ ] } @logfile;

Paul Lalli



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

Date: Thu, 24 May 2007 17:43:21 -0000
From: gbacon@hiwaay.net (Greg Bacon)
Subject: Re: sort?
Message-Id: <135bjlpege2k74e@corp.supernews.com>

In article <1180026173.627588.321570@q75g2000hsh.googlegroups.com>,
     <g4173c@motorola.com> wrote:

: I have the following code to sort an array of dirs/files:
: 
:     @sorted = sort { -M $b <=> -M $a } @logfile;
:     foreach $lastfilemod (@sorted) {
:         $dir = (dirname $lastfilemod);
:         if (! exists $srt{$dir} ) {
:             push(@srtlist, $lastfilemod);
:             $srt{$dir} = 1;
:         }
:     }
: 
: The @logfile looks like:
: 
: /dir/dir/file1
: /dir/dir/file2
: /dir/dir2/file1
: ...
: 
: What I was trying to do is have @sorted list the files by last
: modified and then I could print out each file last modified in one per
: directory. However the sort isn't working correctly and I'm not
: getting the last file modified for some directories. Could anyone
: point out what I'm doing wrong?

For each file, remember it if it was modified more recently than the
current frontrunner for the file's parent directory:

    $ cat try
    #! /usr/bin/perl

    use warnings;
    use strict;

    use File::Basename;

    sub filename { $_[0]->[0] }
    sub modified { $_[0]->[1] }

    my %last;

    for (`find /tmp -type f 2>/dev/null`) {
      chomp;

      my $dir = dirname $_;
      my $mod = -M $_;

      $last{$dir} = [ basename($_), $mod ]
        if !$last{$dir} || $mod > modified $last{$dir};
    }

    foreach my $dir (sort keys %last) {
      print "$dir: ", filename($last{$dir}), "\n";
    }

    $ ./try
    /tmp: sh-thd-1172576387
    /tmp/exportfig: restorefig.m
    /tmp/shared: .Xdefaults
    /tmp/split-sequence: split-sequence.lisp

Hope this helps,
Greg
-- 
The idea that the vote of a people, no matter how nearly unanimous, makes or
creates or determines what is right or just becomes as absurd and
unacceptable as the idea that right and justice are simply whatever a king
says they are.             -- Robert Welch


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

Date: 24 May 2007 11:28:28 -0700
From: g4173c@motorola.com
Subject: Re: sort?
Message-Id: <1180031308.435608.283970@w5g2000hsg.googlegroups.com>

Hi All:

Thanks for all the responces! I found that -M doesn't give the
granularity I needed. Some of the files were only seconds away for the
other. I changed to the following:

use File::stat;
    @sorted = sort { (stat($b)->mtime) <=> (stat($a)->mtime) }
@logfile;
    foreach $lastfilemod (@sorted) {
        $dir = (dirname $lastfilemod);
        if (! exists $srt{$dir} ) {
            push(@srtlist, $lastfilemod);
            $srt{$dir} = 1;
        }
    }




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

Date: 24 May 2007 11:32:24 -0700
From: g4173c@motorola.com
Subject: Re: sort?
Message-Id: <1180031544.881249.278900@h2g2000hsg.googlegroups.com>

Hi All:

Thanks for all the responces! I found that the -M doesn't give the
granularity I need. Some of the files were only seconds apart. I
changed to the following:

    use File::stat;
    @sorted = sort { (stat($b)->mtime) <=> (stat($a)->mtime) }
@logfile;
    foreach $lastfilemod (@sorted) {
        $dir = (dirname $lastfilemod);
        if (! exists $srt{$dir} ) {
            push(@srtlist, $lastfilemod);
            $srt{$dir} = 1;
        }
    }

This got just what I was looking for. Thanks again for all the replys!

Tom



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

Date: 24 May 2007 11:54:49 -0700
From: Paul Lalli <mritty@gmail.com>
Subject: Re: sort?
Message-Id: <1180032889.021915.177180@g4g2000hsf.googlegroups.com>

On May 24, 2:28 pm, g41...@motorola.com wrote:
> Thanks for all the responces! I found that -M doesn't give the
> granularity I needed.

I'm sorry, what?!

[14:43:46] ~/tmp $ touch file.txt
[14:43:52] ~/tmp $ perl -le'print -M "file.txt"'
0.000115740740740741

Exactly how much more granularity do you need?!

Paul Lalli


Some of the files were only seconds away for the
> other. I changed to the following:
>
> use File::stat;
>     @sorted = sort { (stat($b)->mtime) <=> (stat($a)->mtime) }
> @logfile;

The reason this works and your other one didn't is because you're now
comparing the last modified times as seconds sine the epoch, not days
since last modified.  So NOW, your descending numerical sort is
correct.  The file with the greatest seconds since the epoch is in
fact the most recently modified.  Compare and contrast with the file
with the greatest days since last modified. *

If you had just swapped $a and $b in your original, it would have been
fine.

Paul Lalli

* Here's an example.  Presuming we're running at 14:55:00 on May 24,
2007....
file1 - last modified Jan 1, 1970 00:00:00
file2 - last modified May 23, 2007, 14:55:00
file3 - last modified May 24, 2007, 14:55:00

-M file1 returns 13657.7849421296
-M file2 returns 1
-M file3 returns 0

stat(file1)->mtime returns 0
stat(file2)->mtime returns 1179946500
stat(file3)->mtime returns 1180032900

Do you see now what you did wrong the first time?



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

Date: Wed, 23 May 2007 19:46:09 +0200
From: Markus E Leypold <development-2006-8ecbb5cc8aREMOVETHIS@ANDTHATm-e-leypold.de>
Subject: Re: The Concepts and Confusions of Prefix, Infix, Postfix and Fully Functional Notations
Message-Id: <1oveejxwke.fsf@hod.lan.m-e-leypold.de>


> On 2007-05-23, Xah Lee <xah@xahlee.org> wrote:
>> The Concepts and Confusions of Prefix, Infix, Postfix and Fully
>> Functional Notations
>>
>> Xah Lee, 2006-03-15
>
> Xah, why do you post year-old essays to newsgroups that couldn't care
> less about them?


And even more to the point -- why does he post now again the same
drivel he already posted on the 9th of May 2007? And will we now
treated to repeats of his garbage every 2 weeks?

The answer to your question is very simple: Xah Lee is a troll.

Regards -- Markus





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

Date: 24 May 2007 12:48:30 -0700
From: grocery_stocker <cdalten@gmail.com>
Subject: Why put a debug option in a production code perl script?
Message-Id: <1180036110.428110.294040@o5g2000hsb.googlegroups.com>

In the following perl script snippet, the author has a debug option

sub main() {
  my $dir;

  error ("LANG is $ENV{LANG} -- UTF is no good, man!")
    if ($ENV{LANG} && $ENV{LANG} =~ m/utf/i);

  while ($_ = $ARGV[0]) {
    shift @ARGV;
    if ($_ eq "--verbose") { $verbose++; }
    elsif ($_ eq "--debug")  { $debug_p++; }
    elsif (m/^-v+$/) { $verbose += length($_)-1; }
    elsif (m/^-./) { usage; }
    elsif (!defined($dir)) { $dir = $_; }
    else { usage; }
  }
  usage unless $dir;
  $dir =~ s@/+$@@;
  if (! -d $dir) {
    print STDERR "$progname: directory $dir does not exist\n";
    usage;
  }
  build_index $dir;
}

main();
exit 0;

What's the point of shoving a debug option into a script that is
supposed to be used by other users?



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

Date: 24 May 2007 20:15:22 GMT
From: xhoster@gmail.com
Subject: Re: Why put a debug option in a production code perl script?
Message-Id: <20070524161524.364$5E@newsreader.com>

grocery_stocker <cdalten@gmail.com> wrote:
> In the following perl script snippet, the author has a debug option
>
 ...
>
> What's the point of shoving a debug option into a script that is
> supposed to be used by other users?

You think that stuff that is supposed to be used by other users has no
need to be debugged?

Xho

-- 
-------------------- http://NewsReader.Com/ --------------------
Usenet Newsgroup Service                        $9.95/Month 30GB


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

Date: Thu, 24 May 2007 20:20:33 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: Why put a debug option in a production code perl script?
Message-Id: <x77iqy0y9a.fsf@mail.sysarch.com>

>>>>> "gs" == grocery stocker <cdalten@gmail.com> writes:

  gs> In the following perl script snippet, the author has a debug option

forget about the debug option, the code is nutso!

  gs> sub main() {

don't use prototypes, especially for no reason.

  gs>   my $dir;

  gs>   while ($_ = $ARGV[0]) {
  gs>     shift @ARGV;

what a wacky way to loop over @ARGV. ever heard of foreach ( @ARGV )??
and his loop fails if ARGV has a '' or 0 value.

  gs>     if ($_ eq "--verbose") { $verbose++; }
  gs>     elsif ($_ eq "--debug")  { $debug_p++; }
  gs>     elsif (m/^-v+$/) { $verbose += length($_)-1; }
  gs>     elsif (m/^-./) { usage; }
  gs>     elsif (!defined($dir)) { $dir = $_; }
  gs>     else { usage; }

ewww. not much more i can say about that. 

  gs> What's the point of shoving a debug option into a script that is
  gs> supposed to be used by other users?

it would be harder to maintain 2 versions of the code, with/without
debugging options. if the real debug code isn't in the way or slows down
the program, this little debug option is not a problem.

uri

-- 
Uri Guttman  ------  uri@stemsystems.com  -------- http://www.stemsystems.com
--Perl Consulting, Stem Development, Systems Architecture, Design and Coding-
Search or Offer Perl Jobs  ----------------------------  http://jobs.perl.org


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

Date: 24 May 2007 13:45:20 -0700
From: grocery_stocker <cdalten@gmail.com>
Subject: Re: Why put a debug option in a production code perl script?
Message-Id: <1180039520.093823.253290@p77g2000hsh.googlegroups.com>

On May 24, 1:15 pm, xhos...@gmail.com wrote:
> grocery_stocker <cdal...@gmail.com> wrote:
> > In the following perl script snippet, the author has a debug option
>
> ...
>
> > What's the point of shoving a debug option into a script that is
> > supposed to be used by other users?
>
> You think that stuff that is supposed to be used by other users has no
> need to be debugged?
>

It hurts to think somedays. Today is one of those days.



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

Date: Thu, 24 May 2007 19:40:43 -0500
From: l v <veatchla@yahoo.com>
Subject: Re: Why put a debug option in a production code perl script?
Message-Id: <135cc3asd1l9498@news.supernews.com>

grocery_stocker wrote:
> In the following perl script snippet, the author has a debug option
> 
[snip]
>   while ($_ = $ARGV[0]) {
>     shift @ARGV;
>     if ($_ eq "--verbose") { $verbose++; }
>     elsif ($_ eq "--debug")  { $debug_p++; }
>     elsif (m/^-v+$/) { $verbose += length($_)-1; }
>     elsif (m/^-./) { usage; }
>     elsif (!defined($dir)) { $dir = $_; }
>     else { usage; }
>   }
[snip]

On a side note to what others have said, it would be better to use
Getopt::Long vs. looping through @ARGV.

-- 

Len


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

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 V11 Issue 458
**************************************


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