[7573] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 1199 Volume: 8

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Oct 20 11:07:15 1997

Date: Mon, 20 Oct 97 08:00:24 -0700
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Mon, 20 Oct 1997     Volume: 8 Number: 1199

Today's topics:
     Re: @ + @  =  %   but how? <bugaj@bell-labs.com>
     Re: Best way to comma seperate a number? (Mike Stok)
     Re: Best way to comma seperate a number? (Andrew M. Langmead)
     BOOKS????????????????? <u5rjw@csc.liv.ac.uk>
     Re: BOOKS????????????????? (Scott McMahan)
     Re: Can someone look at this and tell me why it doesn't <seay@absyss.fr>
     Re: Can someone look at this and tell me why it doesn't <jgostin@shell2.ba.best.com>
     Re: Fastest Compare On Array Elements (Andrew M. Langmead)
     Re: Help me, please! <seay@absyss.fr>
     Re: help on Win32odbc(perl) (Scott McMahan)
     Re: Help with MacPerl help (Chris Nandor)
     Re: How do I collect email address using perl? <seay@absyss.fr>
     How to change user password?? <robertn@dawid.com.pl>
     Re: How to make a word bold? (G.Embery)
     Re: Input from plain text file (Andrew M. Langmead)
     Re: New Perl syntax idea (Janne Leppdnen)
     Re: New Perl syntax idea <seay@absyss.fr>
     Re: Perl equivalent to #ifdef in C? (Janne Leppdnen)
     Re: Perl equivalent to #ifdef in C? <seay@absyss.fr>
     Pop up browser authentification dlg with perl???..... <soyouz1@easynet.fr>
     Re: Q: How to setup a default argument in a function? (Honza Pazdziora)
     Re: text wrap (Tad McClellan)
     Undef in my list -- syntax suggestion (Honza Pazdziora)
     Re: Why am I running out of memory? (bug in perl?) (Joseph Scott Stuart)
     Wildcards in Perl file search? (Paul Ryder)
     Windoze question.. (Janne Leppdnen)
     Digest Administrivia (Last modified: 8 Mar 97) (Perl-Users-Digest Admin)

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

Date: Mon, 20 Oct 1997 10:28:08 -0400
From: Stephan Vladimir Bugaj <bugaj@bell-labs.com>
Subject: Re: @ + @  =  %   but how?
Message-Id: <344B6A78.2781@bell-labs.com>

