[18380] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 548 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Mar 22 11:05:41 2001

Date: Thu, 22 Mar 2001 08:05:09 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <985277108-v10-i548@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Thu, 22 Mar 2001     Volume: 10 Number: 548

Today's topics:
        Bulk HTML editing <TeKno@supportinfo.com>
    Re: Bulk HTML editing ()
    Re: Can't combine > and $ <jrk@sys.uea.ac.uk>
    Re: CGI redirect implementation <flavell@mail.cern.ch>
    Re: CGI redirect implementation <me@dev.null>
    Re: DBI and Activestate's perlapp <bart.lateur@skynet.be>
    Re: h2xs recursive failure in assign_typemap_entry david_no_spam_@carter.net
    Re: how do you pass arguements into the "do" command? <bart.lateur@skynet.be>
    Re: how to execute non-Perl program from Perl (David)
    Re: Limiting the number of connections with a fork'ing  (Anno Siegel)
        Need help with Win32::PerfLib <martin@people-com.com>
        Need Perl Programmer <jobs@radixcorp.com>
        NEWBIE: Command "Prompt" executing <no@spam.com>
    Re: NEWBIE: Command "Prompt" executing <tony_curtis32@yahoo.com>
        Overloading in perl <sree@india.ti.com>
    Re: Perl 5.6 - Spinning cursor routine? <bart.lateur@skynet.be>
    Re: Perl 5.6 - Spinning cursor routine? (Damian James)
    Re: Perl 5.6 - Spinning cursor routine? <krahnj@acm.org>
    Re: Print "tar" Success or Failure <goldbb2@earthlink.net>
        Problem installing Net-LDAPapi-1.42 <acki@ivu.de>
        using closures (road to OO) <b_nospam_ill.kemp@wire2.com>
    Re: using closures (road to OO) <joe+usenet@sunstarsys.com>
    Re: using closures (road to OO) <tom@power.net.uk>
    Re: using closures (road to OO) (Greg Bacon)
    Re: Weird(?) magic word for sh to invoke perl under Lin <hughett@mercur.uphs.upenn.edu>
    Re: Why do "Learning Perl" Books Do This? A Subroutine  (Randal L. Schwartz)
        Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)

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

Date: Thu, 22 Mar 2001 13:26:59 GMT
From: "TeKno" <TeKno@supportinfo.com>
Subject: Bulk HTML editing
Message-Id: <D4nu6.493$_l5.110404715@newssvr10-int.news.prodigy.com>

I need to be able to search numerous html files and rip out all data between
<head> and </head>, then  the  <body> tag only and insert code to include a
header file. Then I need to rip off the </body> tag and replace it with a
footer include. any ideas here? I am just starting this.


Thanks




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

Date: Thu, 22 Mar 2001 14:13:34 +0000 (UTC)
From: bernard.el-hagin@gdndev25.dev.lido-tech ()
Subject: Re: Bulk HTML editing
Message-Id: <slrn9bk1v7.3vvp2nt.bernard.el-hagin@gdndev25.dev.lido-tech>

In article <D4nu6.493$_l5.110404715@newssvr10-int.news.prodigy.com>,
TeKno wrote:
>I need to be able to search numerous html files and rip out all data between
><head> and </head>, then  the  <body> tag only and insert code to include a
>header file. Then I need to rip off the </body> tag and replace it with a
>footer include. any ideas here? I am just starting this.

Well, when you've got some working code post it here and we'll take a look
at it. Just to get you started I'll give you a freebie - read about the
'...' operator and read about the HTML::Parser family of modules.

Cheers,
Bernard
--
#requires 5.6.0
perl -le'* = =[[`JAPH`]=>[q[Just another Perl hacker,]]];print @ { @ = [$ ?] }'


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

Date: 22 Mar 2001 11:22:38 GMT
From: Richard Kennaway <jrk@sys.uea.ac.uk>
Subject: Re: Can't combine > and $
Message-Id: <99cn9u$7an$1@cpca14.uea.ac.uk>

In article <3AB9C2FE.69578100@acm.org> John W. Krahn, krahnj@acm.org
writes:
>Joe Schaefer wrote:
>> (It actually works just as Richard advertised on my 5.6).
>
>Yes, and he also claims that it "would be better." Is this also true?

I gave my reason in my original posting:

> With two arguments, I'd worry about $_ beginning with a character that
> open() will read as part of the mode.

When I know from the purpose of my program that it is to open an actual
file, and not any of the other things that 2-argument open() provides,
like pipes, STDIN, and whatnot, then I use the three-argument form.  This
prevents unusual characters in the filename having unintended effects.

