[24218] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 6410 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Apr 16 11:05:49 2004

Date: Fri, 16 Apr 2004 08:05:09 -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           Fri, 16 Apr 2004     Volume: 10 Number: 6410

Today's topics:
    Re: A serious question about cgi (intermediate-newbie) (Vetle Roeim)
        alternative to "cwd()" <sunil_franklin@hotmail.com>
    Re: alternative to "cwd()" (Anno Siegel)
    Re: alternative to "cwd()" <brian.mcgonigle@verizon.net>
    Re: alternative to "cwd()" <vek@station02.ohout.pharmapartners.nl>
    Re: alternative to "cwd()" (Anno Siegel)
    Re: alternative to "cwd()" <tassilo.parseval@rwth-aachen.de>
    Re: alternative to "cwd()" <jlell@jakoblell.de>
    Re: Checking whether a socket has been closed by the pe <vek@station02.ohout.pharmapartners.nl>
        Create MD5 of files in directories and subdirectories (nicogroen)
    Re: Create MD5 of files in directories and subdirectori <jwillmore@remove.adelphia.net>
    Re: Create MD5 of files in directories and subdirectori <jwillmore@remove.adelphia.net>
        Drawing graphs <porter970@lycos.com>
        print LIST vs print join "", LIST (Xavier Noria)
    Re: print LIST vs print join "", LIST <nobull@mail.com>
    Re: print LIST vs print join "", LIST <thepoet_nospam@arcor.de>
    Re: print LIST vs print join "", LIST <jwillmore@remove.adelphia.net>
        Problems using regexp with cygwin diff on Windows 2000 (Joerg Moeller)
    Re: Problems using regexp with cygwin diff on Windows 2 <mothra@mothra.pub>
    Re: question about substr (Anno Siegel)
    Re: recording votes (Randal L. Schwartz)
        regexes <perl@my-header.org>
    Re: regexpr question   is w2 taken (Anno Siegel)
    Re: running multiple versions of perl <mothra@mothra.pub>
    Re: strange side-effect (bug?) in Net::SMTP (Ian D.)
    Re: strange side-effect (bug?) in Net::SMTP <jwillmore@remove.adelphia.net>
    Re: sub should return modified value (Anno Siegel)
    Re: sub should return modified value <matternc@comcast.net>
    Re: sub should return modified value <tadmc@augustmail.com>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: 16 Apr 2004 04:18:43 -0700
From: vetro@online.no (Vetle Roeim)
Subject: Re: A serious question about cgi (intermediate-newbie)
Message-Id: <a09be51e.0404160318.4c76edaf@posting.google.com>

"Robin" <robin @ infusedlight.net> wrote in message news:<c5n4am$ut8$1@reader2.nmix.net>...
> "Vetle Roeim" <vetro@online.no> wrote in message
> news:m33c75ndtu.fsf@quimby.dirtyhack.org...
> > * robin @ infusedlight.net
> > > I'm beginng to understand cgi.pm....and I'm wondering if there's any
> > > way to deny a client side user their privelege to submit a form over
> > > and over again by clicking back on their browser and submitting it
> > > again or clicking the button to submit the form before the page with
> > > the form goes on to the next page...do I have to log ips or
> > > something?
> >
> >   You can generate a "ticket" that can only be used
> >   once. I.e. generate a ticket when the form is accessed, and check
> >   that the ticket is valid in the Perl code that recieves the form
> >   data when the user clicks the submit button.
> 
> good point. Thanks.

  This won't prevent users from posting a lot of annoying messages
  on a bulletin board, though.

  I've used this kind of one time ticket if submitting the form kicks
  off some kind of specific action on the server... If it sends a mail,
  for instance. Generating a one time ticket may prevent the user from
  sending the same data in the mail multiple times.


vr


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

Date: Fri, 16 Apr 2004 16:21:44 +0530
From: "Sunil" <sunil_franklin@hotmail.com>
Subject: alternative to "cwd()"
Message-Id: <02Pfc.8$Py2.83@news.oracle.com>

All,
    I have code like
                use Cwd;
                my $currDir =  cwd();
    and I get an error
                Can't locate Cwd.pm in @INC (@INC contains:
 .................................. .......... .........)

    I cannot change @INC by setting the value of  PERL5LIB. or do a  "use
lib ..."

    Is there any other very basic way of getting the current working
directory, which will work always.



Thanks,
Sunil.




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

Date: 16 Apr 2004 11:05:51 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: alternative to "cwd()"
Message-Id: <c5oemf$2cb$2@mamenchi.zrz.TU-Berlin.DE>

Sunil <sunil_franklin@hotmail.com> wrote in comp.lang.perl.misc:
> All,
>     I have code like
>                 use Cwd;
>                 my $currDir =  cwd();
>     and I get an error
>                 Can't locate Cwd.pm in @INC (@INC contains:
> .................................. .......... .........)
> 
>     I cannot change @INC by setting the value of  PERL5LIB. or do a  "use
> lib ..."

What's stopping you?