Apologies for the 3 copies of my post... Netscape Communicator news
crashed while I was posting (not like that's unusual).


LL+P,
Stephan


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

Date: 20 Oct 1997 13:37:49 GMT
From: mike@stok.co.uk (Mike Stok)
Subject: Re: Best way to comma seperate a number?
Message-Id: <62fmrd$ad3@news-central.tiac.net>

In article <62ekss$1s1$1@gte2.gte.net>, Eric <pojo@gte.net.nospam> wrote:

>Okay, I found this in the FAQ.  Why does it work?  More specifically, why does:
>
> 1 while s/^(-?\d+)(\d{3})/$1,$2/;
>
>do what it does??  What is that 1 doing in there?

It works from right to left on a number, and each time it puts in a comma
it re-scans the contents of $_ as the first set of parens consume an
optional - and as many digits as possible to still leave 3 over for the
second set of parens.  The 1 is simply a "nop" statement to a while
statement modifier.  Try this:

!/usr/local/bin/perl -w

$number = 1234567.89;

while ($number =~ s/^(-?\d+)(\d{3})/$1,$2/) {
  print "\$1 is $1, \$2 is $2, \$number is $number\n";
}

and you'll see that once the comma is inserted between the 4 and 5 $1 and
$2 have to match a new set of strings on the second iteration.

Some people have pointed out that this operation can be more efficiently
done by reversing the string so you can process it from left to right
using a /g modifier in the substitution, for example something like

  $number = 1234567.89;
  $number = reverse $number;
  $number =~ s/(\d{3})(?=\d)/$1,/g;
  $number = reverse $number;

uses perl 5's zero width lookakead (?=\d) to look ahead one character and
make sure it's a digit but not "use it up."

Hope this helps,

Mike
-- 
mike@stok.co.uk                    |           The "`Stok' disclaimers" apply.
http://www.stok.co.uk/~mike/       |   PGP fingerprint FE 56 4D 7D 42 1A 4A 9C
http://www.tiac.net/users/stok/    |                   65 F3 3F 1D 27 22 B7 41
stok@psa.pencom.com                |      Pencom Systems Administration (work)


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

Date: Mon, 20 Oct 1997 14:32:49 GMT
From: aml@world.std.com (Andrew M. Langmead)
Subject: Re: Best way to comma seperate a number?
Message-Id: <EICtqr.9qD@world.std.com>

pojo@gte.net.nospam (Eric) writes:

>Okay, I found this in the FAQ.  Why does it work?  More specifically, why does:

> 1 while s/^(-?\d+)(\d{3})/$1,$2/;

>do what it does??  What is that 1 doing in there?

Nothing, except providing proper syntax for the perl interpreter. The
while is what perl calls a "statement modifier", and all of the work
is being done in the modifer. Its just that you can't have a statement
modifier without a statement to work on. If you turn it into a full
fledged loop, you get something like this:

   while (s/^(-?\d+)(\d{3})/$1,$2/) {
       1;
   }

So the while loop keeps getting executed, and as a side effect, alters
$_. As long as the substitution is successful, the loop continues,
(and again, the loop itself does nothing.) once the substutution
fails, the loop ends and $_ has the desired value.

Now lets look at the substitution itself.

^      matches the beginning of the string
(      starts collecting data for $1
-?     matches a minus sign, if present (otherwise it matches nothing)
\d+    matches as many digits as possible
)      ends what will be put into $1
(      starts collecting data for $2
\d{3}  matches exactly three digits
)      ends what will be put into $2

So starting a the beginning of the string, a minus sign will be
matched if the number is negagive, and the the \d+ matches all of the
numbers. Once it gets to the end, the \d{3} will fail, so the \d+
gives up its last matching character and tries again. After the \d+
fails three times, the \d{3} will succeed, and we have a match for the
entire expression. $1 will contain the entire number except for the
last three digits and $2 will have the last three. Then the right hand
side of the substitute gets executed, and a comma is put between what
got matched by the parens corresponding to $1 and $2.

Since the while loop was successful, the statement (in the original
statement modifier form) or the loop (in my conversion to a while
loop) gets executed, but does nothing. Then the conditional gets
executed again. It goes through the same processes, except that the
\d+ will stop at the comma we just inserted, and \d{3} will match the
three characters to the left of the comma. So then $1 and $2 will
refer just to the character to the left of the comma.

When the string no longer matches the regular expression, (due to the
fact that there are no longer four consecutive digits from the
beginning of the string for \d+\d{3} to match) then the substitute
operator returns false, the while condition fails, and the script
continues at the next statement after the while modified statement or
while loop.


For fun, try changing the statement into:

  print "$_\n" while s/^(-?\d+)(\d{3})/$1,$2/;

Or for a more obscure definition of fun, try recompiling perl with the
-DDEBUGGING switch, and execute the script with the -Dr switch.
-- 
Andrew Langmead


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

Date: Fri, 17 Oct 1997 10:30:46 GMT
From: "R.J. Willacy" <u5rjw@csc.liv.ac.uk>
Subject: BOOKS?????????????????
Message-Id: <34473E56.3B92@csc.liv.ac.uk>

I`m looking for a good book about perl that uses microsoft access as the
database.

I am writing an on-line quote system for a multinational company here in
england for my dissertation.  It must use ACCESS to fit in with there
systems.

Any recommendations

Cheers

Rob


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

Date: 20 Oct 1997 13:01:54 GMT
From: scott@lighthouse.softbase.com (Scott McMahan)
Subject: Re: BOOKS?????????????????
Message-Id: <62fko2$muf$3@mainsrv.main.nc.us>

R.J. Willacy (u5rjw@csc.liv.ac.uk) wrote:
: I`m looking for a good book about perl that uses microsoft access as the
: database.

Microsoft Access can only be accessed through ODBC (it has no native
CLI API deal like Oracle, etc), so any book that discusses using the
Win32 Perl version's ODBC support will do the trick. Off the top of my
head, I can't think of any book which actually discusses this, however,
and I've read most of them.

Access' database engine, the Jet engine, can be driven using DAO
through Automation. You could do this in Perl, but ...  first of all,
I've never seen any documentation on it anywhere, let alone a book.
Theoretically, Perl's Automation support would allow you to use DAO as
well as anything else, but frankly the few times I've tried Automation
from Perl, the result has been a nightmare.

I personally would use a more Access friendly language to write the
guts of the program as a helper program, and call it from Perl.

Scott

PS: Yes, I know you can access Access via its own Automation interface,
but that would be very, very painful.



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

Date: Mon, 20 Oct 1997 10:36:19 +0200
From: Doug Seay <seay@absyss.fr>
Subject: Re: Can someone look at this and tell me why it doesn't work!!
Message-Id: <344B1803.1C2224DA@absyss.fr>

Toutatis wrote:
> 
> In article <344248D5.470D@icl.fi>, petri.backstrom@icl.fi wrote:
> 
> > Jeff Gostin wrote:
> > >
> > > If this is an RTFM, point me at the FM, and I'll happily read away. I don't
> > > suspect it is, and I suspect that the answer is 'no' because of PERL's lack
> > > of specific data types, but here's the question:
> > >
> > > Is there a way to determine if a scalar (or an array element, or whatever)
> > > contains a numeric sequence or an alphanumeric sequence?
> >
> > Sure. Read away in the part about regular expressions (perlre)
> > in the FM...
> 
> Read the F thread to find out this F question has been thoroughly answered
> before you give your F boring replies.

Excuse me, but Petri's answer was correct.  An "numeric sequence" is one
that contains digits, no?  Looking up \d in perlre seems perfectly
reasonable to me.  Of course, he could use a character class or
something else of the sort, but that is defined in perlre too.  No, I
think that you should lay off the F key and read some docs.

What Jeff wants (I think) is

	How do I determine whether a scalar is a number/whole/integer/float?

Which is defined perlfaq4.  The answer to this frequentlty asked
question starts with the sentence

       Assuming that you don't care about IEEE notations like
       "NaN" or "Infinity", you probably just want to use a
       regular expression.

so advice to read "perlre" seems to be good advice to me.

- doug


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

Date: 20 Oct 1997 11:18:11 GMT
From: Jeff Gostin <jgostin@shell2.ba.best.com>
Subject: Re: Can someone look at this and tell me why it doesn't work!!
Message-Id: <62felj$eab$1@nntp1.ba.best.com>

Doug Seay <seay@absyss.fr> wrote:
: What Jeff wants (I think) is
Absolutely so, and RTFFAQ was sound advice. I R'd away, and now I know
TFscking answer. :)

				--Jeff


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

