[7836] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 1461 Volume: 8

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Dec 12 11:17:23 1997

Date: Fri, 12 Dec 97 08:00:25 -0800
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, 12 Dec 1997     Volume: 8 Number: 1461

Today's topics:
     Re: A ^M question. (Gabor)
     Re: a certain bug...!!! (Brandon S. Allbery KF8NH; to reply, change "void" to "kf8nh")
     Re: a certain bug...!!! (Tad McClellan)
     Re: a simple question (Mike Stok)
     Re: accessing a file in directory other than cgi script (Tad McClellan)
     Re: Basic beginner quesition <twolf@sampo.creighton.edu>
     Call a script automatically from a webpage <Webmaster@builders-connection.com>
     Re: Chunking up a large input file (Tad McClellan)
     date conversation ??? (Sigi)
     Re: date conversation ??? <xxTony.Curtis@vcpc.univie.ac.at>
     Re: Encryption <barnett@houston.Geco-Prakla.slb.com>
     Re: eof and low level io <qdtcall@esb.ericsson.se>
     eval / variable scope problem <bruno_pagis@aur.alcatel.com>
     Re: File Sorting with UNIX from Perl <$_=qq!fearless\@NOSPAMio.com!;y/A-Z//d;print>
     Re: Foreach, array, s/// problem <bruno_pagis@aur.alcatel.com>
     Re: Foreach, array, s/// problem (Andrew M. Langmead)
     Re: how to hide .pl file (Brandon S. Allbery KF8NH; to reply, change "void" to "kf8nh")
     Re: just starting with perl <$_=qq!fearless\@NOSPAMio.com!;y/A-Z//d;print>
     Re: Memory leak in perl 5.004_04 (Ken)
     Re: mkdir command (Gabor)
     Re: newbie: compact an array <brossard@bch.umontreal.ca>
     Perl Programmers wanted! <joedevon@travelin.com>
     Re: Perl support for the long long type <vincent.joseph@usa.net>
     Re: Q: I can't print to a file. (Tad McClellan)
     Socket problems <A.P.Hope@btinternet.com>
     Re: Socket problems <gbarr@ti.com>
     Re: Socket woes.... (Andrew M. Langmead)
     Threading in NT <jeffery@mitre.org>
     Re: what does qq() do? <rets@meta3.com>
     Write in file from perl body <postmaster@ivan.udm.ru>
     Digest Administrivia (Last modified: 8 Mar 97) (Perl-Users-Digest Admin)

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

Date: 12 Dec 1997 13:47:30 GMT
From: gabor@vinyl.quickweb.com (Gabor)
Subject: Re: A ^M question.
Message-Id: <slrn692foj.cls.gabor@vinyl.quickweb.com>

- T. Jones wrote:
- 
- What is a way to delete those stupid ^M's at the end of each line of my
- downloaded flat files?
- 
- Thanks,
- Tj
- 
- --
- Very funny scotty!  Now beam down the rest of my clothes.

your options are

tr -d \\r < infile > outfile
or
perl -pi -e 'tr/\r//d' [files]
or
perl -pi -e 's/\r$//' [files]

if you want to do it on more than one file I recommend the 'perl way'

gabor.
--
    Even if you aren't in doubt, consider the mental welfare of the person who
    has to maintain the code after you, and who will probably put parens in
    the wrong place.
        -- Larry Wall in the perl man page 



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

Date: Fri, 12 Dec 97 08:35:39 -0500
From: bsa@void.apk.net (Brandon S. Allbery KF8NH; to reply, change "void" to "kf8nh")
Subject: Re: a certain bug...!!!
Message-Id: <34913df4$3$ofn$mr2ice@speaker>

In <881865758.228401@thrush.omix.com>, on 12/11/97 at 06:39 PM,
   Zenin <zenin@best.com> said:
+-----
| 	When opened with "+>>" you can ONLY read data that you (or someone
| 	else...) has added since you opened it.  You can NOT read the data
| 	already in the file, even with a seek (FH, 0, 0).  You'd need to
+--->8

Pardon?  Has Perl redefined the semantics of O_APPEND?  I see no indication of
this in the Fine Manual.

