[19766] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 1961 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Oct 19 03:05:40 2001

Date: Fri, 19 Oct 2001 00:05:11 -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: <1003475110-v10-i1961@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Fri, 19 Oct 2001     Volume: 10 Number: 1961

Today's topics:
    Re: Any modules to help printing html files? <jonf@rgb.com>
        Attach a file to email (Andrew Hutchinson)
    Re: Attach a file to email (Logan Shaw)
    Re: Attach a file to email <mbudash@sonic.net>
    Re: Attach a file to email <tintin@snowy.calculus>
    Re: Can't get the output for shell command from CGI <goldbb2@earthlink.net>
    Re: Compiling Error (Rafael Garcia-Suarez)
        How can I know my  current directory before chdir() so  <sj88@cornell.edu>
    Re: How can I know my  current directory before chdir() <theaney@toadmail.toad.net>
    Re: How can I know my  current directory before chdir() blah@blah.blah.invalid
    Re: how can i make perl retreive a web page and save it <qc@apk.net>
    Re: how can i make perl retreive a web page and save it (Martien Verbruggen)
        How do I disambiguate within the curly braces of a tied (Bob)
    Re: How do I disambiguate within the curly braces of a  <kevin@vaildc.net>
    Re: how to get the user logon name with getlogin(). <goldbb2@earthlink.net>
    Re: need value of struct for system() (Garry Williams)
    Re: Perl CGI problem printing Javascript... <goldbb2@earthlink.net>
    Re: Perl remote communication - Is it tcp port, netbios <qc@apk.net>
    Re: POD documentation question (Rafael Garcia-Suarez)
    Re: Problem with output order (Mark Jason Dominus)
    Re: rename return value <bwalton@rochester.rr.com>
    Re: Scaling a DNA string <DocDodge@hotmail.com>
    Re: Scaling a DNA string (Martien Verbruggen)
    Re: Splitting on value pairs <goldbb2@earthlink.net>
    Re: Stange DBI Error (Rafael Garcia-Suarez)
    Re: Stange DBI Error (Martien Verbruggen)
    Re: taint unique to Perl? <djberg96@hotmail.com>
    Re: What changes atime (David Efflandt)
    Re: What changes atime (Tad McClellan)
    Re: Writing and reading encrypted string (password) <goldbb2@earthlink.net>
        www.LearnFromWeb.com provides free tutoring services (David Z.)
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: 19 Oct 2001 01:11:16 GMT
From: "Jon Feldhammer" <jonf@rgb.com>
Subject: Re: Any modules to help printing html files?
Message-Id: <9qnujk$qe9@dispatch.concentric.net>

> > I need to be able to print an html file I generate with a perl program.
> > The problem is if this file goes beyond one page.  I want a header for
the
> > second page, so the program needs to recognize when the second page
begins
> > and the first page ends.
> >
> > Has anyone encountered/worked through this problem before?
>
> What you ask for is impossible to achieve without client side scripting.
The
> server cannot know the size of the browser window on the client (or the
> paper size on the client printer for that matter). And if I'm using e.g.
> large fonts then all bets are off anyway (unless you hardcode the font
size
> which is bad for accessibility).
>
> If you want the concept of a "physical page" then you should use PDF or
> Postscript instead of HTML.
>
> jue

Are there any perl scripts/tools to make html to pdf possible?  I found a
html to ps and a ps to pdf, but the ps to pdb doesn't work right.  They are
useless to me in ps format unfortunately.

Jon




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

Date: Fri, 19 Oct 2001 04:26:44 GMT
From: ahutch@macatawa.org (Andrew Hutchinson)
Subject: Attach a file to email
Message-Id: <3bcfaa3f.24873756@news.vanderbilt.edu>

I'm trying to add functionality to a script that generates several
report files as output.  Currently, I have the reports formatted in
HTML and posting to a intranet site.  However, several people would
like the files emailed directly to them.

I've sent email from scripts before by binding a handle to sendmail,
piping to sendmail, and using Net::SMTP and Mail::Mailer.  However, I
can't seem to find anything on CPAN that allow a file _attachment_.  

Anybody know of anything like this?

TIA,

Andrew Hutchinson
Vanderbilt University Medical Center
Informatics/NCS/Network Security
andrew.hutchinson@vanderbilt.edu


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

Date: 19 Oct 2001 00:04:12 -0500
From: logan@cs.utexas.edu (Logan Shaw)
Subject: Re: Attach a file to email
Message-Id: <9qoc8c$4eq$1@charity.cs.utexas.edu>

In article <3bcfaa3f.24873756@news.vanderbilt.edu>,
Andrew Hutchinson <ahutch@macatawa.org> wrote:
>I'm trying to add functionality to a script that generates several
>report files as output.  Currently, I have the reports formatted in
>HTML and posting to a intranet site.  However, several people would
>like the files emailed directly to them.
>
>I've sent email from scripts before by binding a handle to sendmail,
>piping to sendmail, and using Net::SMTP and Mail::Mailer.  However, I
>can't seem to find anything on CPAN that allow a file _attachment_.  

File attachments are done via MIME.  A MIME message is a
valid mail message, and it can contain attachments.  So, all
you need to is create a MIME message and then send it just
like it's a regular e-mail message (because it is one).

See http://search.cpan.org/search?dist=MIME-tools .
(The overview documentation is under the MIME::Tools module.)

  - Logan
-- 
"In order to be prepared to hope in what does not deceive,
 we must first lose hope in everything that deceives."

                                          Georges Bernanos


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

Date: Fri, 19 Oct 2001 06:27:55 GMT
From: Michael Budash <mbudash@sonic.net>
Subject: Re: Attach a file to email
Message-Id: <mbudash-F54209.23275618102001@news.sonic.net>