Date: Mon, 20 Oct 1997 14:41:01 GMT
From: aml@world.std.com (Andrew M. Langmead)
Subject: Re: Fastest Compare On Array Elements
Message-Id: <EICu4D.GDI@world.std.com>

Stephan Vladimir Bugaj <bugaj@bell-labs.com> writes:

>First off, Thanks to those who helped debug the CGI.pm program I posted
>about earlier.

>Next...
>What is the fastest way (computation time, not programmer time) to use
>all of
>the elements in an array for && and || comparison?

The method shown in the FAQ entry "How do I efficiently match many
regular expressions at once?"

<URL:http://www.perl.com/CPAN/doc/manual/html/pod/perlfaq6/
How_do_I_eficiently_match_many_.html>

  How do I efficiently match many regular expressions at once?

    The following is super-inefficient:

        while (<FH>) {
            foreach $pat (@patterns) {
                if ( /$pat/ ) {
                    # do something
                }
            }
        }

    Instead, you either need to use one of the experimental Regexp
    extension modules from CPAN (which might well be overkill for your
    purposes), or else put together something like this, inspired from a
    routine in Jeffrey Friedl's book:

        sub _bm_build {
            my $condition = shift;
            my @regexp = @_;  # this MUST not be local(); need my()
            my $expr = join $condition => map { "m/\$regexp[$_]/o" } (0..$#regexp);
            my $match_func = eval "sub { $expr }";
            die if $@;  # propagate $@; this shouldn't happen!
            return $match_func;
        }

        sub bm_and { _bm_build('&&', @_) }
        sub bm_or  { _bm_build('||', @_) }

        $f1 = bm_and qw{
                xterm
                (?i)window
        };

        $f2 = bm_or qw{
                \b[Ff]ree\b
                \bBSD\B
                (?i)sys(tem)?\s*[V5]\b
        };

        # feed me /etc/termcap, prolly
        while ( <> ) {
            print "1: $_" if &$f1;
            print "2: $_" if &$f2;
        }

  Why don't word-boundary searches with `\b' work for me?

    Two common misconceptions are that `\b' is a synonym for `\s+', and
    that it's the edge between whitespace characters and non-whitespace
    characters. Neither is correct. `\b' is the place between a `\w'
    character and a `\W' character (that is, `\b' is the edge of a
    "word"). It's a zero-width assertion, just like `^', `$', and all the
    other anchors, so it doesn't consume any characters. the perlre
    manpage describes the behaviour of all the regexp metacharacters.

    Here are examples of the incorrect application of `\b', with fixes:

        "two words" =~ /(\w+)\b(\w+)/;          # WRONG
        "two words" =~ /(\w+)\s+(\w+)/;         # right

        " =matchless= text" =~ /\b=(\w+)=\b/;   # WRONG
        " =matchless= text" =~ /=(\w+)=/;       # right

    Although they may not do what you thought they did, `\b' and `\B' can
    still be quite useful. For an example of the correct use of `\b', see
    the example of matching duplicate words over multiple lines.

    An example of using `\B' is the pattern `\Bis\B'. This will find
    occurrences of "is" on the insides of words only, as in "thistle", but
    not "this" or "island".

