[23522] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 5731 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Oct 30 18:07:26 2003

Date: Thu, 30 Oct 2003 15:05:16 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Thu, 30 Oct 2003     Volume: 10 Number: 5731

Today's topics:
    Re: Can't do setuid and file permision denied errors <usenet@morrow.me.uk>
    Re: Checkbox -  database checkbox, if checked gives val (James Willmore)
    Re: Checkbox -  database checkbox, if checked gives val <usenet@morrow.me.uk>
        DBI problems: from MySQL to Access <tunmaster@hotmail.com>
    Re: DHCP client tool (James Willmore)
    Re: DHCP client tool <usenet@morrow.me.uk>
    Re: difference between defined & exists <usenet@morrow.me.uk>
    Re: DOS window. <usenet@morrow.me.uk>
        File test operator (-r) returns 'not exist' rather than <kf1zr0y02@sneakemail.com>
    Re: File test operator (-r) returns 'not exist' rather  (Mike Stok)
    Re: File test operator (-r) returns 'not exist' rather  <grazz@pobox.com>
    Re: File test operator (-r) returns 'not exist' rather  <kf1zr0y02@sneakemail.com>
    Re: File test operator (-r) returns 'not exist' rather  <usenet@morrow.me.uk>
    Re: fork process to handle fifo input <usenet@morrow.me.uk>
        help to mirror cpan to local server <seawolf@attglobal.net>
        How to tell what modules are installed? (Jim Anderson)
    Re: How to tell what modules are installed? <noreply@gunnar.cc>
    Re: Java with apache from perl script? (i5513)
        Logic Flow Question (JR)
    Re: Parsing of blocks (e.g. foo { bar }) <torh+news@removethisbitbeforethedot.bogus.net>
    Re: Perl Cut Command <usenet@dwall.fastmail.fm>
    Re: Perl Cut Command <zawrotny@jaguar.sb.fsu.edu>
    Re: Perl Cut Command <jc_va@hotmail.com>
        Script Help <karigna@verizon.net>
    Re: Script Help <jgibson@mail.arc.nasa.gov>
    Re: Singleton process (JR)
    Re: Singleton process <usenet@morrow.me.uk>
        Socket.pm busted in get() ? (the_swadster)
    Re: Socket.pm busted in get() ? <no@email.com>
    Re: strange effect with [:lower:] in perl <flavell@ph.gla.ac.uk>
    Re: Win::OLE excel function run twice <brian_helterline@hp.com>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Thu, 30 Oct 2003 22:23:59 +0000 (UTC)
From: Ben Morrow <usenet@morrow.me.uk>
Subject: Re: Can't do setuid and file permision denied errors
Message-Id: <bns31v$afn$2@wisteria.csv.warwick.ac.uk>


chrisw@lu.csi.com.ph (Chris) wrote:
> tadmc@augustmail.com (Tad McClellan) wrote in message
> news:<slrnbpuk6d.gld.tadmc@magna.augustmail.com>...
> > Most uses of Perl do not require a server at all, so the least
> > you could do was tell us what _kind_ of server you are
> > dealing with: SMTP, NNTP, FTP, HTTP...
> 
> yeah, this is supposed to be dial-up authentication server..

You seem to under a common misapprehension of the meaning of 'server':
at least in this group, a server is a program, not a machine. In this
case, the particular server (among the many running on the machine
concerned) which perl will be talking to is an HTTP or web server.

> > 2) _Why_ do you think you want this? 
> 
> This is what they suggest me so I just need to make it work..

My honest suggestion is that you go back to whomever asked you to do
this and say that you do not think you are competent to write such a
security-critical application yet. The chance are they don't realise
either how important it is to get it right or how many subtle but
fatal mistakes it's only too easy to make.

> > It is *profoundly* dangerous you know...
> 
> Heah, I agree... I Was thinking of making security on the page..
> When the  pasword changer works, I supposed to make security access on
> the web page..it should be only accessed by authorized user.. I still
> dont know how but I'll figure it out..

You *MUST* make sure only authorized users can access the page before
you make it possible to change the password with it. Test the script
on a different machine, which is either not connected to the network
or is behind a girt big firewall.

Ben

-- 
               EAT
               KIDS                                          (...er, whoops...)
               FOR                                             ben@morrow.me.uk
               99p


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

Date: 30 Oct 2003 13:13:57 -0800
From: jwillmore@myrealbox.com (James Willmore)
Subject: Re: Checkbox -  database checkbox, if checked gives value of 1 .. how to sum ?
Message-Id: <d61170e5.0310301313.70a0426e@posting.google.com>

searsdvdtech@yahoo.com (randy) wrote in message news:<506a5f6b.0310300630.39b68fbf@posting.google.com>...
> I don't need you to tell me how to handle my messages. If I want to
> top post. This is my choice. Who are you the Internet miss manners
> police? If you can't help then don't post to this thread.

No.  However, there are posting guidelines for this group.
http://mail.augustmail.com/~tadmc/clpmisc/clpmisc_guidelines.html
(reference "Use an effective followup style" section)

And if you don't have a _specific_ question about programming in Perl
(meaning, something _you_ wrote, not some application you downloaded
from the 'Net and want support for), don't post.

Case closed.  Have a nice day :-)