In article <3bcfaa3f.24873756@news.vanderbilt.edu>, ahutch@macatawa.org 
wrote:

> I'm trying to add functionality to a script that generates several
> report files as output.  Currently, I have the reports formatted in
> HTML and posting to a intranet site.  However, several people would
> like the files emailed directly to them.
> 
> I've sent email from scripts before by binding a handle to sendmail,
> piping to sendmail, and using Net::SMTP and Mail::Mailer.  However, I
> can't seem to find anything on CPAN that allow a file _attachment_.  
> 
> Anybody know of anything like this?

use MIME::Lite;

hth-
-- 
Michael Budash ~~~~~~~~~~ mbudash@sonic.net


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

Date: Fri, 19 Oct 2001 16:32:51 +1000
From: "Tintin" <tintin@snowy.calculus>
Subject: Re: Attach a file to email
Message-Id: <wPPz7.17$iu3.431216@news.interact.net.au>


"Andrew Hutchinson" <ahutch@macatawa.org> wrote in message
news:3bcfaa3f.24873756@news.vanderbilt.edu...
> I'm trying to add functionality to a script that generates several
> report files as output.  Currently, I have the reports formatted in
> HTML and posting to a intranet site.  However, several people would
> like the files emailed directly to them.
>
> I've sent email from scripts before by binding a handle to sendmail,
> piping to sendmail, and using Net::SMTP and Mail::Mailer.  However, I
> can't seem to find anything on CPAN that allow a file _attachment_.
>
> Anybody know of anything like this?

MIME::Lite

or even

MIME::Lite::HTML




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

Date: Thu, 18 Oct 2001 21:54:18 -0400
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: Can't get the output for shell command from CGI
Message-Id: <3BCF87CA.1A004DF1@earthlink.net>

Carfield Yim wrote:
> 
> > My goodness that's ugly.  There are much better ways of doing that.
> 
> Thx for reply. Yes, that was ugly, because this script suppost only
> know by a few people and as apache run as user apache who can't write
> any files in my system. So there should have no security problem even
> if the script is ulgy, is that right? or it is common
> mis-understanding?

Well, no, but if you can't read it, it's not maintainable.  And if you
can't maintain it, then it's too easy to accidentally introduce security
holes.

> Actually I code java in most of the time but I like perl in some task
> when it done tasks quick and clever. However it waste me so much time
> so I write a jsp to replace it. Why I still ask the question here
> because I am so curious that why the shell command will know my domain
> that I haven't pass it to the command.

The web server knows your domain, and it's the web server which captures
the error output of the CGI and puts it into it's logs [prepended with
the time, domain, etc].