-- 
use 5.004;sub AUTOLOAD{print$_{$_.++$x{$_}}}sub new{my%x;%_=map{++$a%2?$_.++$x{
$_}:$_}split(//,pack('N*',unpack('w*',unpack('u*','M@H*HP\'2"@\C`88+SE/!EA(F!'.
"A'6\$LZV0+(3;C9QRA9NAPG2&D\\G(88:KL=A0\n4AN.5W\"\"&\\[W>;H>3S>0\@A\\N\@PB\$`")
)));bless{}}$b=(new main);map{$b->_}split(//,' Brandon S. Allbery KF8NH') # :-)


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

Date: Fri, 12 Dec 1997 00:31:14 -0600
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: a certain bug...!!!
Message-Id: <inlq66.441.ln@localhost>

Zenin (zenin@best.com) wrote:
: Christian Khoury <Christian.Khoury@inria.fr> wrote:
: : i read in "Programming Perl" (2nd edition) that i just need to add a
: : "+>" to a file's name to be able to open it in read write mode...i tried
: : it and it failed....but with "+<", it worked fine...
: :
: : is this a known bug?

[snip]

: 	To take a wild guess, you might just be getting surprised by the
                                                ^^^^^^^^^^^^^^^^^
: 	fact that "+>filename" will truncate the file to 0 bytes if it
: 	already exists, and thus you can't read anything from it because
: 	it's been nuked.


No, that can't be it.

His question was about open(), and the description of that function
in the documentation that was shipped with his perl distribution
('perlfunc') says that +> clobbers the file.

So I don't see how he could have been surprised  ;-)


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


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

Date: 12 Dec 1997 09:12:44 -0500
From: mike@stok.co.uk (Mike Stok)
Subject: Re: a simple question
Message-Id: <66rgos$q9$1@stok.co.uk>

In article <3490FAAD.6B1E@lab.nig.ac.jp>,
Petur Henry Petersen  <ppeterse@lab.nig.ac.jp> wrote:
>if I have @arry which contain 10 numbers and i do a pattern searc for
>one of these numbers how can I get the position of that number in the
>array?

(Assuming 0-based arrays...)

You can use an explicit index and write it in a traditional C-like way,
putting all indicies of matching elements in an array:

  for ($index = 0, @result = (); $index < @arry; $index++) {
    push @result, $index if $arry[$index] =~ /$pattern/;
  }

  if (@result) {
    ...
  }

or you can iterate over the list like this, this time just finding the
first index that matches:

  $position = undef;
  $index = 0;
  for (@arry) {
    if (/$pattern/) {
      $position = $index;
      last;
    }
    $index++;
  }

  if (defined $position) {
     ...
  }

As this is perl there's more than one way to do it, and there are a number
of more terse ways which I can imagine.

Hope this helps,

Mike

-- 
mike@stok.co.uk                    |           The "`Stok' disclaimers" apply.
http://www.stok.co.uk/~mike/       |   PGP fingerprint FE 56 4D 7D 42 1A 4A 9C
http://www.tiac.net/users/stok/    |                   65 F3 3F 1D 27 22 B7 41
stok@colltech.com                  |            Collective Technologies (work)


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

Date: Fri, 12 Dec 1997 00:19:44 -0600
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: accessing a file in directory other than cgi script?
Message-Id: <02lq66.a31.ln@localhost>


[ trimmed c.l.p.m from followups]


none@nowhere.com wrote:
: Is it possible to open a file in a perl cgi script that is in a
: superdirectory (or any other directory for that matter) than the one
: which is in the script itself?


Yes.


: I've got a directory 'cgi-bin' under my root directory, and I'd like to
: run a script from it which opens a file in my root directory.  I thought
  ^^^^^^^^^^^^

How do you run this script?

>From the command line? 

If so, then it should work.



As a CGI (I assume so from looking at the crossposted newsgroups)?

If so, then you ("you" in this case being whoever owns the CGI process)
may not have permission to open the file.


You should (Always. Really, *always*, but especially when you are having
a problem...) check the return value from calls to open():

   open(FILE, '/myfile.htm') || die "could not open '../myfile.htm'  $!";

Then see what it says in the server error log...


[snip bad code]

: but neither of these successfully open the file.  I know that if I place
: the file in the same directory as the script itself and use:

:      open(FILE, "myfile.htm");  # refering to the file in the current
: directory

: it will open it with no problem, so either I'm using incorrect syntax to
: specify the directory, or you simply can't access files in directories
: other than your script.  Can anyone give me some insight?


You are using the correct syntax.

You _can_ access files in directories where the server setup allows
such things.


I'll bet you have a permission problem. 

Permission problems are either OS or HTTP server
questions, so this is off topic for c.l.p.m


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


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

Date: Thu, 11 Dec 1997 13:40:03 -0500
From: "Thomas Charron" <twolf@sampo.creighton.edu>
Subject: Re: Basic beginner quesition
Message-Id: <66pc23$rdt1@biko.telecom.ups.com>

There is freeware web server out there named fnord.  You will have to:

    a) Install Perl, and relate .pl extentions to the perl executable.

    b) Install Fnord, and give a directory a cgi-bin mode, then put the pl
files in there, and pull it up..  ;-P


JJ wrote in message <348CA0DD.3885@usa.net>...
>Trying to learn perl for cgi and more!
>
>1. What is the best way to learn perl in windows, but to use these
>scripts for cgi purposes?
>2. Do I have to load them on server every time to make them work?
>3. I've installed perl, on my computer but to make the scripts run I
>have to keep them in the same directory? (I've already done everything
>to my path statement but it dos'nt help)
>
>
>please if you can Help
>Thank you
>JJ




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

Date: Fri, 12 Dec 1997 07:57:13 -0700
From: Builders Connection <Webmaster@builders-connection.com>
Subject: Call a script automatically from a webpage
Message-Id: <349150C8.506@builders-connection.com>

Call a script automatically from a webpage
is there a way to call script automatically from a webpage just by
logging on to that page. Say you go to http://mysite.com/thepage.htm
and have the script run automatically to redirect you? All the scripts
I've seen require some kind of action to make them work.


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

Date: Fri, 12 Dec 1997 08:47:47 -0600
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: Chunking up a large input file
Message-Id: <jqir66.fs.ln@localhost>

Daniel Mills - Software Engineer Alexandria (dmills@riag.com) wrote:
: I've written a program that processes SGML files (you know...HTMLs
: dad).  

I've heard of it  ;-)


: This program has, however, a very serious problem.  When the
                             ^
                             ^