The original question suggests that that is the case here:

> $_ contains a directory name. I tried:

> open(OUT, >${_}/scripts/make_mask.txt) || die "can not make mask \n ";

In addition, if I am opening a file whose name I read from external data,
then I don't want to think about the stuff that might happen through
accident or hostile intent.  But I don't have to: I use three arguments
and the issue goes away.

I think that is better.

I use two arguments only when I need to, and I know at compile time
exactly what effects it is limited to producing.

-- Richard Kennaway, jrk@sys.uea.ac.uk, http://www.sys.uea.ac.uk/~jrk/
   School of Information Systems, Univ. of East Anglia, Norwich, U.K.


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

Date: Thu, 22 Mar 2001 11:43:21 +0100
From: "Alan J. Flavell" <flavell@mail.cern.ch>
Subject: Re: CGI redirect implementation
Message-Id: <Pine.LNX.4.30.0103221137020.2024-100000@lxplus003.cern.ch>

On Thu, 22 Mar 2001, Jan Gruber wrote:

> I tried to do that with pure HTML,

"pure HTML" is markup.  It doesn't "do" anything.  So your failure
comes as no surprise.

> but after some time i found out, its
> easier to use Javascript for that.

If you want to ensure that it won't work on secured browsers, sure.

This is OT for c,l.p.misc.  Take it to the proper group(s).

> This little code snippet displays a Confirm dialog.

It does nothing at all on my browser, because your server's in my
untrusted domain.  You lose.

