[23060] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 5281 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Jul 28 14:06:06 2003

Date: Mon, 28 Jul 2003 11:05:07 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Mon, 28 Jul 2003     Volume: 10 Number: 5281

Today's topics:
        array question (grep -v on array) (NetComrade)
    Re: Concatenation <grazz@pobox.com>
    Re: FTP in ASCII mode from UNIX to NT (jiju)
    Re: hash problems (Tad McClellan)
        IntrOOspection: ISO an object's methods set <jill_krugman@yahoo.com>
    Re: IntrOOspection: ISO an object's methods set <usenet@expires082003.tinita.de>
    Re: Is there a clean way to export all constants from a <stevea@wrq.com>
    Re: Is there a clean way to export all constants from a <stevea@wrq.com>
        LWP::Request (Kevin Su)
    Re: LWP::Request <NOSPAM@bigpond.com>
    Re: Net::IMAP::Simple  (2nd post) <hasting@agere.com>
        Net::IMAP::Simple <hasting@agere.com>
    Re: Net::IMAP::Simple (Sam Holden)
        on dprofpp <perseus_medusa@hotmail.com>
    Re: Perl compiler? error <nobull@mail.com>
        Perl training resources? <Bill_Fields@azb.uscourts.gov>
    Re: Perl training resources? <uri@stemsystems.com>
    Re: perlcc makes it big <Juha.Laiho@iki.fi>
        Warnings on Win32::NetResouce::AddConnection() call to  <nospam@ceo.com>
    Re: what is perl's no op operator? <nospam-abuse@ilyaz.org>
        you *must* be able to shorten this... (Ghee)
    Re: you *must* be able to shorten this... <pinyaj@rpi.edu>
    Re:  <bwalton@rochester.rr.com>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Mon, 28 Jul 2003 17:54:35 GMT
From: andreyNSPAM@bookexchange.net (NetComrade)
Subject: array question (grep -v on array)
Message-Id: <3f256291.591394830@nyc.news.speakeasy.net>

Hi,

I have an output of errors fed into an array, after which I only look
at things I care about and put them in a different array:

@oracle_errors =
grep(/ORA-/||/neededarchiving/||/FULL/||/archival/||/Standby/||/deadlock/,@output);

However, I would like to have (yet another array), e.g. @ignore_errors
which will contain values such as
ORA-error can be ignored
ORA-error2 can be ignored

How can I set that up?

Alternatively, (if simpler), i'd like to add some kind of 'grep -v'
functionality to my grep command (but the array method seems sweeter).

Thanks.
 .......
We use Oracle 8.1.7.4 on Solaris 2.7 boxes
remove NSPAM to email


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

Date: Mon, 28 Jul 2003 16:36:01 GMT
From: Steve Grazzini <grazz@pobox.com>
Subject: Re: Concatenation
Message-Id: <RhcVa.8383$cM6.2314@nwrdny01.gnilink.net>

Tina Mueller <usenet@expires082003.tinita.de> wrote:
>  use strict;
>  print test."";
> 
> which prints "test" (instead of complaining)
> (perl 5.8.0, linux)
> 
> is that a bug or do I oversee something?

I think it's a bug.

> (in article <afs6gg$tbn$1@news.netmar.com> there seems to
> be described a similar problem)

That one was fixed in 5.8.

-- 
Steve


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

Date: 28 Jul 2003 10:36:57 -0700
From: jmkuruvilla@yahoo.com (jiju)
Subject: Re: FTP in ASCII mode from UNIX to NT
Message-Id: <c396a971.0307280936.20015ca@posting.google.com>

hello guys, you all have been very helpful. 'unix2dos' does the job.
thank you.
someone else also gave me a tip. `perl -p -i -e 's/\\n/\\r\\n/'
$filename` to replace the newlines with carriage returns in DOS.

thanks much to you guys.