-- 
Andrew Langmead


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

Date: Mon, 20 Oct 1997 11:49:52 +0200
From: Doug Seay <seay@absyss.fr>
To: "Nikolai A. Prokofiev" <nprokofiev@wperiod.ru>
Subject: Re: Help me, please!
Message-Id: <344B2940.2CCF8B0F@absyss.fr>

[posted and mailed]

Nikolai A. Prokofiev wrote:
> 
> Hello and great PRIVET from Russia!
>     I have a troubles leaning PERL... The trouble is: I have NO
> literature on PERL, except man-files from www.perl.org and
> www.cit-forum.ru. Please, sent me URL's to examples of live PERL-scripts
> because of it can help me to learn it...

The man-files are excellent and contain thousands upon thosands of lines
of text.  They should do if you already know how to program.  Of course,
if you've never programmed before, you have lots of basics to learn. 
Try "perldoc perlsyn" and see if you get get information about Perl
syntax.  "perldoc" comes standard with all newer perl5 distributions. 
Things like "perlipc" are loaded with examples.

- doug


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

Date: 20 Oct 1997 13:04:52 GMT
From: scott@lighthouse.softbase.com (Scott McMahan)
Subject: Re: help on Win32odbc(perl)
Message-Id: <62fktk$muf$4@mainsrv.main.nc.us>

Connie Wang (c0w0461@unix.tamu.edu) wrote:
: I use win32odbc(perl) and MS Access to process a form from WWW. The
: problems are:
: 1. The value of radio box or checkbox can not be added (inserted) to
: Access database. Why?
: 2. If I leave a textbox blank, the all information from the Form
: cann't be added to the Access database. Why?

These sound like CGI processing problems to me .... and you really
don't supply enough information to tell much about what is going on. It
sound like you're trying to read the CGI input to your program and
stuff it into the database without processing it first. #2 sound like
you need to give the database an intelligent default, like NULL or
"(none)".

Scott



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

Date: Mon, 20 Oct 1997 09:42:22 -0400
From: pudge@pobox.com (Chris Nandor)
Subject: Re: Help with MacPerl help
Message-Id: <pudge-ya02408000R2010970942220001@news.idt.net>

In article <dmerberg-1410972208580001@d13.dial-2.ltn.ma.ultra.net>,
dmerberg@genetics.com (David Merberg) wrote:

# My copy of Shuck is v 1.0.