[f'ups prophylactically set]




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

Date: Thu, 22 Mar 2001 12:48:58 +0100
From: Jan Gruber <me@dev.null>
Subject: Re: CGI redirect implementation
Message-Id: <99cokc$dk6$1@news.intern.primacom.net>

Alan J. Flavell wrote:

-- lots of b*t deleted --

Wow, thx for the enlightment, didnt know that b4 !

Jan
-- 
cat /dev/world | perl -e "(/(^.*? \?) 42 \!/) && (print $1))"
errors->(c)
_ 



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

Date: Thu, 22 Mar 2001 11:10:48 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: DBI and Activestate's perlapp
Message-Id: <8anjbtks1labdc8sovumhjflt9f17smev5@4ax.com>

Anthony Carbone wrote:

>When you have a script that 'uses DBI' and you compile the script using
>'perlapp -s <script name> -e <script exe> -f -r -v', the executable crashes
>on and DBI method call. For example, this is a small test script that works
>if you don't compile it and use perl.exe to process it and DOES NOT WORK if
>you compile it using 'perlapp' and invoke the made executable. There is no
>output what so ever about why it crashes.

Caveat: I don't have "perlapp". This is just a guess.

It might just happen with any module that uses a DLL by default. Are you
sure that your plain perl and your perlapp are binary compatible? For
example, DLL's written for Activestate's 5.005 make 5.6.0 crash. (Sorry
I forgot the build numbers.)

-- 
	Bart.


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

Date: 22 Mar 2001 15:46:41 GMT
From: david_no_spam_@carter.net
Subject: Re: h2xs recursive failure in assign_typemap_entry
Message-Id: <99d6p1$8q0$1@news.netmar.com>

After a little experimentation, it appears that h2xs was having problems with
the named union within a typedef, which is then referenced inside a struct.
Making the union anonymous seems to have fixed the problem.

Changed from:
typedef union  arm_user_metric1_u {
    .<snip>
    .<end snip>
} arm_user_metric1_u;

typedef struct arm_user_data1_t {
    .<snip>
    arm_user_metric1_u   metric[6];     /*  User metrics  */
    .<snip>
} arm_user_data1_t;

Changed to:
typedef union {
    .<snip>
    .<end snip>
} arm_user_metric1_u;

typedef struct arm_user_data1_t {
    .<snip>
    arm_user_metric1_u   metric[6];     /*  User metrics  */
    .<snip>
} arm_user_data1_t;

Looks like a bug in h2xs, but the workaround is not too painful, once you
figure it out.

-David



In article <99at9i$7hd$1@news.netmar.com>, <davidz@carterz.net> writes:
>I'm trying to create a "better" Perf::ARM module. ARM is a cross-platform
>industry-std API for transaction response time measurement. Vendors supply
>various ARM libraries (libarm.sl, libarm32.dll, etc.).  Current version of
>Perf::ARM (0.03) is an extremely "light" XS wrapper. I plan to produce
>a version with "full" XS capabilities, and (maybe) a later version with a
more
>"OO" interface.
>
>I've studied all the XS-related manpages, and think I have a fairly good
>handle on what I'm trying to do.
>
>>$ perl -v
>>This is perl, v5.6.1 built for cygwin
>>(with 1 registered patch, see perl -V for more detail)
>
>Command I'm trying to run:
>>h2xs -Oaxn Perf::ARM -F "-D_PROTOTYPES" -M'^(ARM_|arm_){1}[A-Za-z]+[a-z]'
-v
>>0.04 arm.h -larm 
>
>You can see arm.h here:  http://www.cmg.org/regions/cmgarmw/sdk/arm201.h
>
>Problem #1:
>C::Scan dies. Complains about missing parens, after "panic"ing many
>times about missing commas.
>Work-around: I prevent arm.h from #including <windows.h>. Doesn't seem
>to cause any problems under cygwin. 
>
>Problem #2:
>Now it runs for a looong while, and then dies with:
>
>>Overwriting existing Perf/ARM!!!
>>Scanning typemaps...
>> Scanning /usr/lib/perl5/5.6.1/ExtUtils/typemap
>>Scanning arm.h for functions...
>>Scanning arm.h for typedefs...
>>Writing Perf/ARM/ARM.pm
>>Writing Perf/ARM/ARM.xs
>>Writing Perf/ARM/typemap
>>Out of memory during "large" request for 266240 bytes, total
>sbrk() is
>>265283584 bytes at /usr/bin/h2xs line 1607.
>
>
>Debugging under the perl debugger, I find that at line 1645 (first time
>through) %types_seen contains 27 entries:
>
>>main::(/bin/h2xs:1645):   for $type (sort keys %types_seen) {
>>  DB<2> x sort keys %types_seen
>>0  '_types_fd_set'
>>1  '_types_fd_set *'
>>2  'arm_app_correlator_t'
>>3  'arm_app_correlator_t *'
>>4  'arm_bit8_t'
>>5  'arm_cntrdivr32_t'
>>6  'arm_cntrdivr32_t *'
>>7  'arm_gaugedivr32_t'
>>8  'arm_gaugedivr32_t *'
>>9  'arm_int16_t'
>>10  'arm_int32_t'
>>11  'arm_int64_t'
>>12  'arm_unsigned32_t'
>>13  'arm_unsigned64_t'
>>14  'arm_user_data101_t'
>>15  'arm_user_data101_t *'
>>16  'arm_user_data1_t'
>>17  'arm_user_data1_t *'
>>18  'arm_user_data2_t'
>>19  'arm_user_data2_t *'
>>20  'arm_user_meta101_t'
>>21  'arm_user_meta101_t *'
>>22  'arm_user_metric1_u'
>>23  'arm_user_metric1_u *'
>>24  'fd_mask'
>>25  'struct _types_fd_set { fd_mask fds_bits [ ( ( ( 64 ) + ( ( ( sizeof (
>>fd_mask ) * 8 ) ) - 1 ) ) / ( ( sizeof ( fd_mask ) * 8 ) ) ) ] ; }'
>>26  'struct _types_fd_set { long fds_bits [ ( ( ( 64 ) + ( ( ( sizeof (
>>long
>) * 8 ) ) - 1 ) ) / ( ( sizeof ( long ) * 8 ) ) ) ] ; }'
>
>Stepping through h2xs, all goes well processing these %types_seen entries,
>until it hits type # 16, 'arm_user_data1_t', which is defined in arm.h as:
>
>>typedef struct arm_user_data1_t {
>>    arm_int32_t          format;        /*  Version/format id (userdata_e)
>
>*/
>>    arm_bit8_t           flags[4];      /*  Flags for metrics' presence 
>*/
>>    arm_user_metric1_u   metric[6];     /*  User metrics  */
>>    char                 string32[32];  /*  32 byte non-terminated string 
>*/
>>    arm_app_correlator_t correlator;    /*  Correlator  */
>>} arm_user_data1_t;
>
>Stack trace shows that we're in what appears to be an infinite loop,
>recursively calling sub 'assign_typemap_entry' from line 1616 in that sub.
>I'm not 100% certain, but it appears that $type is being continuously
>appended to.
>
>What's different about this struct from the others in %types_seen that we've
>already processed? Only thing I see is that it contains union
>arm_user_metric1_u, which appears later in the (sorted) list %types_seen.
>
>Any thoughts as to what's going on here, and what I can do to fix it?
>
>Also, it seems curious to me that _types_fd_set, 2 related structs, and
>fd_mask appear in %types_seen. Should they be there?
>
>Thanks for any help you can provide.
>-David
>
>
>
>
>
>
> -----  Posted via NewsOne.Net: Free (anonymous) Usenet News via the Web 
-----
>  http://newsone.net/ -- Free reading and anonymous posting to 60,000+
groups
>   NewsOne.Net prohibits users from posting spam.  If this or other posts
>made through NewsOne.Net violate posting guidelines, email abuse@newsone.net


 -----  Posted via NewsOne.Net: Free (anonymous) Usenet News via the Web  -----
  http://newsone.net/ -- Free reading and anonymous posting to 60,000+ groups
   NewsOne.Net prohibits users from posting spam.  If this or other posts