[snip]
> > > The $command can successful run at shell and display the HTML to
> > > stdout, however in this CGI I get the following error:
> > >
> > > /usr/local/bin/java2html: unrecognized option
> > > `--code=http://www.carfield.com.hk/java_store/SUN_j2se_runtime_lib_src_1.4/java/lang/String.java'
> > > can't close file:  at /var/www/cgi-bin/java2html.pl line 14.
> > > [Wed Oct 17 00:50:13 2001] [error] [client 10.0.0.1] Premature end
> > > of script headers: /var/www/cgi-bin/java2html.pl
> > >
> > > why will this happen?
> 
> > Well, the reason for the part in [] about "premature..." is that
> > perl buffers STDOUT, so that the error message created by
> > java2html.java was printed out before your print "content-type:
> > text/html" got done.
> 
> Thx, I will call out.flush() in java but I never do similar thing in
> perl. But it just done the task before...

There are two ways to cause STDOUT to be flushed after every print.  One
is to turn autoflush on.  Look in perlvar to see how to do this.  The
other way is to use IO::Handle, and use the autoflush method:

use IO::Handle;
STDOUT->autoflush(1);

I don't know how you would have autoflush off, and then have one single
[explicit] flush, as you might get from java's out.flush().

> > The reason for the earlier part is that you have the --title after
> > you redirect the input of the program... which the shell doesn't
> > like.
> 
> I have some confusion here. Even if I remove --title, I still get that
> error.

You would have to remove both --title and the argument after.

> And more important, support the shell doesn't like adding
> parameter after redirect.

That's what I said, you put the parameter after the redirect, and it
complained.  You have to put the parameter BEFORE the redirect.

> It should reply some error like file not
> find or illegel option --title... But now the error is illegel option
> --code=http://www.carfield.com.hk/java_store/SUN_j2se_runtime_lib_src_1.4/java/lang/String.java
> where it is the whole query string. That should be happen even shell
> dont' like it. Can you explain more?

I probably could, but I'm not going to bother.  I already told you that
coding in that style isn't the proper way to do what you want.

Don't use open( ... "...|"), use exec(), as below.

> > I would replace your code with the following:
> >
> > #!/usr/bin/perl -w
> > use strict;
> > $| = 1; # turn on autoflush.  Very important sometimes.
> > print "Content-Type: text/html\n\n";
> > open( STDIN, "</server/http/java_store/applet/chat/src" .
> >     "/com/lyrisoft/auth/mysql/Mysql.java" ) or do {
> >     print "<HTML><HEAD></HEAD><BODY><XMP>\n";
> >     print "Couldn't open Mysql.java: $!\n";
> >     print "</XMP></BODY></HTML>\n";
> >     exit;
> > };
> > {   # extra {} to disable warning "Statement unlikely to be reached"
> >     exec( qw( /usr/local/bin/java2html
> >         --title "powered by java2html from gun.org"
> >     ) );
> > }
> > print "<HTML><HEAD></HEAD><BODY><XMP>\n";
> > print "Exec java2html failed: $!\n";
> > print "</XMP></BODY></HTML>\n";
> > __END__
> 
> > This is a much cleaner way to run your program than via open.
> > NB: This code is untested.

Try the code above, and tell me what your results are.

-- 
"What does stupid old man mean pidgin talk?
Shampoo does not talk like a bird."


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

Date: 18 Oct 2001 07:06:14 GMT
From: rgarciasuarez@free.fr (Rafael Garcia-Suarez)
Subject: Re: Compiling Error
Message-Id: <slrn9ssvra.1dv.rgarciasuarez@rafael.kazibao.net>

Peter Reid wrote in comp.lang.perl.misc:
} Whenever I use perlcc to compile a script into an executable, I ALWAYS get
} the following error:
} 
} "Use of uninitialized value in C:/Perl/lib/B.pm line 194"
} 
} written lots of times and then
} 
} "Unassigned value assigned to typeglob at C:/perl/lib/B.pm line 192
} Compiling C(tester) for tester.pl!
} Couldn't open!"
} 
} (I was trying to compile a file called "tester.pl" but it doesn't work with
} any filenames).
} 
} I use Win98 with ActiveState Perl 5.005_003

Looks like a bug in the compiler suite. Upgrade to a more recent perl.

-- 
Rafael Garcia-Suarez / http://rgarciasuarez.free.fr/


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

Date: Thu, 18 Oct 2001 22:33:36 -0400
From: "Shi Jin" <sj88@cornell.edu>
Subject: How can I know my  current directory before chdir() so I can return ?
Message-Id: <20011018.223336.1239036029.3814@jinshi.dhs.org>

I want to know how to get the current directory.
Please help me.
thanks


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

Date: 18 Oct 2001 23:00:31 -0400
From: Tim Heaney <theaney@toadmail.toad.net>
Subject: Re: How can I know my  current directory before chdir() so I can return ?
Message-Id: <87n12otju8.fsf@susie.watterson>

"Shi Jin" <sj88@cornell.edu> writes:
>
> I want to know how to get the current directory.

  use Cwd;
  $dir = cwd;


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

Date: Fri, 19 Oct 2001 03:06:23 -0000
From: blah@blah.blah.invalid
Subject: Re: How can I know my  current directory before chdir() so I can return ?
Message-Id: <tsv65f545h773a@corp.supernews.com>

Shi Jin <sj88@cornell.edu> wrote:
> I want to know how to get the current directory.
> Please help me.
> thanks

use Cwd;

It's probably the easiet and most portable way to go.  It's also a core
perl module.

-- 
Eric Wong
eric+pgp@taedium.com                        http://www.taedium.com/pgp.txt


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

Date: Fri, 19 Oct 2001 01:05:31 GMT
From: Pat Gunn <qc@apk.net>
Subject: Re: how can i make perl retreive a web page and save it to my website?
Message-Id: <3BCF7D24.8020201@apk.net>

Tad McClellan wrote:

> [ Please put your text *following* the quoted text that you are
>   commenting on.
> 
>   Please do not quote an entire article.
> 
>   Please do not quote .signatures
> 
>   Please see: http://www.geocities.com/nnqweb/nquote.html
> 
>   Thank you.
> 
>   Text rearranged into actual chronology.
> ]
> 
> 
> ']['rull <trullock@yahoo.com> wrote:
> 
>>"Tad McClellan" <tadmc@augustmail.com> wrote in message
>>news:slrn9strnp.p4l.tadmc@tadmc26.august.net...
>>
>>>']['rull <trullock@yahoo.com> wrote:
>>>
>>>
>>>>im absolutely fine when i have got the page saved, its just making perl
>>>>fetch it.

Is it just me, or is the above message really really funny considering
where Tad's addition is? :)



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

Date: Fri, 19 Oct 2001 06:22:09 GMT
From: mgjv@tradingpost.com.au (Martien Verbruggen)
Subject: Re: how can i make perl retreive a web page and save it to my website?
Message-Id: <slrn9svhkh.e62.mgjv@verbruggen.comdyn.com.au>

On Fri, 19 Oct 2001 01:05:31 GMT,
	Pat Gunn <qc@apk.net> wrote:
> Tad McClellan wrote:
> 

[snip stuff about keeping articles and threads sane]

>> 
>> ']['rull <trullock@yahoo.com> wrote:
>> 
>>>"Tad McClellan" <tadmc@augustmail.com> wrote in message
>>>news:slrn9strnp.p4l.tadmc@tadmc26.august.net...
>>>
>>>>']['rull <trullock@yahoo.com> wrote:
>>>>
>>>>
>>>>>im absolutely fine when i have got the page saved, its just making perl
>>>>>fetch it.
> 
> Is it just me, or is the above message really really funny considering
> where Tad's addition is? :)

Not really. Tad's additions to the actual thread were after the quoted
text. It is quite customary to put comments that are of a general
nature, and not relevant to the content of the message/thread before
the attribution, often marked with square or curly brackets. Quite
like Tad did, actually.

Martien
-- 
Martien Verbruggen              | 
                                | 42.6% of statistics is made up on the
Trading Post Australia Pty Ltd  | spot.
                                | 


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

Date: Thu, 18 Oct 2001 18:54:11 -0700
From: null@null.com (Bob)
Subject: How do I disambiguate within the curly braces of a tied hash reference?
Message-Id: <null-1810011854110001@user176.lwpw-01.cwia.com>

It is my understanding that one disambiguates variable names from
contigous text by using curly braces as in: 

print "${foo}'s scripts suck";

How does one disambiguate within the curly braces of a reference to a DBM
data file which already contains opening and closing curly braces?

I want to do this:

print $datafile{$fooG.shtml};

I have tried it several ways without success. $foo is obviously the
variable and what follows is constant. Disambiguating with curly braces
has not worked for me. I have tried several combinations of braces and
quotes.

Any help would be appreciated.


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

Date: Thu, 18 Oct 2001 22:43:52 -0400
From: Kevin Michael Vail <kevin@vaildc.net>
Subject: Re: How do I disambiguate within the curly braces of a tied hash reference?
Message-Id: <181020012243526705%kevin@vaildc.net>

In article <null-1810011854110001@user176.lwpw-01.cwia.com>, Bob
<null@null.com> wrote:

> It is my understanding that one disambiguates variable names from
> contigous text by using curly braces as in: 
> 
> print "${foo}'s scripts suck";
> 
> How does one disambiguate within the curly braces of a reference to a DBM
> data file which already contains opening and closing curly braces?
> 
> I want to do this:
> 
> print $datafile{$fooG.shtml};

print $datafile{"${foo}G.shtml"};

If this doesn't do it, we need to see some code.

-- 
Kevin Michael Vail | a billion stars go spinning through the night,
kevin@vaildc.net   | blazing high above your head.
 . . . . . . . . .  | But _in_ you is the presence that
 . . . . . . . . . | will be, when all the stars are dead.  (Rainer Maria Rilke)


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

Date: Thu, 18 Oct 2001 22:17:51 -0400
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: how to get the user logon name with getlogin().
Message-Id: <3BCF8D4F.6B60E8F7@earthlink.net>

WebBat wrote:
> 
> All,
> 
> I need to find the user logon name. but each time i try using
> getlogin, it returns the user name on the server not the client.

This is a CGI question, not a perl question, but I'll answer it for you
anyway.

One way is to look in the REMOTE_IDENT environment variable.  Most web
servers won't bother to fill this in for you, but you can read RFC 931
yourself and try and find the userid using the method described there.
[Note, if REMOTE_IDENT is filled in by your httpd, will should be
identical to whatever results you would get from doing the RFC 931 thing
yourself]

Another way is to request Basic type authentification.  This is useful
since even with cookies disabled, the browser will, once the person at
the keyboard has entered a username and password, continue to send that
same username and password with each request to that site, until the
browser exits.

A third way is to use a form to request a username.  You would then use
a cookie to have their browser remember it and send it with future
requests to you.

A fourth way is to use a form to request a username, and then store it
and their ip [from the REMOTE_ADDR environment variable] in a database,
and on future requests, lookup the name using the ip as a key.
This is generally considered evil, since many folks have dynamic ips.

Last is to try a hybrid approach.  For example, first try to use ident.
If it works, and if the name produced isn't some kind of microsoft
default, like "Preferred Customer", then use it.  If it doesn't work,
then use one of the other approaches.

-- 
"What does stupid old man mean pidgin talk?
Shampoo does not talk like a bird."


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

Date: Fri, 19 Oct 2001 03:21:24 GMT
From: garry@ifr.zvolve.net (Garry Williams)
Subject: Re: need value of struct for system()
Message-Id: <slrn9sv71k.li6.garry@zfw.zvolve.net>

On Thu, 18 Oct 2001 23:15:07 GMT, Tad McClellan <tadmc@augustmail.com> wrote:
> MJ <bogus@bogus.com> wrote:
>>
>>	if ( system("rcp $RCCVAR/$vc->vm1 $system1:$RCCVAR/$vc->vm1") ) {
>>             # code to print error
>                      ^^^^^^^^^^^^^^
> 
> Code in this block executes when there is NO error!

It depends on what you call an error: 

  $ perl -wle 'print system "true"'
  0
  $ perl -wle 'print system "false"'
  65280
  $ perl -wle 'print system "no_such"'
  Can't exec "no_such": No such file or directory at -e line 1.
  -1
  $ 

A non-zero return code from a command is _usually_ considered an
error.  

-- 
Garry Williams


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

Date: Fri, 19 Oct 2001 01:37:38 -0400
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: Perl CGI problem printing Javascript...
Message-Id: <3BCFBC22.2DD4B866@earthlink.net>

Brian Carlson wrote:
> 
> I have a perl cgi script, that when ran, prints out javascript.  I
> have the following in my page....
> 
> <SCRIPT LANGUAGE="Javascript" SRC="www.pschallenge.com/cgi-bin/bc.pl"
> type="text/javascript">
> </script>
> 
> This doesn't work.  I don't get the perl JS code ran on the browser.
> But when I run the perl code from the command line, and paste it in
> the page, it runs fine.
> 
> Any thoughts?

Does it run properly as a CGI program?  That is, if you open in your
browser:

    http://www.pschallenge.com/cgi-bin/bc.pl

Does it work?

Also, when the program prints out the CGI header, does it print
"Content-Type: text/javascript\n\n" or some other type?

To ease debugging, I would suggest doing:
if( $ENV{HTTP_REFERER} ) {
    print "Content-Type: text/javascript\n\n";
} else {
    print "Content-Type: text/plain\n\n";
}

Assuming of course that a "Referer" field is supplied when a page is
fetched via <SCRIPT SRC=...>, but not when you type in a url by hand.

-- 
"What does stupid old man mean pidgin talk?
Shampoo does not talk like a bird."


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

Date: Fri, 19 Oct 2001 01:09:22 GMT
From: Pat Gunn <qc@apk.net>
Subject: Re: Perl remote communication - Is it tcp port, netbios or what?
Message-Id: <3BCF7E0C.1060805@apk.net>

Alessandro Augusto wrote:

> I would like to know what kind of communication does Perl uses
> to connect to remote computers?
> 
> I use Win32::TieRegistry. Does it uses TCP/IP? Netbios? what
> port does it use? RPC?
> 
> I don't understant what kind of communication does it use, because
> using the modules, you just have to specify the remote computers
> names, and I don't know whats under it.
> 
> Can someone give me a brieth explanation about it?
> 
> Ps. I'm asking because, suppose it use some especify tcp port, i
> can create a IPSec policy for the communication between my computers
> when using the perl scripts.


You might have better luck if you phrase your question,
"How does Win32::TieRegistry connect to remote systems?".
Perl can use many different mechanisms to talk to remote
systems, and it's only how Win32::TieRegistry works that
interests you.



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

Date: 18 Oct 2001 08:12:23 GMT
From: rgarciasuarez@free.fr (Rafael Garcia-Suarez)
Subject: Re: POD documentation question
Message-Id: <slrn9st3na.e0d.rgarciasuarez@rafael.kazibao.net>

Warren L Dodge wrote in comp.lang.perl.misc:
} I want to do some pod documentation for the programs I have written. It looks
} as though it can do most of what I want to do.
} 
} I have many programs which actually do multiple functions depending on how the
} program is called. I would like to write the POD documentation such that it can
} be output into multiple files of data. One for each function of the program.
} 
} I don't see how I could do this as I read the manual.

Sorry, but I don't really understand what to want to do. Split your POD
doc into multiple files, or generate multiple files with common sections
from one POD file ?

} Am I missing something? Ideas?

My suggestion is that you should look at Pod::Select and the podselect
utility.

-- 
Rafael Garcia-Suarez / http://rgarciasuarez.free.fr/
Could Marconi have invented the radio if he hadn't by pure chance
spent years working at the problem? -- Monty Python, Penguins


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

Date: Fri, 19 Oct 2001 04:28:33 GMT
From: mjd@plover.com (Mark Jason Dominus)
Subject: Re: Problem with output order
Message-Id: <3bcfabf0.2fe9$12d@news.op.net>

In article <3BCEDAF5.4040908@Clapham.org>,
Chris Hall  <Chris@Clapham.org> wrote:
>> You should set STDOUT to autoflush:
>> 	my $oldfh = select STDOUT; $|=1; select $oldfh;
>
>
>Thankyou, that's got it
>

You may want to read the article 'Suffering from Buffering', which
discusses this problem and the solution in some detail, under the
heading "My output is coming out in the wrong order!".

http://perl.plover.com/FAQs/Buffering.html

-- 
@P=split//,".URRUU\c8R";@d=split//,"\nrekcah xinU / lreP rehtona tsuJ";sub p{
@p{"r$p","u$p"}=(P,P);pipe"r$p","u$p";++$p;($q*=2)+=$f=!fork;map{$P=$P[$f^ord
($p{$_})&6];$p{$_}=/ ^$P/ix?$P:close$_}keys%p}p;p;p;p;p;map{$p{$_}=~/^[P.]/&&
close$_}%p;wait until$?;map{/^r/&&<$_>}%p;$_=$d[$q];sleep rand(2)if/\S/;print


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

Date: Fri, 19 Oct 2001 01:56:57 GMT
From: Bob Walton <bwalton@rochester.rr.com>
Subject: Re: rename return value
Message-Id: <3BCF8883.BDE608F9@rochester.rr.com>

Andrew Fry wrote:
> 
> Im using rename to rename directories and files in a tree.
> It renames all files OK, but not the directories.
> However, the odd thing is that it returns 0 (false) in ALL cases - even upon
> success.
> I dont understand - the books say it returns 1 (true) upon success. What's
> going on ?
> ---
> Andrew F

From perldoc -f rename:

"Behavior of this function varies wildly depending on your system
implementation. For example, it will usually not work across file system
boundaries, even though the system mv command sometimes compensates for
this. Other restrictions include whether it works on directories, open
files, or pre-existing files. Check the perlport manpage and either the
rename(2) manpage or equivalent system documentation for details."

Thus, you'll need to let us know your platform, OS and version, and
probably Perl version.  The doc's do say rename returns true for success
and false otherwise; however, that might possibly vary by platform also
-- if whatever implements rename for Perl on your platform doesn't
return good error codes, Perl probably won't either.
-- 
Bob Walton


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

Date: Thu, 18 Oct 2001 22:09:35 -0400
From: "DocDodge" <DocDodge@hotmail.com>
Subject: Re: Scaling a DNA string
Message-Id: <9qo1nr$1r4$1@bob.news.rcn.net>

Hi,

I've finally arrived back were I can post to this newsgroup, and I see that
people have been posting great responses all day long.  The answer to my
problem might lie in this thread; it will take me a while to wrap my mind
around some of the more complicated perl.  But her is a clarification of the
biology of the problem.

Martien is right; I am just looking for some decent compression so that the
data is more visually manageable.  What I didn't tell you is that I have
hundreds of these strings, that correspond to hundreds of genes and that I'm
going to need to print this out on ordinary letter size paper.  Here is what
that might look like when done (requires a non-proportional font to look
right):


--------G--------------------G---------- gene A
----------------CG--G------------------- gene B
---------------G-G-C--C----------------- gene C
-----------G---------------------------- gene D
---------------------------------------- gene E
--C------------------------------------- gene F
---------------GGG--C--G------------G--- gene G
---------------------------------------- gene H
-----------C---------------------------- gene I

In this example, each string was derived from 2000 characters, so each dash
or letter represents 50 characters.  A dash means that in those 50
characters, no motifs are found.  A "G" or "C" means that in those 50
characters, one or more motifs were found.  I know the resolution of exactly
were the motifs lie is not so good, but when I look at this I can gleam a
lot of information.  You see, I know what these genes do in most cases.  And
if I know that gene B, gene C, and gene G are all involved in cancer, that
cluster of motifs at about the 1000 character mark has meaning.  This
pattern would not be likely to occur by chance, and so I will perform some
biological experiments to see if the GGGG or CCCC are found near other
cancer genes, or what the motif can do to ordinary genes.

Martin asked the clever question:

"GGGG--CCCC" => G or C or something else?

"GGGG-GGGG-" => Only one G? or something else?

To the latter, initially I called a single GGGG in a region "g" while more
than one motif garnered a "G", but when I started to have trouble scaling I
eliminated that complications from my code.  The answer to the former is the
same.  It would be usefully to call a region with both GGGG and CCCC in it
some other letter (S perhaps) but I'm still taking baby steps He also asked
what I want to do with motifs that straddle the boundary.  The answer is,
put the mark on one side or the other but not both.  Which side does not
really matter, in the total 2000 characters I won't be off by that much.

Some wonder what exactly defines a motif.  Is it GGGG or GGGGG  and is
GGGGGGGG one motif or two.  The answer is flexible.  Eight G's in a row is
certainly two motifs; four G's is one motif.  Between 4 and 8 could be one
or two motifs, whatever is easier to implement.  I've been calling it one
motif for now.

Finally, sorry for not having a stitch of perl code in this post.  I'll be
up much of the night working on this problem, so if the interest is still
there tomorrow perhaps I can say more.






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

Date: Fri, 19 Oct 2001 06:09:01 GMT
From: mgjv@tradingpost.com.au (Martien Verbruggen)
Subject: Re: Scaling a DNA string
Message-Id: <slrn9svgrs.e62.mgjv@verbruggen.comdyn.com.au>

On Thu, 18 Oct 2001 22:09:35 -0400,
    DocDodge <DocDodge@hotmail.com> wrote:
> Hi,
> 
> I've finally arrived back were I can post to this newsgroup, and I see that
> people have been posting great responses all day long.  The answer to my
> problem might lie in this thread; it will take me a while to wrap my mind
> around some of the more complicated perl.  But her is a clarification of the
> biology of the problem.

Ok, now that a few of the questions have been settled, here's a small
subroutine that (I think) does what you want. It seems rather longish,
but most of it is comments.

Before relying on its correctness, let it float around this group for
a few days. I suspect that I made an error here or there, or that
someone has a faster way to do what I do with my two substitutions.
Also, it is possible that I still have misunderstood things.

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

# For this example, data file contents should be
#  CGACCACCGGCTATGGTTACCCGTGCGTCCATCC Name of gene

while (<>)
{
    my ($gene, $name) = split ' ', $_, 2;
    my $pgene = parse_gene($gene, 40);
    print "$pgene $name";
}

# parse_gene($gene, $sample_len)
# 
# Break up a gene in $sample_len blocks. For each block, output
# 
#  -        if nothing interesting was found
#  c or g   if one C or G motif was found
#  C or G   if more than one C(G) motif was found
#  *        if at least one C and one G motif were found.
# 
# A motif is defined as a succession of exactly 4 C or G. 
# 
# Boundary conditions:
# 
# If a motif straddles a boundary between two samples, the right most
# sample will get this motif counted.

sub parse_gene
{
    my $gene       = shift;
    my $sample_len = shift || 50;
    my $pgene      = "";

    # Split up the gene in blocks of specified length
    #
    # If length($gene) is not a multiple of $sample_len, the last
    # sample will be shorter than the others.
    my @samples = $gene =~ m#.{1,$sample_len}#g;

    while (my $sample = shift @samples)
    {
        # Count the number of C and G motifs entirely within the
        # string
        my $ng = () = $sample =~ /G{4}/g;
        my $nc = () = $sample =~ /C{4}/g;

        # Find the largest number of G or C at the end of the sample
        # that have not already been counted. 
        # First remove everything which isn't a block of G or C at
        # the end, and reset $sample if there is no match.
        # Then remove all blocks that have already been counted
        # This could be done in one go, but the backtracking slows
        # things down unnecessarily. two steps is much faster.
        $sample =~ s/.*?(G+|C+)\z/$1/ or $sample = "";
        $sample =~ s/(G{4}|C{4})+//;

        if ($sample)
        {
            # We have found a possible start of a motif at the end of
            # the current string. We simply prepend it to the next
            # sample so it can be counted there. We only do this, if
            # there is a next sample.
            $samples[0] = $sample . $samples[0] if @samples;
        }

        $pgene .= ($ng && $nc) ? "*"
                : ($ng  > 1  ) ? "G"
                : ($ng == 1  ) ? "g"
                : ($nc  > 1  ) ? "C"
                : ($nc == 1  ) ? "c"
                :                "-" ;
    }

    return $pgene;
}
__END__

I used this program to generate 'test genes':

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

# gen_gene($len, $sample_len)
# 
# Create a "gene" of length $len (default 2000) with samples of length
# $sample_len (default 6). Both arguments are optional.
# Repeatedly pick a random $sample_len section from a template.
#
sub gen_gene
{
    # The srand is here to create reproducibility.
    BEGIN { srand 123456 }

    my $template   = "ACCACCGGTCCATCAGGGTGGTTACCGTGCCCAATCCGTCTGGGCTATTCAGTC";
    my $len        = shift || 2000;
    my $sample_len = shift || 6;
    my $out        = "";

    while (length $out < $len)
    {
        my $off = int(rand length($template) - $sample_len);
        $out .= substr $template, $off, $sample_len;
    }
    return substr $out, 0, $len;
}

print gen_gene(2000), " gene $_\n" for ("A".."F");
__END__


output of:

$ ./gen_gene.pl | dna.pl
--g--gc---------g-ggc------g------c---*------g---- gene A
---------*cgcg-c-----g--c--c*gg-----------g----c-- gene B
-c--c------c------c-----g-----g---cggcg*---c--g-c- gene C
-----g------g----c-----*-----gcgc-----g-----cgG--- gene D
C--g--C------gg--gg-------g-g---G-g---cc-----*---- gene E
-g-c--c-g-c----g------g--Cgc-----gg----------ggcc- gene F

I suspect that my test genes don't really represent nature very well.
Your example didn't contain quite as many hits as I'm seeing here :)

If you're on a system with a different rand() than mine, your genes
will vary :) I don't want to post the full fake genes I used, since
that would be 6 x 2000 bytes or so. Bit too much.

Martien
-- 
Martien Verbruggen              | 
                                | Unix is user friendly. It's just
Trading Post Australia Pty Ltd  | selective about its friends.
                                | 


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

Date: Fri, 19 Oct 2001 01:17:38 -0400
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: Splitting on value pairs
Message-Id: <3BCFB772.DF69FC5F@earthlink.net>

Tintin wrote:
> 
> I'm trying to parse a WELF (Webtrends Extended Log Format) file.
> 
> Each record is on a single line terminated by CRLF, and each field is
> a simple id/value pair.  Each field is separated by whitespace, but if
> there is whitespace in the value, it is enclosed in quotes.  For
> example:
> 
> id=firewall time="2001-10-14 12:01:05" fw=199.9.9.9 src=199.9.9.9
> 
> Obviously, I could do a simple split (if all values had no whitespace)
> to get each value pair, but how do I cater for the quoted values?

my %line = m[([^ =]+)=("[^"]*"|\S*)]g;
s/^"([^"]*)"$/$1/ foreach @line{keys %line};

> Utimately, I want to have all the fields in a hash.

-- 
"What does stupid old man mean pidgin talk?
Shampoo does not talk like a bird."


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

Date: 19 Oct 2001 06:34:48 GMT
From: rgarciasuarez@free.fr (Rafael Garcia-Suarez)
Subject: Re: Stange DBI Error
Message-Id: <slrn9svicc.ri6.rgarciasuarez@rafael.kazibao.net>

Brad wrote in comp.lang.perl.misc:
} Howdy,
} 
} I installed DBI, DBD, MySQL modules on a sun4u sparc without error.
} 
} MySQL client works fine. (from command line)
} 
} But Perl says this:
} 
} my $dbh = DBI->connect("DBI:mysql:user=root;database=NETWORK",
} {'RaiseError' => 1});
} 
} -- error message --
} ld.so.1: /usr/local/bin/perl: fatal: relocation error: file
} /usr/local/lib/perl5/site_perl/5.6.1/sun4-solaris/auto/DBD/mysql/mysql.so:
} 
} symbol mysql_init: referenced symbol not found
} Killed
} 
} Does anyone have any idea what I can do to fix? Checked numerous mailing
} list archives addressing this issue, though I did not see any conclusive
} suggestions...

Give us more info :
    What's the OS?
    Which compiler has been used to compile perl ? (enter "perl -V:cc"
    at the command-line to get this info)
    Which compiler has been used to compile MySQL and the DBD::mysql
    modules ? (have you installed MySQL from source) ?
    Does these two compilers match ?

-- 
Rafael Garcia-Suarez / http://rgarciasuarez.free.fr/


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

Date: Fri, 19 Oct 2001 06:46:25 GMT
From: mgjv@tradingpost.com.au (Martien Verbruggen)
Subject: Re: Stange DBI Error
Message-Id: <slrn9svj21.e62.mgjv@verbruggen.comdyn.com.au>

On 19 Oct 2001 06:34:48 GMT,
	Rafael Garcia-Suarez <rgarciasuarez@free.fr> wrote:
> Brad wrote in comp.lang.perl.misc:
> } Howdy,
> } 
> } I installed DBI, DBD, MySQL modules on a sun4u sparc without error.

And you ran the tests without problem?

> } MySQL client works fine. (from command line)
> } 
> } But Perl says this:
> } 
> } my $dbh = DBI->connect("DBI:mysql:user=root;database=NETWORK",
> } {'RaiseError' => 1});
> } 
> } -- error message --
> } ld.so.1: /usr/local/bin/perl: fatal: relocation error: file
> } /usr/local/lib/perl5/site_perl/5.6.1/sun4-solaris/auto/DBD/mysql/mysql.so:

Most likely the mysql shared libraries are not in the path that your
runtime linker searches. Check the documentation for your runtime
linker to fix that. Most likely you can fiddle with LD_LIBRARY_PATh or
LD_RUN_PATH.

Your mysql client probably works because it was linked with this
information supplied to the compile time linker (via -R or so).

> } symbol mysql_init: referenced symbol not found
> } Killed
> } 
> } Does anyone have any idea what I can do to fix? Checked numerous mailing
> } list archives addressing this issue, though I did not see any conclusive
> } suggestions...
> 
> Give us more info :
>     What's the OS?

It's Solaris, we just don't know the version, and in this case, that's
quite important if the OP wants more precise information. However,
this information should probably be asked for on a Solaris group.

>     Which compiler has been used to compile perl ? (enter "perl -V:cc"
>     at the command-line to get this info)
>     Which compiler has been used to compile MySQL and the DBD::mysql
>     modules ? (have you installed MySQL from source) ?
>     Does these two compilers match ?

Could be relevant, but since the MySQL module compiled, tested (I
assume) and installed, I suspect that's not it.

Martien
-- 
Martien Verbruggen              | 
                                | True seekers can always find
Trading Post Australia Pty Ltd  | something to believe in.
                                | 


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

Date: Fri, 19 Oct 2001 03:44:01 GMT
From: "Daniel Berger" <djberg96@hotmail.com>
Subject: Re: taint unique to Perl?
Message-Id: <5kNz7.11975$CN5.940486@typhoon.mn.mediaone.net>


"Miko O'Sullivan" <miko@idocs.com> wrote in message
news:db27ea77.0110181417.261f2ffb@posting.google.com...
> I hope this is considered on-topic.  I couldn't find an
> everything_except_perl newsgroup.  :-)
>
> Is tainting unique to Perl?  What other languages, if any, have this
> cool built-in concept?   I'm writing a presentation about Perl and
> I'll use tainting as one of the selling points for Perl, but it would
> help to know if any other languages use tainting also.
>
> -Miko
> Just another marketer who hacks perl

Ruby has taint-checking as well, though the implementation is different,
using "safe levels" and several built-in methods.  See the following link:

http://www.rubycentral.com/book/taint.html

Regards,

Mr. Sunblade

PS - Python probably has it, too




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

Date: Fri, 19 Oct 2001 01:05:14 +0000 (UTC)
From: efflandt@xnet.com (David Efflandt)
Subject: Re: What changes atime
Message-Id: <slrn9suv2a.rar.efflandt@typhoon.xnet.com>

On 18 Oct 2001, michael.e.grimes.nospam@fritolay.com 
<michael.e.grimes.nospam@fritolay.com> wrote:
> 
> I am on an NT box and need to write a little script to perform some file
> management. In particular, I have an FTP server and once a file has been
> accessed, I would like to move it to another directory. I thought fine, I
> will work with the stat function's atime variable. Trouble is , I can not
> make the variable change unless I edit and save the file (this also changes
> the mtime variable). After all, you have to access the file to modify it, but
> I don't expect FTP clients to be editing my files!!! I have a test script to
> watch what is happening:
> (snip) 
> Is there a GURU out there who can tell me what constitutes an "access"
> (something that will update the atime variable) or, maybe someone has done
> this already and can point me in the right direction.

I imagine that atime is only useful on a file system that keeps track of 
file access.  Windows apparently does not.  Unix (or Linux) does:

> pico test.txt (an editor)
> date
Thu Oct 18 19:49:42 CDT 2001
> cat test.txt (read file)
This is test text
> date
Thu Oct 18 19:51:28 CDT 2001
> ./mytest test.txt
file: test.txt
mtime: Thu Oct 18 19:49:40 2001
atime: Thu Oct 18 19:51:26 2001

The differnce between this and the date command was the 2 seconds it took 
me to type 'date'.

-- 
David Efflandt - All spam is ignored - http://www.de-srv.com/
http://www.autox.chicago.il.us/  http://www.berniesfloral.net/
http://cgi-help.virtualave.net/  http://hammer.prohosting.com/~cgi-wiz/


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

Date: Fri, 19 Oct 2001 02:19:21 GMT
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: What changes atime
Message-Id: <slrn9sv0q0.r4l.tadmc@tadmc26.august.net>

michael.e.grimes.nospam@fritolay.com <michael.e.grimes.nospam@fritolay.com> wrote:

>I am on an NT box and need to write a little script to perform some file
>management. In particular, I have an FTP server and once a file has been
>accessed, I would like to move it to another directory. I thought fine, I
>will work with the stat function's atime variable.


>Is there a GURU out there who can tell me what constitutes an "access"


That is not a Perl question. That is an OS question, best asked
in an applicable OS newsgroup, such as comp.os.ms-windows.*


>(something that will update the atime variable) 


   perldoc -f utime


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


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

Date: Thu, 18 Oct 2001 21:40:58 -0400
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: Writing and reading encrypted string (password)
Message-Id: <3BCF84AA.9C1C2F70@earthlink.net>

Lars Oeschey wrote:
> 
> On Wed, 17 Oct 2001 22:42:38 GMT, Bart Lateur <bart.lateur@skynet.be>
> wrote:
> 
> >But what if the key is a digest  (MD::Digest, a CRC or something like
> >that) of the script itself? Once the hacker edits the source to get
> >at
> 
> That's a cool idea indeed. I also thought about it today when looking
> at the Blowfish module. But how could I get a CRC of the script source
> itself from within the program? (First I thought about using the
> source of the prog itself as key, but that would be too long)

For a MD5 digest, something like this should work:

#!/usr/local/bin/perl -w
use strict;
use Digest::MD5;
seek DATA, 0, 0;
print Digest::MD5->new->addfile(\*DATA)->hexdigest, "\n";
__END__

For a simple CRC, then something like this should work:
#!/usr/local/bin/perl -w
use strict;
seek DATA, 0, 0;
print pack("H*",unpack "%32C*", do { local $/; <DATA>} ), "\n";
__END__

However, there is a serious problem with this idea if you expect it to
provide any serious amount of security:  An attacker merely has to first
calculate the digest or checksum of the perl program using an external
program, and when editing the file, replace the code which would
calculate the digest with a hardcoded value, which would be the
digest/checksum from before he started editing.

In other words, it's no more secure than using base64 encoding, or
uuencoding, or any other unkeyed system.

You might as well say:
   $encoded = pack "u", $original;
   $decoded = unpack "u", $encoded;

-- 
"What does stupid old man mean pidgin talk?
Shampoo does not talk like a bird."


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

Date: 18 Oct 2001 21:57:05 -0700
From: netb2b@yahoo.com (David Z.)
Subject: www.LearnFromWeb.com provides free tutoring services
Message-Id: <4b502fe8.0110182057.15c16025@posting.google.com>

www.LearnFromWeb.com provides free tutoring services on computer
programming, networking, web designing and other subjects. Its
standard service is free to anyone.


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

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


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