[17473] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 4893 Volume: 9

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Nov 15 09:10:31 2000

Date: Wed, 15 Nov 2000 06:10:12 -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: <974297412-v9-i4893@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Wed, 15 Nov 2000     Volume: 9 Number: 4893

Today's topics:
    Re: Please tell me why this code is wrong (ActiveState  <nospam@david-steuber.com>
    Re: Please tell me why this code is wrong (ActiveState  <nospam@david-steuber.com>
    Re: Q: Getting program line number? (Tom Christiansen)
    Re: replacing strings in a file.... (Bernard El-Hagin)
    Re: replacing strings in a file.... <dave@dave.org.uk>
    Re: replacing strings in a file.... (Gwyn Judd)
    Re: Sort files by date (Gwyn Judd)
    Re: Sort files by date (Martien Verbruggen)
    Re: Splitting up a regex <mdemello@kennel.ruf.rice.edu>
    Re: What's wrong with the script <jochen@c-lab.de>
    Re: Win32 - Active Directory <carvdawg@patriot.net>
        Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)

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

Date: Wed, 15 Nov 2000 12:32:00 GMT
From: David Steuber <nospam@david-steuber.com>
Subject: Re: Please tell me why this code is wrong (ActiveState build 613 on Winblows)
Message-Id: <m3em0difgh.fsf@solo.david-steuber.com>

garry@ifr.zvolve.net (Garry Williams) writes:

' As to the typo, you can probably see that it is important to cut and
' paste actual code here, so people don't debug phantom problems.  

Yes, I can.  What I did was write a new script to reproduce the
compile error I was getting rather than copy and paste sections from a
230 line script, or worse, paste in the entire script.

I then ran `perl -c test.pl' to confirm the compile error.  At that
point, I thought I had the code I was asking about.

' >Does ActiveState Perl work with the -w option in the script?  
' 
' This is from the perlrun manual page that comes with ActiveState perl: 
' 
'      The #! line is always examined for switches as the line is
'      being parsed.  Thus, if you're on a machine that allows only
'      one argument with the #! line, or worse, doesn't even
'      recognize the #! line, you still can get consistent switch
'      behavior regardless of how Perl was invoked

Ok, so I am not wasting my time using the standard shebang line.
Thanks to you and others for pointing that out.

'     use strict;
'     my %foo_hash = { bar => "baz" };
'     $ perl -c x
'     x syntax OK
'     $ perl x
'     Reference found where even-sized list expected at x line 3.
'     $ 
' 
' There is *no* warning generated at compile time for your incorrect
' assignment.  Since further down in the same program there was a fatal
' compile time error due to the failure to run to the drug store, there
' could have never been a warning about the first error.  Jeff Pinyan
' admonished you to use -w to catch that (which you actually did), but
' it wouldn't have caught it anyway since your script never made it to
' run time.  

Right.  I never ran the script because of the compile time errors.

' (Jeesh!  It wouldn't have caught it anyway since you transcribed it
' wrong in the first place and there really wasn't *any* problem there.
' All this for lack of cutting and pasting.)  

And to make matters worse, the error was the same regardless.  I have
also done copy and paste code reuse where things needed to be slightly
altered and then burned when I forgot to make the changes.  Copy and
paste is a two edged sword.

' In perl 5.6.0, it seems to be the preference to `use warnings;'
' instead of the -w switch.  Anyway, either one will work on Windows as
' well as Unix.  

Would it be a bad thing to use both?  I presume they both simply set a
flag in the compiler to generate the appropriate run time checks.

I guess I shouldn't presume.  It makes a pre out of u and me.

-- 
David Steuber | Perl apprentice.  The axe did not stop the
NRA Member    | mops and buckets from flooding my home.
ICQ# 91465842
***         http://www.david-steuber.com/          ***


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

Date: Wed, 15 Nov 2000 12:42:47 GMT
From: David Steuber <nospam@david-steuber.com>
Subject: Re: Please tell me why this code is wrong (ActiveState build 613 on Winblows)
Message-Id: <m37l65ieyi.fsf@solo.david-steuber.com>

Ren Maddox <ren.maddox@tivoli.com> writes:

' dsteuber@my-deja.com writes:
' 
' > #!/usr/bin/perl -w
' > use strict;
' > 
' > package Foo;
' > 
' > my %foo_hash = { bar => "baz" };
' 
' Oops... the curlies create a hash *reference*, which isn't what you
' want.  Is that just a typo here, because if not then you should have
' gotten an error: "Reference found where even-sized list expected".

Yes, typo. :-(

As I mentioned in a previous post, I was taking my big script and
creating a little one suitable for posting that reproduced the compile
error and accidently used the curely braces.  (I've been doing a bunch
of new subs in this form:

sub new {
  $type = shift;
  $self = {};
  bless $self, $type;
  # additional code here
  return $self;
}

I guess I had waves on the brain.  In the real script, as opposed to
the example script, I had used () to initialize the hash.

' > printf "%s\n", $foo_hash_ref{bar};
' 
' Here, $foo_hash_ref{bar} is the syntax for accessing the value
' associated with the key "bar" in the hash, %foo_hash_ref.  You need to
' dereference it first:
' 
'   printf "%s\n", $foo_hash_ref->{bar};

Yes, that was the problem.  I stared at the original script for a good
(well actually it wasn't such a good) hour before I finally gave up
and posted via deja.

Then about thirty minutes later the answer came to me like a slap on
the forehead.  I canceled my post, but not all news servers honor
cancels.  My ISP's does :-/.

It's just as well becuase I still got useful information from the
responses I have received.

Thanks, all.

-- 
David Steuber | Perl apprentice.  The axe did not stop the
NRA Member    | mops and buckets from flooding my home.
ICQ# 91465842
***         http://www.david-steuber.com/          ***


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

Date: 15 Nov 2000 06:35:31 -0700
From: tchrist@perl.com (Tom Christiansen)
Subject: Re: Q: Getting program line number?
Message-Id: <3a129123@cs.colorado.edu>

In article <8FE866D90quuxi@194.203.134.135>, someone who lacks the
personal responsibility to use his own address wrote:

>It's a backronym then (as defined in the Jargon file)

You mean "retronym".  Although one might argue that mixing Latin
and Greek may be something of a chimera, this is a well-established
procedure.  And it certainly isn't the abomination that mixing Greek
and Old English is, which is more like infelicitously mixing in a
few lightning bug genes into some sweet peas that are then spliced
into a third genome to make these grow twining and blinking out of
a lion's mane to produce a brand new frankenspecies, perhaps something
like a "felix lucileguminosus" :-)

--tom


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

Date: Wed, 15 Nov 2000 08:50:52 +0000 (UTC)
From: bernard.el-hagin@lido-tech.net (Bernard El-Hagin)
Subject: Re: replacing strings in a file....
Message-Id: <slrn914jg0.7hk.bernard.el-hagin@gdndev25.lido-tech>

On Wed, 15 Nov 2000 08:58:47 +0100, Didier Lefevre
<didier.lefevre@elias.be> wrote:
>hello,
>
>Anyone an idea on how to replace a string by another one in a file 
>(iside a perl program)?? Ok, I'll probably find it in one or more doc 
>pieces but I don't have much time to read heaps of documentation at this 
>moment, so...

Since you don't have time to search all of the docs I'll just point you
in the right direction. Mosy on down to:

perldoc perlop

and search for s/PATTERN/REPLACEMENT/egimosx

Cheers,
Bernard
--
perl -le '$#="Just Another Perl Hacker"; print \Bernard'


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

Date: Wed, 15 Nov 2000 09:34:04 -0000
From: "Dave Cross" <dave@dave.org.uk>
Subject: Re: replacing strings in a file....
Message-Id: <8utlcg$7jp$1@taliesin.netcom.net.uk>


Bernard El-Hagin <bernard.el-hagin@lido-tech.net> wrote in message
news:slrn914jg0.7hk.bernard.el-hagin@gdndev25.lido-tech...
> On Wed, 15 Nov 2000 08:58:47 +0100, Didier Lefevre
> <didier.lefevre@elias.be> wrote:
> >hello,
> >
> >Anyone an idea on how to replace a string by another one in a file
> >(iside a perl program)?? Ok, I'll probably find it in one or more doc
> >pieces but I don't have much time to read heaps of documentation at this
> >moment, so...
>
> Since you don't have time to search all of the docs I'll just point you
> in the right direction. Mosy on down to:
>
> perldoc perlop
>
> and search for s/PATTERN/REPLACEMENT/egimosx

Or maybe the question "How do I change one line in a file/delete a line in a
file/insert a line in the middle of a file/append to the beginning of a
file?" from perlfaq5 might be even more appropriate.

Dave...





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

Date: Wed, 15 Nov 2000 09:57:21 GMT
From: tjla@guvfybir.qlaqaf.bet (Gwyn Judd)
Subject: Re: replacing strings in a file....
Message-Id: <slrn914nfu.fjg.tjla@thislove.dyndns.org>

I was shocked! How could Didier Lefevre <didier.lefevre@elias.be>
say such a terrible thing:
>hello,
>
>Anyone an idea on how to replace a string by another one in a file 
>(iside a perl program)?? Ok, I'll probably find it in one or more doc 
>pieces but I don't have much time to read heaps of documentation at this 
>moment, so...

This is a good way:

print <<EOS;
Please replace the string '$original' with the string '$replacement'.
Thanks
EOS

system $ENV{EDITOR}, $filename and 
    die "What? No editor? Better read the faq: $!";

-- 
Gwyn Judd (print `echo 'tjla@guvfybir.qlaqaf.bet' | rot13`)
Two can Live as Cheaply as One for Half as Long.
		-- Howard Kandel


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

Date: Wed, 15 Nov 2000 09:21:26 GMT
From: tjla@guvfybir.qlaqaf.bet (Gwyn Judd)
Subject: Re: Sort files by date
Message-Id: <slrn914lcj.fjg.tjla@thislove.dyndns.org>

I was shocked! How could Chris Fedde <cfedde@fedde.littleton.co.us>
say such a terrible thing:

>Of course if you were shooting for a low golf score you might try this:
>
>-M>-M$o and$o=$_ for(<*>);print"$o\n"

or:

-M>-M$o?$o=$_:1for(<*>);print"$o\n"

-- 
Gwyn Judd (print `echo 'tjla@guvfybir.qlaqaf.bet' | rot13`)
Fortune's real live weird band names #553:

Psycho Sluts from Hell


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

Date: Wed, 15 Nov 2000 20:43:30 +1100
From: mgjv@tradingpost.com.au (Martien Verbruggen)
Subject: Re: Sort files by date
Message-Id: <slrn914mm2.gs3.mgjv@martien.heliotrope.home>

On Wed, 15 Nov 2000 15:16:52 +0930,
	Wyzelli <wyzelli@yahoo.com> wrote:
> "Martien Verbruggen" <mgjv@tradingpost.com.au> wrote in message
> news:slrn91478u.gs3.mgjv@martien.heliotrope.home...
> 
>> >> my $oldest = (sort { -M $a <=> -M $b } @files)[-1];
>> >
>> > The -1 refers to the last element of the array @files.
>>
>> Mind the brackets. The -1 refers to the last element of the sorted list.
>> Unless @files is already sorted, those are most likely not the same :)
> 
> Yeah, I saw that, and cancelled my post, and then read your excellent
> answer before correcting mine, so I didn't bother to re-do it...
> 
> You must've been quick! :)

Fastest poster on the continent. That's me.

:)
-- 
Martien Verbruggen              | 
Interactive Media Division      | We are born naked, wet and hungry.
Commercial Dynamics Pty. Ltd.   | Then things get worse.
NSW, Australia                  | 


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

Date: 15 Nov 2000 11:35:30 GMT
From: Martin Julian DeMello <mdemello@kennel.ruf.rice.edu>
Subject: Re: Splitting up a regex
Message-Id: <8utse2$1cu$1@joe.rice.edu>

Sean McAfee <mcafee@waits.facilities.med.umich.edu> wrote:

> When using the /x modifier, you have to escape whitespace to be matched:

[...]

> Not much better, is it?

Nope :) 

