[22704] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 4925 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri May 2 03:10:39 2003

Date: Fri, 2 May 2003 00:10:11 -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           Fri, 2 May 2003     Volume: 10 Number: 4925

Today's topics:
    Re: Problem serving binary files <spam@thecouch.homeip.net>
    Re: Quickie about a $scalar - convert it <anthony@no_spam.movielink.net.au>
    Re: Quickie about a $scalar - convert it <noreply@gunnar.cc>
    Re: search, replace and insert. <krader@skepticism.us>
    Re: sockets, sysread <spam@thecouch.homeip.net>
    Re: waste of time (Tad McClellan)
    Re: What is the best software to run for an aspiring Pe (Tad McClellan)
    Re: What is the best software to run for an aspiring Pe (Sam Holden)
    Re: What is the best software to run for an aspiring Pe <mgjv@tradingpost.com.au>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Thu, 01 May 2003 19:01:34 -0400
From: Mina Naguib <spam@thecouch.homeip.net>
Subject: Re: Problem serving binary files
Message-Id: <mHhsa.2389$dB2.30469@wagner.videotron.net>

-----BEGIN xxx SIGNED MESSAGE-----
Hash: SHA1

Topspin wrote:
> I have the following Perl script runnin on a Unix box with Apache HTTP.  It
> works perfectly.  I changed the top line to get the script to work on a
> Windows box and it appears to work, but the the gif image never appears in
> the browser.  It appears to be incomplete because if I right mouse click on
> the center of the page, I can "Save the image" to my hard drive.  When I
> open the saved image up in a paint program, it shows the correct dimensions
> and color pallete, but the image is blank.  It's as if the browser is trying
> to show the image before it is done being sent.  Any ideas why this works
> perfectly on Unix but dies on Windows.  No errors are generated and both
> machines are running Apache.

See perldoc -f binmode or 
http://www.perldoc.com/perl5.8.0/pod/func/binmode.html


-----BEGIN xxx SIGNATURE-----
Version: GnuPG v1.2.1 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQE+sadSeS99pGMif6wRApj4AKDZyokr/QU2QIJAOwVmV6M1FjaZAgCfThJb
Jpy71JMHw1+sI9RqBG4Xjxc=
=rKrW
-----END PGP SIGNATURE-----



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

Date: Fri, 02 May 2003 09:57:56 +1000
From: "Tony" <anthony@no_spam.movielink.net.au>
Subject: Re: Quickie about a $scalar - convert it
Message-Id: <pan.2003.05.01.23.57.55.416546@no_spam.movielink.net.au>

On Thu, 01 May 2003 13:11:57 +0200, Gunnar Hjalmarsson wrote:

> Gunnar Hjalmarsson wrote:
>>     $scalar =~ s/"\)$//;
>>     @ar = split /" , "/, substr $string, 2;
> 

Thanks Gunnar,

When I first looked I thaught I saw a pusyca..ehhmm, sorry,
(To many cartoons) when I saw your split it looked
like I would get just the 2 first sections until I tried.


The "substr" in your split did it - I have some catching up
to do on regexes, they are a bit hard to get around.

Do you (Or others) know of a very good tutorial on that
specific part of perl that deals with manipulating strings
and text as well as converting $scalars to @arrays and back.


For a beginner it seems that a lot of the DOCS are a bit
terse and do asume you know what you want and just tell you
the syntax and little more. 

(Except some of the perldoc stuff)
 
Tony

> Correction:
> 
>      $scalar =~ s/"\)$//;
>      @ar = split /" , "/, substr $scalar, 2;
> 
> / Gunnar

-- 
--------------------------------------------------------------
To reply directly send to: anthony AT movielink DOT net DOT au
Replace AT and DOT with @ and . and mail will get through.
Any spammers will be persued until they get booted off the net



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

Date: Fri, 02 May 2003 03:44:06 +0200
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: Quickie about a $scalar - convert it
Message-Id: <b8siih$d1bro$1@ID-184292.news.dfncis.de>

Tony wrote:
> The "substr" in your split did it - I have some catching up
> to do on regexes, they are a bit hard to get around.

Well, when I saw Tad's solution, I realized that it can easily be both 
simplified and improved:

     @ar = split /"\s*,\s*"/, substr $scalar, 2, -2;

> Do you (Or others) know of a very good tutorial on that
> specific part of perl that deals with manipulating strings
> and text as well as converting $scalars to @arrays and back.

perlfaq, in this case perlfaq4, is always good when you are asking 
yourself "How do I...".

And modules, of course. Tad pointed you to Text::ParseWords, for instance.

> For a beginner it seems that a lot of the DOCS are a bit
> terse and do asume you know what you want and just tell you
> the syntax and little more.

No need to tell me. I'm also at a beginner level; just trying to help 
out with a few questions which I feel comfortable with. ;-)

/ Gunnar

-- 
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl



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

Date: Thu, 01 May 2003 21:40:15 -0700
From: "Kurtis D. Rader" <krader@skepticism.us>
Subject: Re: search, replace and insert.
Message-Id: <pan.2003.05.02.04.40.12.769328@skepticism.us>