"Stefan" <someone@somewhere.nl> wrote in message news:<3f22f6af$0$76455$e4fe514c@dreader8.news.xs4all.nl>...
> "jiju" <jmkuruvilla@yahoo.com> schreef in bericht
> news:c396a971.0307251713.79ca8790@posting.google.com...
> > hi,
> >
> > I can't open up a text file that I FTP'd from UNIX to Windows 2000
> > even though I set the type to ASCII mode ($ftp->ascii();). I guess it
> > has to do with carriage return character not encoding correctly on
> > 2000 machine. Is there any work around to fix this problem so I could
> > open this file up in Notepad?? Need to have it in Notepad to use with
> > MS Access
> >
> > thanks,
> > jju
> 
> 
> Windows text files use CR (= \r) + LF (= \n) as an end-of-line marker, while
> Unix just use LF (= \n). So, before you FTP over a text file, change the
> end-of-line marker and store everything in a temporary file. Then transfer
> the tmp-file as if it was the source file: $ftp->put(tmp-file, source-file).
> Make sure to use binary mode (or at least test ascii mode).
> 
> FreeBSD has the commands unix2dos and dos2unix which describe what you're
> seeing. Perhaps your Unix flavour has it too.
> 
> Bye,
> Stefan


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

Date: Mon, 28 Jul 2003 08:45:43 -0500
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: hash problems
Message-Id: <slrnbiaa87.30b.tadmc@magna.augustmail.com>

Mihai Maris <mihai.maris@alcatel.ro> wrote:

>  First of all : I'm a beginner in Perl. 


Nothing wrong with that.

And an expert has just shown you how to get fast answers to 
common Perl questions.

Getting fast answers to questions that are very likely to occur
to you is a great benefit.

You (could) have learned something valuable here...


> And I found this a shortest way to find the
> answeear to my problem.


Posting to Usenet is the *longest* way to find an answer. It can take
hours or days or even forever.

Finding the answer in the docs that came with the software you are
using, or in a newsgroup archive will much faster than typing up
a question and hoping that someone sometime will answer it.


>  And I even didn't know about this FAQs 


Then a well-socialized response would have been:

   I didn't know about that, thanks.

rather than whining about it.


> and I also don't have so much time to
> navigate throw.


But we do?

Asking thousands of people to read the docs to you is inefficient
and wasteful.

You have done serious damage to your ability to get help with any
future Perl questions that you might have. So long.


   *plonk*



[snip TOFU]


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


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

Date: Mon, 28 Jul 2003 15:15:54 +0000 (UTC)
From: J Krugman <jill_krugman@yahoo.com>
Subject: IntrOOspection: ISO an object's methods set
Message-Id: <bg3ena$lcd$1@reader1.panix.com>



I am aware of the UNIVERSAL::can method to determine whether an
object can perform a particular method, but is there a way to get
all the methods that an object can perform (including the inherited
ones, of course)?  I realize this question is complicated by
AUTOLOAD, but I'd be happy if I could find all of an object's
non-AUTOLOADed methods.

More generally, how does UNIVERSAL determine whether object $foo
can 'fandango'?  Does it simply run eval { $foo->fandango() } and
then pick through the bloody aftermath in $@, or does it use a more
civilized approach, such as looking up some suitable tables?  If
the latter is true, how can a program access these tables of methods
directly?

Thanks!

	-Jill



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

Date: 28 Jul 2003 15:44:22 GMT
From: Tina Mueller <usenet@expires082003.tinita.de>
Subject: Re: IntrOOspection: ISO an object's methods set
Message-Id: <bg3gcm$ju2m9$1@ID-24002.news.uni-berlin.de>

J Krugman wrote:

> I am aware of the UNIVERSAL::can method to determine whether an
> object can perform a particular method, but is there a way to get
> all the methods that an object can perform (including the inherited
> ones, of course)?

well, there *is* a way. there are many modules on CPAN that
are playing with inheritance and things like that. problem
is, it's complicated.

for example, to determine all the subs that a *class* (not
an object) can perform, you would have to search through
the symbol-table and see if there are any subroutines in it.

now for an object you would determine it's package, search
this symbol table, then determine the object's super-class(es),
and search them recursively the same way.
take a look at modules like NEXT or so to see how this is done.

>  I realize this question is complicated by
> AUTOLOAD, but I'd be happy if I could find all of an object's
> non-AUTOLOADed methods.

> More generally, how does UNIVERSAL determine whether object $foo
> can 'fandango'?  Does it simply run eval { $foo->fandango() } and
> then pick through the bloody aftermath in $@,