I see two serious problems, and one thing that is just kinda strange.


: input file becomes excessively large (approx. > 10Mb), the program bombs
                                                  ^^^^

How much _virtual_ memory does your computer have?

10Mb is not that big compared to the virtual memory on most
computers nowadays.



: and gives an "Out of memory" message.  As far as I can tell this is
: happening because of the way I'm using the input stream which is as a
: single string.

: e.g.
: open(FILEIN,"text.sgml")


Not checking the return value from open() is a serious problem.

Your program will continue even if the open() call failed to
open the file...

   open(FILEIN,'text.sgml') || die "could not open 'text.sgml'   $!";


: undef $/;
: while(<FILEIN>){


Strange to have a loop that will always iterate only one time (at most)...


: }

: The out of memory problem can be solved if I replace the while with:
: while(read FILEIN,$buffer,BUFSIZE)

: The problem with this approach is if the read stops in the middle of an
: SGML tag, I've got problems.  For example, if the program is crusing
: along and the read has nearly finished grabbing BUFSIZE bytes and the
: input stream looks like:

: .....and she said, don't look at me that way</quote><quote>His reply ...
: 						^
: 					   read ends here

: If BUFSIZE bytes have been read in where the end read is indicated,
: information will be lost.

: Is there a simple way to make the read smart so that it won't break up
: any tags or do I need to devise a completely different approach?


You need to devise a completely different approach.

Several possibilities:


1) "chunk" the file (usually at element boundaries) so you can deal
   with smaller parts

2) buy more RAM  ;-)

3) increase swap space

4) process an ESIS stream line-by-line instead of slurping the raw SGML

5) write your own routine to read in "chunks" at a time without
   breaking at inappropriate places (determining what is 
   inappropriate in the general case is likely to be problematic)


I think I'd try #3 first.

Good luck.


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


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

Date: Fri, 12 Dec 1997 14:27:42 GMT
From: sigi@remsmurr.de.delete.this (Sigi)
Subject: date conversation ???
Message-Id: <34914968.30566751@news.remsmurr.de>


Hello

I was wondering if someone has a fine little script or know of it wich
takes todays date and says to me what date last friday (sample) had. I
thank very much for grandiose answers and tips.

Sigi.


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

Date: 12 Dec 1997 16:00:27 +0100
From: Remove xx <xxTony.Curtis@vcpc.univie.ac.at>
To: sigi@remsmurr.de
Subject: Re: date conversation ???
Message-Id: <7xu3cer4hg.fsf@vcpc.univie.ac.at>

Re: date conversation ???, Sigi
<sigi@remsmurr.de.delete.this> said:

Servus,

Sigi> I was wondering if someone has a fine little script or
Sigi> know of it wich takes todays date and says to me what
Sigi> date last friday (sample) had. I thank very much for
Sigi> grandiose answers and tips.

Try strftime() from the POSIX module.

hth,
tony


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

Date: Fri, 12 Dec 1997 09:00:29 -0600
From: Dave Barnett <barnett@houston.Geco-Prakla.slb.com>
Subject: Re: Encryption
Message-Id: <3491518B.A2839D5A@houston.Geco-Prakla.slb.com>

Ian Duchesne wrote:

> Hi all,
>
> Here's my situation.  I'm using perl 5.001. Trying to use the crypt
> program.
>
> I am able to crypt a word but I cannot uncrypt the crypted word.

This is a planned issue.  If you could easily un-crypt, you could easily
get passwords from the /etc/password file, and wreak havoc with the
system.

I'm assuming that you are trying to do some sort of "password" type word
crypting, no?

Programming Perl [1] page 153 has something to say about using crypt:

     crypt PLAINTEXT, SALT

     To see whether a typed-in password $guess matches the password
     $pass obtained from a file (such as /etc/passwd), try something
     like the following:

          if (crypt($guess, $pass) eq $pass) {
              # guess is correct
          }


The SALT is a two character entry used to 'salt' the crypt function.  It
only reads the first two characters of the input as the SALT.  The rest
is ignored.  Conveniently enough, the password field of the /etc/passwd
file has the SALT used to encrypt the word as the first two characters
of password.

The above, never actually "knows" what the password from /etc/passwd
actually is, it just encrypts the users guess and compares it against
what is already in the file.  If they match, then bingo! and away you
go.  Much safer than actually having the password stored in plain text
anywhere in the system.


[1]    Programming Perl, 2nd Edition
           Larry Wall, Tom Christiansen & Randal L. Schwartz
            O'Reilly & Associates, Inc.
            ISBN:  1-56592-149-6

(a.k.a. "The Blue Camel" for the blue tinted picture of a camel that is
printed on the front cover)
(a.k.a.  Great Reference Material)

HTH.

Dave

--
"Security through obscurity is no security at all."
                -comp.lang.perl.misc newsgroup posting

------------------------------------------------------------------------
* Dave Barnett               U.S.: barnett@houston.Geco-Prakla.slb.com *
* DAPD Software Support Eng  U.K.: barnett@gatwick.Geco-Prakla.slb.com *
------------------------------------------------------------------------





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

Date: 12 Dec 1997 16:24:26 +0100
From: Calle Dybedahl <qdtcall@esb.ericsson.se>
Subject: Re: eof and low level io
Message-Id: <isen3ik2j9.fsf@godzilla.kiere.ericsson.se>