You should upgrade to the latest version of MacPerl (5.1.4r4, tho a 5.1.5
is imminent) and Shuck, which is at 1.2.  I might be able to help fix your
problem with 1.0, but I prefer not to try.  :-)

--
Chris Nandor               pudge@pobox.com           http://pudge.net/
%PGPKey=('B76E72AD',[1024,'0824 090B CE73 CA10  1FF7 7F13 8180 B6B6'])
#==                    MacPerl: Power and Ease                     ==#
#==    Publishing Date: Early 1998. http://www.ptf.com/macperl/    ==#


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

Date: Mon, 20 Oct 1997 11:43:43 +0200
From: Doug Seay <seay@absyss.fr>
To: guess <56160@udel.edu>
Subject: Re: How do I collect email address using perl?
Message-Id: <344B27CF.227A6918@absyss.fr>

[posted and mailed]

guess wrote:
> 
> This is for a school project.
> Your help is greatly appreciated.

First of all, it is bad form to ask others to do your homework. What
will happen if your professor happens to read this group?  Are there
academic integrity rules that say that this is a no-no?

That asside, you don't give us enough information.  Where will you be
getting them from?  Not from culling usenet postings, I hope.  From
email it is kinda simple, you can just look at the From:, To:, CC:, and
similar lines.

Email addresses are much more complicated than most people think.  TomC
once wrote a little routine for validating email addresses that works
fairly often, but nothing always works.  Randal has said that the only
valid way is to mail it and if you get an error (directly or via email)
then it was invalid.  Otherwise you don't know.  Not too reassuring.

- doug

<joke>
The easist way would be to buy the list that Sanford Wallace is
selling.  It should have millions of addresses, every one of which is
valid and whose owner likes getting email.
</joke>

Don't worry if you don't understand the joke, it's more sick than funny.


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

Date: Mon, 20 Oct 1997 14:22:19 +0100
From: "Robert Nosko" <robertn@dawid.com.pl>
Subject: How to change user password??
Message-Id: <62fisq$iql$1@sunsite.icm.edu.pl>

Hi,
How can I change user password on Linux using CGI  script??
Thanks in advance,
--
++++++++++++++++++++++++++++++++++++++++++
 Robert Nosko        e-mail: robertn@dawid.com.pl
 studio DAWID        ICQ: 1219984
 Lodz                        IRC nickname: ninja
++++++++++++++++++++++++++++++++++++++++++




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

Date: 20 Oct 1997 08:02:48 GMT
From: gke@meteorology.bom.gov.au (G.Embery)
Subject: Re: How to make a word bold?
Message-Id: <62f379INNc9q@meteorology.ho.BoM.GOV.AU>

: John Robson wrote:
: > I'm trying to search for a word in a text file and then change that word
: > to bold.  More precisely, print the line containing the word on the screen,
: > but show the word in BOLD.  I'm thinking maybe there is some kind of
: > special ASCII code in MS-DOS or Unix that you can substitute to make
: > something look "bold" or "underlined".  How does a word processor do it
: > anyway?  How does a word processor translate from one document format to
: > another and still preserve the word attributes?  Maybe it's not a Perl
: > question, but if Perl can do it, I'll be happy! :)

  i do the following :-

  on unix
    $HIGH = `tput bold`    # puts escape codes for bold into var HIGH.
          ##  `tput smul` for underline, `tput rev` for reverse-video
    $NORM = `tput rmso`  # codes to restore normal mode.
  or if on a color_xterm
    $HIGH = "\033[00;32m";    # the 32 gives green, 31 red , 34 blue ....
    $NORM="\033[0m";

  on MSDOS similar to color_xterm
    $HIGH = "\033[1;32m";
    $NORM="\033[0m";

 then something like this in my perl script :- 
    print if s/${word}/${HIGH}$&${NORM}/ ;


--
Gerald K. Embery ;  e-mail: G.Embery@BoM.GOV.AU ;  URL=http://www.BoM.GOV.AU/
Bureau of Meteorology Research Centre,  Melbourne,  Australia ;
Disclaimer:  These are *my* opinions, *not* those of my employer.....  [ my employer has no opinions....   ;-) ] ;
   "It's ugly but it works!"   ... old BMRC saying ...


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