no, of course not. running a subroutine usually causes a side-
effect, and you don't want to happen this, considering:
print "ok" if $object->can("delete_all_files_on_system");

> or does it use a more
> civilized approach, such as looking up some suitable tables?  If
> the latter is true, how can a program access these tables of methods
> directly?

look into the symbol table, like %main:: or %Your::Module::.

you would have to learn a bit about globs and things like
that, maybe in 'perldoc perldata', and other pages.
look them up in 'perldoc perldoc'

hth, tina
-- 
http://www.tinita.de/     \  enter__| |__the___ _ _ ___
http://Movies.tinita.de/   \     / _` / _ \/ _ \ '_(_-< of
http://www.perlquotes.de/   \    \ _,_\ __/\ __/_| /__/ perception
- my mail address expires end of august 2003 -


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

Date: Mon, 28 Jul 2003 16:03:21 GMT
From: Steve Allan <stevea@wrq.com>
Subject: Re: Is there a clean way to export all constants from a module?
Message-Id: <u8yqiljuf.fsf@wrq.com>

tiltonj@erols.com (Jay Tilton) writes:

>The assignment to %build_properties happens at run-time, but
>"use constant \%build_properties;" happens at compile time.  
>Put the assignment in a BEGIN{} block so it too happens during
>compilation.
>
>    my %build_properties;
>    BEGIN{
>        %build_properties = (
>            CURRENTCHANGE => 'currentChange',
>            BLDNUM => 'buildNumber',
>            STAGEROOTDIR   => 'stageRootDir',
>            WEBREPORTDIR   => 'webReportDir',
>        );
>    }
>    use constant \%build_properties;
>    @EXPORT_OK = (keys %build_properties);
>

Works like a charm - Thanks!

-- 
-- Steve


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

Date: Mon, 28 Jul 2003 16:09:46 GMT
From: Steve Allan <stevea@wrq.com>
Subject: Re: Is there a clean way to export all constants from a module?
Message-Id: <u4r16ljjp.fsf@wrq.com>

"Eric J. Roode" <REMOVEsdnCAPS@comcast.net> writes:

>Steve Allan <stevea@wrq.com> wrote in news:ud6fykuzh.fsf@wrq.com:
>
>> 
>> I'm creating a module for the sole purpose of defining constants to be
>> shared among several Perl scripts.  I'm looking for a way to simplify
>> getting all the constant names into the @EXPORT_OK array...
>
>You might want to try my experimental Config::Vars module, which is 
>designed for what you have in mind -- although it doesn't support 
>constants, it does support Readonly variables.
>

Being Readonly and easily maintained are the two things I'm after.

>Perhaps I should add support for constants to the module.

Constants are nice because you can tell by looking at them that they
are readonly.  But I'm very interested in checking out Config::Vars to
see what all it does.

Thanks.

-- 
-- Steve


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

Date: 28 Jul 2003 08:52:49 -0700
From: ksu@amaranthllc.com (Kevin Su)
Subject: LWP::Request
Message-Id: <5dd555c5.0307280752.10805a1e@posting.google.com>

Can someone show me how to use LWP::request properly?  Specifically,
for authorization.  I want to get information from a protected website
by automating the log in process.  I googled it online because someone
at my company recommended it to me, and I found a site containing:

"-C <username>:<password>
Provide credentials for documents that are protected by Basic
Authentication. If the document is protected and you did not specify
the username and password with this option, then you will be prompted
to provide these values."

http://toons.cs.ucsb.edu:4080/man?lwp-request

This looks useful to what I am trying to do, though I do not know how
to use it.


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

Date: Tue, 29 Jul 2003 03:07:09 +1000
From: "Gregory Toomey" <NOSPAM@bigpond.com>
Subject: Re: LWP::Request
Message-Id: <bg3l6j$kgedv$1@ID-202028.news.uni-berlin.de>

"Kevin Su" <ksu@amaranthllc.com> wrote in message
news:5dd555c5.0307280752.10805a1e@posting.google.com...
> Can someone show me how to use LWP::request properly?  Specifically,
> for authorization.  I want to get information from a protected website
> by automating the log in process.  I googled it online because someone
> at my company recommended it to me, and I found a site containing:
>

What you probably want (as dictinct from what you asked for) is how to use
basic authntication when retrieving a page:

#!/usr/bin/perl
use LWP::Simple;

my $screen_scraper=get("http://username:password\@site.com/restofurl");
# @ has been escaped


You can type URLS of the form http://username:password@site.com/restofurl
straight into your browser to avoid getting the popup for basic
authentication.

gtoomey




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

Date: Mon, 28 Jul 2003 11:28:29 -0400
From: "Joe Hasting" <hasting@agere.com>
Subject: Re: Net::IMAP::Simple  (2nd post)
Message-Id: <bg3feu$bu7$1@alageremail2.agere.com>

Does anyone have any experience with this?
thanks
J

"Joe Hasting" <hasting@agere.com> wrote in message
news:bfos6d$3jv$1@alageremail2.agere.com...
> I would like to use the IMAP:Simple module to poll a IMAP server.  I want
to
> look at messages and search the subject and body for a string.  I got the
> sample script from CPAN (below), but I can't get it to work.  I changed
> someserver to my IMAP server, and someuser, somepassword, and somefolder
to
> the appropriate values, but when I run it it returns immediatly with no
> responce (I can use a mail client and see me mesages in the folder on my
> IMAP server).  Can someone let me know how I can check to see if I am
> logging into the server,  or an alternate method that has worked for use
to
> read IMAP.
>
> thanks
> J
>
>
> use Net::IMAP::Simple;
>
>
>     # open a connection to the IMAP server
>     $server = new Net::IMAP::Simple( $self->param( 'someserver' ) );
>
>     # login
>     $server->login( 'someuser', 'somepassword' );
>
>     # select the desired folder
>     $number_of_messages = select( 'somefolder' );
>
>     # go through all the messages in the selected folder
>     foreach $msg ( 1..$number_of_messages ) {
>
>         # get the message
>         $lines = $server->get( $msg );
>
>         # print it
>         print @$lines;
>     }
>
>     # the list of all folders
>     @folders = $server->mailboxes();
>
>     # create a folder
>     $server->create_mailbox( 'newfolder' );
>
>     # rename a folder
>     $server->rename_mailbox( 'newfolder', 'renamedfolder' );
>
>     # delete a folder
>     $server->delete_mailbox( 'renamedfolder' );
>
>     # copy a message to another folder
>     $server->copy( $self, $msg, 'renamedfolder' );
>
>     # close the connection
>     $server->quit();
>
>




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

Date: Mon, 28 Jul 2003 11:30:09 -0400
From: "Joe Hasting" <hasting@agere.com>
Subject: Net::IMAP::Simple
Message-Id: <bg3fi3$c5k$1@alageremail2.agere.com>

I am re-posting to see if anyone has a suggestion, or experience using this
module.:


------------------------------------------------------
I would like to use the IMAP:Simple module to poll a IMAP server.  I want to
look at messages and search the subject and body for a string.  I got the
sample script from CPAN (below), but I can't get it to work.  I changed
someserver to my IMAP server, and someuser, somepassword, and somefolder to
the appropriate values, but when I run it it returns immediatly with no
responce (I can use a mail client and see me mesages in the folder on my
IMAP server).  Can someone let me know how I can check to see if I am
logging into the server,  or an alternate method that has worked for use to
read IMAP.

thanks
J


use Net::IMAP::Simple;


    # open a connection to the IMAP server
    $server = new Net::IMAP::Simple( $self->param( 'someserver' ) );

    # login
    $server->login( 'someuser', 'somepassword' );

    # select the desired folder
    $number_of_messages = select( 'somefolder' );

    # go through all the messages in the selected folder
    foreach $msg ( 1..$number_of_messages ) {

        # get the message
        $lines = $server->get( $msg );

        # print it
        print @$lines;
    }

    # the list of all folders
    @folders = $server->mailboxes();

    # create a folder
    $server->create_mailbox( 'newfolder' );

    # rename a folder
    $server->rename_mailbox( 'newfolder', 'renamedfolder' );

    # delete a folder
    $server->delete_mailbox( 'renamedfolder' );

    # copy a message to another folder
    $server->copy( $self, $msg, 'renamedfolder' );

    # close the connection
    $server->quit();





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