made through NewsOne.Net violate posting guidelines, email abuse@newsone.net


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

Date: Thu, 22 Mar 2001 11:16:09 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: how do you pass arguements into the "do" command?
Message-Id: <0injbtc9c6ac1b99avv0etj2lsa9batp6j@4ax.com>

David wrote:

>I'm trying to pass an arguement into a perl program that I am
>executing from another Perl program. I try:
>
>do "program.plx data1";
>
>It doesn't work. It doesn't do anything that I can see.
>
>do "program.plx";
>
>works fine, but doesn't accomplish what I want.

Guess what. You're loading and executing the script, but not as a
separate program. Oh yeah, there are ways to do just that, look at "``"
(AKA backticks) and system(). But in your case, the script is loaded in
the same variable space as your main script, so it can see all you
global variables.

So, use one of those variables to pass around info. If you want the same
effect as running the script from the command line, use @ARGV. Just make
sure that no input file is still open on ARGV, because then that file
will be read till the end, first. Maybe local(*ARGV) has been patched,
but it used to not work. The magic disappeared.

-- 
	Bart.


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

Date: Thu, 22 Mar 2001 12:06:40 GMT
From: dsedrich@yahoo.com (David)
Subject: Re: how to execute non-Perl program from Perl
Message-Id: <3ab9dbf5.945546@news>



On Mon, 19 Mar 2001 21:45:42 GMT, dsedrich@yahoo.com (David) wrote:

>I've been trying to execute a batch file from Perl using the System
>command and Exec command with limited success.
>
>Both will execute a batch file in my ...\apache\cgi-bin directory but
>only a limited number of things appear that I can do successfully and
>I haven't figured out what the pattern is.
>
>I can do "DIR > filename" in it
>I can call another batch file  with (Dir>filname in it)
>
>I can run a simple EXE program, it appears, that is on my path (not in
>the cgi-bin directory) with the exec command at least.
>
>But I can't seem to run imagemagick identify command (identify
>-verbose filename > filename) , even if the imagemagick directory is
>on the path. 
>
>Can somebody tell me either the correct method to call programs from
>within Perl? Or any details associated with the system or exec command
>that could explain why I am having these problems?
>
>I dump my path while in the batch file (that works). To the begining
>is appended ....c:\program files\apache group\apache.
>
>I try changing that to eliminate that string as well before I execute
>anything else but there is no apparent effect.  -- Dave

I was able to answer my own question:
I simply needed to add some data to my ENV by:

$ENV{'SomeEnvVariable'}="c:\somedir";

I do this before the system call and all is well.


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

Date: 22 Mar 2001 11:26:00 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Limiting the number of connections with a fork'ing server
Message-Id: <99cng8$855$1@mamenchi.zrz.TU-Berlin.DE>

According to Daniel Berger  <djberge@uswest.com>:
> -=-=-=-=-=-
> 
> Hi all,
> 
> I've got a fork'ing echo server (yes, it's a toy while I'm learning).  I want
> to limit the maximum number of connections to 2.  However, because I'm
> fork'ing, simply using "IO::Socket::INET->new(Listen => 2) doesn't work.  I'd
> rather not have 100 or more children being created at 5 MB per child!
> 
> Will I simply have to 'grep' through a ps -ef command in this case?  Is there a
> better way?  I realize this is somewhat silly since there's no point in
> fork'ing if I want to limit the maximum number of connections to such a small
> number, but hey, I just wanna know for academic reasons.

You'll have to install a SIGCHLD handler anyway when you're forking.
(See %SIG in perlvar, plus code in the numerous client/server examples
on how to do that.)  With that in place, it's trivial keep count of
the live children: Increment a counter on every successful fork, and
decrement it in the handler.

Anno


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

Date: Thu, 22 Mar 2001 12:32:47 +0100
From: Martin Mielke <martin@people-com.com>
Subject: Need help with Win32::PerfLib
Message-Id: <3AB9E2DF.47F03C1@people-com.com>

Dear all,