Date: Mon, 20 Oct 1997 14:02:08 GMT
From: aml@world.std.com (Andrew M. Langmead)
Subject: Re: Input from plain text file
Message-Id: <EICsBK.EEK@world.std.com>

dward@pla.net.au (Darren Ward) writes:

>I need a way to read a variable length string from a file for use as a
>variable to another program.

How do you know when you have the end of a record in your variable
length input. If it is a fixed sequence of characters, you can set the
$/ variable to that string, and use the <FILEHANDLE> operator. The
value of $/ defaults to a newline, which is why <> normally returns
each line of a text file. 

If that won't work, and the file is small, then maybe you can read the
whole file into a single string, and use something like the s///
operator or maybe the substr() function. 

If the file is too big to be slurped into a string, then maybe you
could use fixed length read()s, and scan each block for the
delimiter. If you do this, I'm sure you would probably want to wrap
the input into some sort of read_next_record() subroutine.

If the input has no delimiter, then maybe you could alter some of
these suggestions based on whatever method you need of finding the end
of the record.

-- 
Andrew Langmead


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

Date: 20 Oct 1997 11:41:03 GMT
From: Janne.Leppanen@metla.fi (Janne Leppdnen)
Subject: Re: New Perl syntax idea
Message-Id: <62fg0g$tvq$2@bambu.metla.fi>

>> Well, he's not alone in thinking that "$self = shift" at the start of
>> every method is needless fluff.  (After all - Perl is happy to define $a
>> and $b for sort - why not $self for methods?)
>
>$a and $b are ugly.  They are only done for speed reasons (they're
>aliases to the real data, not actual variables).  That is a sacrifice at
>the altar of performance.
>
>As someone else asked, what will $self be.  Will it be the same as "my
>$self = shift;" or "$My::Package::self".  Perhaps it should be "local
>$self = shift;"?  I can see reasons for all three, although I would hope
>that the 'my' solution would win, althought $My"::Package::self seems
>more consistant (ie AUTOLOAD).  But what is really gained?  I agree that
>methods that don't take any parameters look dumb starting with "my
>($self) = @_;", but most of my methods take a parameter or two, so mine
>usually look like "my ($self, $arg1, @arg2) = @_;", so the extra bit for
>$self is trivial.

why not something like:

**sub->startup_code = 'my $this = shift';
**sub->exit_code    = '';

meaning

**sub or something as easy is used to configure sub meaning.
It could be restricted to cases where it actually can be used. 
I haven't thought about it that much.

I believe in flexible coding... reading OpenGL and perl manual
inspired me to it.



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

Date: Mon, 20 Oct 1997 15:20:10 +0200
From: Doug Seay <seay@absyss.fr>
To: Janne Leppdnen <Janne.Leppanen@metla.fi>
Subject: Re: New Perl syntax idea
Message-Id: <344B5A8A.6ED209A0@absyss.fr>

[posted and mailed]

Janne Leppdnen wrote:
> 
> why not something like:
> 
> **sub->startup_code = 'my $this = shift';
> **sub->exit_code    = '';
> 
> meaning
> 
> **sub or something as easy is used to configure sub meaning.
> It could be restricted to cases where it actually can be used.
> I haven't thought about it that much.

Is this some sort of meta-prototype that says all my subs will start
with this line?  This sounds like fun.  Kinda like modifying Object in
SmallTalk, eh?  What is the second line?  Does it say all subs will exit
with '' unless an explict return is used?  This is less interesting as I
like the last value being an implicit return.

- doug


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

Date: 20 Oct 1997 11:01:01 GMT
From: Janne.Leppanen@metla.fi (Janne Leppdnen)
Subject: Re: Perl equivalent to #ifdef in C?
Message-Id: <62fdld$tvq$1@bambu.metla.fi>