Jim
(jwillmore _at_ adelphia _dot_ net)


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

Date: Thu, 30 Oct 2003 22:47:14 +0000 (UTC)
From: Ben Morrow <usenet@morrow.me.uk>
Subject: Re: Checkbox -  database checkbox, if checked gives value of 1 .. how to sum ?
Message-Id: <bns4di$afn$5@wisteria.csv.warwick.ac.uk>

searsdvdtech@yahoo.com (randy) wrote:
> I don't need you to tell me how to handle my messages. If I want to
> top post. This is my choice. Who are you the Internet miss manners
> police? If you can't help then don't post to this thread.

*PLONK*

Getting the idea yet?

-- 
Musica Dei donum optimi, trahit homines, trahit deos.    |
Musica truces molit animos, tristesque mentes erigit.    |   ben@morrow.me.uk
Musica vel ipsas arbores et horridas movet feras.        |


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

Date: Thu, 30 Oct 2003 21:32:03 GMT
From: "joe" <tunmaster@hotmail.com>
Subject: DBI problems: from MySQL to Access
Message-Id: <nrfob.2634$WD4.1174750@amsnews02.chello.com>

Dear guru's,

Here is what it is. I used to have my sites run on a UNIX-based webserver.
My cgi-scripts were connecting to a MySQL-database perfectly. Now I tried to
do the same thing on my Windows machine. I installed Apache, ActivePerl, DBI
and DBD to connect to a Access database. So far, so good. Everything was
going just the way I planned it. Untill...

Untill some querys weren't handled by the Access db the way they were by the
MySQL db. Simple select and delete queries are ok, but even slightly more
difficult ones make the db-connection hang.

My question: is there a possibillity to use the exact same queries on
Windows as on UNIX? I tried installing Win32::ODBC but didn't get far. Is
Win32::ODBC my promised land?

I'd be really gratefull if anyone could help me out,
Thanks in advance,

Joe




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

Date: 30 Oct 2003 13:28:59 -0800
From: jwillmore@myrealbox.com (James Willmore)
Subject: Re: DHCP client tool
Message-Id: <d61170e5.0310301328.79b7597f@posting.google.com>

pelohh@compuserve.de (Peter Lohmeier) wrote in message news:<ebbdbbfe.0310300324.442d438e@posting.google.com>...
> James Willmore <jwillmore@remove.adelphia.net> wrote in message news:<20031029111929.200f7de8.jwillmore@remove.adelphia.net>...
> > On 29 Oct 2003 05:32:35 -0800
> > pelohh@compuserve.de (Peter Lohmeier) wrote:
> > 
> > > want to test DHCP responses ...
> > > 
> > > Do you mean, it is possible to send a DHCP request with Active State
> > > Perl under W2k ??
> > 
> > Not sure.  Try using 'ppm' to 'search' for a DHCP module.
> 
> I found one in the news. 

Good :-)

<snip>
> > > And if so, would it be possible to set a special MAC Address also ??
> > > 
> > 
> > Huh?  That's a very difficult task to perform.  The MAC address is a
> > hardware address.  So, you _could_ use different NIC's to change the
> > MAC address - but that's not practical :-)  
> > 
> > I'm thinking that you _could_ do it in Perl, but it's a very difficult
> > task.
> > 
> > What is it you're trying to test?
> 
> Simply I want to prove whether a DHCP request for a specific Client PC
> - and that isn't actually my PC - gets the right answer from the
> Server.
> Therefore I have to fake the MAC Address of the Client. 

And, to further complicate an already complicated task, if you're on a
switch, the MAC address becomes even more critical.  This is because a
switch _cares_ about the MAC address - versus a hub, which listens and
sends _everything_ on the same subnet.  Read on ...

> 
> ? But if I think about that ? obviously the answer to that request
> would get lost, because although my scanning PC has a different MAC
> than the client to fake it would never listen to the answer, right ??

If you're trying to test DHCP requests, the MAC address only comes
into play _after_ getting a lease.  Before that, the DHCP server (at
least, most of them) don't care about MAC addresses.  It's only
important _after_ getting the lease.  Then the DHCP server is going to
marry the IP's and MAC's together.  Before that, it doesn't care about
what MAC addresses are out there - only the ones with leases.

> 
> In that case I have to change to the promiscuous mode of a ?sniffer'
> with perl and filter the right packets for the faked client. That
> might be the main problem. :-/

Well, depending upon the issue you're having, you may just want to
skip writting something in Perl and just snif the line :-)  Not real
sure _why_ you want to fake a client.  No offense, but this sounds a
lot like a "man in the middle" type situation you're trying to set up.

> 
> May perl be mighty to do that ??

I'm thinking yes (minus the MAC address mileu).

HTH

Jim
(jwillmore _at_ adelphia _dot_ net)


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

Date: Thu, 30 Oct 2003 22:26:51 +0000 (UTC)
From: Ben Morrow <usenet@morrow.me.uk>
Subject: Re: DHCP client tool
Message-Id: <bns37b$afn$3@wisteria.csv.warwick.ac.uk>