On Wed, 30 Apr 2003 11:48:46 +0200, Winfried Koenig wrote:

> the perlrun description of option -0 may be not valid for all
> environments.  The code point 0x1ff describes a legal character.
> 
> code    01FF
> name    LATIN SMALL LETTER O WITH STROKE AND ACUTE block Latin Extended-B
> script  Latin

From the perl v5.8.0 perlrun man page:

  The special value 00 will cause Perl to slurp files in paragraph
  mode.  The value 0777 will cause Perl to slurp files whole because
  there is no legal character with that value.

I'll grant that I don't run Perl on anything but UNIX and have very little
experience with non-ISO-8859 character sets (i.e., CJKV Unicode), and have
yet to write a perl program that deals with utf-8 encoding. What systems do
not honor the -0 switch? Under which conditions does -0777 not result in
the entire file being read as a single "line"? If there are such exceptions
then I'd certainly encourage you to submit changes to the perlrun man page.


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

Date: Thu, 01 May 2003 19:10:12 -0400
From: Mina Naguib <spam@thecouch.homeip.net>
Subject: Re: sockets, sysread
Message-Id: <tPhsa.2403$dB2.32390@wagner.videotron.net>

-----BEGIN xxx SIGNED MESSAGE-----
Hash: SHA1

Stijn Meurkens wrote:
> Hello,
> 
> I'm catching messages from a socket with sysread, but now it happens 
> sometimes that multiple messages are stored in one string. How can I 
> prevent this, or how can I split this string up (splitting up by newlines 
> doesn't work; newlines can be part of a message).
> 
> Thanks already,
> Stijn

What's your definition of "a message" ?

If you're talking about a custom client+server you wrote, then you must 
separate your different "messages" by a character that's never used in 
the actual message content.

Depending on your message payload, this can be as simple as 1 character 
(chr(0) comes to mind) or something more complex (chr(0) . "SEP" . 
chr(0)). You can also use \n as the separator, then escape (and 
un-escape) actual occurances ofit in the payload.

If this is not viable, then go with each message being something like:
XYZ.payload

where XYZ is the length of the payload, followed by some separator, then 
the payload itself.  The receiving end would then read the length up 
until the separator, then read that length as the payload. After that 
point, it expects another "message" starting with the length. etc...

OR

If you're not worried about compatability between your processes and 
third-party tcp clients/servers, look at a module I wrote. Net::EasyTCP 
located at http://search.cpan.org/author/MNAGUIB/EasyTCP/EasyTCP.pm 
automatically fixes this issue, and a lot more, for you.

These are the solutions that come to mind right now.  There are other 
ways out there.

-----BEGIN xxx SIGNATURE-----
Version: GnuPG v1.2.1 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQE+salZeS99pGMif6wRAlgEAJ98/OgNO3GSiVT2xhDh/xXlkIt60QCgvONa
IAm7tOcTRTCWuSv6teOwvmo=
=ZosM
-----END PGP SIGNATURE-----



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

Date: Thu, 1 May 2003 23:10:02 -0500
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: waste of time
Message-Id: <slrnbb3rsq.2al.tadmc@magna.augustmail.com>

trwww <toddrw69@excite.com> wrote:
> smugbuster@hotmail.com (smugbuster) wrote in message news:<677cff64.0304300948.7e8878c4@posting.google.com>...


>> legitimate questions are disparaged, ridiculed, and made fun of.
>> what's wrong with you people? you were all newbies once!
>> 
> 
> Well, alot of questions that should never get posted to this list do
> get posted here.


The only questions that should not be posted here are questions
that are not about Perl, or ones that can be easily found in
the documentation for the software being used.


> Beginners should use the perl.beginners news group on the nntp server
> nntp.perl.org


Beginner's questions are perfectly OK here.

Questions answered by a perfunctory search of the docs are the "not OK" ones.

(it can be easy to get your mistaken impression as beginners are often
 inept at searching the docs effectively.
)


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


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

Date: Thu, 1 May 2003 23:10:49 -0500
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: What is the best software to run for an aspiring Perl programer?
Message-Id: <slrnbb3ru9.2al.tadmc@magna.augustmail.com>

Thaddeus L. Olczyk <olczyk@interaccess.com> wrote:


> This makes me wonder about you.


That will not keep me awake at night.


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


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

Date: 2 May 2003 04:49:12 GMT
From: sholden@flexal.cs.usyd.edu.au (Sam Holden)
Subject: Re: What is the best software to run for an aspiring Perl programer?
Message-Id: <slrnbb3u67.16k.sholden@flexal.cs.usyd.edu.au>

On Thu, 01 May 2003 20:05:40 GMT,
	Thaddeus L. Olczyk <olczyk@interaccess.com> wrote:
> On Thu, 1 May 2003 06:22:26 -0500, tadmc@augustmail.com (Tad
> McClellan) wrote:
> 
>>Thaddeus L. Olczyk <olczyk@interaccess.com> wrote:
>>> On 30 Apr 2003 11:51:32 -0700, dalgould@hotmail.com (dalgould) wrote:
>>
>>>>What is the best and most avaiable way of testing my perl script from
>>>>my computer itself and not from my web server.
>>
>>
>>> Ok. My best advice is stopaspiring. Not just on Perl
>>> but on programming altogether. You just don't have
>>> the intelligence.
>>
>>
>>Bullshit.
>>
>>Ignorance does not imply a lack of intelligence.
>>
>>
> It's not ignorange. It's a basic lack of problem solving skills.
> When starting to write CGI scripts, thye very first things that a
> programmer should ask are:
> "What is CGI?"
> "How do CGI programs work?"
> "What is the enviroment they run under?"
> In fact the last one is discussed extensively in SCIP's second chapter
> ( the first real chapter ).
> "How would I go about debugging a CGI script?"
> 
> Once these are asked then to a fairly intellegent person a script like
> the one I suggest should be obvious. The fact that it didn't indicates
> that the person doesn't have the intelligence to program.

Wow, you are an arrogant fool aren't you...

Problem solving is something that can be learnt. Sure some people have
more of a knack for it, but nothing that can't be overcome with good
old fashioned honest work.

Learning to problem solve is part of learning to program. Just as learning
boolean logic is part of learning to program.

Instead of pointing someone in the right direction so that they might learn,
your 'help' is to tell them they are too stupid to possibly learn something.

You are an arrogant fool.

> 
> 
>>> open  OUTPUT,">testscript.sh";
>>
>>
>>You should always, yes *always*, check the return value from open():
>>
>>   open OUTPUT, '>testscript.sh' or die "could not open 'testscript.sh' $!";
>>
>>most especially when you aspire to instructing others on how to do it.
>>
> This makes me wonder about you.
> 
> The first ( and obvious ) question is if you should *always* check the
> return value from open(), then why doesn't open require that you do
> so? It would be easy for the implementors to make it so that the
> language requires it: open HANDLE,FILENAME,DIESTATEMENT
> . They don't, so it is not something that you should *always* check
> for.

You should *always* check in code posted to a public forum that less
experienced people read. You should *always* check in code that will be
run more than once. 

And your argument is stupid anyway. Something like:

open(FILE, '>foo') or open(FILE, '>&STDOUT') or die ...

or

die ... unless open(FILE1,'file1')&&open(FILE2,'file2')&&open(FILE3,'file3');

is sometimes needed, your DIESTATEMENT straw man would make that harder.

Also there are more forms of open than just open HANDLE, FILENAME. How
would I do

open FILE or die...;

without it being confused with the more usual form?


-- 
Sam Holden



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

Date: Fri, 02 May 2003 07:03:00 GMT
From: Martien Verbruggen <mgjv@tradingpost.com.au>
Subject: Re: What is the best software to run for an aspiring Perl programer?
Message-Id: <slrnbb4614.3gj.mgjv@verbruggen.comdyn.com.au>

On Thu, 01 May 2003 20:05:40 GMT,
	Thaddeus L. Olczyk <olczyk@interaccess.com> wrote:
> On Thu, 1 May 2003 06:22:26 -0500, tadmc@augustmail.com (Tad
> McClellan) wrote:
> 
>>You should always, yes *always*, check the return value from open():
>>
>>   open OUTPUT, '>testscript.sh' or die "could not open 'testscript.sh' $!";
>>
>>most especially when you aspire to instructing others on how to do it.
>>
> This makes me wonder about you.
> 
> The first ( and obvious ) question is if you should *always* check the
> return value from open(), then why doesn't open require that you do
> so? It would be easy for the implementors to make it so that the

The statement that Tad made does not say that the
language should force you to always do things a certain way, it says
that _you_, as a programmer, should always check these sorts of
things, and it adds that you should especially do that when you are
attempting to teach other people something.

>     It would be easy for the implementors to make it so that the
> language requires it: open HANDLE,FILENAME,DIESTATEMENT
> . They don't, so it is not something that you should *always* check
> for.

It would be easy, would it? Could you please submit a patch for the
perl sources, preferrably through a pragma[1], that would enforce that
the programmer check the return value of open. Remember that I want to
do be able to something like:

if (open(FH, "some_file"))
{
    # Do stuff...
}

or even

my $rc = open(FH, "some_file");
# Do many other things
if ($rc)
{
    # Oops, we had an open() error 50 lines ago, better do something
    # about it here.
}

And I also want to be able to do things without checking, allowing a
fatal error inside eval blocks.

Do you still think it's easy?

> As for this script, it is a quick and dirty one-use script meant to be
> run by a Perl programmer.

You were attempting to teach someone something. When you do, be
prepared to receive criticism of, and additions to your code. Even if
you're not trying to teach, be prepared for those.

Martien

[1] ... so that it is selectable by the user whether they want this
behaviour. I can think of marginal cases where I do not want to check
the return value of open(), but as said, they are marginal.
-- 
                        | 
Martien Verbruggen      | Never hire a poor lawyer. Never buy from a
Trading Post Australia  | rich salesperson.
                        | 


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

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


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