>     Is there any other very basic way of getting the current working
> directory, which will work always.

"use lib ..." works always, as far as anything works "always".  Your
question is like saying, "I want to turn the light on, but I can't use
the switch.  Is there a method that works always?"

You can push things on @INC directly, but that's harder to do (in time)
than "use lib".

Anno


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

Date: Fri, 16 Apr 2004 11:27:35 GMT
From: Brian McGonigle <brian.mcgonigle@verizon.net>
Subject: Re: alternative to "cwd()"
Message-Id: <HqPfc.45434$F9.11437@nwrddc01.gnilink.net>

Sunil wrote:
> All,
>     I have code like
>                 use Cwd;
>                 my $currDir =  cwd();
>     and I get an error
>                 Can't locate Cwd.pm in @INC (@INC contains:
> .................................. .......... .........)
> 
>     I cannot change @INC by setting the value of  PERL5LIB. or do a  "use
> lib ..."
> 
>     Is there any other very basic way of getting the current working
> directory, which will work always.
> 
> 
> 
> Thanks,
> Sunil.
> 
> 

"$currDir = $ENV{PWD}" works on unix/linux and maybe MacOS X, I heard it 
was unix-based.

"$currDir = `chdir`" will print the cwd on Win32.


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

Date: 16 Apr 2004 11:31:43 GMT
From: Villy Kruse <vek@station02.ohout.pharmapartners.nl>
Subject: Re: alternative to "cwd()"
Message-Id: <slrnc7vh0u.4bo.vek@station02.ohout.pharmapartners.nl>

On 16 Apr 2004 11:05:51 GMT,
    Anno Siegel <anno4000@lublin.zrz.tu-berlin.de> wrote:


>
> "use lib ..." works always, as far as anything works "always".  Your
> question is like saying, "I want to turn the light on, but I can't use
> the switch.  Is there a method that works always?"
>


lib.pm and Cwd.pm usualy lives in the same directory and if a program
can't find Cwd.pm it may also have trouble find lib.pm.


> You can push things on @INC directly, but that's harder to do (in time)
> than "use lib".

The only tricky part is to do it in a BEGIN block for it to have any effect
for the "use" statements.


Villy


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

Date: 16 Apr 2004 11:47:43 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: alternative to "cwd()"
Message-Id: <c5oh4v$4in$2@mamenchi.zrz.TU-Berlin.DE>

Villy Kruse  <nobody> wrote in comp.lang.perl.misc:
> On 16 Apr 2004 11:05:51 GMT,
>     Anno Siegel <anno4000@lublin.zrz.tu-berlin.de> wrote:
> 
> 
> >
> > "use lib ..." works always, as far as anything works "always".  Your
> > question is like saying, "I want to turn the light on, but I can't use
> > the switch.  Is there a method that works always?"
> >
> 
> 
> lib.pm and Cwd.pm usualy lives in the same directory and if a program
> can't find Cwd.pm it may also have trouble find lib.pm.

These are standard modules.  If a binary called "perl" can't find
them, it isn't perl and should be renamed :)

> > You can push things on @INC directly, but that's harder to do (in time)
> > than "use lib".
> 
> The only tricky part is to do it in a BEGIN block for it to have any effect
> for the "use" statements.

That's why the "lib" pragma exists in the first place.

Anno


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

Date: 16 Apr 2004 12:17:54 GMT
From: "Tassilo v. Parseval" <tassilo.parseval@rwth-aachen.de>
Subject: Re: alternative to "cwd()"
Message-Id: <c5oith$3jdl0$1@ID-231055.news.uni-berlin.de>

Also sprach Anno Siegel:

> Villy Kruse  <nobody> wrote in comp.lang.perl.misc:
>> On 16 Apr 2004 11:05:51 GMT,
>>     Anno Siegel <anno4000@lublin.zrz.tu-berlin.de> wrote:
>> 
>> 
>> >
>> > "use lib ..." works always, as far as anything works "always".  Your
>> > question is like saying, "I want to turn the light on, but I can't use
>> > the switch.  Is there a method that works always?"
>> >
>> 
>> 
>> lib.pm and Cwd.pm usualy lives in the same directory and if a program
>> can't find Cwd.pm it may also have trouble find lib.pm.
> 
> These are standard modules.  If a binary called "perl" can't find
> them, it isn't perl and should be renamed :)

There are some contrived examples where things are a little more
complicated. I remember some of my experiments I made with FreeBSD. One
of the first things I set up was my mp3-player which is written in Perl.
However, one of the essential modules it relied on wasn't installable
on FreeBSD. So what I did was using FreeBSD's linux-emulation to use my
Debian Perl. As the Debian partition naturally was not mounted as /, I
at first wasn't able to do anything with this perl because no modules
could be loaded, _including_ lib.pm and Config.pm. I eventually solved
the problem by changing the shebang line in my mp3-player to

    #!/mnt/linux/usr/bin/perl -w -I/mnt/linux...

Sometimes the -I switch can be real lifesaver.

