[17312] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 4734 Volume: 9

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Oct 26 14:10:45 2000

Date: Thu, 26 Oct 2000 11:10:17 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <972583817-v9-i4734@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Thu, 26 Oct 2000     Volume: 9 Number: 4734

Today's topics:
    Re: Hey guys... can you lend an ear? joelwebb@usa.net
    Re: Hey guys... can you lend an ear? <godzilla@stomp.stomp.tokyo>
    Re: Hey guys... can you lend an ear? (Tad McClellan)
    Re: How can I word wrap on STDOUT? (Randal L. Schwartz)
    Re: How can I word wrap on STDOUT? (NP)
    Re: How can I word wrap on STDOUT? <mjcarman@home.com>
    Re: How can I word wrap on STDOUT? (Tom Christiansen)
        How to connect perl+oracle? <phil_xxx@my-deja.com>
    Re: indirect sub call with strict <nickco3@yahoo.co.uk>
    Re: indirect sub call with strict <mjcarman@home.com>
    Re: Malformed header resulting from use of mkdir() <secursrver@hotmail.com>
    Re: Newbie 5defcon5@my-deja.com
    Re: newline in Unix and DOS [Was: Removing line breaks  <mjcarman@home.com>
    Re: newline in Unix and DOS [Was: Removing line breaks  <mischief@motion.net>
    Re: Packaging CPAN Modules With Application <elaine@chaos.wustl.edu>
    Re: Question about perl -w <jeff@vpservices.com>
    Re: Question about perl -w <camerond@mail.uca.edu>
    Re: socket flushing problem <bomr@lin01.triumf.ca>
    Re: socket hang <uri@sysarch.com>
    Re: String Comparison <xerxes_2k@my-deja.com>
    Re: substituting up to the beginning of the line joekind@my-deja.com
    Re: Syntax Problem for Newbie nobull@mail.com
    Re: two dimensional arrays nobull@mail.com
    Re: Use VS Require (M.J.T. Guy)
    Re: What is the point of the new keyword 'our'? (Tad McClellan)
        Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)

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

Date: Thu, 26 Oct 2000 15:07:56 GMT
From: joelwebb@usa.net
Subject: Re: Hey guys... can you lend an ear?
Message-Id: <8t9hc5$iud$1@nnrp1.deja.com>

I am not getting a "1" as the output probably because we have a lot of
hosts and it is not finishing the program.

I am getting:

Now querying 196.168.23.1 ...



In article <slrn8vg9oc.f69.tadmc@magna.metronet.com>,
  tadmc@metronet.com (Tad McClellan) wrote:
> On Thu, 26 Oct 2000 12:59:04 GMT, webbgroup@my-deja.com
>    <webbgroup@my-deja.com> wrote:
> >I am writing a script that is querying a series of routers. When I
> >execute the snmp command alone I get output, but when I execute the
> >script, nothing appears on the screen. What's the beef??
>          ^^^^^^^
>
> Eh?
>
> You are printing the return value from print(), so you should
> see some sort of "true" value (probably a "1") being printed...
>
> I don't know why you are not seeing output from the first
> print() call, but you should be seeing a one from the second
> print() call.
>
> >All I need is to see if the router responds and I can go onto the
next
> >one
> >
> >open(FILE,"hostfile.txt") || die
> >        "Cannot file host file \"hostfile.txt\";
>
> You should include the $! special variable in your diagnostic message.
>
> You can avoid backslashing by using alternate quoting.
>
> You should use single quotes for constant strings.
>
>    open(FILE, 'hostfile.txt') ||
>       die qq/Cannot open host file "hostfile.txt" $!/;
>
> >@host = <FILE>;
> >foreach (@host){
>
> Why read the whole file into memory if you are only going to
> process it line-by-line anyway?
>
> You also don't need the @host temporary variable:
>
>    while ( <FILE> ) {
>
> >        $line = $_;
>
> If you want it in $line, why don't you just put it there in the
> first place instead of putting it somewhere else and then copying
> it to where you really want it?
>
>    foreach my $line (@hosts) {
>
> or
>
>    while ( defined $line = <FILE> ) {
>
> >        $output = print `/opt/OV/bin/snmpwalk -c !!r0ygb1v12 $ip`;
>
> Here you print the STDOUT from snmpwalk. Does snmpwalk make output
> on STDOUT (or is it on STDERR instead)?
>
> If you don't need to capture the STDOUT from the program, then
> you shouldn't capture the STDOUT from the program.
>
> You appear to want the output from snmpwalk to go to the same
> STDOUT (or STDERR) that your Perl program is using. You can
> get that with:
>
>    !system "/opt/OV/bin/snmpwalk -c !!r0ygb1v12 $ip" or
>       die 'problem running "snmpwalk"';
>
> No need to capture it into your Perl program when all you do
> with the captured data is print it anyway...
>
> >        print $output;
>
> Here you print the "true" or "false" return value from print(),
> NOT the output from the snmpwalk program.
>
> --
>     Tad McClellan                          SGML consulting
>     tadmc@metronet.com                     Perl programming
>     Fort Worth, Texas
>


Sent via Deja.com http://www.deja.com/
Before you buy.


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

Date: Thu, 26 Oct 2000 08:56:30 -0700
From: "Godzilla!" <godzilla@stomp.stomp.tokyo>
Subject: Re: Hey guys... can you lend an ear?
Message-Id: <39F8542E.EF516347@stomp.stomp.tokyo>

joelwebb@usa.net wrote:
 
> I am not getting a "1" as the output probably because we have
> a lot of hosts and it is not finishing the program.
 
> I am getting:

My presumption is you fixed your fatal syntax
error despite initially claiming your script
runs correctly.

 
> Now querying 196.168.23.1 ...


SNMP: 1.3
196.168.23.1
return code=10004 (Timed out)

SNMP: 1.3.6.1.2.1.11
196.168.23.1
return code=10004 (Timed out)

Lookup: PTR
196.168.23.1
return=Failed to resolve address 196.168.23.1

Scan: 1:254 dns:ftp:http:pop3:smtp:ip
196.168.23.1
return=No return

Port Scan: 1:8080
196.168.23.1
return=No open ports


As you now know, there are a lot of problems
and contradictions with your original article.
I continue to read deceit at play.


Godzilla!


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

Date: Thu, 26 Oct 2000 11:07:48 -0400
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: Hey guys... can you lend an ear?
Message-Id: <slrn8vgi64.fjm.tadmc@magna.metronet.com>

On 26 Oct 2000 09:01:48 -0700, Tom Christiansen <tchrist@perl.com> wrote:
>In article <slrn8vg9oc.f69.tadmc@magna.metronet.com>,
>Tad McClellan <tadmc@metronet.com> wrote:
>
>Tad, rest assured that this is *not* tchrist-picks-on-tad day.  


Bumma.

I was hoping it would catch on, and I could gain some notoriety.

"bad" notoriety wouldn't be as good as "good" notoriety, but would
be better than the "no" notoriety that I currently enjoy.


>I
>wouldn't say these things if it were someone who knew less, because
>they wouldn't be as likely to appreciate the subtleties.


I think I have already considered the subtleties you point
out below, and have still adopted the style guides I suggested.

I didn't disclaim them, because nearly all "style" discussions
have an implicit "unless you like to do it some other way"
disclaimer  :-)


>>>open(FILE,"hostfile.txt") || die
>>>        "Cannot file host file \"hostfile.txt\";
>>
>>
>>You should include the $! special variable in your diagnostic message.
>>You can avoid backslashing by using alternate quoting.
>>You should use single quotes for constant strings.
>>
>>   open(FILE, 'hostfile.txt') || 
>>      die qq/Cannot open host file "hostfile.txt" $!/;
>
>"Should" is a strong term, and you might wish to consider relaxing
>this to a "maybe you would prefer".  


Surely you must be referring to the second "should".

(I cannot see any argument for omitting $!)


>Double quotes provide a more
>visually distinctive graphical representation than single quotes,


But they also mean "look inside here" if you are scanning for
(interpolated) variables while debugging.

I don't like cueing myself to look when what I am looking for
cannot possibly be there.

It doesn't matter much with only "hostfile.txt" in the string,
but carefully scanning

   "find / -name '*.html' -print |"

or some such, for variables when there are no variables
annoys my Software Engineering "optimize for maintenance"
mind set.


>both because they are pixelwise bigger, and also because they're
>guaranteed to be readily distinguishable from backquotes.


That is a non-issue for me, due a different style guide that
I use:

   never use `backquotes`, always use qx//


I probably adopted that one because backquotes are not visually
distinctive from the single quotes that I'm using around all of
my constant strings, heh.


>One could also write it in these ways
[snip]
>    open(FILE, "hostfile.txt") 
>	|| die "Cannot open host file 'hostfile.txt': $!";


I would not have chosen double quotes for the filename delimiters
if they were in a double quoted string (because backslashing slows
down human understanding).

So I habitually use the style above anyway.



>Or, so that it reads correctly in English:
>
>    for my $line (@hosts) { }


That runs afoul of yet another style guide that I adhere to:

   Use "foreach" for the "walk across a list" thingie, use
   "for" for the 3-part C-like thingie.

Though I can see that it _does_ read more Englishy your way.


>>   while ( defined $line = <FILE> ) {
>
>I'm afraid that won't quite work precisely as it is there written.
>Assignment is of lower precedence than the unary operator defined().


I knew that. I just didn't type that  :-(


[ snip "wrapped in define() anyway" ]


>If you peer deeply into the abyss of src/perl/op.c, 


I avoid such things to protect my normally sunny disposition.

(But I hope to let the gloom descend for perl 6...)


[ snip decoding of internals, thanks for the insight ]


>It's a DWIM thing.


perl, gotta love her.


>>   !system "/opt/OV/bin/snmpwalk -c !!r0ygb1v12 $ip" or
>>      die 'problem running "snmpwalk"';
>
>It's certainly a shame that system() has its true/false status
>returns flipped like that.  I'm not sure, though, that adding more
>Boolean arithmetic there is necessarily more legible.  One could
>easily argue that factoring out gratuitous not-like operations makes
>code easier to read; after all, that's why we've got unless() and
>until().   So, you *could* just write that this way:
>
>    system("/opt/OV/bin/snmpwalk -c !!r0ygb1v12 $ip") 
>	&& die "problem running snmpwalk";


Yeah, I'm familiar with the relevant truth tables  ;-)


>Although because people are used to the consistency of a "\n\t||
>die" for error handling, that might be far enough away from that
>as to cause raised eyebrows.


That's the justification I use.


>    system($snmpwalk, "-c", "!!r0ygb1v12]", $ip) == 0
>	|| die "problem running $snmpwalk";


Arranging for multi-arg system() is something I should have
worked into my answer...


>>No need to capture it into your Perl program when all you do
>>with the captured data is print it anyway...
>
>Quite.


Memory and cycles are for spending, right?   :-(


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


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

Date: 26 Oct 2000 08:13:57 -0700
From: merlyn@stonehenge.com (Randal L. Schwartz)
Subject: Re: How can I word wrap on STDOUT?
Message-Id: <m14s1zocsq.fsf@halfdome.holdit.com>

>>>>> "Tom" == Tom Christiansen <tchrist@perl.com> writes:

>> The Text::Wrap module will do this for you.

Tom> What, doesn't anyone know regular Perl anymore? :-(

Given the four out of five people who answer this question wrong on
the average, apparently not. {grin}

In that case, the module answer is quicker and provides a better meme
to carry around.

Same reason we say "use CGI" instead of "copy and paste from MSA".

print "Just another Perl hacker,"

-- 
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!


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

Date: Thu, 26 Oct 2000 15:46:37 GMT
From: nvp@spamnothanks.speakeasy.org (NP)
Subject: Re: How can I word wrap on STDOUT?
Message-Id: <vlYJ5.44474$YX4.1362932@news2.giganews.com>

merlyn@stonehenge.com wrote:
: 
: In that case, the module answer is quicker and provides a better meme
: to carry around.

While the "use this module" answer is quicker, the only way to get
people to use the standard Perlstuff is to NOT default to the "use this
module" answer, particularly when the "use this module" solution leads
the OP down the wrong path or to a less-than-great solution.

There are many good and useful modules, but there are just as many that
have been suggested (here) that probably shouldn't have been.

: Same reason we say "use CGI" instead of "copy and paste from MSA".

And that's a problem, not referring to "use CGI" in particular, but to
the general "here, 'use blah blah'".

-- 
Nate II


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

Date: Thu, 26 Oct 2000 11:01:27 -0500
From: Michael Carman <mjcarman@home.com>
Subject: Re: How can I word wrap on STDOUT?
Message-Id: <39F85557.5E7A5EF8@home.com>

Tom Christiansen wrote:
> 
> Michael Carman  <mjcarman@home.com> wrote:
> >Eric wrote:
> >>
> >> [W]hen it prints the abstract(s) to the screen, I wish it
> >> would word wrap rather than just wrap at the terminal boundary
> >
> >The Text::Wrap module will do this for you.
> 
> What, doesn't anyone know regular Perl anymore? :-(

Heh. Well, I must admit to not knowing formats. I tend to here-docs and
[s]printf instead. I suppose I should study up on them, just for
completeness' sake.

As for having just tossed out the easy module answer; it's pretty
trivial to rewrite your own little wrapping function, but why bother?

Anyway, it's good to see you here, Tom.

-mjc


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

Date: 26 Oct 2000 11:54:58 -0700
From: tchrist@perl.com (Tom Christiansen)
Subject: Re: How can I word wrap on STDOUT?
Message-Id: <39f86ff2@cs.colorado.edu>

In article <39F85557.5E7A5EF8@home.com>,
Michael Carman  <mjcarman@home.com> wrote:
>As for having just tossed out the easy module answer; it's pretty
>trivial to rewrite your own little wrapping function, but why bother?

That's the point: you don't *have* to "write your own little wrapping
function", because Perl already has this built right into as part
of the fundamental language!

For example, here's the format I posted in the signature writing
program:

     # Wrap quote at up to *but not exceeding* three lines, because we
     # need to leave one for the attribution, and Thou Shalt Not Exceed
     # Four Lines Of Signature.  Format each such line with a 4-space
     # indent, plus up to 72 characters following it, wrapping at word
     # boundaries and hyphens.  Then add right-justified author
     # attribution on line following.
 
 format sigformat =
     ^<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
 $quote
    ~^<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
 $quote
    ~^<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
 $quote
                                                 @>>>>>>>>>>>>>>>>>>>>>>>>>>
 $author
 .

This not only requires no modules, it offers greater functionality
than [s]printf does, or that rather annoying Text::Wrap module.
How would you do what this does with a printf, or using that module?
Well, you could, but it would require programmatic monkey-business.
Format are pure WYSIWYG declarations, not indirect diddling around,
which ends up making them easier to understand and work with, and
least in many situations.  Imagine a makefile's dependency rules:
Can you imagine having to expression those imperatively each time
rather than declaratively?  That would be a real pain.

And the visual appeal of a convenient WYSIWIG layout is not to be
easily discarded, either.

--tom


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

Date: Thu, 26 Oct 2000 16:43:54 GMT
From: Phil xxx <phil_xxx@my-deja.com>
Subject: How to connect perl+oracle?
Message-Id: <8t9n08$o5h$1@nnrp1.deja.com>

I was wondering what is the best module to use to connect perl to oracle
8.16.  I preferably want to use sqlnet rather than odbc.

Thanks in advance!


Sent via Deja.com http://www.deja.com/
Before you buy.


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

Date: Thu, 26 Oct 2000 17:30:44 +0100
From: Nick Condon <nickco3@yahoo.co.uk>
Subject: Re: indirect sub call with strict
Message-Id: <39F85C34.2477F7BB@yahoo.co.uk>

grey_owl7@my-deja.com wrote:

> P.S. Please reply to email address.

No. Post to newsgroup read in newsgroup.

> #!/usr/bin/perl5 -w
>
> use strict;
>
> sub Bingo() {print "It's Bingo!\n"}
> sub Bongo() {print "No, it's Bongo!\n"}
> my $beg = "Bi";
> my $full = $beg."ngo";
> &$full();
> print "1 $full\n";
>
> $beg = "Bo";
> $full = ($beg).("ngo");
> print "2 $full\n";
>
> &{$full};
> print "\n";
>
> __END__
>
> Results without "use strict;":
>         It's Bingo!
>         1 Bingo
>         2 Bongo
>         No, it's Bongo!
>
> Results with "use strict;":
>         Can't use string ("Bingo") as a subroutine ref while "strict refs" in use at
> ./test_subcall.pl line 9.

You're storing the name of the function in a variable. This is a symbolic reference not
a hard reference, they are forbidden by 'use strict'.

Symbolic references are a bad idea, they aren't reference counted, and they can't access
lexical variables only global ones, they don't include package information so if
executed in a different package the wrong function would be called.

Use a hash with hard references in it instead:

#!/usr/local/bin/perl -w
use strict;

my %func = (
    "Bingo" => sub {print "It's Bingo!\n"},
    "Bongo" => sub {print "No, it's Bongo!\n"}
);

my $beg = "Bi";
my $full = $beg."ngo";
$func{$full}->();
print "1 $full\n";

$beg = "Bo";
$full = ($beg).("ngo");
print "2 $full\n";

$func{$full}->();
print "\n";

__END__
Results:

It's Bingo!
1 Bingo
2 Bongo
No, it's Bongo!






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

Date: Thu, 26 Oct 2000 11:19:51 -0500
From: Michael Carman <mjcarman@home.com>
Subject: Re: indirect sub call with strict
Message-Id: <39F859A7.6DB7B61A@home.com>

grey_owl7@my-deja.com wrote:
> 
> What's wrong with the following?

You're attempting to use soft (symbolic) references, which are not
allowed under 'use strict.'

> How can I call a subroutine using a variable when I use strict?

Use hard references instead.

> P.S. Please reply to email address.

Sorry, please read the newsgroup for responses. That way a) you get
better (implicity peer-checked) information, and b) others may be helped
out as well.
 
> #!/usr/bin/perl5 -w
> 
> use strict;
> 
> sub Bingo() {print "It's Bingo!\n"}
> sub Bongo() {print "No, it's Bongo!\n"}

Okay so far.

> my $beg = "Bi";
> my $full = $beg."ngo";
> &$full();
> print "1 $full\n";

my $fctn = \&Bingo;
&$fctn();

$fctn = \&Bongo;
&$fctn();

-mjc


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

Date: Thu, 26 Oct 2000 15:16:32 GMT
From: "Ed Grosvenor" <secursrver@hotmail.com>
Subject: Re: Malformed header resulting from use of mkdir()
Message-Id: <kVXJ5.26239$rD3.1786091@newsread2.prod.itd.earthlink.net>

I've got the malicious stuff taken care of.  As for writing the header
first, that only caused the browser to try to download the script rather
than execute it.  That's been happening alot lately on this box.  I'm not
quite sure why.  On Linux, I would think permissions, but this is a Windows
box.  Anyway, I'll look into the header method of CGI.pm and see if that
will do the trick.  Thanks for your help.
M. van den Bos <mvdbos@integral.nl> wrote in message
news:39f816df.3307459@news.nl.net...
> On Thu, 26 Oct 2000 00:57:03 GMT, "Ed Grosvenor"
> <secursrver@hotmail.com> wrote:
>
> >$dir  is dynamically assigned based on user input.
>
> Are you checking the user input for system commands and other
> malicious stuff?
> >
> >print("mkdir() ", mkdir("$dir", 0777), "\n");
>
> are you printing a content header to the browser first?
> print "content-type:text/html\n\n";
> Or even better, use cgi.pm and use the header method.
>
> --
> Matthijs van den Bos     INTEGRAL BV
> <mvdbos@integral.nl>     www.integral.nl




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

Date: Thu, 26 Oct 2000 14:57:55 GMT
From: 5defcon5@my-deja.com
Subject: Re: Newbie
Message-Id: <8t9gpd$icq$1@nnrp1.deja.com>

In article <DBTJ5.759$ZA5.11607@news.dircon.co.uk>,
  Jonathan Stowe <gellyfish@gellyfish.com> wrote:
> On Wed, 25 Oct 2000 20:09:20 GMT, 5defcon5@my-deja.com Wrote:
> > I am writing a web page that has a form taking in a username and
> > password.  I would like to verify this username and password against
> > the system password file.
>
> This is the wrong place to discuss this but you really, really, really
> dont want to do that if your system is accessible to the wide world.
>
> >                            Is there a module or something to help
me do
> > this and can someone give me an example of how this module is used.
> >
> No it's an intranet and I want the users to be able to use their
system passwords instead of having to use a new one.
> Read about crypt() in the perlfunc manpage.
>
> /J\
>


Sent via Deja.com http://www.deja.com/
Before you buy.


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

Date: Thu, 26 Oct 2000 12:14:42 -0500
From: Michael Carman <mjcarman@home.com>
Subject: Re: newline in Unix and DOS [Was: Removing line breaks from a string -  HELP!]
Message-Id: <39F86682.A0CE0690@home.com>

Michael Balenger wrote:
> 
> Seems that within Perl "\n" means different things on Unix and Win32
> systems.  (So far, no brainer.  Classic Unix vs. DOS (and of course
> WinDOS) brain split.)

Effectively, yes. Strictly speaking, no.
 
> Here's where the brain split comes in for me.
> 
> Where does the translation happen?

During I/O, which means that within Perl "\n" is always a single
character, regardless of platform.

> Consistency: Internally to Perl, "\n" is one character in DOS and
> HPUX.

And any other platform you may run Perl on. (Perl internally uses LF.)
 
> Inconsistency: Looking at Perl's STDOUT gives different results.  DOS
> shows 2 characters.  HPUX shows 1 character.

Yep. The behind-the-scenes I/O translates between "\n" and the native
OS's idea of what a line ends in when interfacing with the OS. This
allows Joe User to stay fat, dumb, and happy when writing his script.

> Is there a dos2unix or unix2dos translation program or module?

There are ones available, but it's pretty simple to write your own.
 
> Are these programs portable?  (i.e. do both programs work in both
> environments?).  

They certainly can be.

> I have written both programs in both environments,
> but they are different programs.  (i.e. they are *not* portable).  I
> think that's because I'm trying to use the \n and \r literals.  I have
> a feeling that using hex characters would work, but haven't tried it
> yet.

If you're writing your own, you should use binmode() to allow you to
access the true (raw) data stream, and then use the hex/octal/control
codes instead of the abstracted \n, \r, etc.
 
> Real Motivation:
> 
> I'm transferring source code and data from my home office PC to my
> client site Unix machine.

Blah. Any decent FTP program will perform this translation for you when
you transfer the files in text mode.

-mjc


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

Date: Thu, 26 Oct 2000 11:28:22 -0500
From: Chris Stith <mischief@motion.net>
Subject: Re: newline in Unix and DOS [Was: Removing line breaks from a string -  HELP!]
Message-Id: <Pine.LNX.4.21.0010261056040.32484-100000@velma.motion.net>

On Mon, 23 Oct 2000, Ian Boreham wrote:

> Michael Balenger wrote:
> 
> >
> > Questions:
> >
> > Where does the translation happen?
> 
> See Perl Cookbook p292 for a detailed explanation.
> 
> >
> > Is there a dos2unix or unix2dos translation program or module?

I've written one before that went both directions in one program,
depending on the command-line flags. It also worked on both Unixy
and DOSish platforms to change to and from Mac, but I never tested
running it on Mac. I imagine that since it ran under Linux, and
Solaris x86 under Perl 5, and OpenDOS under Perl 4 that probably
would have worked almost anywhere. Unfortunately, it's one of the
projects lost when I changed jobs rather abruptly. (Read :
it was on my Linux desktop the day I walked out, and that box was
a Windows machine the next day).

> > ================
> > Extra credit:
> >
> > Are these programs portable?  (i.e. do both programs work in both
> > environments?).  I have written both programs in both environments,
> > but they are different programs.  (i.e. they are *not* portable).  I
> > think that's because I'm trying to use the \n and \r literals.  I have
> > a feeling that using hex characters would work, but haven't tried it
> > yet.

Mine worked on both platforms. Don't try using \n as a literal, because
\n is exactly the one that isn't a literal. Use \l as linefeed and \r
as carriage return. The newline (\n) is equivalent to \l on Unix,
to \r\l (although \l\r is often recognized but not officially supported)
on DOS, and \r on Mac.

So what you'd want to do for Unix to DOS is to replace \l with \r\l.
For DOS to Unix you'd want to replace \r\l with \l. For Mac to DOS,
replace \r with \r\l. For Mac to Unix, replace \r with \l. For DOS to
Mac, replace \r\l with \r. For Unix to Mac, replace \l with \r.

> I think actual character codes would be the way to go, for clarity if
> nothing else. Other threads in this newsgroup have already suggested
> approaches like this, although I haven't tried them out. there should be
> no reason why the principle doesn't work, though. And if line ending
> conversion is the only issue, it should be a one-liner...

For clarity, I like the C-style literal escapes. Numeric codes would also
work though. In my copious free time I'll write a quick and dirty script
to do this.

Chris


-- 
Christopher E. Stith
mischief@motion.net



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

Date: Thu, 26 Oct 2000 15:57:20 GMT
From: "Elaine Ashton" <elaine@chaos.wustl.edu>
Subject: Re: Packaging CPAN Modules With Application
Message-Id: <AvYJ5.12692$AM5.238841@news1.nokia.com>

<asimjalis@my-deja.com> wrote in message
news:8t824l$egu$1@nnrp1.deja.com...
> My question is this: Is there a module on CPAN that already does this?

You might have go with CPAN.pm's bundle feature and see if you can use it
with a directory of several modules. I've never tried it but don't see why
it wouldn't work and if it doesn't, it would be a nice feature.

> CPAN.pm does not appear to fit the bill. The initial configuration
> dialog it engages the user in totally violates the idea of automated
> installation.

There isn't a package manager in the world that completely automates an
installation.

Also, be sure that you are respecting the module authors license as you
distribute your package.

e.




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

Date: Thu, 26 Oct 2000 09:04:54 -0700
From: Jeff Zucker <jeff@vpservices.com>
Subject: Re: Question about perl -w
Message-Id: <39F85626.D3E98C5D@vpservices.com>

"Andrew N. McGuire" wrote:
> 
> >>>>> "NM" == Nicolas MONNET <nico@monnet.to> writes:
> 
> NM> If I get too many warnings, do I get suspended?
> 
> I must be missing something...  what do you mean "do I get suspended"?
> What does that have to do with '-w'?

You, know, like if the teacher gives you a warning not to talk in class
and if you ignore X number of warnings you get kicked out of school. 
AFAIK, this only occurs when you build perl with the -S&M option.

colon, hyphen, right-parens.

-- 
Jeff


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

Date: Thu, 26 Oct 2000 11:33:19 -0500
From: Cameron Dorey <camerond@mail.uca.edu>
Subject: Re: Question about perl -w
Message-Id: <39F85CCF.42486BC1@mail.uca.edu>

Jeff Zucker wrote:
> 
> "Andrew N. McGuire" wrote:
> >
> > >>>>> "NM" == Nicolas MONNET <nico@monnet.to> writes:
> >
> > NM> If I get too many warnings, do I get suspended?
> >
> > I must be missing something...  what do you mean "do I get suspended"?
> > What does that have to do with '-w'?
> 
> You, know, like if the teacher gives you a warning not to talk in class
> and if you ignore X number of warnings you get kicked out of school.
> AFAIK, this only occurs when you build perl with the -S&M option.

-S&M option, do you mean the option that is default (required) when you
work in Window$? 

semicolon, right paren

Cameron

-- 
Cameron Dorey
Associate Professor of Chemistry
University of Central Arkansas
Phone: 501-450-5938
camerond@mail.uca.edu


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

Date: 26 Oct 2000 16:51:52 GMT
From: "Rod B. Nussbaumer" <bomr@lin01.triumf.ca>
Subject: Re: socket flushing problem
Message-Id: <8t9nf8$o99$1@nntp.itservices.ubc.ca>

Uri Guttman <uri@sysarch.com> wrote:
>>>>>> "RBN" == Rod B Nussbaumer <bomr@lin01.triumf.ca> writes:

>here is a simple map:

>perl		c
>----            ----
>syswrite	write
>sysread		read

>print		printf

>write		no equivilent but it would use printf underneath.
>read		no equivilent but is it a buffered read.

>and perl's read and write have very little to do with each other. this
>is one of larry's (few) poor naming decisions.

>the cross use of the name write confuses people. perl's write is
>formatted and buffered output. only syswrite is unbuffered which is why
>it is the best call for sockets.

Points taken.  I will try using syswrite()...



>  RBN> my  $Sock = IO::Socket::INET->new( PeerAddr => $Address,
>  RBN>                                    PeerPort => $Port,
>  RBN>                                    Proto    => 'tcp' 
>  RBN>                                  ) || die "IO::Socket \"$Address ($Port)\" : $!\n";
>    
>  RBN>     print "Socket connected\n";
>  RBN>     while( 1 ){    
>  RBN>         if( eof( STDIN ) ){
>  RBN>             last;
>  RBN>         }
>  RBN>         if( defined( $Input = <STDIN> ) ){

>  RBN> Okay, I've done what you suggest; code sample below.  Still, the
>  RBN> non line oriented packet refuses to to be flushed out.  


>are you sure the flushing isn't working? do you have proof the server
>see the data? have the server print to stdout or a log what it really gets.

Yes.  The server prints everything it receives to STDOUT.  On the first
iteration, it prints the value read from the client's STDIN, and nothing
else.  On subsequent iterations, it prints the contents of the $Struct
packet from the previous iteration, followed by the current iteration's
STDIN string.  When the client closes the connection, the final $Struct
packet is flushed to the server alone.


>  RBN>             print $Sock $Input;		# line oriented, flushed for sure...
>  RBN>             print $Sock $Struct;	# should be sent too...
>  RBN>             $Count++;
>  RBN>         }

>  RBN>         #
>  RBN>         #  The companion server just echoes everything we send it...
>  RBN>         #
>  RBN>         if( defined( $Input = <$Sock> ) ){
>  RBN>             print "rec\'d : $Input";		# $Struct comes back on next iteration!

>note that your structure is not newline terminated. you are reading with
><> which by default read LINES of text. so you never read the echoed
>struct as you are waiting for a newline. on the next loop you send the
>input line and then see the struct.

Nope.  I see the packets arrive at the server, and print them, as I said
above.

>solution: use sysread and make the socket nonblocking (with fcntl). use
>IO::Select to see if the socket has data to read. i bet your c code
>uses read which does not look for a record terminator.  

Your surmise is correct.

>note: never mix <> and sysread on a given file handle unless you know
>deep black magic.

Right.  As I see it, I need to use strictly sysread & syswrite for
any non line-oriented socket IO.  I will try that.  Maybe that's
why my server doesn't see the $Struct packet immediately, too.

Thanks for your patient replies.  Did I miss this info in a book,
man file, help document, FAQ or somewhere else, or is this the 
only/best way to find out about this stuff.   

Oh, and if you don't mind my editorializing just a bit, I think 
it kind of sucks when perl documentation explains things by 
simply saying 'This is the very same as the related UNIX 
mechanism', and leaving it at that.  I'm not saying this is your
fault, Uri.  Just that I find it irksome, and felt a need to
say where someone else can hear it.

	---   rod.




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

Date: Thu, 26 Oct 2000 15:33:26 GMT
From: Uri Guttman <uri@sysarch.com>
Subject: Re: socket hang
Message-Id: <x71yx3mxbt.fsf@home.sysarch.com>

>>>>> "T" == T  <tommylebrun@yahoo.com> writes:

  T> In article <x74s20mes8.fsf@home.sysarch.com>,
  T>   Uri Guttman <uri@sysarch.com> wrote:
  >> jeez, the third socket buffering problem today. turn on autoflushing
  T> on
  >> the socket and use non-blocking reads.
                        ^^^^^^^^^^^^^^^^^^

  T> I am autoflushing the socket & I am using sysread to get back the data.
  T> Here is what I am experiencing. My script sends data to a server &
  T> waits for acknowledgement data to come back. The records are sent fine.
  T> The problem occurs when the data is sent back. I get a few bytes & then
  T> it seems like the server stops sending. At that point my program is
  T> still waiting for the rest of the record. And it waits,,,, forever....

see the marked comment above. and remember, the server also has to flush
its buffers for you to see the data. is it doing so? are you POSITIVE
the server is working correctly? test it with some other know working
client like telnet.

uri

-- 
Uri Guttman  ---------  uri@sysarch.com  ----------  http://www.sysarch.com
SYStems ARCHitecture, Software Engineering, Perl, Internet, UNIX Consulting
The Perl Books Page  -----------  http://www.sysarch.com/cgi-bin/perl_books
The Best Search Engine on the Net  ----------  http://www.northernlight.com


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

Date: Thu, 26 Oct 2000 16:02:46 GMT
From: arse <xerxes_2k@my-deja.com>
Subject: Re: String Comparison
Message-Id: <8t9kj1$lp1$1@nnrp1.deja.com>

might be leading/trailing white space
--
[][][]{}{}~~';:.<<//?|1¬!"£$$%^^&*(())__+/*+
oooh random characters i must be coool!


Sent via Deja.com http://www.deja.com/
Before you buy.


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

Date: Thu, 26 Oct 2000 17:11:02 GMT
From: joekind@my-deja.com
Subject: Re: substituting up to the beginning of the line
Message-Id: <8t9oiv$pep$1@nnrp1.deja.com>

In article <hISJ5.763$262.75378@news010.worldonline.dk>,
  Anders Lund <anders@wall.alweb.dk> wrote:
> joekind@my-deja.com wrote:
>
> > Hi, I need to substitute a string up to a given point.
> > For example, if I have the following code:
> > $code = "<B>text</B>,<font size=1>text,<I>text/<U>text";
> >
> > now I want to substitute the code with nothing before the "," and
the
> > other "," and the "/".
> > so I want to be able to have the code broken up into this:
> > <font size=1>text,<I>text/<U>text
> > <I>text/<U>text
> > <U>text
>
> # eat anything before and including first comma:
> $code = s/^[^,]+,//;
>
> # eat up anything before and including first slash:
> $code =~ s#^[^/]+/##;
>
> Read the perlre and perlop manuals!
>
> -anders
>
> --
> [ the word wall - and the trailing dot - in my email address
> is my _fire_wall - protecting me from the criminals abusing usenet]
>

That didn't work because I want this to be universal.  Instead of
having the code just to substitute up to a comma or a slash, I want it
to be able to substitute up to anything.
so if I had the variable $subto which could be anything (ex. text, #, ;
etc)
I want to be able to substitute all the code before $subto with nothing.


Sent via Deja.com http://www.deja.com/
Before you buy.


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

Date: 26 Oct 2000 17:39:05 +0100
From: nobull@mail.com
Subject: Re: Syntax Problem for Newbie
Message-Id: <u9y9zb5zh2.fsf@wcl-l.bham.ac.uk>

"Andrew Gilmour" <arg@interact.net.au> writes:

> Subject: Re: Syntax Problem for Newbie

> sub parse_form {
> 
>    read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});

If you are a newbie you really seriously should not even dream of
rolling your own implementation of the CGI API.

As for the syntax errors I recommend you fix them.  Perl will tell you
where they are.  The first one is the word "If" just sitting in the
middle of nowhere for no apparent reason.

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


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

Date: 26 Oct 2000 17:49:02 +0100
From: nobull@mail.com
Subject: Re: two dimensional arrays
Message-Id: <u9wvev5z0h.fsf@wcl-l.bham.ac.uk>

"Brian McDonald" <mcdonabNO@SPAMyahoo.com> writes:

> Subject: two dimensional arrays

Hmmm... odd title for what appears to be a question involving a 3D
array.

> Hi. (I hope the following is not too much info to swallow...)

It is - before posting always try to reduce the problem.

> I have a question about how to implement a two-dimensional array in Perl.

perldoc perllol

> Specifically, what I am trying to do is create an array named @authors that
> is composed of elements of type @author, where @author is defined to be
> 
> my @author = ( $lname, $fname, $minit, $suffix, $prefix, $title,
> $affiliation, );
> 
> So, I imagine I want to declare @authors in this way...
> 
> my @authors = (
>     @author,
> );

No, the _structure_ of arrays in Perl does not need to be declared.
Just declare:

my @authors;


> I will have to grow @authors at run-time.

No problem - this is Perl.

>         # size the @authors array
>         #
>         $size = scalar(@authors_field);
>         @authors = (0) x $size;

Don't do this, this is Perl.  If you want to pre-size an array in Perl:

$#authors = $#authors_field;

But pre-sizing arrays is rarely useful in Perl and is positively
detremental where you want to append to an array.

> Then, I increment the x-dimension index of the 2D array (initialized to 0
> earlier)...
> 
>         $nn++;

Don't do this, this is Perl.  You can append to arrays using push().
No need to keep remembering the current size.

> Finally, I loop over...
> 
>         # loop over each element in @author_field (i.e. each "author"
> sub-field)
>         # and initialize the @authors array
>         #
>         for ($y = 0; $y < $size; $y++) {

Don't do this, this is Perl not C.  In perl you really can "loop over
each element" - no need for loop counter variables.

>             # parse this "author" field into the @authors array
>             #
>             if ($objCSVAuthor->parse($authors_field[$y])) {
>             @author = $objCSVAuthor->fields;

The missing my() here will burn you.  Not all missing my()s will burn
you, but when they burn they burn you hard.  Avoid this by getting
into the habit of using my() except where there's a reason why you
can't rather than using it only where you've found your code fails
without it.

>             $authors[$nn][$y] = \@author;

@authors is now a 3D array.

>             }
>             $nn++;
>         } # end for
>     }
> 
> But, I get the following error:
> 
> "Can't use string ("0") as an ARRAY ref while "strict refs" in use at
> txt2xml.pl line 839, <CSV> line 1."

This would be bacause you made @authors an array of strings containing
zeros.  Don't do this.

> It is possible that I am either screwing up on my understanding of
> multi-dimensional arrays or dereferencing in Perl... or both.

Both, and more.

> But I am going cross-eyed trying to debug my problem...

You are not close enough to a solution to start considering what you
are doing to be "debugging".  For a start you have to decide if you
are trying to create a 2D or a 3D array.  Since you _say_ you are
trying to create a 2D array but your code is clearly trying to create
a 3D one it's kinda hard to help you since we don't actually know
which is your goal.

Simply removing the bit where you fill the array with zeros will help
a lot but there's other stuff wrong too.

One hint though always, and I mean always my() your varaibles in the
smallest enclosing scope unless you have a really compelling reason
not to.  Even if you'd got enverything else right your failure to do
this would send you cross-eyed when debugging.

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


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

Date: 26 Oct 2000 15:58:11 GMT
From: mjtg@cus.cam.ac.uk (M.J.T. Guy)
Subject: Re: Use VS Require
Message-Id: <8t9kaj$ogb$1@pegasus.csx.cam.ac.uk>

Troy Rasiah <troyr@vicnet.net.au> wrote:
>Hi all,
>       can anyone tell me whats the advantages and disadvantages of using
>"Use" instead of "Require"

Does the information from

perldoc -q require

answer your question?


Mike Guy


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

Date: Thu, 26 Oct 2000 10:12:37 -0400
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: What is the point of the new keyword 'our'?
Message-Id: <slrn8vgeul.fgf.tadmc@magna.metronet.com>

On Thu, 26 Oct 2000 16:31:36 +0200, Shimon Bollinger 
   <bollinge@wholefamily.com> wrote:

>I couldn't find an answer in the Perl 5.6 FAQ.


The FAQs are only 10 of about 80 files that form Perl's
standard documentation.

our() is described in one of the 70 files that you ignored (perlfunc.pod).

   perldoc -f our


       our EXPR
               An `our' declares the listed variables to be valid
               globals within the enclosing block, file, or
               `eval'.  That is, it has the same scoping rules as
               a "my" declaration, but does not create a local
               variable.

               ...

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


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

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


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