[23885] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 6088 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Feb 6 11:05:42 2004

Date: Fri, 6 Feb 2004 08:05:06 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Fri, 6 Feb 2004     Volume: 10 Number: 6088

Today's topics:
    Re: Arrays Of Arrays: Is it an Array or Scalar? <tore@aursand.no>
    Re: Callback during FTP <lusol@Dragonfly.cc.lehigh.edu>
    Re: Clarifications <matthew.garrish@sympatico.ca>
    Re: Counting words <bmb@ginger.libs.uga.edu>
        filter a string in perl (Dino)
    Re: How to execute a command line in Perlscript <ceo@nospan.on.net>
    Re: Need help passing arrays by reference pls. <1usa@llenroc.ude>
    Re: Perl For Amateur Computer Programmers <bik.mido@tiscalinet.it>
    Re: Perl For Amateur Computer Programmers <bik.mido@tiscalinet.it>
    Re: Perl For Amateur Computer Programmers <bik.mido@tiscalinet.it>
    Re: perl identifier limits <1usa@llenroc.ude>
        Perl's read() vs. sysread() (J. Romano)
    Re: Perl's read() vs. sysread() <ittyspam@yahoo.com>
    Re: Perl's read() vs. sysread() <usenet@morrow.me.uk>
        problem with regex <Paul.Johnston@umist.ac.uk>
    Re: problem with regex <ittyspam@yahoo.com>
    Re: problem with regex <usenet@morrow.me.uk>
        Shameless plug <bmb@ginger.libs.uga.edu>
        trying to create a network script: <Nex6@nospam.com>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Fri, 06 Feb 2004 15:10:19 +0100
From: Tore Aursand <tore@aursand.no>
Subject: Re: Arrays Of Arrays: Is it an Array or Scalar?
Message-Id: <pan.2004.02.05.16.47.24.460993@aursand.no>

On Thu, 05 Feb 2004 15:58:24 +0000, Hal Vaughan wrote:
> I have a function that I'm using to perform operations on strings in an
> array.  There are times where I'd like to have this function work on arrays
> of arrays.  Is there a simple way to tell if the value of an element in an
> array is a scalar, or is, instead, a reference to another array?

Yes, by using the ref() function;

  perldoc -f ref