could you please provide me with some examples of usage for
Win32::PerfLib? But please don't point me to CPAN or
comp.lang.perl.modules ... :-) I already posted this question on the
latter and still got no answer... :-(

Please, CC me your replies, as I cannot check the newsgroups that often.



Thanks in advance,

Martin







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

Date: Thu, 22 Mar 2001 09:37:04 -0500
From: "Radix Corporation" <jobs@radixcorp.com>
Subject: Need Perl Programmer
Message-Id: <99d2mt$14b2$1@news.gate.net>

Company needs advanced Perl programmer to modify some scripts.  Must have
knowledge of XML.  This is a small job that will probably take 1-3 days, but
could lead to ongoing contract work.  Please respond with hourly rates to
jobs@radixcorp.com.

Also looking for someone with indepth knowledge of Apache to configure a
remote server.

Thanks,
Mike




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

Date: Thu, 22 Mar 2001 14:49:23 GMT
From: "Who Cares" <no@spam.com>
Subject: NEWBIE: Command "Prompt" executing
Message-Id: <Thou6.1466$Gn3.6251@dbsch1.home.nl>

What perl command do I give to execute for instance "adduser -d
/www/$username -g users $username"
what do I do?

Thanx




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

Date: 22 Mar 2001 09:01:32 -0600
From: Tony Curtis <tony_curtis32@yahoo.com>
Subject: Re: NEWBIE: Command "Prompt" executing
Message-Id: <8766h1onjn.fsf@limey.hpcc.uh.edu>

>> On Thu, 22 Mar 2001 14:49:23 GMT,
>> "Who Cares" <no@spam.com> said:

> What perl command do I give to execute for instance
> "adduser -d /www/$username -g users $username" what do I
> do?

to just run a command and come back: perldoc -f system
for more precise process control:    perldoc perlipc
scripting interactive commands:      perldoc Expect

hth
t
-- 
Just reach into these holes.  I use a carrot.


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

Date: Thu, 22 Mar 2001 17:05:02 +0530
From: Sreekanth <sree@india.ti.com>
Subject: Overloading in perl
Message-Id: <3AB9E366.CA149D8D@india.ti.com>

Hi,

 I am trying to overload Hash access in perl. Here's the code
i am using for it. Perl goes into infinite loop. Can somebody
let me know what is wrong.

Thanks a lot,
sreekanth

package ol;

use overload  '""' => \&stringify,
              '%{}'=> \&gethash1;

sub new {
    my $this = shift;;
    my $class = ref($this) || $this;
    my $self = { @_};
    bless $self, $class;
    return $self;
}
sub gethash1 {
    my $self = $_[0];
    return %{$self};
}
sub stringify {
    my $self = shift;
    return ref($self);
}

1;


Driver program

use ol;
$a = new ol (1,a,2,b);
print "Access Hash ", $a->{1} ,"\n";


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

Date: Thu, 22 Mar 2001 11:36:03 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: Perl 5.6 - Spinning cursor routine?
Message-Id: <hsojbtodfrfvi8qeea70eh4qo21u2smdm2@4ax.com>

Damian James wrote:

>        return "\b"x($count>0).$chars[$count++%4];

Let's hope that this program doesn't run for too long, or you'll get an
integer overflow. "%" is  limited in what it accepts.

We're talking *ages* here, I know.

-- 
	Bart.


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

Date: 22 Mar 2001 13:21:50 GMT
From: damian@qimr.edu.au (Damian James)
Subject: Re: Perl 5.6 - Spinning cursor routine?
Message-Id: <slrn9bjv2l.sn8.damian@puma.qimr.edu.au>

Bart Lateur chose Thu, 22 Mar 2001 11:36:03 GMT to say this:
>Damian James wrote:
>
>>        return "\b"x($count>0).$chars[$count++%4];

Should have been $chars[$count++%@count] to allow for arbitrary @chars.

>
>Let's hope that this program doesn't run for too long, or you'll get an
>integer overflow. "%" is  limited in what it accepts.
>

I had a peek inside Tie::Cycle after brian d foy's post in this
thread, and noticed that it worked the same way. 

So I'm not the only one :-).

>We're talking *ages* here, I know.
>

@ages = map { $_ % 42 } 0..(2**32-1); # ?   :-)

Cheers,
Damian
-- 
@;=0..23;@;{@;}=split//,<DATA>;while(@;){for($;=@;;--$;;){next if($:=rand($;
+1))==0+$;;@;[$;,$:]=@;[$:,$;]}print map{$;{$_}}(@| ,@;);push@|,shift@;if$;[
0]==@|;$|=1;select$&,$&,$&,1/80;print"\b"x(@;+@|)}print"\n"__END__
Just another Perl Hacker


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