pelohh@compuserve.de (Peter Lohmeier) wrote:
> But I'm not shure wether it works with my Active State Perl
> Answer to "perl -v" is
> "This is perl, version 5.005_03 built for MSWin32-x86-object
>  ......."

That's very old... are you unable to upgrade for some reason?

Ben

-- 
   Although few may originate a policy, we are all able to judge it.
                                             - Pericles of Athens, c.430 B.C.
  ben@morrow.me.uk


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

Date: Thu, 30 Oct 2003 21:50:25 +0000 (UTC)
From: Ben Morrow <usenet@morrow.me.uk>
Subject: Re: difference between defined & exists
Message-Id: <bns131$9lm$2@wisteria.csv.warwick.ac.uk>


Brian McCauley <nobull@mail.com> wrote:
> BTW: Don't (yet) bother trying to understand what exists() (and
> delete()) mean when applied to array elements - it's not really
> useful[1].  
>
> [1] It has to do with pseudo-hashes which are deprocated anyhow.

Is this so? I hadn't realised. Apologies if I confused the OP:
pseudohashes are *definitely* something you don't want to know about
yet (or ever, given that they're going away soon).

Is exists() not still useful for an array element, with exists($a[$n])
being equivalent to ($n < @a)? (delete() obviously isn't.)

Ben

-- 
'Deserve [death]? I daresay he did. Many live that deserve death. And some die
that deserve life. Can you give it to them? Then do not be too eager to deal
out death in judgement. For even the very wise cannot see all ends.'
 :-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-: ben@morrow.me.uk


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

Date: Thu, 30 Oct 2003 21:52:15 +0000 (UTC)
From: Ben Morrow <usenet@morrow.me.uk>
Subject: Re: DOS window.
Message-Id: <bns16f$9lm$3@wisteria.csv.warwick.ac.uk>


"Richard S Beckett" <spikeywan@bigfoot.com.delete.this.bit> wrote:
> It's a shame that microsoft not supporting their own hardware

Err.. I don't think Microsoft are a hardware company... :)

Ben

-- 
And if you wanna make sense / Whatcha looking at me for?          (Fiona Apple)
                            * ben@morrow.me.uk *


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

Date: Thu, 30 Oct 2003 14:24:01 -0500
From: Justin <kf1zr0y02@sneakemail.com>
Subject: File test operator (-r) returns 'not exist' rather than 'not readable'
Message-Id: <3fa16552$0$560$b45e6eb0@senator-bedfellow.mit.edu>

Hi,

I've noticed that the -r operator returns undef if used on a file in an 
unreadable directory (where undef indicates the file is missing) - I'd 
like -r to return false (unreadable) in such a case.

I'm comparing our back-up file-list to the file-system. I need to know 
if a file exists or if I just can't read it.

ls returns 'Permission Denied' which is what I'd like -r to return.

Any ideas?

Cheers,

Justin

Here's an example of what I mean:

[/tmp] mkdir Test
[/tmp] touch Test/testfile
[/tmp] ls -l Test
total 0
-rw-rw-r--   1 ja              0 Oct 30 12:58 testfile
[/tmp] chmod 000 Test
[/tmp] perl -e 'print "Not Exist\n" unless defined (-r "Test/testfile")'
Not Exist
[/tmp] ls Test/testfile
ls: Test/testfile: Permission denied
[/tmp] perl -e 'print "Not Exist\n" unless defined (-r "Test")'
[/tmp]



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

Date: Thu, 30 Oct 2003 19:41:17 GMT
From: mike@ratdog.stok.co.uk (Mike Stok)
Subject: Re: File test operator (-r) returns 'not exist' rather than 'not readable'
Message-Id: <xPdob.69498$7B1.5911@news04.bloor.is.net.cable.rogers.com>

In article <3fa16552$0$560$b45e6eb0@senator-bedfellow.mit.edu>,
Justin  <kf1zr0y02@sneakemail.com> wrote:
>Hi,
>
>I've noticed that the -r operator returns undef if used on a file in an 
>unreadable directory (where undef indicates the file is missing) - I'd 
>like -r to return false (unreadable) in such a case.
>
>I'm comparing our back-up file-list to the file-system. I need to know 
>if a file exists or if I just can't read it.
>
>ls returns 'Permission Denied' which is what I'd like -r to return.
>
>Any ideas?

>[/tmp] perl -e 'print "Not Exist\n" unless defined (-r "Test/testfile")'
>Not Exist

[mike@ratdog src]$ touch foo
[mike@ratdog src]$ chmod 0 foo
[mike@ratdog src]$ perl -e 'print "Not Exist\n" unless -e "foo"'
[mike@ratdog src]$ perl -e 'print "Not Readable\n" unless -r "foo"'
Not Readable
[mike@ratdog src]$

Hope this helps,

Mike

-- 
mike@stok.co.uk                    |           The "`Stok' disclaimers" apply.
http://www.stok.co.uk/~mike/       | GPG PGP Key      1024D/059913DA 
mike@exegenix.com                  | Fingerprint      0570 71CD 6790 7C28 3D60
http://www.exegenix.com/           |                  75D2 9EC4 C1C0 0599 13DA


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

Date: Thu, 30 Oct 2003 19:47:45 GMT
From: Steve Grazzini <grazz@pobox.com>
Subject: Re: File test operator (-r) returns 'not exist' rather than 'not readable'
Message-Id: <BVdob.37110$4O1.27825@nwrdny01.gnilink.net>

Justin <kf1zr0y02@sneakemail.com> wrote:
> I've noticed that the -r operator returns undef if used on a
> file in an unreadable directory (where undef indicates the file 
> is missing) - I'd like -r to return false (unreadable) in such 
> a case.

It doesn't matter whether the directory is readable -- it's the
execute bit (search bit) that determines whether you can stat() a
file in that directory.

> I'm comparing our back-up file-list to the file-system. I need to know 
> if a file exists or if I just can't read it.

If you can't read *or* search the directory, you simply can't know
whether the file exists or not.  If you can read it, you could use
opendir() to check...

> ls returns 'Permission Denied' which is what I'd like -r to return.

But this is easy; just check $! if the file test returns undef.

-- 
Steve


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

Date: Thu, 30 Oct 2003 16:40:55 -0500
From: Justin <kf1zr0y02@sneakemail.com>
Subject: Re: File test operator (-r) returns 'not exist' rather than 'not readable'
Message-Id: <3fa18568$0$557$b45e6eb0@senator-bedfellow.mit.edu>

Steve Grazzini wrote:
> Justin <kf1zr0y02@sneakemail.com> wrote:
> 
>>I've noticed that the -r operator returns undef if used on a
>>file in an unreadable directory (where undef indicates the file 
>>is missing) - I'd like -r to return false (unreadable) in such 
>>a case.
[snip]
>>ls returns 'Permission Denied' which is what I'd like -r to return.
> 
> But this is easy; just check $! if the file test returns undef.

That's the key - I checked if $! eq 'Permission denied' after an undef 
-r, that tells me if it failed due to an unreadable dir.

Thanks Steve - much appreciated!

Justin




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

Date: Thu, 30 Oct 2003 22:55:31 +0000 (UTC)
From: Ben Morrow <usenet@morrow.me.uk>
Subject: Re: File test operator (-r) returns 'not exist' rather than 'not readable'
Message-Id: <bns4t3$afn$6@wisteria.csv.warwick.ac.uk>


Justin <kf1zr0y02@sneakemail.com> wrote:
> Steve Grazzini wrote:
> > Justin <kf1zr0y02@sneakemail.com> wrote:
> > 
> >>I've noticed that the -r operator returns undef if used on a
> >>file in an unreadable directory (where undef indicates the file 
> >>is missing) - I'd like -r to return false (unreadable) in such 
> >>a case.
> [snip]
> >>ls returns 'Permission Denied' which is what I'd like -r to return.
> > 
> > But this is easy; just check $! if the file test returns undef.
> 
> That's the key - I checked if $! eq 'Permission denied' after an undef 
> -r, that tells me if it failed due to an unreadable dir.

Better would be to use Errno (or perl -MErrno) and check $!{EACCES}.

Ben

-- 
Musica Dei donum optimi, trahit homines, trahit deos.    |
Musica truces molit animos, tristesque mentes erigit.    |   ben@morrow.me.uk
Musica vel ipsas arbores et horridas movet feras.        |


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

Date: Thu, 30 Oct 2003 22:13:06 +0000 (UTC)
From: Ben Morrow <usenet@morrow.me.uk>
Subject: Re: fork process to handle fifo input
Message-Id: <bns2di$afn$1@wisteria.csv.warwick.ac.uk>

[brian has already alluded to the virtues of proper snipping]

oviaudmurat@web.de (Ole) wrote:

> Ben Morrow <usenet@morrow.me.uk> wrote in message
> news:<bnoto5$k9a$1@wisteria.csv.warwick.ac.uk>...
> > oviaudmurat@web.de (Ole) wrote:
> > > 1.) How do I trap e.g. a "kill -9" command, directed to the parent
> > > process in order to collect to child processes before quiting. Now
> > > the child processes get init for as parent.
> > 
> > You can't. That's the point of SIGKILL: it can't be trapped. If you
> > want to trap other signals, look at %SIG in perlvar.
> 
> So, if i "use wait_zombies", the child processes are terminated, er ..
> waited for automatically or do i have to define a reaper function ?

No, no... if your parent process is killed with SIGKILL, you have
absolutely no choice about what happens next. Your parent process will
terminate, and the children will be picked up by init and be
automatically reaped when they exit. (Note: this has nothing to do
with Perl, it is simply how SIGKILL works under Unix).

If, on the other hand, you kill the parent process with SIGTERM, which
is the accepted way to ask a process to terminate, you can install a
handler in %SIG{TERM} to kill the children as well. Read perlipc and
the description of %SIG in perlvar. I'm not going to say this again :).

> > > 2. ) How can manage it to have only one child process trying to read
> > > from the fifo ?
> > 
> > a. Use a lockfile to synchronise access.
> 
> But what if syslog wants to write to the fifo while me having locked
> the pipe ?