Michael Reed <mreed@cis.ohio-state.edu> writes:

> Problem is... at the end of the file it keeps trying to read, and I'm
> not sure how to get it to throw some sort of exception to let me handle
> it. 

You seem to have missed this little bit when you read about sysread()
in the perlfunc manpage (you *did* read the manpage, right?):

"Returns the number of bytes actually read, or undef if there was an error."

Reading at end of file counts as an error.
-- 
		    Calle Dybedahl, UNIX Sysadmin
       qdtcall@esavionics.se  http://www.lysator.liu.se/~calle/


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

Date: Fri, 12 Dec 1997 09:57:19 -0500
From: Bruno Pagis <bruno_pagis@aur.alcatel.com>
Subject: eval / variable scope problem
Message-Id: <349150CE.8CA0D44D@aur.alcatel.com>

The following program prints nothing but
Value:
I was expecting
Value:1  2  3
I assume it's a problem with the scope
of the variables evaluated by eval.
The messages displayed using -w option confirm that:
Use of uninitialized value at /homes/pagib/work/perl/src/bp8 line 10.
Use of uninitialized value at /homes/pagib/work/perl/src/bp8 line 10.
Use of uninitialized value at /homes/pagib/work/perl/src/bp8 line 10.

I don't know how to solve that. Thanks. BRUNO.

1  #!/usr/local/bin/perl -w
2  use strict;
3  my @A=("A","B","C");
4  my ($A,$B,$C);
5  my $elem;
6
7  format =
8  Value:@<< @<< @<<
9  $A,$B,$C
10 .
11 my $index=1;
12 foreach $elem (@A)
13 {
14   eval "\$$elem=\$$index";
15   $index++;
16 }
17 write;

---------------------------------------------------------------
   \                      Bruno Pagis
 ___\o     ___o      ^_o  mailto:bruno_pagis@aur.alcatel.com
 \       _ |\ \     | \/  Phone:(919)850-5174 Fax:(919)850-6670
 /      / \|// \   /_\                 ___
/       \_/  \_/  /                    \ /
                                  A L C A T E L
---------------------------------------------------------------




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

Date: Fri, 12 Dec 1997 06:24:27 -0800
From: "Creede Lambard" <$_=qq!fearless\@NOSPAMio.com!;y/A-Z//d;print>
Subject: Re: File Sorting with UNIX from Perl
Message-Id: <66rhgv$9ff@mtinsc04.worldnet.att.net>

Probably the easiest way would be

`sort mumble`

where mumble would be replaced with the parameters you normally send to
sort, e.g. `sort <foo >bar`.

You can also (if you care to investigate) use the Perl sort command on a
file by just reading it into an array:

open(FILE,"myfile") or die "Can't open myfile";
@unsorted = (<FILE>);

then sort @unsorted and write it back to a different file. There Is More
Than One Way To Do It (TM).

--- Creede Lambard
Minister of Irregular Expressions
Programming Republic of Perl

Stuart Trower wrote in message <34912E88.D533EDD7@ims.ltd.uk>...
>Hello,
>
>I'm fairly new to perl programming. How can I call the UNIX sort command
>from within a perl script. I want to sort the lines of a text file based
>on the first charcater of each line (which I  currently use the SORT
>command in UNIX for). I want to automate this so that everytime I run a
>script it does the sort for me, this is part of a bigger script.  The
>sort command in Perl kind of confuses me and only seems to work with
>arrays, lists....So how can I call the Unix sort command and not the
>perl sort command.  Help
>
>Stuart
>strower@ims.ltd.uk
>
>
>




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

Date: Fri, 12 Dec 1997 10:07:38 -0500
From: Bruno Pagis <bruno_pagis@aur.alcatel.com>
To: James Gryga <jamesgry@netcom.com>
Subject: Re: Foreach, array, s/// problem
Message-Id: <3491533A.CBDEE879@aur.alcatel.com>

James Gryga wrote:

> #!/usr/bin/perl -pi
>
> @Array = ("Word1: ", "Word2: ", "Word3: ", ...and so on);
>
> foreach $element (@Array) {
>         s/^$element (.*)\n//g;
>         }

assumes you have two spaces after the colon. That was not thecase in the first
example.
BRUNO.

---------------------------------------------------------------
   \                      Bruno Pagis
 ___\o     ___o      ^_o  mailto:bruno_pagis@aur.alcatel.com
 \       _ |\ \     | \/  Phone:(919)850-5174 Fax:(919)850-6670
 /      / \|// \   /_\                 ___
/       \_/  \_/  /                    \ /
                                  A L C A T E L
---------------------------------------------------------------




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

Date: Fri, 12 Dec 1997 15:49:02 GMT
From: aml@world.std.com (Andrew M. Langmead)
Subject: Re: Foreach, array, s/// problem
Message-Id: <EL32Lq.Cy4@world.std.com>

jamesgry@netcom.com (James Gryga) writes:

[old script looked like this:]
>#!/usr/bin/perl -pi

>s/^Word1: (.*)\n//g;
>s/^Word2: (.*)\n//g;
>.
>.
>.
>and so on.

>this works very well.  However, since most of the lines are identical 
>except for the key work, I thought of using an array and the foreach 
>statement.

>#!/usr/bin/perl -pi

>@Array = ("Word1: ", "Word2: ", "Word3: ", ...and so on);