>? the platypus {aka David Formosa} wrote:
>>
>> There is a question that I have been wondering about and it now seems like
>> a good time to ask.  Will
>> 
>> BEGIN {
>>   if ($config_option) {
>> 
>>     sub foo {
>> #Foo code for config_option true
>>     }
>>   }  else {
>> 
>>     sub foo {
>> #Foo code for config_option false
>> 
>>    }
>> }
>> 
>> do what I thinnk its doing?
>
>No, subs are declared where ever they are seen.  You'd need an eval()s
>around your subs, otherwise the second foo() will replace the first and
>you'll get a warning (at least with -w and strict you will).


I can't understand why don't you just preprocess the perl script
with something. (that would be EQUIVALENT to #ifdef)



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

Date: Mon, 20 Oct 1997 15:10:20 +0200
From: Doug Seay <seay@absyss.fr>
To: Janne Leppdnen <Janne.Leppanen@metla.fi>
Subject: Re: Perl equivalent to #ifdef in C?
Message-Id: <344B583C.1CF57E7F@absyss.fr>

[posted and mailed]

[removed eli's newsgroup]

Janne Leppdnen wrote:

[I think I wrote this bit, the attribute line is missing]
> >No, subs are declared where ever they are seen.  You'd need an eval()s
> >around your subs, otherwise the second foo() will replace the first and
> >you'll get a warning (at least with -w and strict you will).
> 
> I can't understand why don't you just preprocess the perl script
> with something. (that would be EQUIVALENT to #ifdef)

There are a number of reasons, the main one being that Perl doesn't have
a preprocessor.  With BEGIN blocks, you have the ability to run code
while things are still compiling.  This gives you the same type of
functionality, without a different compilation step.

There is an option to use cpp to preprocess commands, but many of us
don't like it.  Personally, I don't like using cpp for several reasons

	- this is Perl, not C (why not use m4?)
	- compilation would take even longer
	- it adds no new functionality
	- # is now for comments and cpp commands

I'd rather see stuff like

BEGIN	{
	if ( $config_option )
		{ eval { sub foo() { "yes"; } } };
	else
		{ eval { sub foo() { "no"; } } };
	die "error with foo: @_\n";
	}

or for this particular (trivial) case

	use constant FOO => ($config_option ? "yes" : "no" );

For more complicated options, how about

BEGIN	{
	if ( $config_option )
		{ require 'unix.stuff.pm'; }
	else
		{ require 'non-unix.stuff.pm'; }
	}

Actually the BEGIN would be optinal here, but I'd rather get the errors
from require early and not start "real" processing with invalid
syntax.   Of course, YMMV and you can use that ugly cpp all you like.

- doug


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

Date: 20 Oct 1997 13:04:07 GMT
From: "Samir" <soyouz1@easynet.fr>
Subject: Pop up browser authentification dlg with perl???.....
Message-Id: <01bcdd60$fb1b4ac0$5a5c72c3@samir95>

Hi,

	Could someone help me..

	I would like to write a script in perl which asks the browser  to pop up
an authenfication dialog box....
	
	I had this sctipt:

	
print "HTTP/1.0 401 Access Denied\n";
print "WWW-Authenticate: Basic\n\n";


	I tried it, but nothing happens!!!

			Thank you.


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

Date: Mon, 20 Oct 1997 08:28:21 GMT
From: adelton@fi.muni.cz (Honza Pazdziora)
Subject: Re: Q: How to setup a default argument in a function?
Message-Id: <adelton.877336101@aisa.fi.muni.cz>

Eric Heft <eheft@dnaco.net> writes:

> Hi, 
> 
>    What I want to do is have a function that takes a variable number of
> arguments. 
> If an argument is not passed, I'll like to set a specific value to it.

You do not set the default value to the argument but to the variable
to which you assign the argument.

[...]

> The function works but with the strict checking turned on, complains
> that cnt has 
> not been initialized on line number 10, when called as rnd(1,6). It
> doesn't complain 
> (of course) when called as rnd(1,6,0).
> 
>  1: #! /usr/bin/perl5 -w
>  2: 
>  3: use strict;
>  4: 
>  5: sub rnd 
>  6: {
>  7:    my ($numDie,$die,$cnt) = @_;

$die = 5 unless defined $die;	$cnt = 0 unless defined $cnt;

# should be enough

>  8:    while ($numDie > 0)
>  9:    {
> 10:        $cnt = $cnt + sprintf("%d",rand($die)+1);
> 11:        $numDie --;
> 12:    }
> 13:    return ($cnt);
> 14: }
> 
> I've check the FAQ, but didn't find anything on the subject :(
> Thanks for helping me pickup perl.

Hope this helps.

--
------------------------------------------------------------------------
 Honza Pazdziora | adelton@fi.muni.cz | http://www.fi.muni.cz/~adelton/
                   I can take or leave it if I please
------------------------------------------------------------------------


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

Date: Mon, 20 Oct 1997 06:30:27 -0500
From: tadmc@flash.net (Tad McClellan)
Subject: Re: text wrap
Message-Id: <jcff26.6k.ln@localhost>

Mike Rambour (name@server.com) wrote:
:   I am trying to make the text::wrap module work, but I dont have
: privs on the server to put the module anywhere but my own cgi
: directory.  I dont know how to do this


Perl FAQ, part 8:

   "How do I keep my own module/library directory?"


--
    Tad McClellan                          SGML Consulting
    tadmc@flash.net                        Perl programming
    Fort Worth, Texas


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

Date: Mon, 20 Oct 1997 12:29:52 GMT
From: adelton@fi.muni.cz (Honza Pazdziora)
Subject: Undef in my list -- syntax suggestion
Message-Id: <adelton.877350592@aisa.fi.muni.cz>


Hallo,

I wonder if anyone else also thinks that allowing undef in my
definition would be nice to have. I do parsing of binary data and
quite often I would need something like

my ($a, undef, $b) = unpack "CCC", "ABC";

As for 5.004_01, I get "Can't declare undef operator in my" message
and even if I admit that it doesn't make sense to make undef my, it
would be a nice syntax sugar.

Or wouldn't it?

--
------------------------------------------------------------------------
 Honza Pazdziora | adelton@fi.muni.cz | http://www.fi.muni.cz/~adelton/
                   I can take or leave it if I please
------------------------------------------------------------------------


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

Date: 20 Oct 1997 12:36:04 GMT
From: nospam@ll.mit.edu (Joseph Scott Stuart)
Subject: Re: Why am I running out of memory? (bug in perl?)
Message-Id: <NOSPAM.97Oct20083604@pickering.ll.mit.edu>


In article <628pr7$r9l$1@gazette.corp.medtronic.com> news@bofh.com (Jot Powers) writes:

>I ran your program, unmodified, with the results to /dev/null for about
>10 CPU minutes on a Sun Ultra 1/170 and saw no increase in memory consumption.


Yeah, when I run it on an SGI here I see no increase in memory size.
It only eats memory on the DEC.

scott
-- 
Scott Stuart
stuart at ll mit edu



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

Date: Mon, 20 Oct 1997 09:03:35 GMT
From: paul@f1world.com (Paul Ryder)
Subject: Wildcards in Perl file search?
Message-Id: <344b1d77.2623242@news.u-net.com>

Hi,

I have a form which lets me search a file, but atm it doesnt search
for any instances of the word to search for.. ie, it only picks up
full words

Say i search for the word  toy  , it will pick up the full word 'toy'
from the file, but wont pick out the word  'newtoy' .. any simple way
to do it?   Im using   eq   atm but this doesnt support the above.

Thanks for any help in advance.
email replies to paul@pry.u-net.com

_________________________________________________
Paul Ryder                 http://www.f1world.com         
paul@pry.u-net.com         ICQ : 262573
paul@f1world.com
paul@quake2.com


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

Date: 20 Oct 1997 11:52:32 GMT
From: Janne.Leppanen@metla.fi (Janne Leppdnen)
Subject: Windoze question..
Message-Id: <62fgm0$tvq$3@bambu.metla.fi>

Does anyone know can I automate installation of printer drivers with perl?

Can I handle program groups with it? (the startup-folder for example)

Can I automate installation of stupid programs like Netscape,Acrobat viewer
somehow?

Under Windoze NT,95 and 3.1...
I'll have to do those for near 200 machines so please!!

Or any other suggestion of net configuration of those machines.
(I know Windows sux.. but this deeply)





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

Date: 8 Mar 97 21:33:47 GMT (Last modified)
From: Perl-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 8 Mar 97)
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". The real FAQ, as it
appeared last in the newsgroup, can be retrieved with the request "send
perl-users FAQ". Due to their sizes, neither the Meta-FAQ nor the FAQ
are included in the digest.

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

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


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

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