Date: 28 Jul 2003 15:52:47 GMT
From: sholden@flexal.cs.usyd.edu.au (Sam Holden)
Subject: Re: Net::IMAP::Simple
Message-Id: <slrnbiahmc.o1a.sholden@flexal.cs.usyd.edu.au>

On Mon, 28 Jul 2003 11:30:09 -0400, Joe Hasting <hasting@agere.com> wrote:
> I am re-posting to see if anyone has a suggestion, or experience using this
> module.:

Ask perl for help (by enabling warnings, and prevent silly errors
by also using "use strict;").

What do you think $self is? What does perl think it is? What makes
you think it has a param method?

It has been over *three and a half years* since the documentation
of that module was corrected. Why are you still using the incorrect
example (which was corrected *five days* after it was released)?

[snip buggy example code from Net::IMAP::Simple 0.90 docs]

That module hasn't been updated for a long time, if it works then
I guess it'll do fine. But something like Mail::IMAPClient seems to
be under more active development.

-- 
Sam Holden



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

Date: Tue, 29 Jul 2003 01:17:58 +0800
From: "j" <perseus_medusa@hotmail.com>
Subject: on dprofpp
Message-Id: <3f25594e$1@newsgate.hknet.com>

hi all,

    I am using dprofpp to profile my code. I have some questions on that:

1) Will the subroutine shown overlap with each other ? say :
9 %   Foo1::Foo2::Request
8 %   Foo1::Foo2::subRequest

but actually Foo1::Foo2::Request is calling Foo1::Foo2::subRequest. How
could I make it clear in that presentation ?

2) I profiled that LWP::UserAgent::Begin is always very large in CPU user
time. Is there any way to reduce that ?

3) Is there any tools for profiling which is preferably free ?

Thanks.

Persues




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

Date: 28 Jul 2003 17:58:08 +0100
From: Brian McCauley <nobull@mail.com>
Subject: Re: Perl compiler? error
Message-Id: <u93cgqk2qn.fsf@wcl-l.bham.ac.uk>

fatted@yahoo.com (fatted) writes:

> Lets say a friend of mine :) wrote code which had a bad error in it:
> 
> #!/usr/bin/perl
> use warnings;
> use strict;
> 
> my $words = ["a", "b", "c"];
> my $num = 612;
> 
> if($num == 1)
> {
>         print "moo\n";
> }
> elsif (map($_->[0] =~ /\d{6}/, @$words))
> {
>         print "Don't give up day job\n";
> }
> 
> When run this gives the error:
> Can't use string ("a") as an ARRAY ref while "strict refs" in use at
> ./test.pl line 8.

Yes good.

> After about 1/2 hour of head banging, the problem (which was
> originally in a much larger program) was finally discovered. The code
> problem wasn't on line 8 :).

Boggle!

> However this leads to my real question:
> Is the error message above, an error in the compiler?

No it is a totally correct run-time error, _not_ a compiler error.

>  For instance if
> the close bracket of an elsif is forgotton, you get an error on the
> line where the close bracket was left out. *Not* on the line where the
> start of the IF THEN ELSE syntax began.
> 
> e.g. if I fixed line 8 to (oops left out close bracket for elsif):
> 
> elsif (map(/\d{6}/, @$words)
> 
> Error message is:
> 
> syntax error at ./test.pl line 14, near ")
> {"
> Execution of ./test.pl aborted due to compilation errors.

Yes that correct.

In the case of syntax errors, compilers usually report the location of
the error at the point where it became inpossible to interpret the
source as valid syntax.  The error may have occoured some time
earlier.

In the case of runtime errors, runtimes ususally report as best they
can the point in the source where the statement that failed is
located.  Of course the actual error may be someplace earlier but in
the general case there's no way to say where the error was.  

I would give an example to illustrate this point but in fact your own
example illustrates it perfectly well.

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


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

Date: Mon, 28 Jul 2003 10:04:12 -0700
From: "William Fields" <Bill_Fields@azb.uscourts.gov>
Subject: Perl training resources?
Message-Id: <bg3l2d$aj3$1@apollo.nyed.circ2.dcn>

Hi everyone,

I'm looking for Perl training resources in the Phoenix, Arizona area.

Thanks.

-- 
William Fields
MCSD - Microsoft Visual FoxPro
MCP - Win2k Pro
US Bankruptcy Court
Phoenix, AZ

The secret to creativity is knowing how to hide your sources.

        - Albert Einstein





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

Date: Mon, 28 Jul 2003 17:34:12 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: Perl training resources?
Message-Id: <x7he56tv1s.fsf@mail.sysarch.com>

>>>>> "WF" == William Fields <Bill_Fields@azb.uscourts.gov> writes:

  WF> I'm looking for Perl training resources in the Phoenix, Arizona area.

how close is phoenix to boston? :-)

damian conway will be teaching 4 days of classes in boston in late
september. i will post more info when i finalize what the classes will
be.

  WF> MCSD - Microsoft Visual FoxPro
  WF> MCP - Win2k Pro
  WF> US Bankruptcy Court

i take it that using the first two led to the last one?

:-)