I feel that I personally tend to write functions/methods that no matter
what turns the argument data into an array reference (if that's applicable);

  sub foo {
      my $input = shift;
      $input = ( ref($input) eq 'ARRAY' ) ? $input : [ $input ];

      foreach ( @$input ) {
          # ...
      }
  }

That way I never (...) need to know what the function/method wants.


-- 
Tore Aursand <tore@aursand.no>
"I am become Death, shatterer of worlds." -- J. Robert Oppenheimer,
 upon witnessing the explosion of the first atomic bomb.


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

Date: Fri, 6 Feb 2004 14:14:20 +0000 (UTC)
From: Steve Lidie <lusol@Dragonfly.cc.lehigh.edu>
Subject: Re: Callback during FTP
Message-Id: <c007fs$csq$1@fidoii.CC.Lehigh.EDU>

In comp.lang.perl.tk Yehuda Berlinger <jon@actcom.co.il> wrote:
> Ben Morrow <usenet@morrow.me.uk> wrote in message news:<bvp9th$g71$1@wisteria.csv.warwick.ac.uk>...
> 
> ...
> 
> 
> Cool.
> 
> Actually, I decided to subclass Net::FTP, copying over the get and put
> functions, and adding one parameter $cb, and one line in the
> appropriate place:
> 
> &{$cb}($buf,$len) if ref $cb eq 'CODE';
> 
> For the life of me, I can't figure out why this is not in Net::FTP, as
> it is trivial.
> 
> Yehuda

I think Ben's trick is really cool. And, generally, your method, which
I've used in the past, is great most of the time. Still, when doing
network I/O with a Tk GUI I prefer a mulit-process approach.
The child handles network activities and talks to the Tk parent via
fileselect, using pipes or sockets (or even memory mapped arrays!).



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

Date: Fri, 6 Feb 2004 09:33:30 -0500
From: "Matt Garrish" <matthew.garrish@sympatico.ca>
Subject: Re: Clarifications
Message-Id: <WANUb.29618$9U5.1325112@news20.bellglobal.com>


"Keith Keller" <kkeller-usenet@wombat.san-francisco.ca.us> wrote in message
news:5s1vvb.ilv.ln@goaway.wombat.san-francisco.ca.us...
> -----BEGIN xxx SIGNED MESSAGE-----
> Hash: SHA1
>
> On 2004-02-06, Brad Baxter <bmb@ginger.libs.uga.edu> wrote:
> >
> > (I don't know why I can't resist jumping in on this thread.  I wonder if
> > it's a mass hypnosis worm ...)
>
> It must be the usenet equivalent of a spectacular car crash, where
> passersby feel compelled to stop and stare.
>

More like a smash-up derby. The sheer stupidity of the OP (which makes me
wonder about his claims of being a scientist) and his utter inability to
comprehend what is being told to him just makes you want to take a run at
him in the hopes of finally knocking him out of commission.

Matt




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

Date: Fri, 6 Feb 2004 09:02:29 -0500
From: Brad Baxter <bmb@ginger.libs.uga.edu>
Subject: Re: Counting words
Message-Id: <Pine.A41.4.58.0402060901330.29390@ginger.libs.uga.edu>

On Thu, 6 Feb 2004, Walter Roberson wrote:

> In article <Pine.A41.4.58.0402052134460.28924@ginger.libs.uga.edu>,
> Brad Baxter  <bmb@ginger.libs.uga.edu> wrote:
> :On Wed, 4 Feb 2004, Fran wrote:
> :> Can anybody please tell me how to count words? If a need to know if an
> :> input has n words, how do I do it? Thank you
>
> :perl -pale '$=+=@F}{*_=*=' input
>
> That's cruel!

Flatterer.


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

Date: 6 Feb 2004 08:00:13 -0800
From: no.sec@tin.it (Dino)
Subject: filter a string in perl
Message-Id: <f8ebbc.0402060800.6e848318@posting.google.com>

hi guys,

need some help with a perlscript.
i have a guestbook written in perl and it gets overfilled with spam.
but the spammers always use another IP, so i can't filter with that
option.
is there a possibility to check the entries and compare them with a
string?
lets say, if in the message body there is a string like:
"hi guys, i really liked your page!blablabla...Buy Viagra..blabla" 
the message will not be moved to the guestbook.
something like:
if in message-body "blabla" then exit;

thanks for any help!
Dino


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

Date: Fri, 06 Feb 2004 14:38:02 GMT
From: Chris <ceo@nospan.on.net>
Subject: Re: How to execute a command line in Perlscript
Message-Id: <eFNUb.32366$CB4.7973@newssvr33.news.prodigy.com>

Eric SALGON wrote:
> In article <u1vUb.19065$po6.10019@newssvr16.news.prodigy.com>, 
> ceo@nospan.on.net says...
> 
>>Eric SALGON wrote:
>>
>>>Hi,
>>>
>>>Is there someone who knows how to execute a command line (such a simple 
> 
> echo 
> 
>>>cmd) in PerlScript.
>>>
>>>I hve tryed '' or system() but the result is the same: no result but no 
> 
> error 
> 
>>>!
>>>
>>>This syntax works fine in a perl program but not in PerlScript
>>>
>>>An idea ?
>>
>>Well, to answer your question successfully, I'll have to make some 
>>assumptions.  Some people, when they say "PerlScript," they really mean 
>>"Perl script."  But since there IS a product called "PerlScript," I'll 
>>answer in that context.  And even within THAT, there are two ways this 
>>could be viewed: PerlScript under ASP and PerlScript under Windows 
>>Scripting Host.  I'll assume the later, but answer both.
>>
>>PerlScript ASP cannot use 'print' or 'echo' to write to the end client 
>>browser.  You have to use $Response->Write().  Assuming you know that 
>>already...
>>
>>...the answer when running PerlScript in a WSH context is:
>>
>>$WScript->Echo( "This is how to print in PerlScript\n" );
>>
>>A tip: I personally like Ruby's use of a call named puts() which, named 
>>in C-style convention, out Puts a string.  I've adopted THAT as my 
>>standard "outputing call" and I write wrappers in each environment I'm 
>>in to handle it the right way (so I don't have to remember any more how 
>>to write a string; it gets ridiculously out of hand esp. in the Windows 
>>world where Microsoft can't get it together and each side of their house 
>>invents a new standard for something so simple -- in ASP it's 
>>Response.Write in WSH it's WScript.Echo, in Access it's print.debug or 
>>whatever...)
>>
>>So...  I recommend this approach and then you never have to remember any 
>>more:
>>
>>ASP: sub puts { for (@_) { $Response->Write( "$_\n" ) } }
>>WSH: sub puts { for (@_) { $WScript->Echo( "$_\n" ) } }
>

>> [Top Posting Fixed]

> Thx Chris for your answer,
> 
> My question was for "PerlScript" under ASP, and the 'Echo' command was only a 
> sample. 
> 
> In fact, my goal is  to run the 'dnscmd' command (which is used to manage dns 
> on w2000/w2003 server) and analyse the result.
> 

Well, hopefully you read my other answer where I was reading and 
comprehending instead of reading and jumping the gun...

Chris
-----
Chris Olive
chris -at- --spammers-are-vermin-- technologEase -dot- com
http://www.technologEase.com
(pronounced "technologies")


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

Date: 6 Feb 2004 14:20:22 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude>
Subject: Re: Need help passing arrays by reference pls.
Message-Id: <Xns94875F016A80Casu1cornelledu@132.236.56.8>

g_klinedinst@hotmail.com (G Klinedinst) wrote in 
news:168f035a.0402052146.4c5c1df0@posting.google.com:

> Hi all. I have a question I have been pulling my hair out all day
> over. Can someone tell me what is happening in the following code. The
> first print statements create the results I expect. The subroutines
> statments print arrays with 1 element but not data in [0]. What gives?
> I am passing by reference and then dereferencing in the sub. Can you
> point me towards what I am missing? I have looked at the perlfaqs and
> read the perldocs on references but it I can't find what I am looking
> for. It could also be my sleep deprived mind is seeing it but not
> grokking it. TIA.
> 
> -Greg
> 
> ***********CODE****************
> #!/usr/local/bin/perl
> 
> use strict;
> use warnings;
> 
> my @arr1;
> my @arr2;
> 
> $arr1[0] = 1;
> 
> print( $arr1[0] . ":" . scalar( @arr1 ) . "\n" );
> print( $arr2[0] . ":" . scalar( @arr2 ) . "\n" );
> print( "\n\n" );
> 
> test( \@arr1, \@arr2 );
> 
> sub test
> {
>     my @subArr1 = @$_[0];
>     my @subArr2 = @$_[1];

Life would be much easier if you did:

#! perl

use strict;
use warnings;

my @arr1 = (1, 2, 3);
my @arr2 = (4, 5, 6);

$arr1[0] = 1;

print $arr1[0], ':', scalar @arr1, "\n" ;
print $arr2[0], ':', scalar @arr2, "\n" ;

# You should avoid the unnecessary concatenations you had in your code.

print "\n\n" ;

test(\@arr1, \@arr2);

sub test {
    my ($subArr1, $subArr2) = @_;

    print $subArr1->[0], ':', scalar @{$subArr1}, "\n" ;
    print $subArr2->[0], ':', scalar @{$subArr2}, "\n" ;
}

-- 
A. Sinan Unur
1usa@llenroc.ude (reverse each component for email address)


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

Date: Sat, 07 Feb 2004 16:21:45 +0100
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: Perl For Amateur Computer Programmers
Message-Id: <ldf920hpfngaasp27b4pv0k1amf0f5r3hc@4ax.com>

On Wed, 04 Feb 2004 16:36:07 GMT, "edgrsprj" <edgrsprj@ix.netcom.com>
wrote:

>"Michele Dondi" <bik.mido@tiscalinet.it> wrote in message
>news:apus101fs05mppvmeccqrc5pqkqgh55rtn@4ax.com...
>> On 31 Jan 2004 23:21:47 GMT, "Tassilo v. Parseval"
>> <tassilo.parseval@rwth-aachen.de> wrote:
>>
>
>> Well, it is clear that the OP is *not* "yet another troll", or at
>
>There is a very serious informal, international scientific project involved
>with this.  As I have said in other posts, time limitations are controlling
>what is and is not being done.  I managed to get a full day free in order to
>create that Perl Web page.  And since then I have not been able to get any
>large blocks of time free to do any more work on it.  At the moment there
>can even be several day periods of time between the times when I can post
>notes here or answer my e-mail.

I don't know what you intended to communicate with this comment. You
had already said this and IMHO there was no need to stress the point.

*My* point was indeed that notwithstanding what the OP wrote, it is
worth to continue discussing with you. Because *it is clear* that
you're not a troll, even if, sorry to say this, there's something
(unintendedly, I hope) trollish in your modus operandi.

What is being discussed here is *not* your scientific project but your
web page about Perl, some misunderstandings you expressed, related to
that web page and other related issues.


Michele
-- 
you'll see that it shouldn't be so. AND, the writting as usuall is
fantastic incompetent. To illustrate, i quote:
- Xah Lee trolling on clpmisc,
  "perl bug File::Basename and Perl's nature"


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

Date: Sat, 07 Feb 2004 16:21:46 +0100
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: Perl For Amateur Computer Programmers
Message-Id: <dpk9209ldgsdpa1707cs0766c9hplsh13d@4ax.com>

On Wed, 04 Feb 2004 17:10:31 GMT, "edgrsprj" <edgrsprj@ix.netcom.com>
wrote:

>The applications it is needed for are not that complex.  I myself can
>already create the necessary code.  So once things get past a certain point
>it might work fine.  Right now I need to determine how well Perl, Python,
>Ruby, or some other language can do with controlling Windows screens.  On my
                                                      ^^^^^^^^^^^^^^^

One thing that continues puzzling me in your posts is this repeated
recurrence of the above underlined expression. AFAICT there's not such
a concept as a "Windows screen": I suppose you mean simply a Windows
(TM, i.e. the OS) window (GUI concept), am I right?

Well a window is something and the program associated with that window
is another thing. The program uses resources provided by the window
manager to create the window itself and the various elements of the
UI, but this relationship AFAIK *generally* is not two-way, period.

>PC I already have Perl controlling Windows screens by having it send
>instructions to a simple Windows control program through the Windows
>clipboard.  And it works.  But it is slow.  And I would rather have Perl or
>whatever do all of those Windows screen operations itself.

You have already received informed hints from more knowledgeable
posters than I am. The fact is that there is no one answer, but *many*
answers and they're all partial. As a general rule programs can
interact/intercommunicate only if they were designed to do so.

Standard input and output streams together with that tiny, slim thing
called pipe provide an extremely simple but just at the same time
surprisingly powerful way for programs to intercommunicate each other.
And then one has FIFOs, sockets, and more complex protocols.

I'm very ignorant in these matters, but for Windows applications you
have OLE as a protocol for the exchange of information between
programs, and there's also CORBA et similia. And yes, I've never used
them, but there are Perl modules to deal "natively" with these
protocols. But then the programs you need to "drive" must be compliant
in the first place...

Said this, a practical suggestion could be as follows: instead of
writing to the clipboard, write to a file. Then write a daemon (but I
think it would be called "service" under win) to monitor that file and
launch programs and do other stuff as new stuff is written to the
file. Does this make sense?!?


Michele
-- 
you'll see that it shouldn't be so. AND, the writting as usuall is
fantastic incompetent. To illustrate, i quote:
- Xah Lee trolling on clpmisc,
  "perl bug File::Basename and Perl's nature"


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

Date: Sat, 07 Feb 2004 16:21:47 +0100
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: Perl For Amateur Computer Programmers
Message-Id: <tju920hh3g0a0lsk5527m2db1e5hjl8dro@4ax.com>

On Wed, 04 Feb 2004 17:47:45 GMT, "edgrsprj" <edgrsprj@ix.netcom.com>
wrote:

>"Michele Dondi" <bik.mido@tiscalinet.it> wrote in message
>news:9unu10d236pg8sfi86jpmg5p3rvn64q4di@4ax.com...
>> On Sat, 31 Jan 2004 13:45:58 GMT, "edgrsprj" <edgrsprj@ix.netcom.com>
>> wrote:
>>
>
>Michele, here is what that Web page says or is intended to say:

As a side note, please quote correctly the post you're replying to as
common sense (and the posting guidlines regularly posted here, in case
common sense lacks) suggests.

Here this is not a major problem for me, because I do remember more or
less what I wrote, which is not something obvious, btw, but it may
well be a problem for others to follow this discussion, that is not
our private discussion.

>If you have never used Perl and want to write a simple program which will
>read two numbers from the keyboard, multiply them together, and store the
>results in a file then do "this, this, and that."  And when you are done the
>numbers you want should be present in that file.

Wrong assumption! it should be:

| If you have never... then you *can* do "this, this, and that."!

The wrong assumption being that "there is one way to do it". Indeed
TMTOWTDI, as is well known. This is true of any language, but it is
much "more true" for Perl than any other language. Now I suppose that
you're aware of this, but judging both from your attempt itself and
from what you wrote in that page it *seems* that you ignore it
instead.

"So what?", you may say, "I'll present them just *one* WTDI". So far
so fine. But even assuming that each particular example you give will
be free of errors, due to the nature of Perl the particular
"ingredient" you're focusing on may not be well suited for recipes
other than the one under consideration.

For more details on this issue, please read on...

>It is presently intended to a large extent just to provide people with
>enough information that they can write a simple program and get it running
>without having to spend weeks reading through the documentation.  The codes

The point is, and it is supported by *facts* that there are plenty of
information available either in printed form or on-line that would
enable one to "write a simple program and get it running without
having to spend weeks reading through the documentation".

And AFAICT all those resources are far better than yours and more well
suited to their purpose.

I wrote my first program with the help of an old edition of the llama
book (Perl4, unfortunately!): I was not doing "Hello World!" kind of
stuff, I wrote the program I needed, and yes: it was horrible, but
worked.

Now, if you only need Perl for *one* task like that, then probably
Perl is not the language for you. It is a complex language, face it!
And if it is that complex there will be a reason: if you choose it you
choose to cope with that complexity and use it to your own advantage.
But this means: *never* *stop* *learning*!

Never stop learning... why?!? Because you want to get the best out of
it, don't you? Otherwise you should have chosen a language more
suitable for a one-time-only task.

Well, what I exposed above is MHO anyway, based upon my own
experience.

>From what I can tell, so far just a relatively few people have looked at
>that Web page.  And I would guess that most of them were probably
>experienced Perl users who are not about to change the way they write
>programs based on the information on that page.

They may also be experienced Perl users who first learned Perl from
sources that gave them "wrong" ideas and habits. And they may have
been used to apply bad programming techniques learned from such
sources and may have had to learn how to overcome them...

>I have been making extensive use of the available .html documentation files.
>However I found that quite often there would be helpful information in some
>file which you would not be able to find by just following the links.  If

I must admit you're right: this is true of any kind of documentation
that is sufficiently complex. Only I have the *impression* you're
overestimating the size of the phenomenon, as far as perl is
concerned. May well be wrong, though...

>you do a Windows search for a particular word or group of words then you can
>find all of those references and check them individually.

Don't mind, I have an idiosincrasy with Windows search... fortunately
I have find.exe from UNXUTILS, and File::Find.

>Most of the people with whom I am talking are using the Windows program as
>am I.  So I am trying to organize things so that as many people as possible
>will be able to understand the material.

This is sensible. To be fair I don't know anyone in that area of
research. Would have thought that scientists working in it would have
more experience with some flavour of UNIX though...

>And finally, as I have been saying, that Web page will probably remain there
>only if it appears that it is going to be helpful to people.  It is largely
>experimental at the moment.  At this point no decision has been made on its
>future.

As it is *now* it can't be helpful to anyone. More precisely, it can
be *falsely* helpful, that is: it can be helpful in being a sort of
advertising that says "hey, you know, there's this thing called Perl
and you can happily use it without risking impotence".

It will be counterproductive in that you provide wrong information
that can work (at most) only in a restricted set of cases. Most
probably people following your advices may soon get frustrasted by
insuccesses arising from this lack of proper information and decide
that perl is not for them.

So, I would judge it as an extremely positive thing that you want to
keep the "ad", possibly by describing how useful Perl was for your own
reasearch work. But then point them to good resources, be them already
existing ones (such as those you've been suggested) or something
you'll write when you will have the maturity to do that...


Michele
-- 
>It's because the universe was programmed in C++.
No, no, it was programmed in Forth.  See Genesis 1:12:
"And the earth brought Forth ..."
- Robert Israel on sci.math, thread "Why numbers?"


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

Date: 6 Feb 2004 14:07:21 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude>
Subject: Re: perl identifier limits
Message-Id: <Xns94875CCCBA6B8asu1cornelledu@132.236.56.8>

Alex Shinn <foof@synthcode.com> wrote in
news:87n07wtu3f.wl@strelka.synthcode.com: 

> At Fri, 06 Feb 2004 09:36:23 GMT, Uri Guttman wrote:
>> 
>> >>>>> "AS" == Alex Shinn <foof@synthcode.com> writes:
>> 
>>   AS> Not that I'd write such a long identifier, but I've got
>>   auto-generated AS> code that reaches twice that length.  Any ideas
>>   apart from applying AS> compression algorithms to the id names? 
>>   Any plans on fixing this? 
>> 
>> fix your code. i can't see any possible reason to generate names that
>> long. you would have to come up with some amazing reasons to support
>> your claim that you need it.
> 
> You obviously don't write Perl with a Lisp mindset.  If you
> auto-generate code on the fly it is not always easy to design it such
> that names won't conflict.  In my case I'm working with an application
> server which can have a *huge* base of dynamically generated code.  A
> potential workaround is to use only hashtables and store anonymous
> subroutines in them,

Complete shot in the dark: How about using the MD5 or SHA1 hash of the very 
very very very long names you need?

-- 
A. Sinan Unur
1usa@llenroc.ude (reverse each component for email address)


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

Date: 6 Feb 2004 06:55:37 -0800
From: jl_post@hotmail.com (J. Romano)
Subject: Perl's read() vs. sysread()
Message-Id: <b893f5d4.0402060655.5689a060@posting.google.com>

Hi,

   I was wondering if anyone could tell me the differences between
Perl's read() function and its sysread() function.  Now, by reading
the perldocs I know that Perl's read() function implements the
system's fread() call and that Perl's sysread() function implements
the system's read() call, but I really don't know what that means.  I
tried reading the man pages on fread() and read(), but that didn't
help me much.

   Here is what else I know about read and sysread (please correct me
if I'm wrong):

   * read belongs to a group of functions that includes read, print,
write, seek, tell, eof, and the angle-bracket-filehandle-operator.

   * sysread belongs to a group of functions that includes sysread,
syswrite, and sysseek.

   * The functions in these two groups should not be mixed (unless, as
the Camel book says, I am into wizardry and/or pain).  (Just an aside
note:  I once accidentally used a print statement on a socket that I
had used sysread() on.  It worked fine the first day, but froze up on
the print statement the next day.  When I finally found the error and
changed the print statement to syswrite(), the program no longer froze
on me.  This was a classic case of "the program worked fine for me
yesterday.")

   * The functions open, close, and binmode can be used safely with
functions of both groups.

   That's all I know about the difference between Perl's read() and
sysread() functions.  What I would still like to know is:

   * When should I use read() over sysread() (or sysread() over
read())?

   * What differences in program execution can I expect if I switch my
read() statements to sysread() (or vice-versa)?

   * If I were to open a socket over the internet using IO::Socket,
would it best to use the read() group of functions or the sysread()
group of functions?

   * Since Perl's read() function uses the system's fread() call and
Perl's sysread() function uses the system's read() call, what does
that mean to me if I'm using those functions on a non-Unix system,
like Win32 using ActiveState Perl?  I would imagine that, in that
particular circumstance, there would be no difference between Perl's
read() and fread() functions, but the mix-up I mentioned above about
using a print statement with a sysread() function was done on a Perl
program running on a Windows XP machine, so something different must
be happening under the hood even on Win32 operating systems.

   Thanks in advance for any input,

   Jean-Luc


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

Date: Fri, 6 Feb 2004 10:16:24 -0500
From: Paul Lalli <ittyspam@yahoo.com>
Subject: Re: Perl's read() vs. sysread()
Message-Id: <20040206101347.P483@dishwasher.cs.rpi.edu>

On Fri, 6 Feb 2004, J. Romano wrote:

> Hi,
>
>    I was wondering if anyone could tell me the differences between
> Perl's read() function and its sysread() function.  Now, by reading
> the perldocs I know that Perl's read() function implements the
> system's fread() call and that Perl's sysread() function implements
> the system's read() call, but I really don't know what that means.  I
> tried reading the man pages on fread() and read(), but that didn't
> help me much.
>
This is far from a complete answer, but I know that one difference is that
the sys* family of functions operates on data unbuffered, whereas the
read(), print(), etc functions buffer their I/O.  This is because this
second group uses the stdio or perlio layers, whereas sys* bypass those
layers to interface directly with the system.

I'm sure someone else can give more details.

Paul Lalli


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

Date: Fri, 6 Feb 2004 16:01:08 +0000 (UTC)
From: Ben Morrow <usenet@morrow.me.uk>
Subject: Re: Perl's read() vs. sysread()
Message-Id: <c00do4$f46$1@wisteria.csv.warwick.ac.uk>


jl_post@hotmail.com (J. Romano) wrote:
>    I was wondering if anyone could tell me the differences between
> Perl's read() function and its sysread() function.  Now, by reading
> the perldocs I know that Perl's read() function implements the
> system's fread() call and that Perl's sysread() function implements
> the system's read() call, but I really don't know what that means.  I
> tried reading the man pages on fread() and read(), but that didn't
> help me much.
> 
>    Here is what else I know about read and sysread (please correct me
> if I'm wrong):
> 
>    * read belongs to a group of functions that includes read, print,
> write, seek, tell, eof, and the angle-bracket-filehandle-operator.

Yup.

>    * sysread belongs to a group of functions that includes sysread,
> syswrite, and sysseek.

And, most importantly, select.

>    * The functions open, close, and binmode can be used safely with
> functions of both groups.

Yup.

> 
>    That's all I know about the difference between Perl's read() and
> sysread() functions.  What I would still like to know is:
> 
>    * When should I use read() over sysread() (or sysread() over
> read())?

Personally, I'd never use read.

The difference between the two sets is that read, print, etc. all
buffer their IO. What this means is that when you say read(...), Perl
actually reads rather more than you asks for, and returns the rest on
later read calls. This means that there is less low-level access to
the operating system, which makes things more efficient. Similarly,
when you print something, it actually only goes into a buffer. The
whole buffer is then printed in one go when it reaches a certain size
(or when you print a newline if the output is line-buffered). Output
buffering can be turned off with $|.

The only time to use sys* is when using select. select waits for data
to be ready on a filehandle, and sysread then lets you read what data
is there without waiting for more: obviously, if there's a girt big
buffer between you and the filehandle this isn't going to work.

>    * What differences in program execution can I expect if I switch my
> read() statements to sysread() (or vice-versa)?

Buffered IO is always more efficient when you can use it.

>    * If I were to open a socket over the internet using IO::Socket,
> would it best to use the read() group of functions or the sysread()
> group of functions?

The only important thing is not to mix them. If you are using select
(or IO::Select), you *must* use the sys* functions; if you are waiting
for a response from the other end, you'd be better off using the sys*
as otherwise you may find that you're waiting for a response to a
request that's still sitting in your buffer (though this can be dealt
with using $|); otherwise, you're probably best off using buffered IO
for efficiency.

>    * Since Perl's read() function uses the system's fread() call and
> Perl's sysread() function uses the system's read() call, what does
> that mean to me if I'm using those functions on a non-Unix system,
> like Win32 using ActiveState Perl?  I would imagine that, in that
> particular circumstance, there would be no difference between Perl's
> read() and fread() functions, but the mix-up I mentioned above about
> using a print statement with a sysread() function was done on a Perl
> program running on a Windows XP machine, so something different must
> be happening under the hood even on Win32 operating systems.

Any system that supports ANSI C (read: any system perl builds on)
supports fread(3). With 5.8, in fact, the buffering fread(3) does is
re-implemented inside perl, as this gives both more flexibility and a
measure of protection from certain OS's broken stdio libraries.

'Most any OS will also support either read(2) or some equivalent. Most
support read(2) directly: Win32 does, though it also has its own set
of functions, in the classic Microsoft fashion of not doing a thing
well once when you can do it badly five times.

Ben

-- 
Every twenty-four hours about 34k children die from the effects of poverty.
Meanwhile, the latest estimate is that 2800 people died on 9/11, so it's like
that image, that ghastly, grey-billowing, double-barrelled fall, repeated
twelve times every day. Full of children. [Iain Banks]         ben@morrow.me.uk


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

Date: Fri, 06 Feb 2004 11:38:32 +0000
From: Paul Johnston <Paul.Johnston@umist.ac.uk>
Subject: problem with regex
Message-Id: <uku620lmlgmpcao8eeumb6hkdvsume6n6b@4ax.com>

Hi
I have a file encoded using unicode (utf-8) on a Redhat 9 system and
using Perl 5.8.0
It contains mixed estonian and English like below:

<ee> Kaks vana sõpra </ee>
<en> Two old friends </en>
<ee> Tere Piret ! </ee>
<en> Hello Piret ! </en>
<ee> Tere Tõnu ! </ee>
<en> Hello Tõnu ! </en>

I need to do some processing but the expression 
(/õ/) will not match with the õ in any line
The perl script and the file I wish to process were both created using
the same editor (kedit) so I assume they are encoding using the same
scheme.
Any ideas why I cannot for example extract all lines which contain
this symbol "õ"
TIA
Paul




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

Date: Fri, 6 Feb 2004 09:56:14 -0500
From: Paul Lall <ittyspam@yahoo.com>
Subject: Re: problem with regex
Message-Id: <20040206095510.C483@dishwasher.cs.rpi.edu>

On Fri, 6 Feb 2004, Paul Johnston wrote:

> Hi
> I have a file encoded using unicode (utf-8) on a Redhat 9 system and
> using Perl 5.8.0
> It contains mixed estonian and English like below:
>
> <ee> Kaks vana s=F5pra </ee>
> <en> Two old friends </en>
> <ee> Tere Piret ! </ee>
> <en> Hello Piret ! </en>
> <ee> Tere T=F5nu ! </ee>
> <en> Hello T=F5nu ! </en>
>
> I need to do some processing but the expression
> (/=F5/) will not match with the =F5 in any line
> The perl script and the file I wish to process were both created using
> the same editor (kedit) so I assume they are encoding using the same
> scheme.
> Any ideas why I cannot for example extract all lines which contain
> this symbol "=F5"
> TIA
> Paul


Without having seen your code, my guess would be that your locale is not
correctly set up.  See perldoc perllocale and perldoc locale

Paul Lalli


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

Date: Fri, 6 Feb 2004 15:45:44 +0000 (UTC)
From: Ben Morrow <usenet@morrow.me.uk>
Subject: Re: problem with regex
Message-Id: <c00cr8$ec8$1@wisteria.csv.warwick.ac.uk>


Paul Lall <ittyspam@yahoo.com> wrote:
> On Fri, 6 Feb 2004, Paul Johnston wrote:
> 
> > I have a file encoded using unicode (utf-8) on a Redhat 9 system and
> > using Perl 5.8.0
> > It contains mixed estonian and English like below:
> >
> > <ee> Kaks vana sõpra </ee>
> > <en> Two old friends </en>
> > <ee> Tere Piret ! </ee>
> > <en> Hello Piret ! </en>
> > <ee> Tere Tõnu ! </ee>
> > <en> Hello Tõnu ! </en>
> >
> > I need to do some processing but the expression
> > (/õ/) will not match with the õ in any line
> > The perl script and the file I wish to process were both created using
> > the same editor (kedit) so I assume they are encoding using the same
> > scheme.
> > Any ideas why I cannot for example extract all lines which contain
> > this symbol "õ"
> 
> 
> Without having seen your code, my guess would be that your locale is not
> correctly set up.  See perldoc perllocale and perldoc locale

NO! Don't mix locales and unicode with 5.8. It doesn't work.

If you wish to use utf8 literals in your source, you have to 'use
utf8;' at the top.

Ben

-- 
  Joy and Woe are woven fine,
  A Clothing for the Soul divine       William Blake
  Under every grief and pine          'Auguries of Innocence'
  Runs a joy with silken twine.                                ben@morrow.me.uk


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

Date: Fri, 6 Feb 2004 09:42:03 -0500
From: Brad Baxter <bmb@ginger.libs.uga.edu>
Subject: Shameless plug
Message-Id: <Pine.A41.4.58.0402060914300.29390@ginger.libs.uga.edu>

<warning content="baby pictures">

For the last 10 years I've been programming for the (U.S.) state of
Georgia's virtual library system, GALILEO.

    http://www.galileo.usg.edu

This is where the majority of my Perl (and Web) misdemeanors are
committed.  It's main function is to provide access to licensed resources,
so you'll likely only be able to see the public databases, notably those
in the Digital Library of Georgia.

    http://www.galileo.usg.edu/express?link=dlg1

Our newest arrival there is Georgia Aerial Photographs.

    http://www.galileo.usg.edu/express?link=gaph

Not much Perl visible there; the static pages are pregenerated nightly.
Short-range plans: fix all the mistakes; make the ASCS photomosaics
zoomable, too; integrate with gazetteer place data. Longer-range wishes:
scan the rest of the air photos; implement true GIS access.

</warning>

I'm grateful to all the Perl developers for making what I do easy enough
that I can do it, that my employers remain willing to bankroll my
programming habit, and that my wife hasn't murdered me in my sleep.

Thank you for indulging a proud father.

Regards,

Brad


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

Date: Fri, 06 Feb 2004 07:58:28 -0800
From: Nex6 <Nex6@nospam.com>
Subject: trying to create a network script:
Message-Id: <c00dc7$jhj$1@daisy.noc.ucla.edu>

Hello all:


Ok, This is what I am trying to do:

I have a group of machines of maybe 200 workstations running NT 4.0 
workstation. They are on Policy.

I want to push out some changes but the changes MUST happen in a 
controlled and safe way. as these are production machines.

the gist of it is like this,

connect to machine1
          make changes to reset.reg
          make changes to registry
          make change to domain account that matches machine.

connect to machine2
          make changes to reset.reg
          make changes to registry
          make change to domain account that matches machine.


etc etc etc.....


I will be running this from a windows 2000 pro machnie  running active 
state perl.

so this is what I am thinking, have perl, pull the machine name from a 
text file and use that as a $var to pass it to open and the other 
statements and wrap the whole thing in a for or for each loop.

I am having some trouble get it to work , i am working on the text pull 
now so any help would really be great!!!


/code:

open loc, "<testpull.txt";
#my $file = '+<\\\\dsmccsb264da\\c$\\reset.reg';
$file = <loc>;
#$file = '+<\\\\dsmccsb264da\\c$\\reset.reg';


$oldpass = '"password"'; #put old password here
$newpass = '"newpass"';  #put NEW password here
#print $file;
open fh, '+<\\\\$file\\c$\\reset.reg' or die "can't open $file: $!";


$slurp = join '', <fh>;

$slurp =~ s/$oldpass/$newpass/ig;

seek(fh,0,0);
print fh $slurp;


truncate(fh,tell(fh));


close(fh);
close(loc);

/end code:

This is what i have so far,
when everything is staticd in  it works, but now I need to pull just the 
machine name and use it becuase later i will need to use the same var to 
make the domain controller change.


where it seem to have issues is connecting to the file , perl seems to 
be have trouble with the $file and pass it and such.

Thanks!!!!



-Nex6


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

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.  

NOTE: due to the current flood of worm email banging on ruby, the smtp
server on ruby has been shut off until further notice. 

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


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