Tassilo
-- 
$_=q#",}])!JAPH!qq(tsuJ[{@"tnirp}3..0}_$;//::niam/s~=)]3[))_$-3(rellac(=_$({
pam{rekcahbus})(rekcah{lrePbus})(lreP{rehtonabus})!JAPH!qq(rehtona{tsuJbus#;
$_=reverse,s+(?<=sub).+q#q!'"qq.\t$&."'!#+sexisexiixesixeseg;y~\n~~dddd;eval


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

Date: Fri, 16 Apr 2004 15:39:41 +0200
From: Jakob Lell <jlell@jakoblell.de>
Subject: Re: alternative to "cwd()"
Message-Id: <pan.2004.04.16.13.39.40.664050@jakoblell.de>

On Fri, 16 Apr 2004 16:21:44 +0530, Sunil wrote:

> All,
>     I have code like
>                 use Cwd;
>                 my $currDir =  cwd();
>     and I get an error
>                 Can't locate Cwd.pm in @INC (@INC contains:
> .................................. .......... .........)
> 
>     I cannot change @INC by setting the value of  PERL5LIB. or do a  "use
> lib ..."
> 
>     Is there any other very basic way of getting the current working
> directory, which will work always.

Hello,
the POSIX-module provides the function getcwd:

use POSIX qw(getcwd);
my $currdir=getcwd();

Regards
     Jakob



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

Date: 16 Apr 2004 11:46:22 GMT
From: Villy Kruse <vek@station02.ohout.pharmapartners.nl>
Subject: Re: Checking whether a socket has been closed by the peer
Message-Id: <slrnc7vhse.4bo.vek@station02.ohout.pharmapartners.nl>

On Fri, 16 Apr 2004 10:58:05 +0200,
    Jakob Lell <jlell@jakoblell.de> wrote:


> On Fri, 16 Apr 2004 07:01:04 +0000, Villy Kruse wrote:
>
>> The normal way to detect a peer close is reading from the socket and
>> the peer close is indicated by returning an EOF condition.  The socket
>> is considered connected as long there are still bytes to be read from
>> the socket even after the peer has actualy closed.
>
> Hello,
> I know I could try to read from the socket and check for an EOF condition.
> However, as I'm using nonblocking IO, I want to check whether the
> connection is still alive without reading from the socket. eof even
> returns 1 if the connection is still active but there is nothing to read
> at the moment.
>

Check the can_read method from IO::Select.  If the socket has been closed
can_read returns true and a subsequent read will return EOF.

The eof method has to tentatively read from the socket to determine if
the next read would have hit end of file.  If a character was actualy
read it is put back into the read buffer.  This probably don't work
in connection with using the sysread or recv functions.  When no data
is available I expect eof to return true and errno aka $! to be set to
EAGAIN or EWOULDBLOCK.



Villy


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

Date: 16 Apr 2004 03:06:17 -0700
From: nicogroen@planet.nl (nicogroen)
Subject: Create MD5 of files in directories and subdirectories
Message-Id: <b9343f9a.0404160206.59047d8f@posting.google.com>

Can somebody help me out with the following problem. I tried to use
the following script of Ron Savage to create MD5 checksums of files in
a directory and all subdirectories in it, posted here:

http://groups.google.nl/groups?hl=nl&lr=&ie=UTF-8&oe=UTF-8&selm=7dbo9s%24ekh2%40atbhp.corpmel.bhp.com.au&rnum=2

On OpenBSD:
It takes a long time to create MD5 checksums of large files (about 4
seconds of a file of 3MB, 12 sec of a file of 5.5MB, 43 sec of a file
of 10,5MB).

On Windows:
Files having the same filesize (all 14,5MB) creates the same MD5
checksum. This process goes very fast (perhaps too fast).

On Redhat and FreeBSD:
The script retuns the flowing error message: 

can't open (#path#
): No such file or directory at md5.pl line 39.

The script should work on all operation systems.

Thanks in advance,
Nico


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

Date: Fri, 16 Apr 2004 09:24:38 -0400
From: James Willmore <jwillmore@remove.adelphia.net>
Subject: Re: Create MD5 of files in directories and subdirectories
Message-Id: <pan.2004.04.16.13.24.32.836279@remove.adelphia.net>

On Fri, 16 Apr 2004 03:06:17 -0700, nicogroen wrote:

> Can somebody help me out with the following problem. I tried to use the
> following script of Ron Savage to create MD5 checksums of files in a
> directory and all subdirectories in it, posted here:
> 
> http://groups.google.nl/groups?hl=nl&lr=&ie=UTF-8&oe=UTF-8&selm=7dbo9s%24ekh2%40atbhp.corpmel.bhp.com.au&rnum=2
> 
> On OpenBSD:
> It takes a long time to create MD5 checksums of large files (about 4
> seconds of a file of 3MB, 12 sec of a file of 5.5MB, 43 sec of a file of
> 10,5MB).
> 
> On Windows:
> Files having the same filesize (all 14,5MB) creates the same MD5
> checksum. This process goes very fast (perhaps too fast).
> 
> On Redhat and FreeBSD:
> The script retuns the flowing error message:
> 
> can't open (#path#
> ): No such file or directory at md5.pl line 39.
> 
> The script should work on all operation systems.