uri

-- 
Uri Guttman  ------  uri@stemsystems.com  -------- http://www.stemsystems.com
--Perl Consulting, Stem Development, Systems Architecture, Design and Coding-
Search or Offer Perl Jobs  ----------------------------  http://jobs.perl.org


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

Date: Mon, 28 Jul 2003 17:37:00 GMT
From: Juha Laiho <Juha.Laiho@iki.fi>
Subject: Re: perlcc makes it big
Message-Id: <bg3msh$ucf$1@ichaos.ichaos-int>

tassilo.parseval@post.rwth-aachen.de said:
>Also sprach Matt H:
>
>> In article <3F1C2B57.44D98CA9@ass.wipe.com>, butt-fuzz wrote:
 ...
>>> #!/usr/bin/perl
>>> print "test";
 ...
>>> and ran perlcc.
>>> it gave me an a.out 1MB in size!
>>> yikes!
>> 
>> That's odd, I just ran perlcc on the same program and ended up with
>> 37K (after stripping).
>
>That would surprise me:
>ethan@ethan:~$ perlcc -e 'print "hello world"'
 ...
>ethan@ethan:~$ strip a.out
>ethan@ethan:~$ l a.out
>-rwxr-xr-x    1 ethan    100        891128 Jul 22 21:59 a.out
>
>So even after stripping it's still 890K in size. Did you perhaps tell
>perlcc to do dynamic instead of static linking? If so, how?

Could this be dependent on Perl compile-time options? I.e. compiling Perl
core as dynamic as opposed to static library (where static at least used
to be the default - I think still with 5.6.1).
-- 
Wolf  a.k.a.  Juha Laiho     Espoo, Finland
(GC 3.0) GIT d- s+: a C++ ULSH++++$ P++@ L+++ E- W+$@ N++ !K w !O !M V
         PS(+) PE Y+ PGP(+) t- 5 !X R !tv b+ !DI D G e+ h---- r+++ y++++
"...cancel my subscription to the resurrection!" (Jim Morrison)


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

Date: Mon, 28 Jul 2003 17:29:43 GMT
From: Chris Olive <nospam@ceo.com>
Subject: Warnings on Win32::NetResouce::AddConnection() call to map drive...
Message-Id: <b4dVa.141177$o86.74366@news1.central.cox.net>

I'm using ActiveState's Win32::NetResource under W2K to map a drive in a 
script.  Works great except I'm getting warnings on the call 
AddConnection() in that module, which I don't really care for.  The call 
uses a structure (hash ref) documented as a NETRESOURCE hash.