> Personally, I tend to balk at using regexen to match exact strings, since
> eq does it so much faster.  In a situation like this I would probably
> use a closure:

[snip]

Thanks! This one's a lot neater, and far easier to extend legibly.

-- 
Martin DeMello


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

Date: Wed, 15 Nov 2000 13:20:40 +0100
From: Jochen Luig <jochen@c-lab.de>
Subject: Re: What's wrong with the script
Message-Id: <3A127F98.5D712868@c-lab.de>

Hi!

iryna martynenko wrote:
> 
> Can anybody help me with this script.
> When I launch it from the HTML page I got a message "the document
> contain no data"

>        {print "Location: http://www.blabla.net/page2.html"}

This is not a valid header. Try

print "Location: http://www.blabla.net/page2.html\n\n";

instead.

perldoc -q redirect

Jochen


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

Date: Wed, 15 Nov 2000 05:40:45 -0500
From: H C <carvdawg@patriot.net>
Subject: Re: Win32 - Active Directory
Message-Id: <3A12682C.7EA9BF2D@patriot.net>

Also look at WMI classes...they have a wider range of objects to choose from.
If you have Win2K, you don't need to install the WMI classes...they're built in.

I've seen someone post about a WMI.pm module that ships w/ the Win2K
SP 1 Resource Kit...it looks promising.