Date: Thu, 22 Mar 2001 14:01:26 GMT
From: "John W. Krahn" <krahnj@acm.org>
Subject: Re: Perl 5.6 - Spinning cursor routine?
Message-Id: <3ABA073A.E7BF3E16@acm.org>

Damian James wrote:
> 
> Bart Lateur chose Thu, 22 Mar 2001 11:36:03 GMT to say this:
> >Damian James wrote:
> >
> >>        return "\b"x($count>0).$chars[$count++%4];
> 
> Should have been $chars[$count++%@count] to allow for arbitrary @chars.
                                   ^^^^^^
                   $chars[$count++%@chars]


John
-- 
use Perl;
program
fulfillment


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

Date: Thu, 22 Mar 2001 13:49:58 GMT
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: Print "tar" Success or Failure
Message-Id: <3ABA03C3.94A50CEE@earthlink.net>

BUCK NAKED1 wrote:
> 
> bmb@ginger.libs.uga.edu (Brad Baxter)
> > Does the following help at all?
> >    1 #!/usr/local/bin/perl
> >    2 use warnings;
> >    3 use strict;
> >    4
> >    5 my $success = system('tar cvf x.tar qt paste');
> >    6
> >    7 print "\n\$?:$? \$success:$success\n\n";
> >    8
> >    9 my $failure = system('tar Z');
> >   10
> >   11 print "\n\$?:$? \$failure:$failure\n";
> >   12
> >   13 __END__
> > [snipped output]
> > Brad
> 
> Ummm, no. All that the output to the above shows is a success return
> value of 0, and failure return value of 256. However, the failure is
> based on a totally different operation, and incomplete code(tar -Z
> ???). If I replaced either of your 'tar' operations in my $success or
> in my $failure with "tar -zxf", I get a return value of 0 either
> way... whether the tar file is good or bad.
> 
> That's what is confusing me. Why does $? have a return value of 0
> whether the tar operation is successful or not? Is there another
> variable that checks child return status? I know of $@, but it is only
> used with eval.

The reason that $? does not have the value you expect it to be is
because the convention to exit with zero for success and nonzero for
failure is merely a "should be," not a "must be."

It appears that you will need to run tar, capture the output, and
actually parse the output, and see what kind of messages it prints --
both 'normal' messages and 'error' messages.  First try running it and
dumping stdout to /dev/null, and seeing if there are error messages for
a bad tar file, and then try with dumping stderr to /dev/null.  On one
of these two streams from the file, you should see some indication of
failure or success.

This might sound like alot of work, but it's probably not likely that
you'll need to look at more than one line of tar output.

Here's some [untested] sample code:

open( TAR, "tar xf foobar.tar|" );
$firstline = <TAR>;
close( TAR );
if( $? or $firstline =~ m/.* failed .* file not found$/ ) {
	die 'FAILURE';
}

I don't know what kind of error message tar outputs -- the above pattern
is just a guess -- but it's probably something like the above.

Look at the documentation of open and close, to see what is occuring
when you use close on a filehandle which is a pipe from or to a process.

-- 
The difference between theory and practice is that in theory, theory and
practice are identical, but in practice, they are not.


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

Date: Thu, 22 Mar 2001 14:31:08 +0100
From: Ulrich Ackermann <acki@ivu.de>
Subject: Problem installing Net-LDAPapi-1.42
Message-Id: <3AB9FE9C.A08508D0@ivu.de>

Hi all,
has anybody ever succeeded in installing the mentioned module? I am
running Debian Linux 2.2 and chose different ways for installing this
module (which I need for running the openCA software):
I always took the defaults for the Perl-, include- and lib-paths. I
tried Netscape and University of Michigan as my Development Kits. When
chosing Netscape, I tried with and without the option 'Using Netscape's
NEW LDAPv3 Development Kit' (after having installed the Netscape
Development Kit from there developer homepage).
Running 'perl Makefile.PL' went fine (most of the time, sometimes
missing the library ldap10), but the 'make' failed with the following
error messages:

cc -c  -DDEBIAN -fno-strict-aliasing -I/usr/local/include
-D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -O2     -DVERSION=\"1.42\"
-DXS_VERSION=\"1.42\" -fPIC -I/usr/lib/perl/5.6.0/CORE -DNETSCAPE_LDAP
LDAPapi.c
LDAPapi.xs: In function `av2modvals':
LDAPapi.xs:95: `na' undeclared (first use in this function)
LDAPapi.xs:95: (Each undeclared identifier is reported only once
LDAPapi.xs:95: for each function it appears in.)
LDAPapi.xs: In function `parse1mod':
LDAPapi.xs:197: `na' undeclared (first use in this function)
LDAPapi.xs: In function `XS_Net__LDAPapi_ldap_search':
LDAPapi.xs:578: `na' undeclared (first use in this function)
LDAPapi.xs: In function `XS_Net__LDAPapi_ldap_search_s':
LDAPapi.xs:614: `na' undeclared (first use in this function)
LDAPapi.xs: In function `XS_Net__LDAPapi_ldap_search_st':
LDAPapi.xs:660: `na' undeclared (first use in this function)
LDAPapi.xs: In function `XS_Net__LDAPapi_ldap_url_parse':
LDAPapi.xs:1137: `sv_undef' undeclared (first use in this function)
LDAPapi.xs: In function `XS_Net__LDAPapi_ldap_multisort_entries':
LDAPapi.xs:1221: `na' undeclared (first use in this function)
make: *** [LDAPapi.o] Error 1

Is there anyone who can help me with this one?

TIA, Ulrich



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

Date: Thu, 22 Mar 2001 11:54:43 -0000
From: "W K" <b_nospam_ill.kemp@wire2.com>
Subject: using closures (road to OO)
Message-Id: <985262286.23392.0.nnrp-09.c3ad6974@news.demon.co.uk>

I have been trying to get a closure to work for me in an ordinary
subroutine.

I have been reading the OO book, and I thought I could get this to work in
an ordinary subroutine

#!/usr/bin/perl
use strict;
my $i=10;
while(<>){ print a_sub()," <",$i--,">\n" }

{
    my $i=20;
    sub a_sub{return ("#". $i++."#")}
}
##########the end ##############

Now it does work, and there is a closure,
however, the closure $i used in the subroutine starts off at 0 and not 20.
the output is :
#0# <10>

#1# <9>
(... etc etc.)

What have I missed?

(real purpose = have a large hash as a closure, that doesn't get created and
destroyed each time the subroutine is used)

Thanks

(Complete the following "a little knowledge is a ...")




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

Date: 22 Mar 2001 07:49:38 -0500
From: Joe Schaefer <joe+usenet@sunstarsys.com>
Subject: Re: using closures (road to OO)
Message-Id: <m3ae6e3r4t.fsf@mumonkan.sunstarsys.com>

"W K" <b_nospam_ill.kemp@wire2.com> writes:

> #!/usr/bin/perl
> use strict;
> my $i=10;
> while(<>){ print a_sub()," <",$i--,">\n" }
> 
> {
>     my $i=20;
>     sub a_sub{return ("#". $i++."#")}
> }

perl doesn't see the "my $i=20;" line until it's too late. AFAIK, 
what happens is that during the "compilation" phase, perl notes 
the scope of $i for a_sub, but doesn't initialize $i until runtime 
(the closure effect).

The problem here is that at runtime, the a_sub is called *before* 
perl sees the "my $i=20" line.  To see the difference, try appending

  print "final pass=", a_sub(), "\n";

to the end of your code to see what's happening.

To fix it you could either put the initialization within a BEGIN
block, or move it to the top of your code.

HTH
-- 
Joe Schaefer     "Everybody talks about the weather, but nobody does anything
                                          about it."
                                               --Mark Twain


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

Date: Thu, 22 Mar 2001 12:51:42 +0000
From: Tom Scheper <tom@power.net.uk>
Subject: Re: using closures (road to OO)
Message-Id: <a9tjbto20iutfo1k773n9fd91qc1rsrqk7@4ax.com>

On Thu, 22 Mar 2001 11:54:43 -0000, "W K"
<b_nospam_ill.kemp@wire2.com> shed a beam of light on us:

>I have been trying to get a closure to work for me in an ordinary
>subroutine.
>
>I have been reading the OO book, and I thought I could get this to work in
>an ordinary subroutine
>
>#!/usr/bin/perl
>use strict;
>my $i=10;
>while(<>){ print a_sub()," <",$i--,">\n" }
>
>{
>    my $i=20;
>    sub a_sub{return ("#". $i++."#")}
>}
>##########the end ##############

Try removing the "my" before the $i=20;

-=Cornelis


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

Date: Thu, 22 Mar 2001 15:18:35 -0000
From: gbacon@HiWAAY.net (Greg Bacon)
Subject: Re: using closures (road to OO)
Message-Id: <tbk5ub44ktf1f7@corp.supernews.com>