1. Perl's locks (and Unix locks generally) are advisory. If syslog
   wishes to write to the fifo, it will ignore the lock and write.

2. The lock is to synchronise reading, not writing. There is only one
   process writing, so there's no need to sync. My suggestion is that
   you use a separate file created solely for the purpose rather than
   attempting to lock the fifo itself, as I've no idea how well
   locking a fifo works. See http://perl.plover.com/yak/flock/.

> > b. Have a 'reader' process that reads data from the fifo and passes it
> >    to the other children for processing.
> > c. Don't fork()... :)
> 
> But how have children without fork ?

I think Brian's dealt with this.

> There is no question. Here in germany the system lacks structured
> education.
> You must ( or may ) choose what you want to do for the final
> excamination.

In that case, I will change my recommendation to 'I would suggest you
attempt to implement something you understand a little better'. But
far be it from me to discourage you from learning... You need to
understand the issues of multiprocessing before you try this, though,
including:

1. What benefits it can and cannot bring. You should have a clear idea
   of why you want to multiprocess, and of what the jobs of the
   different processes are, before you start.

2. The need for synchronisation, including how file locks work, what
   they can and cannot prevent you from doing, and to avoid races.

3. A better understanding of Unix signals, in this case particularly
   SIGKILL, SIGTERM and SIGCHLD.