"Thomas L. Shinnick" wrote:

> On Mon, 13 Nov 2000 14:02:22 -0500, "SC" <steve@i66.net> wrote:
> >Can anyone point me to a module or modules that provide API access to
> >windows2000 Active Directory objects?
> >
> >I am trying to modify entries in user objects, and can only do so much
> >with NetAdmin and AdminMisc..
>
> Use Win32::OLE to access ADSI.
>
> O'Reilly books:  (Hi David!)
>     _Windows 2000 Active Directory_, ISBN 1-56592-638-2 has a whole
>     section on ADSI (though all of the examples are also in VB). It
>     appears to be an excellent book on AD in general.
>
>     _Perl for System Administration_, ISBN 1-56592-609-9 has part of a chapter
>     devoted to ADSI and using it from Perl
>
> Another book:
>     _Windows NT/2000: ADSI Scripting for System Administration_,
>     ISBN 1-57870-219-4, is not Perl-specific but in VB.
>
> David's book references ADSI/Perl pages at
> http://public.activestate.com/authors/tobyeverett/.  Sounds like he
> has code you can read...
>
> Some more links I gave a fellow at work who used Access instead  %-P
> ADSI 2.5
> http://www.microsoft.com/ntserver/nts/downloads/other/ADSI25/default.asp
>  and more specifically,  the APIs
> http://download.microsoft.com/msdownload/adsi/2.5/ads.exe
>  and development documents and examples
> http://download.microsoft.com/msdownload/adsi/2.5/sdk/x86/en/Sdk.zip
>  and the main help file
> http://www.microsoft.com/ntserver/downloads/bin/nts/adsi25.chm
>
> >
> >Any pointers appreciated..
> >
> >S.
> >
>
> --
> When time permits, your personal life will be exciting.
>   -- Restaurant Fortune Cookie       (They know me there ...)

--
Q: Why is Batman better than Bill Gates?
A: Batman was able to beat the Penguin.




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

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 V9 Issue 4893
**************************************


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