Yes, it should (and appears it has) work(ed) on almost all platforms -
because you noticed a difference in the execution times :-)

Posting your code would be helpful :-)

-- 
Jim

Copyright notice: all code written by the author in this post is
 released under the GPL. http://www.gnu.org/licenses/gpl.txt 
for more information.

a fortune quote ...
 I'll defend to the death your right to say that, but I never
 said I'd listen to it!   -- Tom Galloway with apologies to
 Voltaire 


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

Date: Fri, 16 Apr 2004 09:44:04 -0400
From: James Willmore <jwillmore@remove.adelphia.net>
Subject: Re: Create MD5 of files in directories and subdirectories
Message-Id: <pan.2004.04.16.13.43.57.721000@remove.adelphia.net>

On Fri, 16 Apr 2004 09:24:38 -0400, James Willmore wrote:

> On Fri, 16 Apr 2004 03:06:17 -0700, nicogroen wrote:
> 
>> Can somebody help me out with the following problem. I tried to use the
>> following script of Ron Savage to create MD5 checksums of files in a
>> directory and all subdirectories in it, posted here:
>> 
>> http://groups.google.nl/groups?hl=nl&lr=&ie=UTF-8&oe=UTF-8&selm=7dbo9s%24ekh2%40atbhp.corpmel.bhp.com.au&rnum=2
[ ... ]

> Posting your code would be helpful :-)

My bad, you did post code :-)

I ran it on ye olde Linux box and it worked up until it ran into a
directory that I had no permission to access ... bummer :-(

You're execution time will depend greatly on the OS and the filesystem
being accessed.  That's not the script (in most cases).  

IMHO, you might be able to speed up the script by using File::Find instead
of using Cwd. 

Another option is to use this script as a filter and use a command native
to the OS to feed the script files.  Meaning, use `find` (in *nix) and pipe the
output to the script you're working with.  Now your only concern is check
the MD5 digest of each file the script is being feed :-)   An added plus
to this idea is ... you can check one -or- many files with your script
without the script having to figure out *how* to find the files (using Cwd
or Find::Files).

HTH

-- 
Jim

Copyright notice: all code written by the author in this post is
 released under the GPL. http://www.gnu.org/licenses/gpl.txt 
for more information.

a fortune quote ...
 It is very difficult to prophesy, especially when it pertains to
 the future. 
 


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

Date: Fri, 16 Apr 2004 09:21:56 -0600
From: "porter970" <porter970@lycos.com>
Subject: Drawing graphs
Message-Id: <107vr09f3msjn8b@corp.supernews.com>