Most of these issues are dealt with to some degree in perlipc; a more
detailed exposition should be available in any introductory book about
programming Unix (the same concepts apply regardless of language).

Ben

-- 
don't get my sympathy hanging out the 15th floor. you've changed the locks 3
times, he still comes reeling though the door, and soon he'll get to you, teach
you how to get to purest hell. you do it to yourself and that's what really
hurts is you do it to yourself just you, you and noone else *  ben@morrow.me.uk


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

Date: Thu, 30 Oct 2003 20:27:04 GMT
From: "Les Hazelton" <seawolf@attglobal.net>
Subject: help to mirror cpan to local server
Message-Id: <pan.2003.10.30.20.26.07.197893@attglobal.net>

Some months ago I saw a script to mirror just the latest version of each
CPAN module/bundel on a local server.  Of course, now that I want to do
that, I can no longer locate the reference.

If anyone else is doing something like this could you please share your
script with me or, point me to a HOW-TO that explains it?
 
-- 
Les Hazelton
--- Registered Linux user # 272996 ---
One can search the brain with a microscope and not find the
mind, and can search the stars with a telescope and not find God.
		-- J. Gustav White



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

Date: 30 Oct 2003 12:40:09 -0800
From: james.h.anderson@ssmb.com (Jim Anderson)
Subject: How to tell what modules are installed?
Message-Id: <2cfb060a.0310301240.5d570a03@posting.google.com>

Our SysAdmins have created a Solaris package of perl5.8.0 and
installed a number
of packages from CPAN. What's the best way to get a list of all the
installed modules?

Thanks,

jim


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

Date: Thu, 30 Oct 2003 21:41:42 +0100
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: How to tell what modules are installed?
Message-Id: <bnrtgk$14okgo$1@ID-184292.news.uni-berlin.de>

Jim Anderson wrote:
> What's the best way to get a list of all the installed modules?

That's a FAQ.

     perldoc -q installed

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



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

Date: 30 Oct 2003 14:48:39 -0800
From: i5513@hotmail.com (i5513)
Subject: Re: Java with apache from perl script?
Message-Id: <a657ec02.0310301448.5acda0bc@posting.google.com>

> Give it the full path to java and the program.
> 
> my $java = '/full/path/to/java';
> my $program_java = '/full/path/to/program_java';
> system ($java $program_java) == 0 or die $?;

Thanks you, my 'particular' problem was the classpath.

I solved it with:
$Output = qx/"java -cp /full/path/to/classes
/full/path/to/program_java"

on my local apache it seems like perl had C:\winnt\system32 on
$ENV{PATH}. Java.exe was on winnt\system32 ... I think my perl script
isn't a CGI program where you says path is empty.

Thanks you again.


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

Date: 30 Oct 2003 14:04:01 -0800
From: jrolandumuc@yahoo.com (JR)
Subject: Logic Flow Question
Message-Id: <b386d54b.0310301404.31551ff5@posting.google.com>

I'm having trouble understanding the logic flow of recipe 4.3 in the
Perl Cookbook (the below script is only slightly different from the
recipe in the Cookbook), and am hoping someone can clarify it for me.

Here's where I'm confused:

In the below permute subroutine, I don't understand how the $i
variable can ever reach 1 and 2.  It is initially set to 0 before the
for loop is entered.  Immediately after the unshift line, the permute
subroutine is recursively and unconditionally called.  When the else
loop is hit on any further calls, the $i variable is again set to 0,
yet the below output clearly indicates that the variable is, at some
point, being incremented.  I don't see how this is possible, yet,
clearly it is.  I notice that the variable is always 1 or 2
immediately after a given group of perms is printed, but this just
isn't enough of a clue to help me understand how this works.  I must
be missing the obvious here.  Can someone please point it out to me?

Thanks much.


use strict;
use warnings;

my @array = ('A'..'C');