>foreach $element (@Array) {
>	s/^$element (.*)\n//g;
>	}

You changed the regular expression slightly with your new version. The
old one had one space between the key word and the result of the line,
the new one has two. (One from the variable $element, and one in the
constant text.

I guess that few if any of the lines in your input file have two
spaces between the keyword and the rest of the line.

Since your doing work on this kind of stuff, you might be interested
in looking at the FAQ entry: "How do I efficiently match many regular
expressions at once?" <URL:http://www.perl.com/CPAN-local/doc/manual/
html/pod/perlfaq6/How_do_I_eficiently_match_many_.html>

Also consider that all of the variable in your regular expression
match a common pattern. Maybe you could search for that, and then see
if the text matches one of the variables.

#!/usr/bin/perl -w

%array = map { $_,1 } 'Word1', 'Word2', 'Word3';
while(<>) {
  print unless /^(\w+):/ and $array{$1};
}
-- 
Andrew Langmead


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

Date: Fri, 12 Dec 97 08:38:43 -0500
From: bsa@void.apk.net (Brandon S. Allbery KF8NH; to reply, change "void" to "kf8nh")
Subject: Re: how to hide .pl file
Message-Id: <34913e9e$4$ofn$mr2ice@speaker>

In <66qdci$23p$1@comdyn.comdyn.com.au>, on 12/12/97 at 04:08 AM,
   mgjv@comdyn.com.au (Martien Verbruggen) said:
+-----
| >> I want to hide the .pl program from being read from others. Is there any
| >> way to do it? I am using Perl 5 under WindowsNT 4.0 Please reply me at
| >> venkat5@hotmail.com Regards. venkat.
| >  If you haven't figured it out or gotten an answer email me
| No one else allowed to hear the answer?
+--->8

He's trying to sell consulting services.  *snort*

-- 
use 5.004;sub AUTOLOAD{print$_{$_.++$x{$_}}}sub new{my%x;%_=map{++$a%2?$_.++$x{
$_}:$_}split(//,pack('N*',unpack('w*',unpack('u*','M@H*HP\'2"@\C`88+SE/!EA(F!'.
"A'6\$LZV0+(3;C9QRA9NAPG2&D\\G(88:KL=A0\n4AN.5W\"\"&\\[W>;H>3S>0\@A\\N\@PB\$`")
)));bless{}}$b=(new main);map{$b->_}split(//,' Brandon S. Allbery KF8NH') # :-)


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

Date: Fri, 12 Dec 1997 06:10:11 -0800
From: "Creede Lambard" <$_=qq!fearless\@NOSPAMio.com!;y/A-Z//d;print>
Subject: Re: just starting with perl
Message-Id: <66rhgr$9ff@mtinsc04.worldnet.att.net>

1. You should check to see if you have an AUTOEXEC.BAT file. If so, and if
there is a PATH <something> or PATH=<something> line in there, add C:\PERL5
to the end of that path string so it looks something like this:

PATH=C:\WINDOWS;C:\WINDOWS\COMMAND;C:\PERL5

If you don't have an AUTOEXEC.BAT file, you might want to create one.
Windows 95 doesn't need one and in general I prefer not to use one, but I
write lots of Perl scripts and the ability to run a script from whatever
directory I happen to be in in so useful that I'm willing to put up with the
minor annoyance.

2. The reason you're seeing the behavior with the blank line is, when you
just type PERL<enter> at the command line, Perl is waiting for you to type
the script you want to run. To prove it, try this experiment. Type in the
following lines:

C:\WINDOWS\COMMAND> perl
for ($i = 1; $i <= 10; $i++) {
    print "Hello, Jen!\n";
    }

After you type the three lines of code, hit either control-Z or the F6 key
(they do the same thing in this case) and enter. Perl will run the script
you typed in. I don't recommend this for huge, multi-line scripts because
the possibility of a typo is pretty real and you can't edit a line once you
type it in, but if you need to run a small script that's too long for
"perl -e" and you don't want to save it to a file, this will work just fine.
(Actually, this is probably a FAQ . . .)

3. Associating .pl files with Perl in the file types box under "My Computer"
has no effect on the command line. It means that if you have a .pl file,
say, on your desktop or in Explorer and double-click its icon, the file
opens up with Perl. This also means that (for instance) if you set up the
script properly, you can drag and drop another file's icon on top of the
script's icon to have the script operate on the file you dropped. But that's
another subject for another day.

Hope this helps,

--- Creede Lambard
Minister of Irregular Expressions
Programming Republic of Perl


jennifer wrote in message <01bd0675$8b7e6a60$d6812299@xbwerrsn>...
>Everyone was so helpful on my last question, I'm going to ask another
>num-num question.
>I have perl5 installed on win95. Located in my C: directory (hard drive)
>that being that...
>I type at the dos promt:
>      c:\perl5\perl -e "print 8 * 8;"
> I get the answer -
>      64.... so far so good. Now I've typed a program in notepad
>     #!usr/bin/perl -w
>     print ("Hi Jen!\n");
>I saved this as jen.pl.
>Back at the dos prompt..
>    c:\perl5\perl jen.pl
>"can't open perl script jen.pl no such filde or directory exists."
>So I type...
>    c:\perl5\perl
>Now I'm on a blank line, no prompt of any kind so I type..
>     jen.pl
>Now I'm on another blank line no repsonse from perl
>I type..
>    c:jen.pl
>Another blank line, still no response.
>I have associated .pl with perl.exe in my file types box in 'my computer',
>although it didn't matter before association and it doesn't matter after
>association still no response.  I have O'Reilly Learning Perl, I would like
>to get started with the exercises instead of tinkering with my system.  I
>would appreciate any help that's out there. Also how do you quit perl from
>a blank line.  When I "x out"  a warning box comes on to say I should
>officially exit the program. I type quit, exit, or push escape - no dice. I
>type cd:\
>still can't exit.
>
>Thanks in advance!
>
>




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

Date: Fri, 12 Dec 1997 09:58:02 -0500
From: ken@forum.swarthmore.edu (Ken)
Subject: Re: Memory leak in perl 5.004_04
Message-Id: <ken-1212970958020001@news.swarthmore.edu>

Wow!  Thanks for your help!  This was indeed the problem.  For now, I'll
fix this by adding a line that deletes $main::{$filehandle}.  Eventually
I'll convert this project to use IO::Handle (which I've wanted to do for
some time now anyway).