I need to draw a series of small 50 x 50 pixel graphs.  I'm currently using
GD-2.0.12 and when the graph gets this small the quality is pretty poor.  My
question, is it worth updating to the newest version of GD (2.0.22 according
to http://www.boutell.com/gd/ ?) or is there another option?

Upgrading isn't without problems since I don't have hands on access to the
server and the guy that does NEVER gets things to work first (or second)
try.

Steve




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

Date: 16 Apr 2004 04:06:59 -0700
From: fxn@hashref.com (Xavier Noria)
Subject: print LIST vs print join "", LIST
Message-Id: <31a13074.0404160306.5bedc6e9@posting.google.com>

In a recent article by Dan Sugalski there's this code[*]:

    foreach my $node (@nodes) {
        my (@lines) = process_node(@$node);
        print join("", @lines);
   }

Is that print line a matter of style, or is it a better choice over the much simpler

    print @lines;

?

-- fxn

[*] Near the bottom of the second page: 
http://www.onlamp.com/pub/a/onlamp/2004/04/15/parrot_compiler_construction.html


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

Date: 16 Apr 2004 13:53:01 +0100
From: Brian McCauley <nobull@mail.com>
Subject: Re: print LIST vs print join "", LIST
Message-Id: <u9u0zk3x02.fsf@wcl-l.bham.ac.uk>

fxn@hashref.com (Xavier Noria) writes:

> In a recent article by Dan Sugalski there's this code[*]:
> 
>     foreach my $node (@nodes) {
>         my (@lines) = process_node(@$node);
>         print join("", @lines);
>    }
> 
> Is that print line a matter of style, or is it a better choice over the much simpler
> 
>     print @lines;

That would depend on whether or not it is safe to assume that $,=''

(A lot of commonly used modules _do_ assume this so IMHO it's best never
to muck with $,)

-- 
     \\   ( )
  .  _\\__[oo
 .__/  \\ /\@
 .  l___\\
  # ll  l\\
 ###LL  LL\\


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

Date: Fri, 16 Apr 2004 14:55:47 +0200
From: "Christian Winter" <thepoet_nospam@arcor.de>
Subject: Re: print LIST vs print join "", LIST
Message-Id: <407fd7e9$0$3187$9b4e6d93@newsread2.arcor-online.net>

"Xavier Noria" schrieb:
> In a recent article by Dan Sugalski there's this code[*]:
>
>     foreach my $node (@nodes) {
>         my (@lines) = process_node(@$node);
>         print join("", @lines);
>    }
>
> Is that print line a matter of style, or is it a better choice over the
much simpler
>
>     print @lines;
>
> ?

"print @lines" may yield unexpected results when you
mess around with the output record separator $, that
is inserted in between each list item.
See "perldoc -f print" and "perldoc perlvar" on that.
Maybe Dan just wanted to be sure this won't happen
(especially inside a module it's often a wise thing
not to rely on defaults too heavily).

Just imagine a module a.pm that provides method b looking like
sub b { print @_ }
which is expected to print the given list items concatenated.
If you call it with code like
use a;
$, = "anoddseparator";
a::b(1,2,3);
then your output will be
1anoddseparator2anoddseparator3 instead of 123.


HTH
-Christian



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

Date: Fri, 16 Apr 2004 09:17:25 -0400
From: James Willmore <jwillmore@remove.adelphia.net>
Subject: Re: print LIST vs print join "", LIST
Message-Id: <pan.2004.04.16.13.17.19.672880@remove.adelphia.net>

On Fri, 16 Apr 2004 04:06:59 -0700, Xavier Noria wrote:

> In a recent article by Dan Sugalski there's this code[*]:
> 
>     foreach my $node (@nodes) {
>         my (@lines) = process_node(@$node);
>         print join("", @lines);
>    }
> 
> Is that print line a matter of style, or is it a better choice over the much simpler
> 
>     print @lines;

IMHO, if you just want the list, use the later code.  If you want to print
the list in some format (like using newlines to separate the elements of
the list), use the former.

#print newlines after each element of the list
print join("\n", @list),"\n";

#print ':' between each element of the list
print join(':', @list),"\n";

#print the list
print @list,"\n";

Notice the newlines at the end of each example.  I find it "nice" to put
that in ... try them without to see why it's "nice" to do this :-)

HTH

-- 
Jim

Copyright notice: all code written by the author in this post is
 released under the GPL. http://www.gnu.org/licenses/gpl.txt 
for more information.

a fortune quote ...
 There are three kinds of lies: Lies, Damn Lies, and Statistics. 
 -- Disraeli 
 


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

Date: 16 Apr 2004 04:23:48 -0700
From: joergmoellernexpress@hotmail.com (Joerg Moeller)
Subject: Problems using regexp with cygwin diff on Windows 2000
Message-Id: <caf034b4.0404160323.5faeef79@posting.google.com>

Hello!

I was thinking quite some time if this is the correct group to post to
because actually the problem isn't so much related to the regex but to
os issues. I was wondering if I should post it to unix, msdos,
windows, gnu.... related group but finally decided to try it here
because I hope that here are some experts around with experience in
unix, windows, msdos and gnu. If you could point me to the correct
group I would appreciate it.

Actually the whole problem is that I'm on an Windows 2000 box and need
to use the cygwin diff tool together with a regular expression to omit
some lines. Unfortunately the lines I want to omit contains multiple
occurances of >'<. Even more unfortunately the regular expression for
diff shall be surrounded by >'<. Even if escape the >'< in the regular
expression the diff tool thinks it's the end of the regular expression
and is omplaining about the rest.

Example:

diff -I '^\s*VERSION' aCMNdiskDriveController.contrib1
aCMNdiskDriveController.base

works fine but the regular expression is incomplete. A more complete
expression would be

C:\cygwin\bin>diff -I '^\s*VERSION [\w\d\\_\.\']*'
aCMNdiskDriveController.contrib1 aCMNdiskDriveController.base

What give the following error:
diff: missing operand after `\s*VERSION [\w\d\_\.']*
aCMNdiskDriveController.contrib1 aCMNdiskDriveController.base'
diff: Try `diff --help' for more information.

Anybody an idea what's wrong or how to work around this problem? 

Regards
Joerg


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

Date: Fri, 16 Apr 2004 14:57:40 +0100
From: "Mothra" <mothra@mothra.pub>
Subject: Re: Problems using regexp with cygwin diff on Windows 2000
Message-Id: <c5oomv$51q$1@newsg4.svr.pol.co.uk>


> Anybody an idea what's wrong or how to work around this problem?
>
I think you've already identified the problem:  a bug in the Cygwin shell.




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

Date: 16 Apr 2004 10:56:15 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: question about substr
Message-Id: <c5oe4f$2cb$1@mamenchi.zrz.TU-Berlin.DE>

Chuck <EatMeSpammers_cwtart@commpay.tv> wrote in comp.lang.perl.misc:

> arrogant pricks as you guys in this newsgroup. Don't assume that each new
> poster here is a wet-behind-the-ears computer geek.

We only assume what we can deduce from what you post.

Experienced programmers know how to look things up in the documentation.  
Asking a question (except "where is the documentation") before doing that
marks you as a wet-behind-the-ears computer geek.  That you have managed
to stay one through years of programming experience is remarkable, but
in no way unique.  We have a few regular visitors of that type.

Anno


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

Date: 16 Apr 2004 07:59:02 -0700
From: merlyn@stonehenge.com (Randal L. Schwartz)
To: user99@austin.rr.com (user99)
Subject: Re: recording votes
Message-Id: <86smf47yvd.fsf@blue.stonehenge.com>

*** post for FREE via your newsreader at post.newsfeed.com ***

>>>>> "user99" == user99  <user99@austin.rr.com> writes:

user99> my page has a drop down with names which
user99> people can vote for.  any ideas on how
user99> i can record the individual count of
user99> votes for each name.  i'm thinking about
user99> using a text file to store the names with
user99> the vote count and incrementing the counts
user99> and then write them back to the same file.

user99> any better ideas????

Been there, done that.

        <http://www.stonehenge.com/merlyn/WebTechniques/col59.html>

or for the "more safe for work but annoyingly more abstract" version, see:

        <http://www.stonehenge.com/merlyn/WebTechniques/col59wt.html>

I need to update that script to work with the redesign of their website.

print "Just another Perl hacker,";

-- 
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!


 -----= Posted via Newsfeed.Com, Uncensored Usenet News =-----
http://www.newsfeed.com - The #1 Newsgroup Service in the World!
-----== 100,000 Groups! - 19 Servers! - Unlimited Download! =-----
                  


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

Date: Fri, 16 Apr 2004 15:13:59 +0200
From: Matija Papec <perl@my-header.org>
Subject: regexes
Message-Id: <momv70l57k9v7m1l5tsrqmk3nc04tifvv0@4ax.com>


If you ever come to idea making regexes more challenging, you could always
try it in php,

my $ym = 200405;
my($year, $month) = $ym =~ /^(\d{4})(\d{2})$/;

is "same" as,

$ym = 200405;
preg_match("/^(\d{4})(\d{2})$/", $ym, $tmp);
list($year, $month) = array_slice($tmp, 1);

:)


-- 
Matija


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

Date: 16 Apr 2004 11:48:53 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: regexpr question   is w2 taken
Message-Id: <c5oh75$4in$3@mamenchi.zrz.TU-Berlin.DE>

Richard Bell  <rbell01824@earthlink.net> wrote in comp.lang.perl.misc:
> 
> I'm a bit new to perl and am trying to emulate the behavior of a free
> text search engine that has a feature
> 
> 	is w2 taken
> 
> taken to mean the word 'is' within 2 words of the word 'taken' where
> the distance (2) and the words ('is', 'taken') are arbitrary.
> 
> I've a variable that looks like this
> 
> 'one two three four and so on words seperated by spaces that goes on
                                      ^^^^^^^^^
"separated"

> and on and on and on for a very long way'
> 
> that I'm tring to process.
> 
> I'm having a problem finding a regular expression that handles this
> case.  Something like
> 
> "\bis\b(what goes here){0,2}\btaken\b"
> 
> Can someone point me in the right direction?

An approach:

    my ( $first, $last, $n) = ( 'words', 'spaces', 2);

    my $any_word = qr/\s*\b\S+/;
    print "$1\n" if /($first${any_word}{0,$n}\s*\b$last)/;

> I assume that $pos will point to the last character matched.  Is this
> correct?

$pos?  If you mean the pos() function, it is not correct.  perldoc -f pos.

>           How can I know the index of the first character matched? Can
> I know what '(what goes here)' matched?  How?  As part of this
> process,

You ned to read up on regular expressions.  These are very elementary
questions.  Look for capturing parentheses in perlre and for the
arrays @+ and @- in perlvar.

>             I'm trying to track what characters in the string were
> matched by a number of regular expressions by getting $pos and keeping
> a bit map of the characters matched.

A bit map of the characters matched?  I'm not sure what you mean, but
you may want vec() and ord().  Watch out for unicode.

Anno



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

Date: Fri, 16 Apr 2004 15:05:09 +0100
From: "Mothra" <mothra@mothra.pub>
Subject: Re: running multiple versions of perl
Message-Id: <c5op4v$9he$1@news7.svr.pol.co.uk>

"Yoda Pugsley" <here@there.com> wrote in message
news:Xns94C9A13B64BADheretherecom@65.32.1.6...
> I'm new to perl and need to write a script for work. After doing some
> research into writing perl scripts (I'm a .net dev), I found that a lot of
> the examples I had found did not work. After a lot of head scratching (the
> UNIX admins are a lot of help too /sarcasm)
Those are bad admins then - I'm an Admin and I insisted that all our servers
were upgraded to 5.8.0... but then I'm a Perl coder as well. :o)

> I checked the perl version,
> 5.005_3. Most of the examples are from perl 5.8, hence no workie on
> 5.0whatever.
>
> Given all of this, I'd like to install my own copy of perl 5.8 in my home
> directory. Is that going to interfere with the current 5.0 install? I
don't
> think I could get the admins to move the whole machine to 5.8, so it has
to
> be a local kind of thing. I know what might happen if I tried something
> like this on a Windows machine, but on UNIX, is it possible?
>
Yes it is possible.  We run some Portal Infranet sevrers here and it comes
with its own complete (out-of-date) version of Perl installed under
/export/home/<username>.  As long as you make sure all the files are in one
location and that you don't choose the option to link /usr/bin/perl to
*your* version, you should be fine.




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

Date: 16 Apr 2004 06:30:23 -0700
From: id2001@cablelabs.com (Ian D.)
Subject: Re: strange side-effect (bug?) in Net::SMTP
Message-Id: <1276a5f0.0404160530.13678080@posting.google.com>

Bob Walton <invalid-email@rochester.rr.com> wrote in message news:<407F462E.6050803@rochester.rr.com>...
> Ian D. wrote:
> 
> > This is perl, version 5.005_02 built for sun4-solaris
> > 
> > I have an array that is wiped out when calling Net::SMTP->new.  Here
> > is a debug from it.  Note my array is intact at line 356, but after a
> > 'next', it is gone:
> > 
> > main::check_mailservers(./conchk:356):
> > 356:            $smtp = Net::SMTP->new('ondar',Timeout=>10,Debug=>0);
> >   DB<2> x @MAILSERVERS
> > 0  ARRAY(0x6ea244)
> >    0  'sendmail'
> >    1  'ondar'
> >    2  'nobody@cablelabs.com'
> >    3  'nobody@localhost'
> >    4  150
> 
> 
> So, @MAILSERVERS is a one-element array, the value of which is a 
> reference to another array with 5 elements.  The first four of those 
> elements have values which are various strings, and the fifth has a 
> value which is an integer.
> 
> 
> >   DB<3> n                                                             
> >                                                            
> > main::check_mailservers(./conchk:357):
> > 357:                    $td=tv_interval($t0);
> >   DB<3> x @MAILSERVERS
> > 0  undef  <======= WHAT THE HECK JUST HAPPENED???
> 
> 
> And now @MAILSERVERS is still a one-element array, but the value of it 
> is now undef, rather than an array reference.  This behavior could be 
> explained if junk450.pl is the following program:
> 
> D:\junk>type junk450.pl
> $MAILSERVERS[0]=[
>                   'sendmail',
>                   'ondar',
>                   'nobody@cablelabs.com',
>                   'nobody@localhost',
>                   150,
>                  ];
> for $smtp (@MAILSERVERS){
>          $smtp=undef;
> }
> --------------------------------
> and it is stepped through as follows:
> --------------------------------
> 
> D:\junk>perl -d junk450.pl
> 
> Loading DB routines from perl5db.pl version 1.19
> Editor support available.
> 
> Enter h or `h h' for help, or `perldoc perldebug' for more help.
> 
> main::(junk450.pl:1):   $MAILSERVERS[0]=[
> main::(junk450.pl:2):                    'sendmail',
> main::(junk450.pl:3):                    'ondar',
> main::(junk450.pl:4):                    'nobody@cablelabs.com',
> main::(junk450.pl:5):                    'nobody@localhost',
> main::(junk450.pl:6):                    150,
> main::(junk450.pl:7):                   ];
>   DB<1> s
> main::(junk450.pl:8):   for $smtp (@MAILSERVERS){
>   DB<1> s
> main::(junk450.pl:9):           $smtp=undef;
>   DB<1> x @MAILSERVERS
> 0  ARRAY(0x1558798)
>    0  'sendmail'
>    1  'ondar'
>    2  'nobody@cablelabs.com'
>    3  'nobody@localhost'
>    4  150
>   DB<2> n
> main::(junk450.pl:8):   for $smtp (@MAILSERVERS){
>   DB<2> x @MAILSERVERS
> 0  undef
>   DB<3>
> 
> 
> Note the debug output which is identical to yours (except of course for 
> the address of the anonymous array and the line numbers).
> 
> 
> > 
> > A bug?
> 
> 
> Yes, in your code.
> 
> 
> > 
> > Ian
> >


Thanks for the reply, but I don't think that is it.  I don't have to
assign the new Net::SMTP object to anything, and my array is still
wiped out.  Here's more debug output:

  DB<7> x @MAILSERVERS
0  ARRAY(0x740594)
   0  'sendmail'
   1  'ondar'
   2  'nobody@cablelabs.com'
   3  'nobody@localhost'
   4  150
  DB<8> Net::SMTP->new('ondar');
  DB<9> x @MAILSERVERS
0  undef


Somehow my anonymous array at 0x740594 in this case is being
overwritten in the new() function, but I don't know why.

Ian


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

Date: Fri, 16 Apr 2004 09:55:52 -0400
From: James Willmore <jwillmore@remove.adelphia.net>
Subject: Re: strange side-effect (bug?) in Net::SMTP
Message-Id: <pan.2004.04.16.13.55.47.71969@remove.adelphia.net>

On Fri, 16 Apr 2004 06:30:23 -0700, Ian D. wrote:

[ ... ]

>   DB<7> x @MAILSERVERS
> 0  ARRAY(0x740594)
>    0  'sendmail'
>    1  'ondar'
>    2  'nobody@cablelabs.com'
>    3  'nobody@localhost'
>    4  150
>   DB<8> Net::SMTP->new('ondar');
>   DB<9> x @MAILSERVERS
> 0  undef
> 
> 
> Somehow my anonymous array at 0x740594 in this case is being
> overwritten in the new() function, but I don't know why.

Can you provide the offending code (**NOT** the whole script, just the
portions that appear to be given you issue).  I can see something is going
South, but at a loss to know why.

-- 
Jim

Copyright notice: all code written by the author in this post is
 released under the GPL. http://www.gnu.org/licenses/gpl.txt 
for more information.

a fortune quote ...
 I've given up reading books; I find it takes my mind off myself.
 
 


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

Date: 16 Apr 2004 10:33:53 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: sub should return modified value
Message-Id: <c5ocqh$t7m$1@mamenchi.zrz.TU-Berlin.DE>

Bart Van der Donck <bart@nijlen.com> wrote in comp.lang.perl.misc:
> Hello,
> 
> Suppose this code:
> 
> # ---------------------------
> $a=2;
> print "variable a has now value '$a'.\n";
> &addone($a);
> print "variable a has now value '$a'.\n";
> sub addone
> {
> $b=shift;

$b is now a *copy* of the parameter

> $b++;
> return $b;
> }
> # ---------------------------
> 
> gives as result:
> 
> variable a has now value '2'.
> variable a has now value '2'.
> 
> Is it possible to have $a at value '3' after executing the sub ?
> I tried with 'return', 'shift' and so, but couldn't find a way so that
> $a would directly be affected by what happens in sub &addone (without
> variable $a is mentionned in sub &addone obviously).

You must modify the parameter in @_ directly.

    sub addone { $_[ 0] ++ }

and even

    sub addone { $_ ++ for shift }

do what you want.  After assigning the value to a lexical in the
sub body, you increment *that* and not the original variable.

However, argument-modifying functions are problematic and should
normally be avoided.  In languages like C, where a sub can only
return one value, there often is not much choice if more than one
result is needed from a sub.  Perl subs can return as many values
as they want to, so there is rarely a need for argument-modification.

Anno


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

Date: Fri, 16 Apr 2004 09:08:53 -0400
From: Chris Mattern <matternc@comcast.net>
Subject: Re: sub should return modified value
Message-Id: <G56dnZDGCd57R-LdRVn-ig@comcast.com>

Bart Van der Donck wrote:

> Hello,
> 
> Suppose this code:
> 
> # ---------------------------
> $a=2;

Don't name variables $a; it has a special meaning to sort.

> print "variable a has now value '$a'.\n";
> &addone($a);

Don't use "&" in front of subroutine calls unless you know
what it does.

> print "variable a has now value '$a'.\n";
> sub addone
> {
> $b=shift;

Don't name variables $b; it has a special meaning to sort.
Don't use globals; limit the scope of subroutine variables:

my $variable=shift;

"use strict;" will help you enforce this practice (do "use
warnings;" too).

> $b++;
> return $b;
> }
> # ---------------------------
> 
> gives as result:
> 
> variable a has now value '2'.
> variable a has now value '2'.

Well, why wouldn't it?  You haven't done anything to change $a.
> 
> Is it possible to have $a at value '3' after executing the sub ?

Yes.

> I tried with 'return', 'shift' and so, but couldn't find a way so that
> $a would directly be affected by what happens in sub &addone (without
> variable $a is mentionned in sub &addone obviously).
> 
> Thanks for tips or hints
> Bart

"return" determines what value the subroutine returns--but you don't
use the return value in the code above; you throw it away.  You need
something like this:

$a = addone($a);

-- 
             Christopher Mattern

"Which one you figure tracked us?"
"The ugly one, sir."
"...Could you be more specific?"


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

Date: Fri, 16 Apr 2004 08:53:54 -0500
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: sub should return modified value
Message-Id: <slrnc7vpbi.ha1.tadmc@magna.augustmail.com>

Bart Van der Donck <bart@nijlen.com> wrote:

> $a=2;
> print "variable a has now value '$a'.\n";
> &addone($a);
> print "variable a has now value '$a'.\n";
> sub addone
> {
> $b=shift;
> $b++;
> return $b;
> }


> Thanks for tips or hints


Indent your code blocks so as to reveal your program's structure.

Use $a only for sort()ing, choose some other name for other purposes.

Don't use ampersands on function calls unless you know what it means
and what it means is what you want.

When you have a questions about subroutines, you should read the
standard docs for subroutines before asking thousands of people
around the world.

   perldoc perlsub

Your question is answered in the 3rd paragraph...


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


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

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


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