permute([@array]);
sub permute {
   my @items = @{ $_[0] };
   my @perms = @{ $_[1] } if defined @{ $_[1] };
   if (!@items) {
      print "\@perms=@perms\n"; 
   }
   else {
      my (@newitems, @newperms);
      my $i = 0;
      for my $i (0..$#items) {
print "\$i=$i\n";
         @newitems = @items;
	 @newperms = @perms;
         ## Splice @newitems element and prepend it to @newperms
	 unshift(@newperms, splice(@newitems, $i, 1));
         permute([@newitems], [@newperms]);
      }
   }
}

__END__
$i=0
$i=0
$i=0
@perms=C B A
$i=1
$i=0
@perms=B C A
$i=1
$i=0
$i=0
@perms=C A B
$i=1
$i=0
@perms=A C B
$i=2
$i=0
$i=0
@perms=B A C
$i=1
$i=0
@perms=A B C


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

Date: Thu, 30 Oct 2003 21:17:26 +0000
From: Tor Houghton <torh+news@removethisbitbeforethedot.bogus.net>
Subject: Re: Parsing of blocks (e.g. foo { bar })
Message-Id: <pan.2003.10.30.21.17.26.181839@removethisbitbeforethedot.bogus.net>

On Thu, 30 Oct 2003 18:55:42 +0000, David K. Wall wrote:

> If you're not tied to that particular format you could use
> Config::Simple or one of the numerous other Config::* modules in the
> CPAN.
> 
> 

Thanks for the tip!

For this application, however, I need to make sure it'll work on a system
"out of the box", without the worry of whether a certain CPAN module needs
to be installed.

Tor


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

Date: Thu, 30 Oct 2003 19:04:52 -0000
From: "David K. Wall" <usenet@dwall.fastmail.fm>
Subject: Re: Perl Cut Command
Message-Id: <Xns94248F3DA1F7Ddkwwashere@216.168.3.30>

Buck Turgidson <jc_va@hotmail.com> wrote:

>> 21-40, and just print 1-20 and 21 thru 60 on a line.
>>
> 
> That should read "just print 1-20 and 41 thru 60 on a line"

[untested]

perl -ne "print substr($_,0,20), substr($_,40,20)" filename



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

Date: 30 Oct 2003 19:22:39 GMT
From: Michael Zawrotny <zawrotny@jaguar.sb.fsu.edu>
Subject: Re: Perl Cut Command
Message-Id: <slrnbq2p68.48c.zawrotny@jaguar.sb.fsu.edu>

On Thu, 30 Oct 2003 18:52:10 GMT, Buck Turgidson <jc_va@hotmail.com> wrote:
> > 21-40, and just print 1-20 and 21 thru 60 on a line.
>  
>  That should read "just print 1-20 and 41 thru 60 on a line"

You could try "cut -b1-20,41-60".


Mike

-- 
Michael Zawrotny
Institute of Molecular Biophysics
Florida State University                | email:  zawrotny@sb.fsu.edu
Tallahassee, FL 32306-4380              | phone:  (850) 644-0069


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

Date: Thu, 30 Oct 2003 20:46:40 GMT
From: "Buck Turgidson" <jc_va@hotmail.com>
Subject: Re: Perl Cut Command
Message-Id: <24c565be8a0740fefacc1f8ac3890421@news.teranews.com>

>
> You could try "cut -b1-20,41-60".
>
Thanks.  That works. I didn't know I could do split ranges.




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

Date: Thu, 30 Oct 2003 21:22:35 GMT
From: "Kev" <karigna@verizon.net>
Subject: Script Help
Message-Id: <vifob.37757$4O1.28090@nwrdny01.gnilink.net>

I'm writing a script that is part of a larger script to index a defined list
of websites. The portion that I'm working on is used to find all pages
ending in .htm / .html so that I can search those pages and index them. I
got the script to map out all the links. Can anyone help in eliminating the
non .htm / html links obtained?

#!/usr/bin/perl

use HTML::LinkExtor;
use LWP::Simple;

$base_url = "http://www.cnn.com";
$parser=HTML::LinkExtor->new(undef, $base_url);
$parser->parse(get($base_url))->eof;
@links=$parser->links;

foreach $linkarray(@links)
{
    my @element = @$linkarray;
    my $elt_type = shift @element;
    while (@element)
    {
        my ($attr_name, $attr_value) = splice(@element, 0, 2);
        $seen{$attr_value}++;
    }
}

for (sort keys %seen)
{
    print $_, "\n";
}

K.




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

Date: Thu, 30 Oct 2003 14:44:14 -0800
From: Jim Gibson <jgibson@mail.arc.nasa.gov>
Subject: Re: Script Help
Message-Id: <301020031444148775%jgibson@mail.arc.nasa.gov>

In article <vifob.37757$4O1.28090@nwrdny01.gnilink.net>, Kev
<karigna@verizon.net> wrote:

> I'm writing a script that is part of a larger script to index a defined list
> of websites. The portion that I'm working on is used to find all pages
> ending in .htm / .html so that I can search those pages and index them. I
> got the script to map out all the links. Can anyone help in eliminating the
> non .htm / html links obtained?
> 
> #!/usr/bin/perl

use strict;