Looking at the NetResource.pm source at the offending line in the 
warnings (line 339), every item in the hash is PACKed().  Not every item 
in the hash is necessary for the Win32::NetReource::AddConnection() call 
and in fact every example I have seen of this call DOES NOT have all the 
hash elements initialized.  So the warnings are BOGUS as far as I can 
tell.  When I give every element in the hash a default value, the call 
fails, but when I call with just the elements it needs, the drive gets 
mapped but I get warnings (from PACK() call in the NetResource.pm 
source, trying to PACK() undef'd hash elements.)

Anyone have any luck calling this without turning off warnings before 
the AddConnection() call?  Just wondering.  I guess that's why "no 
warnings" exists, but I don't like using it.  Doesn't seem "clean" to 
me...  I think AS made a mistake trying to universalize the NETRESOURCE 
hash structure.  AddConnection() obviously needs less and some of the 
elements in the NETRESOURCE hash are informational or contextual which 
are unneeded for AddConnection().

Chris
-----
Chris Olive
chris [at] technologEase [dot] com
(pronounced "technologies")



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

Date: Mon, 28 Jul 2003 13:46:57 +0000 (UTC)
From:  Ilya Zakharevich <nospam-abuse@ilyaz.org>
Subject: Re: what is perl's no op operator?
Message-Id: <bg39gh$1vc3$1@agate.berkeley.edu>

[A complimentary Cc of this posting was sent to
Eric J. Roode
<REMOVEsdnCAPS@comcast.net>], who wrote in article <Xns93C63A34815C6sdn.comcast@206.127.4.25>:
> > In the shell, I can do echo $a; : echo $b; echo $c
> > to turn off b with minimal disturbance to the one-liner.
> > In perl, one can't get away with just adding a ": ":
> > print $a; if(0){print $b}; print $c; #best I know
> > Is there a way less disruptive to this one-liner?
> 
> Mmmm, probably prepend "0 and".

Wrong precedence.

 0 and 1 or print "got here\n";

 0 and 1 while print "got here\n";

Hope this helps,
Ilya

P.S.  There is no comment-part-of-line construct in Perl.


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

Date: 28 Jul 2003 07:04:22 -0700
From: ghee2ghee@yahoo.co.uk (Ghee)
Subject: you *must* be able to shorten this...
Message-Id: <7e01b0bc.0307280604.7e851fdf@posting.google.com>

Hello,

I've written a short script to read in a form with HTML-style tags
(form is postscript, can be 0.5MB to 20MB+, tags are alphanumerical
wiht - or _ in), and substitute values into these tags from a separate
data file (pipe delimited, ie data|value), writing out the populated
form as a new file.

The tags will appear in the form enclosed in angled brackets, within a
postscript "text object", which is delimited by rounde brackets - eg:

 ........(....<TAG1>...<TAG2>....)......

The following script works, but I've got the feeling that it's not
very efficient.  So, can any of you suggest improvements over my
perl-newbie script?

#!/usr/bin/perl

#open output file, tag data, and the form
open (OUTPUT,">OUTPUT.ps") || die "can't open output file";
open (DATA,"DATA.PDF") || die "can't open data file";
open (FORM,"FORM1.ps") || die "can't open form file";

#Read in pipe delimited file (PDF), put data in associative array
@data=<DATA>;
foreach $item (@data) {
    @items=split /\|/,$item;
    $variable=$items[0];
    $value=$items[1];
    $$variable=$value; chop $value;
    $array{$variable}=$value;
};

#read through form line by line, identifying any tags and replacing
#values from associative array as neccesary

while(<FORM>) {
    $stuff = $_;
    $done_stuff = "";
    while ($stuff =~ /<[0-9a-zA-Z-_]+>/) {
        $done_stuff = $done_stuff . $`;     #write out pre match
        $stuff = $';     #move post match to $stuff to loop again...
        $tag_name = $&;
        $tag_name =~ s/<|>//g;    #take off < and >
        if (exists $array{$tag_name}) { #replace if exists in array
            $done_stuff = $done_stuff . $array{$tag_name};
        } else {
            $done_stuff = $done_stuff . "<$tag_name>";
        }
    }
    $done_stuff = $done_stuff . $stuff;
    print OUTPUT $done_stuff;
};

close (FORM);
close (DATA);
close (OUTPUT);


Regards,

Ghee


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

Date: Mon, 28 Jul 2003 11:32:10 -0400
From: Jeff 'japhy' Pinyan <pinyaj@rpi.edu>
To: Ghee <ghee2ghee@yahoo.co.uk>
Subject: Re: you *must* be able to shorten this...
Message-Id: <Pine.SGI.3.96.1030728111659.34997C-100000@vcmr-64.server.rpi.edu>

[posted & mailed]

On 28 Jul 2003, Ghee wrote:

>I've written a short script to read in a form with HTML-style tags
>(form is postscript, can be 0.5MB to 20MB+, tags are alphanumerical
>wiht - or _ in), and substitute values into these tags from a separate
>data file (pipe delimited, ie data|value), writing out the populated
>form as a new file.

>#!/usr/bin/perl

I'd suggest

  use strict;
  use warnings;

The 'strict' will require you to declare your variables.

>#open output file, tag data, and the form
>open (OUTPUT,">OUTPUT.ps") || die "can't open output file";
>open (DATA,"DATA.PDF") || die "can't open data file";

"PDF" is a common Adobe file suffix.  It's awfully misleading here.

>open (FORM,"FORM1.ps") || die "can't open form file";

It's helpful to include $! in your error messages; it explains why the
system couldn't do what you asked.

>#Read in pipe delimited file (PDF), put data in associative array
>@data=<DATA>;
>foreach $item (@data) {

There is no reason to read a filehandle into an array, just to iterate
over the array.  Use a while loop, like you did for FORM.

>    @items=split /\|/,$item;
>    $variable=$items[0];
>    $value=$items[1];

Why use @items?  Why not store the values directly into the variables you
want to use?

>    $$variable=$value; chop $value;

EWW!  NO!  Not allowed.  Do not create a variable out of thin air like
that.  If $foo is a string like "name", do NOT create $name by saying

  $$foo = "Jeff";

That is evil.  It's a symbolic reference.  You shouldn't use them.l

>    $array{$variable}=$value;

 ... especially if you're going to store the relationship in a hash anyway!
And %array is a rather poor name for a hash.

>};

  my %vars;

  while (<DATA>) {
    chomp;  # remove the newline; chomp() is safer than chop()
    my ($varname, $value) = split /\|/;
    $vars{$varname} = $value;
  }

>#read through form line by line, identifying any tags and replacing
>#values from associative array as neccesary
>
>while(<FORM>) {
>    $stuff = $_;

There's no reason not to use $_ in this loop.  And if you don't want to
use $_, then why not say

  while (my $stuff = <FORM>) { ... }

>    $done_stuff = "";
>    while ($stuff =~ /<[0-9a-zA-Z-_]+>/) {
>        $done_stuff = $done_stuff . $`;     #write out pre match
>        $stuff = $';     #move post match to $stuff to loop again...

Don't use $`, $&, and $'.  They're bad variables.  They slow things down,
and there's almost always a way around them.  I have a feeling you want to
use a substitution here.

>        $tag_name = $&;
>        $tag_name =~ s/<|>//g;    #take off < and >
>        if (exists $array{$tag_name}) { #replace if exists in array
>            $done_stuff = $done_stuff . $array{$tag_name};
>        } else {
>            $done_stuff = $done_stuff . "<$tag_name>";
>        }
>    }
>    $done_stuff = $done_stuff . $stuff;
>    print OUTPUT $done_stuff;
>};

Definitely.  You definitely want a substitution.

  while (<FORM>) {
    s{
      < ([-\w]+) >  # the ()'s capturing what they match to $1
    }{
      if (exists $vars{$1}) { return $vars{$1} }
      else { return "<$1>" }
    }xge;
    # s{}{} is just another form of s///, and we're operating on $_
    # the /x modifier means the regex has extra whitespace and comments
    # the /g modifier means "do this globally for each match"
    # the /e modifier means the replacement is a block of code to evaluate

    print OUTPUT;  # $_ is the default thing to print
  }

>close (FORM);
>close (DATA);
>close (OUTPUT);

-- 
Jeff Pinyan            RPI Acacia Brother #734            2003 Rush Chairman
"And I vos head of Gestapo for ten     | Michael Palin (as Heinrich Bimmler)
 years.  Ah!  Five years!  Nein!  No!  | in: The North Minehead Bye-Election
 Oh.  Was NOT head of Gestapo AT ALL!" | (Monty Python's Flying Circus)



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

Date: Sat, 19 Jul 2003 01:59:56 GMT
From: Bob Walton <bwalton@rochester.rr.com>
Subject: Re: 
Message-Id: <3F18A600.3040306@rochester.rr.com>

Ron wrote:

> Tried this code get a server 500 error.
> 
> Anyone know what's wrong with it?
> 
> if $DayName eq "Select a Day" or $RouteName eq "Select A Route") {

(---^


>     dienice("Please use the back button on your browser to fill out the Day
> & Route fields.");
> }
 ...
> Ron

 ...
-- 
Bob Walton



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

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


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