In article <985262286.23392.0.nnrp-09.c3ad6974@news.demon.co.uk>,
    W K <b_nospam_ill.kemp@wire2.com> wrote:

: I have been reading the OO book, and I thought I could get this to work in
: an ordinary subroutine
: 
: #!/usr/bin/perl
: use strict;
: my $i=10;
: while(<>){ print a_sub()," <",$i--,">\n" }
: 
: {
:     my $i=20;
:     sub a_sub{return ("#". $i++."#")}
: }
: 
: Now it does work, and there is a closure,

No.  There's no closure.

: however, the closure $i used in the subroutine starts off at 0 and not 20.
: the output is :
: #0# <10>
: 
: #1# <9>
: (... etc etc.)
: 
: What have I missed?

The B::Deparse module provides some illumination:

    % perl -MO=Deparse,-p
    #!/usr/bin/perl
    use strict;
    my $i=10;
    while(<>){ print a_sub()," <",$i--,">\n" }

    {
        my $i=20;
        sub a_sub{return ("#". $i++."#")}
    }

    (my($i) = 10);
    while (defined(($_ = <ARGV>))) {
        print(a_sub(), ' <', ($i--), ">\n");
    }
    sub a_sub {
        return((('#' . ($i++)) . '#'));
    }
    {
        (my($i) = 20);
    }
    - syntax OK

Notice that C<my $i = 20> is compiled into a separate scope.  I can't
explain why a_sub() thinks $i starts at 0, though.

If you want to use a closure, modify your code as such:

    #! /usr/local/bin/perl -w

    use strict;

    my $i = 10;
    my $sub;

    {
        my $i = 20;
        $sub = sub { "#" . $i++ . "#" };
    }

    while (<>) { print $sub->(), " <", $i--, ">\n" }

Maybe you want to be a little more sophisticated:

    #! /usr/local/bin/perl -w

    use strict;

    sub make_counter {
        my $i = shift;
        sub { "#" . $i++ . "#" };
    }

    my $i = 10;
    my $s1 = make_counter 20;
    my $s2 = make_counter 42;

    while(<>) { print $s1->(), " ", $s2->(), " <",$i--,">\n" }

Hope this helps,
Greg
-- 
Science is what we understand well enough to explain to a computer.
Art is everything else.
    -- Donald Knuth


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

Date: 22 Mar 2001 14:35:40 GMT
From: Paul Hughett <hughett@mercur.uphs.upenn.edu>
Subject: Re: Weird(?) magic word for sh to invoke perl under Linux
Message-Id: <99d2js$ead$1@netnews.upenn.edu>

In comp.os.linux.misc * Tong * <sun_tong_001@yahoo.com> wrote:

: Under Solaris, I always use the following lines in my perl code to
: invoke it:

: #!/bin/sh -- # -*- perl -*- -w
: eval 'exec perl $0 ${1+"$@"}' 
:   if 0;


If you use

#! /usr/bin/env perl

as the first line of your script, then it will be run using whatever
copy of perl is found first on your path.  I know this trick works
on both RH Linux and Solaris, and believe that it will work on most
Unix systems.


The problem with using

#! /usr/bin/perl

for the first line, as suggested by some others, is that perl is often
installed in /usr/local/bin/perl instead. (if it doesn't come with the
system and is installed later by the sys admin).


Paul Hughett


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

Date: 22 Mar 2001 06:17:40 -0800
From: merlyn@stonehenge.com (Randal L. Schwartz)
Subject: Re: Why do "Learning Perl" Books Do This? A Subroutine Question.
Message-Id: <m1vgp1c2gr.fsf@halfdome.holdit.com>

>>>>> "Philip" == Philip Newton <pne-news-20010322@newton.digitalspace.net> writes:

Philip> David Ehrens didn't mention the title "Learning Perl" -- Randal
Philip> brought it up since he thought he recognised what book David was
Philip> talking about. David called it "the first edition of the Perl book by
Philip> Larry Wall and Randal Schwartz".

And since "the first edition of the Perl book by Larry Wall and Randal
Schwartz" can mean either the first Camel or the first Llama, and the
subject line is "Learning Perl", I naturally assumed he meant the
first Llama.

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


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

Date: 16 Sep 99 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 16 Sep 99)
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: The mail to news gateway, and thus the ability to submit articles
| through this service to the newsgroup, has been removed. I do not have
| time to individually vet each article to make sure that someone isn't
| abusing the service, and I no longer have any desire to waste my time
| dealing with the campus admins when some fool complains to them about an
| article that has come through the gateway instead of complaining
| to the source.

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


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