> 
> use HTML::LinkExtor;
> use LWP::Simple;
> 
> $base_url = "http://www.cnn.com";

my $base_url ...

> $parser=HTML::LinkExtor->new(undef, $base_url);

my $parser = ...

> $parser->parse(get($base_url))->eof;
> @links=$parser->links;

my @links = ...
my %seen;

> 
> foreach $linkarray(@links)
> {
>     my @element = @$linkarray;
>     my $elt_type = shift @element;

You can start by eliminating img and script links:

      next if $elt_type =~ /^img|script$/i;


>     while (@element)
>     {
>         my ($attr_name, $attr_value) = splice(@element, 0, 2);
>         $seen{$attr_value}++;

You can accept only URLs with '.htm' in them:

         $seen{$attr_value}++ if $attr_value =~ /\.htm/;
>     }
> }
> 
> for (sort keys %seen)
> {
>     print $_, "\n";
> }
> 

leaving 59 links out of the 278 you started with (today anyway).

You will miss some HTML links that don't have explicit file names but
ar depending on the server to supply index.html or its ilk if only a
directory name is give. There might be some false matches for files
that have '.htm' in them somewhere other than the end, but finding the
end of a file name in a URL seems a bit tricky.


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

Date: 30 Oct 2003 11:39:06 -0800
From: jrolandumuc@yahoo.com (JR)
Subject: Re: Singleton process
Message-Id: <b386d54b.0310301139.7e070bc4@posting.google.com>

rjohnson@shell.com (Roy Johnson) wrote in message news:<3ee08638.0310300627.43651d1b@posting.google.com>...
> Ben Morrow <usenet@morrow.me.uk> wrote in message news:<bnphpr$sbi$2@wisteria.csv.warwick.ac.uk>...
> > rjohnson@shell.com (Roy Johnson) wrote:
> > > For some reason, both suggestions (using $0 and using DATA) fail on my
> > > Unix box. I am using flock, though, and when I create a throwaway file
> > > for the purpose, it works properly.
> > 
> > Out of interest: which Unix are you on, what error do you get, and
> > does your perl use flock() or fcntl() locking (if you can tell)?
> 
> I'm on Solaris (5.8).
> The error message I get is
>    Bad file number
> 
> I don't know how to check which form of locking is being done. Here's
> a sample program:
> 
> #!perl
> 
> use strict;
> use warnings;
> 
> use Fcntl ':flock';
> open SELF, $0 or die "Could not open $0: $!\n";
> flock SELF, LOCK_EX | LOCK_NB
>     or die "Could not flock $0: $!\n";
> close SELF;
> print "Done\n";

This is one way to check which form of locking your system supports.
This may be useful to you.

#!/perl/ -w
use strict;
use IO::File;
use Fcntl ":flock";

*FH1 = new_tmpfile IO::File or die "Can't open: $!\n";

eval {flock FH1, LOCK_SH};
die "No locks supported.\n" if $@;

open FH2, ">>&FH1" or die "Can't open: $!\n";

(flock FH2, LOCK_SH|LOCK_NB) ? print "Shared locks supported.\n" :
print "Shared locks not supported.\n";

(flock FH2, LOCK_EX|LOCK_NB) ? print "Exclusive locks supported.\n" :
print "Exclusive locks not supported.\n";


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

Date: Thu, 30 Oct 2003 22:45:52 +0000 (UTC)
From: Ben Morrow <usenet@morrow.me.uk>
Subject: Re: Singleton process
Message-Id: <bns4b0$afn$4@wisteria.csv.warwick.ac.uk>


jrolandumuc@yahoo.com (JR) wrote:
> This is one way to check which form of locking your system supports.
> This may be useful to you.

<snip test for shared/exclusive lock support>

That wasn't the question. There are two ways of locking files under
Unix, using the flock(2) or fcntl(2) syscalls. Perl can (generally
speaking) be built to use either. I was asking which.

AFAIK, all forms of locking support both shared and exclusive locks:
seems pretty useless to me if they don't...

Ben

-- 
And if you wanna make sense / Whatcha looking at me for?          (Fiona Apple)
                            * ben@morrow.me.uk *


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

Date: 30 Oct 2003 11:38:39 -0800
From: the_swadster@yahoo.com (the_swadster)
Subject: Socket.pm busted in get() ?
Message-Id: <cb6337b6.0310301138.78d3cc80@posting.google.com>

I am running a (unix) monitoring perl script that runs hourly
collecting some department stats. Several times a day the scripts
croaks with the below error. As the error does not point me directly
to a problem in my code and I have attempted to eliminate more obvious
things, does anyone understand the error(s) information that is
supplied and can put me on the path for resolving my issue.

 get{sock, peer}name() on closed fd at /usr/perl5/5.00503/sun4-  
solaris/IO/Socket.pm line 274, <DATA> chunk 2706.
 Use of uninitialized value at
/usr/perl5/5.00503/sun4-solaris/Socket.pm line 295, <DATA> chunk 2706.
 Bad arg length for Socket::unpack_sockaddr_in, length is 0, should be
16 at /usr/perl5/5.00503/sun4-solaris/Socket.pm line 295, <DATA> chunk
2706.