Good eye.


In article <66q1qd$b0v$1@agate.berkeley.edu>, ilya@math.ohio-state.edu
(Ilya Zakharevich) wrote:
>In article <ken-1112971845570001@news.swarthmore.edu>,
>Ken <ken@forum.swarthmore.edu> wrote:
>> I've got a program with a memory leak in it.  From my investigations, it
>>  4  for ($i=0; $i<10000; $i++) {
>>  5
>>  6     $filehandle = &get_string;
>>  7
>>  8     open ($filehandle, "test.db") or die $!;
>
>Here you create a glob named $filehandle, and never free it.  This is
>why Perl has IO::Handle's, which are anonymous, thus do not create
>this problem.
>
>Hope it helps,
>Ilya

-Ken Williams
 The Math Forum
 ken@forum.swarthmore.edu


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

Date: 12 Dec 1997 13:41:38 GMT
From: gabor@vinyl.quickweb.com (Gabor)
Subject: Re: mkdir command
Message-Id: <slrn692fdj.cls.gabor@vinyl.quickweb.com>

In article <19971211.170352.953299.NETNEWS@TWSUVM.UC.TWSU.EDU>, Kitty
Smith wrote:
- I am having trouble with the mkdir command.  I can't figure out what
- the permissions should be for the command to achieve a directory with
- 770.  I have a umask of 022 set.  I get permissions of 775 when I use
- the following command:
- 
- 	mkdir("newdir", 777);
                    ^^^
                    shuld be 0777
- 
- I get the same when I change 777 to 757 in the mkdir command.

Your umask affects the file permissions thus
4 turns off read 2 turns off write and 1 turns off execute
eg.  6 turns off read and write
it's the opposite of how you'd use chmod
chmod 660 turns on read and write for user and group
umask 022 turns off write for group and other

- 
- I am rather confused as to how the command infaces with the umask.
- Could someone clear up my understanding of the whole thing?

The umask 'masks' the permissions you supply to mkdir.
- 
- Thanks,
- Kitty Smith
- Wichita State University
- 

gabor.
--
    There is, however, a strange, musty smell in the air that reminds me of
    something...hmm...yes...I've got it...there's a VMS nearby, or I'm a Blit.
        -- Larry Wall in Configure from the perl distribution



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

Date: Fri, 12 Dec 1997 10:05:45 -0500
From: Nicolas Brossard <brossard@bch.umontreal.ca>
Subject: Re: newbie: compact an array
Message-Id: <349152C9.41C67EA6@bch.umontreal.ca>

> In article <66n3jh$617$1@nntp1.ba.best.com>,
>  Xah <xah@best.com> wrote:
>  Suppose @a is an array of integers. I want to compact @a, so
>  that elements that are 0 get deleted. How can I do this without >
>  declaring another array @b such as:
> 
> # compact array
> $j=0;
>  foreach $i (@a) {if ($i) {@b[$j] = $i; $j++;};};

Why not just:

@a = grep($_, @a)


Nick


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

Date: 8 Dec 1997 17:24:55 GMT
From: "JoeDevon" <joedevon@travelin.com>
Subject: Perl Programmers wanted!
Message-Id: <01bd03fe$73da3a20$5fd3afce@jdevon.predictive.com>

This is a multi-part message in MIME format.

------=_NextPart_000_01BD03D4.8B043220
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit

Predictive Systems Inc is looking for talented PERL programmers. 
Networking experience a big plus+.  We have openings in several of our
offices.  Competitive salaries.  Comprehensive benefits package including
401(K), medical, dental, and term life insurance.  

FOR IMMEDIATE CONSIDERATION:

Please send/fax your resume to:  
Predictive Systems, Inc.
c/o Rachel Mozes
145 Hudson Street
6th Flr
New York, NY 10013
FAX:  212/625-9053
email: rachel.mozes@predictive.com

------=_NextPart_000_01BD03D4.8B043220
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable

<html><head></head><BODY bgcolor=3D"#FFFFFF"><p><font size=3D2 =
color=3D"#000000" face=3D"Arial">Predictive Systems Inc is looking for =
talented PERL programmers. &nbsp;Networking experience a big plus+. =
&nbsp;We have openings in several of our offices. &nbsp;Competitive =
salaries. &nbsp;Comprehensive benefits package including 401(K), =
medical, dental, and term life insurance. &nbsp;<br><br>FOR IMMEDIATE =
CONSIDERATION:<br><br>Please send/fax your resume to: =
&nbsp;<br><b>Predictive Systems, Inc.</b><br>c/o Rachel Mozes<br>145 =
Hudson Street<br>6th Flr<br>New York, NY 10013<br><b>FAX: =
&nbsp;212/625-9053<br>email: <font =
color=3D"#0000FF"><u>rachel.mozes@predictive.com</u></b><font =
color=3D"#000000"><br><br></p>
</font></font></font></body></html>
------=_NextPart_000_01BD03D4.8B043220--



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

Date: Fri, 12 Dec 1997 14:50:50 GMT
From: Vincent Joseph <vincent.joseph@usa.net>
To: Tom Phoenix <rootbeer@teleport.com>
Subject: Re: Perl support for the long long type
Message-Id: <34914F77.B69B788C@usa.net>

Hi,

Preliminary loop tests indicate that this is 37 (thirty seven) times faster
than the algorithm/code I was planning on using.

On a loop of 1000 numbers
 the new toSeconds algorithm processed 1 number every 0.001 seconds
 the old toSeconds algorithm processed 1 number every 0.037 seconds.

old > Time per = 0.037 seconds
old > Unix time : +881937197
old > 17 33 9 12 11 97 5 345 0

new > Time per = 0.001 seconds
new > Unix time(2) : 881937197
new > 17 33 9 12 11 97 5 345 0

On a normal day I process over 170000+ records a day, and each record
has this field in it. The time savings are ~90-100 minutes!!.

Thanks again,

Vincent

Tom Phoenix wrote:

> On Thu, 11 Dec 1997, Vincent Joseph wrote:
>
> > The 5 byte integer that I wish to convert is actually Unix time in 100th
> > of a seconds.  (By Unix time I mean the value returned by the time
> > function.)
>
> By that statement, I believe that you mean that your number will normally
> be around 100 times the current Unix time number.
>
> > The value is being read from a file.  I need to convert this value to
> > Unix time in seconds (which will fit in 4 bytes)  The "conversion" is
> > really just a division by 100.  However, there does not seem to be a way
> > to read in a 5 byte field into any of the numeric types using unpack (eg
> > N n)
>
> No, and if you could, you wouldn't be able to work with it very easily.
>
> > sub toSeconds
> > {
> >         my $rawepoch=();  #Raw time (epoch) passed in from outside, 5 byte
> > (100th second)
>
> I don't know what those extra symbols are, or even whether you can see
> them on your screen. To me, they're distracting. :-)
>
> That's an unusual way to set a scalar to undef. I'd either leave off the
> '=()' part, or I'd explicitly say "=undef'. Of course, the value you want
> will be shifted off of @_ later, so you could simply assign it here.
> Otherwise, it's a waste of processor power.
>
> [ remainder of algorithm snipped ]
>
> > Is there a more efficient (time wise, algorithmic)  way of doing
> > this in Perl?
>
> Well, your algorithm could certainly be tweaked some. But I'd try this.
>
>     sub toSeconds {
>         # Given a five-byte bitstring with an unsigned integer
>         # value less than or equal to 429,496,729,599, returns that
>         # value divided by 100, as a long unsigned integer
>         my($first2, @rest) = unpack("SCCC", shift);
>         # $first2 must be in range 0..25599
>         die "Value of \$first2 ($first2) too large"
>             if $first2 > 25599;
>         my $value = int($first2/100);   # in range 0..255
>         my $carry = $first2 - 100*$value;       # 0..99
>         while (@rest) {                 # Obey Newton's 1st? :-)
>             $carry = $carry * 256 + shift @rest;
>             my $quot = int($carry/100);
>             my $rem  = $carry - 100 * $quot;
>             $value = $value * 256 + $quot;
>             $carry = $rem;
>         }
>         # Could return $carry to give remainder
>         return $value;
>     }
>
> Hope this helps!
>
> --
> Tom Phoenix           http://www.teleport.com/~rootbeer/
> rootbeer@teleport.com  PGP   Skribu al mi per Esperanto!
> Randal Schwartz Case:  http://www.rahul.net/jeffrey/ovs/
>               Ask me about Perl trainings!

 



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

Date: Thu, 11 Dec 1997 23:05:03 -0600
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: Q: I can't print to a file.
Message-Id: <vlgq66.hr.ln@localhost>

Bill Guindon (billg@networkapparel.com) wrote:

: Jerry Lineberry wrote:

: > results to a file I simply get the file names without any contents. Here's
: > how my files look:


: > open(STRIP, "str.txt") or die "Can't read from str.txt.\n";

[snip]

: > print @duck;

: Try:
: print STRIP @duck;

: You need to tell it to print to the filehandle, not STDOUT.


Actually, you will need to tell it to print to a filehandle that
has been opened for output.

Filehandle STRIP was only opened for input...


The description of open() in the 'perlfunc' man page shows how
to open a file for output.


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


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

Date: 12 Dec 1997 14:30:45 GMT
From: "Andrew Hope" <A.P.Hope@btinternet.com>
Subject: Socket problems
Message-Id: <01bd070a$7b76e9e0$6b793ec2@charles.nahhas.ans.alcatel.co.uk>

Does anyone know if there is a function which will return the status of a
socket (like the stat function for files but for sockets) ?
Also, how do you set the accept function to non blocking mode. I have tried
playing around with fcntl but I don't understand how to set the flags (the
O'Rielly books are not very specific regarding IPC).
Can anybody help? 
Email: A.P.Hope@btinternet.com


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

Date: Fri, 12 Dec 1997 09:29:19 -0600
From: Graham Barr <gbarr@ti.com>
To: Andrew Hope <A.P.Hope@btinternet.com>
Subject: Re: Socket problems
Message-Id: <3491584F.F9F3CEF5@ti.com>

Andrew Hope wrote:
> 
> Does anyone know if there is a function which will return the status of a
> socket (like the stat function for files but for sockets) ?

What is it that you want to determine form the socket ??

> Also, how do you set the accept function to non blocking mode. I have tried
> playing around with fcntl but I don't understand how to set the flags (the

Take a look at IO::Socket, the lasted version on CPAN uses
non-blocking IO to perform connect with timeouts. But for accepts
just do not call accepts until you know that there a connection
waiting, you can tell this by using select() and checking if
the listening socket is read-able

> O'Rielly books are not very specific regarding IPC).
> Can anybody help?

-- 
Originality is the ability to conceal your source.


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

Date: Fri, 12 Dec 1997 15:09:07 GMT
From: aml@world.std.com (Andrew M. Langmead)
Subject: Re: Socket woes....
Message-Id: <EL30r8.867@world.std.com>

cjb@trog.dra.hmg.gb (Cliff Bradshaw) writes:

>Now we've upgraded all the machines to Solaris 2, and I've recompiled
>Perl 5 but for some reason the web server program refuses to play ball.

Does this entry from the perl FAQ help?

  Why doesn't my sockets program work under System V (Solaris)?
  What does the error message "Protocol not supported" mean?

    Some Sys-V based systems, notably Solaris 2.X, redefined some of the
    standard socket constants. Since these were constant across all
    architectures, they were often hardwired into perl code. The proper
    way to deal with this is to "use Socket" to get the correct values.

    Note that even though SunOS and Solaris are binary compatible, these
    values are different. Go figure.

-- 
Andrew Langmead


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

Date: Fri, 12 Dec 1997 10:34:23 -0500
From: Jeffery Schweiger <jeffery@mitre.org>
Subject: Threading in NT
Message-Id: <3491597F.8FBD5D59@mitre.org>

I  am tryijng to write a multitasking program on Windows NT.  I have
noticed that
the NT version of perl does not support the fork command and threading
in Perl is
suppose to be in the next release of Perl (5.005).

Is there a way to multitask with Peal for NT?

Thanks

Jeff



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

Date: Fri, 12 Dec 1997 07:49:36 -0600
From: Ken Holm <rets@meta3.com>
To: Henry Hartley <henry@DotRose.com>
Subject: Re: what does qq() do?
Message-Id: <349140F0.41C6@meta3.com>

Henry Hartley wrote:
> 
> I cannot find any mention of this function except in code examples, as
> follows:
> 
>       $sql = qq(select * from <table> where LastName like '$lastname\%'
> order by LastName);
> 
> what does the qq do?
> 
> I've been using sprintf("select...  Why should I use qq instead?
> 
> Henry

The qq!Pick your own quotes! q's, eh?

Programming Perl 2nd Ed. tells us that the qq() you are seeing is one
way to represent " (double quotes).  When you use s/// or tr///, you are
using the same type of thing.

Following are different qq!functions!:

q()  - aka '' # single quotes
qq() - aka "" # double quotes
qx() - aka `` # backticks
qw() - aka () # word list

Like single quotes and word lists, q() and qw() do not interpolate.  The
other two do.  You do not have to use ()'s with the q.?'s   You must use
paired characters.  My pesonal fave is qq!.

To be absolutely blah about the whole thing:

$A = "Hello there";

 and

$A = qq!Hello there!;

 are the same thing.  Perhaps there is some ultra-wiz, deep, neat-o kind
of reason why they are different, but it shouldn't affect your code at
all.

-K

-- 
Kennneth A Holm  |        META 3 - Webmaster        |webmaster@meta3.com
PO Box 1508      |----------------------------------|(601)948.3399 x 227
Jackson, MS 39215|PGP Key finger webmaster@meta3.com|(601)948.5999 (fax)


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

Date: Fri, 12 Dec 1997 13:33:19 +0400
From: "Ivan Klabukov" <postmaster@ivan.udm.ru>
Subject: Write in file from perl body
Message-Id: <66r0b5$obn$1@hq.mark-itt.ru>

Can anyone tell me how can I write in file from perl body if I call my
script from html document.
Ivan A. Klabukov




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

Date: 8 Mar 97 21:33:47 GMT (Last modified)
From: Perl-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 8 Mar 97)
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.misc (and this Digest), send your
article to perl-users@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.

The Meta-FAQ, an article containing information about the FAQ, is
available by requesting "send perl-users meta-faq". The real FAQ, as it
appeared last in the newsgroup, can be retrieved with the request "send
perl-users FAQ". Due to their sizes, neither the Meta-FAQ nor the FAQ
are included in the digest.

The "mini-FAQ", which is an updated version of the Meta-FAQ, is
available by requesting "send perl-users mini-faq". It appears twice
weekly in the group, but is not distributed in the digest.

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 V8 Issue 1461
**************************************

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