Thanks a bunch,
- Swad


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

Date: Thu, 30 Oct 2003 22:37:00 -0000
From: "Brian Wakem" <no@email.com>
Subject: Re: Socket.pm busted in get() ?
Message-Id: <bns3qb$14tjan$1@ID-112158.news.uni-berlin.de>


"the_swadster" <the_swadster@yahoo.com> wrote in message
news:cb6337b6.0310301138.78d3cc80@posting.google.com...
> I am running a (unix) monitoring perl script that runs hourly
> collecting some department stats. Several times a day the scripts
> croaks with the below error. As the error does not point me directly
> to a problem in my code and I have attempted to eliminate more obvious
> things, does anyone understand the error(s) information that is
> supplied and can put me on the path for resolving my issue.
>
>  get{sock, peer}name() on closed fd at /usr/perl5/5.00503/sun4-
> solaris/IO/Socket.pm line 274, <DATA> chunk 2706.
>  Use of uninitialized value at
> /usr/perl5/5.00503/sun4-solaris/Socket.pm line 295, <DATA> chunk 2706.
>  Bad arg length for Socket::unpack_sockaddr_in, length is 0, should be
> 16 at /usr/perl5/5.00503/sun4-solaris/Socket.pm line 295, <DATA> chunk
> 2706.


I've had a few "Bad arg length for Socket::unpack_sockaddr_in, length is 0"
errors before.  I tracked them all down to DNS issues.  Each error coincided
with downtime on the DNS servers we use.

-- 
Brian Wakem




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

Date: Thu, 30 Oct 2003 19:51:41 +0000
From: "Alan J. Flavell" <flavell@ph.gla.ac.uk>
Subject: Re: strange effect with [:lower:] in perl
Message-Id: <Pine.LNX.4.53.0310301925170.32163@ppepc56.ph.gla.ac.uk>

On Wed, 29 Oct 2003, Ben Morrow wrote:

> Let us say "5.6 when not under the 'utf8' pragma", then; the behaviour
> is probably the most 'correct' for those assumptions. It is also
> consistent with '\w' under 5.005, which didn't match accented
> characters either, unless you used an appropriate locale.

This is odd. If I execute this code which we discussed before:

for (0x00 .. 0xff) { printf "%02x %s\n" , $_, chr if chr () =~ /[[:lower:]]/}

but with "use locale" in effect, then on a RedHat 7.2 system, it
reports the accented lower-case letters also.  LC_CTYPE is en_GB, and
Perl is RH perl-5.6.1-36.1.72

If I execute the *same* script in RedHat 9, then - even with "use
locale" in effect - it reverts to the old behaviour - nothing above
'z' is reported as a lower-case letter.

LC_CTYPE is "en_GB.UTF-8", and Perl is RH perl-5.8.0-88.3

However, if I set the locale to "en_GB" etc. then the extended
behaviour re-appears: accented lower-case letters are also reported.
Same for "en_GB.ISO8859-1" etc.

If I go back to the RH7.2/Perl5.6.1 system and explicitly setlocale()
to "en_GB.UTF-8", then the 5.6.1 system reports only a-z as lower
case, just as the 5.8.0 one did.


Could I summarise that by saying (applies to both versions):

* if the locale does not include utf-8, then "use locale" switches on
the reporting of lower-case accented letters.

This is what you already explained as being a compatibility feature
in the absence of "use locale", right?

* but if the locale _does_ imply utf-8, then it seems something
different happens.  In this test, "use locale" doesn't report accented
lower-case letters, in either Perl version.

As we saw in the earlier discussion: if the string has been forcibly
upgraded to Perl's unicode format, then those accented letters were
reported, irrespective of "use locale", which is fine by me.

But it seems that if the string has not been upgraded to unicode
format, then even with "use locale" in effect, the accented letters
are not reported - this bit seems, at least, unintuitive (even a
mistake?).

Are my observations correct?  Any insights?


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

Date: Thu, 30 Oct 2003 13:24:01 -0800
From: "Brian Helterline" <brian_helterline@hp.com>
Subject: Re: Win::OLE excel function run twice
Message-Id: <3fa181ee@usenet01.boi.hp.com>


"Jason Chen" <jason4chen@yahoo.com> wrote in message
news:508693ba.0310301046.2667b69f@posting.google.com...
> I have an excel macro in file c:\temp\test1.xls as this:
>
>    Public Function test1(str As String)
>       Debug.Print "the string is: " & str
>    End Function
>
> I run the macro through perl like this:
>
>    use Win32::OLE;
>    my $Excel = Win32::OLE->GetActiveObject('Excel.Application');
>    my $Book = $Excel->Workbooks->Open("C:\\temp\\test1.xls");
>    $Excel->Run('Test1("kabc")');

Wrong syntax.  See the Excel docs for the Run command.
Arg0 = macro name, Arg1...n = arguments. Try:
$Excel->Run( 'Test1', "kabc");


>
> Here is Result:
>
>    here is kabc
>    here is kabc
>
> The problem is the test1 function is run TWICE!!!
>
> I am using Windows 2000 and ActivateState Perl 5.6.
>
> Help!




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

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.  

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


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