[6885] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 511 Volume: 8

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed May 21 19:06:14 1997

Date: Wed, 21 May 97 16:01:55 -0700
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Wed, 21 May 1997     Volume: 8 Number: 511

Today's topics:
     Multipart Mime <salg@inmotion.no>
     Need help with an IF THEN (Dave Mains)
     Re: Need help with an IF THEN (Craig Berry)
     Re: Need help with an IF THEN (John Moreno)
     Re: Need help with an IF THEN <kscott@uab.edu>
     Re: Need help with an IF THEN <rootbeer@teleport.com>
     Need help with sorting <kscott@uab.edu>
     Re: Need help with sorting <owt1@cornell.edu>
     Re: Need help with sorting <rootbeer@teleport.com>
     Re: New warnings in perl 5.004. (Abigail)
     Normal Array to Associative Array (Michael Caver)
     Re: Normal Array to Associative Array <rootbeer@teleport.com>
     Re: Normal Array to Associative Array (Mike Stok)
     Re: NT Perl limitations... permanent? (Neil Briscoe)
     Re: NTPerl - sendmail.pl (Neil Briscoe)
     Re: OO Perl instance variables and lists (Mike Stok)
     Re: Parsing - lots of little or one big text file - a p <dphi@ix.netcom.com>
     Re: Perl and CGI (Abigail)
     Re: PERL SCRIPT FOR PASSOWRD (Magnus Bodin)
     probably a simple question <Scott@wwide.com>
     Re: Problems with form handling <rootbeer@teleport.com>
     Re: Q: Detecting input in STDIN. <rootbeer@teleport.com>
     Random number generator (Simon Pearce)
     Re: saving to a file from perl <rootbeer@teleport.com>
     Re: SEGV from hash declaration <rootbeer@teleport.com>
     send input to external command? (Yi Wang)
     Re: Simultaneous HTTP requests: LWP? Raw sockets? (Ken Shan)
     Re: Simultaneous HTTP requests: LWP? Raw sockets? <aas@bergen.sn.no>
     Re: Site Management Tool With File Locking? (Jeff Wilkinson)
     Size of simple scalar values <douglas@lanl.gov>
     Re: Size of simple scalar values <rootbeer@teleport.com>
     Re: Split function <rootbeer@teleport.com>
     Re: Split function (Craig Berry)
     Stalling Perl Reports.... <djp@sai-baba.demon.co.uk>
     Re: syntax for subroutine reference with sort <rootbeer@teleport.com>
     Re: system calls <rootbeer@teleport.com>
     Re: Time stamping with perl (Aidan Dysart)
     Re: timelocal.pl ? <rootbeer@teleport.com>
     Re: undef package variables <rootbeer@teleport.com>
     Re: Unusual Sys::Syslog behaviour ? <rra@stanford.edu>
     Re: Want perl on Win95 Platform <bri@mojo.calyx.net>
     Re: Year 2000 Issues with Perl5 <usenet-tag@qz.little-neck.ny.us>
     yyyymmdd from localtime? <kargatis@jackaldog.gsfc.nasa.gov>
     Digest Administrivia (Last modified: 8 Mar 97) (Perl-Users-Digest Admin)

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

Date: Wed, 21 May 1997 22:53:09 +0200
From: Lars Magnus Ramnefjell Berg <salg@inmotion.no>
Subject: Multipart Mime
Message-Id: <338360B5.158E@ifi.uio.no>

I am using the 
  new MIME::Parser;
  $parser->output_dir($msgdir);
  $parser->read(\*FILE),
this expands all mime attatchments in the file.

How can i set up the parser to expand a spesific part?
ex:
 Part nr 2
 All parts not in text/plain!


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

Date: 21 May 1997 16:08:53 GMT
From: dbsales@pobox.com (Dave Mains)
Subject: Need help with an IF THEN
Message-Id: <5lv6ml$irh1@baker.se.highway1.com>

The following is taken from a script I'm trying to write.  The problem
is I can't get the IF to be true even if $pfx does = $a.

Please help.

        open(PFX, "w4zrdxcc.txt");# || die print "Can't Open!!\n";
                while (<PFX>)
                 {
                ($a)=split(/./,$_,1);
                print "$a,\n";
                $a =~ s/W.*//; # delete after 1st word
                        if ($pfx = $a) {$found = "1";
                        last;
                        }

                        }

Thanks,

Dave Mains
Dave@db-sales.com



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

Date: 21 May 1997 18:44:40 GMT
From: cberry@cinenet.net (Craig Berry)
Subject: Re: Need help with an IF THEN
Message-Id: <5lvfqo$dnj$2@marina.cinenet.net>

Dave Mains (dbsales@pobox.com) wrote:
: The following is taken from a script I'm trying to write.  The problem
: is I can't get the IF to be true even if $pfx does = $a.
: 
:         open(PFX, "w4zrdxcc.txt");# || die print "Can't Open!!\n";
:                 while (<PFX>)
:                  {
:                 ($a)=split(/./,$_,1);
:                 print "$a,\n";
:                 $a =~ s/W.*//; # delete after 1st word
:                         if ($pfx = $a) {$found = "1";
:                         last;
:                         }
:                         }

There are a few problems with this script other than what you ask, but
let's zero in on the line in question.  There are two errors stacked up. 
First, '=' is the assignment operator; what you're testing is whether $a
evaluates 'true', with a side effect of assigning $pfx the value of $a. 
'==' is probably the operator you were thinking of -- but even *that*
would be wrong (unless I misunderstand your code), because '==' is
*numeric* equality; what it seems more likely that you want is *string*
equality, which is 'eq'. 

I might also suggest adopting a better convention for indentation and 
brace alignment; it would make it easier for you to see the structure of 
your code.

Hope this helps!

---------------------------------------------------------------------
   |   Craig Berry - cberry@cinenet.net
 --*--    Home Page: http://www.cinenet.net/users/cberry/home.html
   |      Member of The HTML Writers Guild: http://www.hwg.org/   
       "Every man and every woman is a star."


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

Date: Wed, 21 May 1997 15:20:13 -0400
From: phenix@interpath.com (John Moreno)
Subject: Re: Need help with an IF THEN
Message-Id: <19970521152013836251@roxboro-180.interpath.net>

Dave Mains <dbsales@pobox.com> wrote:

] The following is taken from a script I'm trying to write.  The problem
] is I can't get the IF to be true even if $pfx does = $a.
] 
]                         if ($pfx = $a) {$found = "1";
]                         last;
]                         }

Looks like you're coming from Pascal (a truly fine lang.) which has a
FEW disadvantages compared to C (which perl sytnax is loosely based on).
One of the two that most frequently bug me has just bitten you (the
other is that pascal doesn't provide a easy way for adding to pointers,
what I wouldn't give to be able to say MyPtrData++).  

Pascal does assignments using := and comparisons using =, C and Perl do
assignments using = and comparisons using ==.  Now this, plus the fact
C and Perl allow you to do assignments within expressions, is causing
problems for you because.

rewrite the if statement to:
        if ($pfx==$a) {$found ="1";last;}

ad as a test add a print "pfx = $pfx and a = $a\n"; before it - that way
you can see what's going to hapen, by the way if your original if is
failing all of the time it can only be because for some reason $a is
alays equal to 0.  Any other value and it would never fail.

-- 
John Moreno


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

Date: 21 May 1997 20:33:16 GMT
From: Kathy Scott <kscott@uab.edu>
To: dbsales@pobox.com
Subject: Re: Need help with an IF THEN
Message-Id: <5lvm6c$okk@maze.dpo.uab.edu>

Do you mean to say
if ($pfx == $a)?



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

Date: Wed, 21 May 1997 14:20:30 -0700
From: Tom Phoenix <rootbeer@teleport.com>
To: Dave Mains <dbsales@pobox.com>
Subject: Re: Need help with an IF THEN
Message-Id: <Pine.GSO.3.96.970521141905.735T-100000@kelly.teleport.com>

On 21 May 1997, Dave Mains wrote:

>                         if ($pfx = $a) {$found = "1";

You are assigning $a to $pfx there. You probably want one of these.

    if ($pfx eq $a) { ... }
    if ($pfx == $a) { ... }

Hope this helps!

-- Tom Phoenix        http://www.teleport.com/~rootbeer/
rootbeer@teleport.com   PGP  Skribu al mi per Esperanto!
Randal Schwartz Case:     http://www.lightlink.com/fors/



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

Date: 21 May 1997 20:30:06 GMT
From: Kathy Scott <kscott@uab.edu>
Subject: Need help with sorting
Message-Id: <5lvm0e$okk@maze.dpo.uab.edu>

I am trying to sort a file of collumns of numbers by a specific collumn.  I am
having trouble figuring out what the best method is to do this.  I thought I
would read the file in line by line and isolate the collumn of intrest into an
array.  Then I could sort the array and go back through the file and pairing up
the collumn data with the original file then printing to a new file.  I'm not
sure that this would work because I don't know how to handle a situation where
the same number appears twice in the collumn of intrest.  There would no way to
locate the corresponding data in the original file.
Can someone please make a suggestion how to go about fixing the double entry
problem or a better method of sorting the file?
Thank you.
Kathy Scott



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

Date: 21 May 1997 17:51:41 -0400
From: Owen Taylor <owt1@cornell.edu>
Subject: Re: Need help with sorting
Message-Id: <lzd8qkijde.fsf@cu-dialup-1311.cit.cornell.edu>


Kathy Scott <kscott@uab.edu> writes:

> I am trying to sort a file of collumns of numbers by a specific
> collumn.

Well, there's certainly more than one way to do this. (The
fastest is probably to use sort(1)). Here's a perl approach that
should work reasonably well.

The following sorts a file numerically on the third (whitespace
deliminated) column. (See the perllol(1) manpage for more information
on what's going on here.)

Hope this helps,
                                        Owen

---------
#!/usr/bin/perl -w

while (<>) {
    push @lines, [ (split)[2], $_ ];
}

foreach (sort { $a->[0] <=> $b->[0] } @lines) {
    print $_->[1];
}





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

Date: Wed, 21 May 1997 15:18:30 -0700
From: Tom Phoenix <rootbeer@teleport.com>
To: Kathy Scott <kscott@uab.edu>
Subject: Re: Need help with sorting
Message-Id: <Pine.GSO.3.96.970521151510.735b-100000@kelly.teleport.com>

On 21 May 1997, Kathy Scott wrote:

> I am trying to sort a file of collumns of numbers by a specific collumn. 

> I don't know how to handle a situation where
> the same number appears twice in the collumn of intrest.  

If it's important that the input data always have a unique number in that
column, you may need to check for that separately. But you would probably
have good results if do the sort with a Schwartzian Transform. Hope this
helps! 

   http://www.5sigma.com/perl/schwtr.html

-- Tom Phoenix        http://www.teleport.com/~rootbeer/
rootbeer@teleport.com   PGP  Skribu al mi per Esperanto!
Randal Schwartz Case:     http://www.lightlink.com/fors/



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

Date: Wed, 21 May 1997 17:40:58 GMT
From: abigail@fnx.com (Abigail)
Subject: Re: New warnings in perl 5.004.
Message-Id: <EAJL4A.4MF@nonexistent.com>

On 21 May 1997 12:15:26 GMT, Mike Stok (mike@stok.co.uk) wrote in
comp.lang.perl.misc
<URL: news:5lup0u$hu9@news-central.tiac.net>:
++ In article <EAIIsz.MFJ@nonexistent.com>, Abigail <abigail@fnx.com> wrote:
++ 
++ >I've noticed that perl 5.004 is a lot pickier than perl 5.003.
++ 
++ This is a benefit, as long as you can tell it to shut up!

I agree.

++ >   - If you do perl -c on a file that starts with
++ >     '#!/usr/local/bin/perl -wT' it'll whine "Too late for -T now"
++ >     and stop. Urgh. How I am supposed to do a syntax check
++ >     now other than actually executing the file or removing the
++ >     -T switch (with the danger to forget it to put back in when
++ >     moving it to common area)?
++ 
++ put the -T on the command line e.g.
++ 
++ vrooom.nis.newscorp.com> perl -c try.pl
++ Too late for "-T" option at try.pl line 1.
++ vrooom.nis.newscorp.com> perl -Tc try.pl
++ Name "main::var" used only once: possible typo at try.pl line 3.
++ try.pl syntax OK
++ 
++ Hope this helps,


Yes it does. (Got the same response from several others).



Abigail, banging her head for not realizing the solution herself.


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

Date: Wed, 21 May 1997 18:28:32 GMT
From: ratboy@cyberenet.net (Michael Caver)
Subject: Normal Array to Associative Array
Message-Id: <5lvetb$2k3@news.tamu.edu>

I'm trying to move the text content of a normal array to an associative array
without a lot of "foreach" statements. I saw some posts here that said use:

   $assoc{'array'} = \@array;

But when I do this I get:

   ARRAY(0x80b88c4)

Any idea what that means or what I might be doing wrong?


-Michael


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

Date: Wed, 21 May 1997 15:13:12 -0700
From: Tom Phoenix <rootbeer@teleport.com>
To: Michael Caver <ratboy@cyberenet.net>
Subject: Re: Normal Array to Associative Array
Message-Id: <Pine.GSO.3.96.970521150958.735Z-100000@kelly.teleport.com>

On Wed, 21 May 1997, Michael Caver wrote:

> I'm trying to move the text content of a normal array to an associative
> array without a lot of "foreach" statements. I saw some posts here that
> said use: 
> 
>    $assoc{'array'} = \@array;

That's using references to do something else (documented in perlref). 

I suspect that you want something resembling one of these, but I'm not
sure which one. :-) 

    $hash{key} = join " ", @values;

    %hash = map { ( $_, 1 ) } @values;

    %hash = map { ( $_, $value[$_] ) } 0..$#values;

Hope this helps!

-- Tom Phoenix        http://www.teleport.com/~rootbeer/
rootbeer@teleport.com   PGP  Skribu al mi per Esperanto!
Randal Schwartz Case:     http://www.lightlink.com/fors/



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

Date: 21 May 1997 19:52:31 GMT
From: mike@stok.co.uk (Mike Stok)
Subject: Re: Normal Array to Associative Array
Message-Id: <5lvjpv$hjg@news-central.tiac.net>

In article <5lvetb$2k3@news.tamu.edu>,
Michael Caver <ratboy@cyberenet.net> wrote:
>I'm trying to move the text content of a normal array to an associative array
>without a lot of "foreach" statements. I saw some posts here that said use:
>
>   $assoc{'array'} = \@array;
>
>But when I do this I get:
>
>   ARRAY(0x80b88c4)
>
>Any idea what that means or what I might be doing wrong?

That's how a reference is displayed as a string, you need to explicitly
dereference in perl,

  print "array is @{$assoc{array}}\n";

would fetch the contents of $assoc{array} and the outer @{} dereference
that letting the "" operate on an array.

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@psa.pencom.com                |      Pencom Systems Administration (work)


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

Date: 21 May 1997 20:31:17 GMT
From: neilb@zetnet.co.uk (Neil Briscoe)
Subject: Re: NT Perl limitations... permanent?
Message-Id: <memo.19970521213138.14347D@skep.compulink.co.uk.cix.co.uk>

In article <5ludn6$afa@news.huji.ac.il>, cerlpvk@cestar.technion.ac.il
(cerlpvk) wrote:

> So far as I know WinNt got no such notion as fork
>

Precisely.  The problem is not with the Perl port but the underlying
operating system.

Regards
Neil



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

Date: 21 May 1997 20:31:14 GMT
From: neilb@zetnet.co.uk (Neil Briscoe)
Subject: Re: NTPerl - sendmail.pl
Message-Id: <memo.19970521213135.14347C@skep.compulink.co.uk.cix.co.uk>

In article <01bc6578$442e57e0$a4578781@n12827>, wkyetman@ingr.com (Warren
Yetman) wrote:

> Hi ,
>
>   Can you tell me where I can get the sendmail.pl and any associated
> files;
>  my Web search is uneventfull.  Thank you.
>

Nope, not sendmail.pl - but I can tell you about smtp.pl - this allows you
to speak native SMTP protocol to any mail server.  I hacked it
unmercifully from the smtp.pm module.

Send me a mail to neil@fourthnet.co.uk - my office address - and I'll bung
you a zip file by return.

Regards
Neil



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

Date: 21 May 1997 17:28:13 GMT
From: mike@stok.co.uk (Mike Stok)
Subject: Re: OO Perl instance variables and lists
Message-Id: <5lvbbd$98l@news-central.tiac.net>

In article <5lv6oc$jgf@vixen.cso.uiuc.edu>,
William L Harrison <harrison@cs.uiuc.edu> wrote:

>	I'm hoping someone can answer a (hopefully not too simple)
>question about lists and OO Perl instance variables. Specifically, I
>want to have an instance variable that contains a list. So, for example,
>if I say:
>
>	$self->{Foo} = ("blah", "blah", "herman");
>
>then "$self->{Foo}" is set to the last value of "herman" instead of to
>the whole list (which is what I want). Is there some way of having 
>"$self->{Foo}" set to the whole list?

Check out the perldsc man page (perl data structures cookbook.)  A hash
value can only contain a single scalar, so complex data structures are
built using references e.g.

  $self{foo} = ['blah', 'blah', 'herman'];

will make an anonymous array with 3 values and stash a reference to it in
$self{foo}.  You can then use $self{foo}[1] etc as expected, or if tou
want to deal with the whole list use @{$self{foo}} as the @{} are used to
dereference the hash element.

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@psa.pencom.com                |      Pencom Systems Administration (work)


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

Date: Wed, 21 May 1997 13:30:04 -0700
From: Dale Phillips <dphi@ix.netcom.com>
Subject: Re: Parsing - lots of little or one big text file - a point of view question.
Message-Id: <33835B4C.5623@ix.netcom.com>

I R A Aggie wrote:
> 
> In article <3383120E.4976@ix.netcom.com>, dphillip@tabfs.com wrote:
> 
> + In perl, do I gain anything by using lots of littles text files
> + to build up a "table" or should I dump the data into one
> + large workfile then parse it out into the same "table."
> 
> I'd go with one file. It should be more efficient to open/read/close
> one file than a bunch. However many that may be... ;)

Thats what I thot. In most "virtual machine like" its better
to go big go once than to eat up workspace with lot-o-tiny stuff.

Thanks for the pointer on opendir - just what the Dr. ordered.
Now for more caffine ... the perl way  !java  ;)

> 
> + I am new to perl as well. How do I process lots of little
> + text files - they all start with SCR*
> 
> Go look up the opendir(), readdir(), closedir() functions. You may
> come up with something like:
> 
> opendir(DIR,".") or die $!;
> @files=grep /SCR/, readdir(DIR);
> closedir(DIR);
> 
> James
> 
> --
> Consulting Minister for Consultants, DNRC
> Support the anti-Spam amendment <url:http://www.cauce.org/>
> To cure your perl CGI problems, please look at:
> <url:http://www.perl.com/perl/faq/idiots-guide.html>

-- 
----------------------
Dale Phillips
dphillip@tabfs.com


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

Date: Wed, 21 May 1997 19:41:40 GMT
From: abigail@fnx.com (Abigail)
Subject: Re: Perl and CGI
Message-Id: <EAJqpG.Dpn@nonexistent.com>

On Wed, 21 May 1997 03:27:34 -0400, Kendal Van Dyke
(kendal@freenet.tlh.fl.us) wrote in comp.lang.perl.misc
<URL: news:3382A3E6.79B3@freenet.tlh.fl.us>:
++ I'm new to the newsgroup (and perl actaully), so forgive me if this is
++ off-subject (not sure which of the perl newsgroups was the correct one
++ for this), but I need a quick bit of programming help.
++ 
++ I'm writing a Java applet that uses a Perl script on the server to
++ retrieve a URL and spit it's contents out back to the applet (Necessary
++ since the URL is different from the original server where the applet
++ comes from, so I have to work my way around browser security using the
++ script). Anyways, I'm using lynx to get the contents of the URL and dump
++ it to a local file I can work with. The line of code giving me trouble
++ is this:
++ 
++ `/usr/local/bin/lynx -dump
++ http://www.nws.fsu.edu/data/text/roundup/ASUS42.KMIA > ASUS42.KMIA';
++ 
++ (all one line of course). The problem I'm having is that when I run it
++ from a command prompt it runs just fine, but when I run it as a cgi
++ script from a browser it doesn't ever create the file locally on my
++ server. I suppose I am calling the command line function wrong or
++ something, I dunno. That's where I figured someone in this newsgroup
++ could shed some light on the situation. If you need to see the script in
++ it's entirety it can be found at www.cs.fsu.edu/~vandyke/cgi-bin


- Have you read the servers error log? What did it say?
- Have you asked in the CGI group? What did they say?
- Have you read Tom's Idiot's Guide to Solving Perl/CGI Problems? [1]
  Why doesn't it solve the problem?
- Have you read the Perl/CGI Faq? [2] Why doesn't it solve the problem?
- Why aren't you using LWP?


[1] http://www.perl.com/perl/faq/cgi/idiots-guide.html
[2] http://www.perl.com/perl/faq/cgi/perl-cgi-faq.html


Your problem is not a Perl problem.



Abigail


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

Date: Wed, 21 May 1997 17:15:09 GMT
From: Magnus.Bodin@tychonides.se (Magnus Bodin)
Subject: Re: PERL SCRIPT FOR PASSOWRD
Message-Id: <33872d47.176061342@news1.telenordia.se>

Michael Lammon <Michael.C.Lammon@mci.com> wrote:

>All,
>
>	Does anyone have a PERL program which will call the User Name:
>Password:
>feature for a Netscape Browser or IE? and upon correct password that
>will allow
>a user to go to the html file??
>
>Thanks
>
>Mike

Much simpler would be to put the html-file in a password-protected
library on the webserver.


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

Date: Wed, 21 May 1997 13:46:30 -0100
From: Scott <Scott@wwide.com>
Subject: probably a simple question
Message-Id: <33830AC6.3F63@wwide.com>

Hello,

I have a (hopefully) simple problem.  I have a perl script that reads a
text file in one character at a time and displays it out to the web. 
the text file is something like this:

sample stuff blah blah

more stuff blah blah blah

joe	21	1998	hi
sam	29	1999	blah blah

more stuff ......

eric	11	1971	stuff stuff

etc,

what I want to do is read this file in a line at a time, and display
only the lines that I want, ie, i want to display just the line about
joe and the one about eric, nothing else.

Here is how it is read in right now:
while (read(SOCK,$charcter,1)) {       # Get a character

can anyone help me? I have read the faq, went to perl.com and looked at
dejanews for related questions and saw nothing, I went and bought "CGI
Programming on the World Wide Web" by O'Reilly & Assoc, it seems good
but if someone can help it would be greatly appreciated!!

Thanks,
Scott
scott@wwide.com


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

Date: Wed, 21 May 1997 14:22:58 -0700
From: Tom Phoenix <rootbeer@teleport.com>
To: Petra Smits <P.Smits@stud.frw.ruu.nl>
Subject: Re: Problems with form handling
Message-Id: <Pine.GSO.3.96.970521142138.735U-100000@kelly.teleport.com>

On 21 May 1997, Petra Smits wrote:

> -The questionnumbers are sent with one name (question_number) and the
> number PERL gives back is not 8 and 10 and 49, but 81049

You may need to request the value in list context; this should be
documented in CGI.pm. I think you'll find the other answers you need there
as well. Hope this helps!

-- Tom Phoenix        http://www.teleport.com/~rootbeer/
rootbeer@teleport.com   PGP  Skribu al mi per Esperanto!
Randal Schwartz Case:     http://www.lightlink.com/fors/



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

Date: Wed, 21 May 1997 14:14:10 -0700
From: Tom Phoenix <rootbeer@teleport.com>
To: Amit Bhati <amit@visi.com>
Subject: Re: Q: Detecting input in STDIN.
Message-Id: <Pine.GSO.3.96.970521140907.735R-100000@kelly.teleport.com>

On 21 May 1997, Amit Bhati wrote:

> Newsgroups: comp.lang.perl, comp.lang.perl.modules

I don't think this has anything to do with modules.

If your news administrator still carries comp.lang.perl, please encourage
him or her to check out the frequent posting about bogus newsgroup names
in news.announce.newgroups. You'll be doing yourself and many others a
favor to use comp.lang.perl.misc (and other valid Perl newsgroups)
instead.

    news:news.announce.newgroups

> In a Perl script, how can I detect if it has input piped to it (versus
> has no input to read via STDIN)? 

You might want the answer in section 5 of the Perl faq, "How can I tell if
there's a character waiting on a filehandle?" 

    http://www.perl.com/CPAN/doc/FAQs/FAQ/html
          /perlfaq5/How_can_I_tel_if_there_s_a_char.html

Or, you might be looking for the -t test, documented in perlfunc(1). Hope
this helps!

-- Tom Phoenix        http://www.teleport.com/~rootbeer/
rootbeer@teleport.com   PGP  Skribu al mi per Esperanto!
Randal Schwartz Case:     http://www.lightlink.com/fors/



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

Date: Wed, 21 May 1997 22:40:03 GMT
From: simon@scoutnet.org.uk (Simon Pearce)
Subject: Random number generator
Message-Id: <33837986.8004055@news.dircon.co.uk>

Hi all,

I'm after a snippet of code that will produce a random number between
1 and 49 (yes for a lottery number generator).

Any ideas?

Simon Pearce
simonp@dircon.co.uk
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
       A message from SIMON PEARCE, General Manager, ScoutNet UK
        Country Co-ordinator (UK), Global ScoutNet Organization
                   Disguised as simon@scoutnet.org.uk
       Find me in uk.rec.scouting   IRC -> #scouting - @Simon_UK
                         Telephone 0370 840412
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
    ScoutNet UK - The BEST in Scouting Online - www.scoutnet.org.uk
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=


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

Date: Wed, 21 May 1997 14:00:57 -0700
From: Tom Phoenix <rootbeer@teleport.com>
To: Killer2345 <killer2345@aol.com>
Subject: Re: saving to a file from perl
Message-Id: <Pine.GSO.3.96.970521135853.735P-100000@kelly.teleport.com>

On 20 May 1997, Killer2345 wrote:

> Does anyone know the syntax for writing to a file using Macperl?

The people who write the Perl documentation would like for you to be able
to find the answer to this question yourself without having to ask for
help. Could you let us know what terms you searched for in the index or by
other means, so that we can be sure to have it better indexed in the
future? Thanks!

-- Tom Phoenix        http://www.teleport.com/~rootbeer/
rootbeer@teleport.com   PGP  Skribu al mi per Esperanto!
Randal Schwartz Case:     http://www.lightlink.com/fors/



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

Date: Wed, 21 May 1997 14:16:18 -0700
From: Tom Phoenix <rootbeer@teleport.com>
To: Felix Morley Finch <felix@crowfix.com>
Subject: Re: SEGV from hash declaration
Message-Id: <Pine.GSO.3.96.970521141429.735S-100000@kelly.teleport.com>

On 21 May 1997, Felix Morley Finch wrote:

> I've got a perl program which causes a segmentation violation under
> certain conditions.  I built a debug-enabled 5.003_093 (?) and tracked
> it down to the following stack trace under gdb:

Excellent! Have you run perlbug to submit this as a bug report? 
Frequently folks who do so are rewarded with a patch in a few hours. Of
course, they also get that warm feeling in their hearts from making the
world a better place. :-) 

Thanks!

-- Tom Phoenix        http://www.teleport.com/~rootbeer/
rootbeer@teleport.com   PGP  Skribu al mi per Esperanto!
Randal Schwartz Case:     http://www.lightlink.com/fors/



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

Date: 21 May 1997 22:01:35 GMT
From: wang16@fas.harvard.edu (Yi Wang)
Subject: send input to external command?
Message-Id: <5lvrbv$t6g$1@news.fas.harvard.edu>

Once you call an external command which also will be waiting an input,
how do you pass the input inside the script?

Thanks much in advance.

Yi

ywang@harvard.edu


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

Date: 21 May 1997 16:58:10 GMT
From: ken@digitas.harvard.edu (Ken Shan)
Subject: Re: Simultaneous HTTP requests: LWP? Raw sockets?
Message-Id: <5lv9j2$q4h$1@news.fas.harvard.edu>

Gisle Aas (aas@bergen.sn.no) wrote:
> Check out http://www.cs.washington.edu/homes/marclang/ParallelUA/

Looks great -- thanks!

(BTW, why isn't this part of the standard libwww-perl distribution?)

--
Edit this signature at http://www.digitas.harvard.edu/cgi-bin/ken/sig
I don' reck'n ah am not goin'ta kiall nobady. Um hmm.


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

Date: 21 May 1997 23:48:29 +0200
From: Gisle Aas <aas@bergen.sn.no>
Subject: Re: Simultaneous HTTP requests: LWP? Raw sockets?
Message-Id: <h2070v6mq.fsf@bergen.sn.no>

ken@digitas.harvard.edu (Ken Shan) writes:

> Gisle Aas (aas@bergen.sn.no) wrote:
> > Check out http://www.cs.washington.edu/homes/marclang/ParallelUA/
> 
> Looks great -- thanks!
> 
> (BTW, why isn't this part of the standard libwww-perl distribution?)

Because I have not had time to look at it yet.  I also believe the
official "parallel" support will use a different approach.  It will be
added together with support for HTTP/1.1.  I'll wait for the "official"
perl EventLoop to appear first.

-- 
Gisle Aas <aas@sn.no>


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

Date: Wed, 21 May 1997 15:35:57 GMT
From: wilkinson@digsys1.md.essd.northgrum.com (Jeff Wilkinson)
Subject: Re: Site Management Tool With File Locking?
Message-Id: <EAJFBx.Lr7%mother@mdnews.md.essd.northgrum.com>

In article <5lq5jt$fkk$1@news.wco.com>, anthony@wco.com says...
>
>Well, I have to make this happen, so you just may be getting some source
>code.  But I don't want to reinvent the wheel, so...
>
>Does anyone know of an existing Perl script that will let users ask for a
>HTML file, return the file, flock it, and then unlock when it it sent
>back?  Preferably the interface would be via HTTP, but that's not
>necessary.  I could modify it.

Please be sure to post any good answers you get on this one.
I know I'm interested in anything that works and I'd bet
a lot of others would as well.

One solution would be a two-level situation, where you have a local RCS-type 
system and then periodically upld from there to the web server.  Your 
developers can access the files on the RCS using a file-system type of access. 
This could use some automated form of uploading, perhaps a cron job to upload 
every xxx minutes/hours or something that the users trigger.

jw

-- 
           ____________________________________________
  ________|                                            |________
  \  ><>  | Jeff Wilkinson       Northrop Grumman ESSD |  <><  /
   \      | wilkinson@digsys1.md.essd.northgrum.com    |      /
   /      |____________________________________________|      \
  /___________)  or use    jwilkinson@who.net     (____________\ 



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

Date: Wed, 21 May 1997 12:31:50 -0600
From: "Douglas A. Smith" <douglas@lanl.gov>
Subject: Size of simple scalar values
Message-Id: <33833F96.608B@lanl.gov>

Hello-

I've gone through various books, and I can't find a answer to this
problem:

I have a script which adds large sets of data and compares small
differences in these sets.  The problem comes when the sums start
to get larger than 2.14 billion.  Everything works for sums less 
than this number, but when they get larger than 2.14 billion I get
negative values, and then just a -1.

Is there a way to get perl to force the use of more bytes used in
integer scalars?  I don't want to force the use of floating point
numbers since I need the absolute accuracy of the integer sum.

Please Help-

Douglas Smith
douglas@lanl.gov


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

Date: Wed, 21 May 1997 14:24:35 -0700
From: Tom Phoenix <rootbeer@teleport.com>
To: "Douglas A. Smith" <douglas@lanl.gov>
Subject: Re: Size of simple scalar values
Message-Id: <Pine.GSO.3.96.970521142406.735V-100000@kelly.teleport.com>

On Wed, 21 May 1997, Douglas A. Smith wrote:

> Is there a way to get perl to force the use of more bytes used in
> integer scalars?  I don't want to force the use of floating point
> numbers since I need the absolute accuracy of the integer sum.

Sounds like you want Math::BigInteger. Hope this helps!

-- Tom Phoenix        http://www.teleport.com/~rootbeer/
rootbeer@teleport.com   PGP  Skribu al mi per Esperanto!
Randal Schwartz Case:     http://www.lightlink.com/fors/



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

Date: Wed, 21 May 1997 14:08:38 -0700
From: Tom Phoenix <rootbeer@teleport.com>
To: Greg <galoi@sdcc13.ucsd.edu>
Subject: Re: Split function
Message-Id: <Pine.GSO.3.96.970521140224.735Q-100000@kelly.teleport.com>

On 20 May 1997, Greg wrote:

> I am new to perl and am a little confused as to how the split
> functin works.  

The second argument is scanned, and anything which matches the first
argument is a delimiter. Actually, it's the "deliminator": Anything which
matches is removed. Then, any place where a match occurred is a break
between one item and the next. 

    @foo = split /\s+/, "This splits     into\nfive items.";
    @foo = split /\s/, "But this splits into  ten items (one is empty)";

> In particular I am trying to spilt up a string by
> the characters / and : and by whitespace.  

Do you mean this?

    @foo = split m#[/:\s]#, $string;

Hope this helps!

-- Tom Phoenix        http://www.teleport.com/~rootbeer/
rootbeer@teleport.com   PGP  Skribu al mi per Esperanto!
Randal Schwartz Case:     http://www.lightlink.com/fors/



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

Date: 21 May 1997 17:31:22 GMT
From: cberry@cinenet.net (Craig Berry)
Subject: Re: Split function
Message-Id: <5lvbha$dnj$1@marina.cinenet.net>

Greg (galoi@sdcc13.ucsd.edu) wrote:
: I am new to perl and am a little confused as to how the split
: functin works.  In particular I am trying to spilt up a string by
: the characters / and : and by whitespace.  I have not found a nifty
: way to do this.

Not sure what your problem might be.  If you want to split in different 
circumstances on each of these independently, it's just

  split /:/
  split /\//
  split /\s+/

If you want to split on any one of these in a single string, it's

  split /:|\/|\s+/

Perhaps if you gave more detail of what you were attempting we could 
provide better assistance.

---------------------------------------------------------------------
   |   Craig Berry - cberry@cinenet.net
 --*--    Home Page: http://www.cinenet.net/users/cberry/home.html
   |      Member of The HTML Writers Guild: http://www.hwg.org/   
       "Every man and every woman is a star."


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

Date: Wed, 21 May 1997 21:42:03 GMT
From: "Daniel J Pearce" <djp@sai-baba.demon.co.uk>
Subject: Stalling Perl Reports....
Message-Id: <01bc662e$e5d806c0$03d4dec2@sai-baba.demon.co.uk>


I am using Perl to generate reports on a fair amount of data, and the
reports need to be viewed online.

What I am having trouble with is holding the screen after stdout is full. 
What I need is to include a statement that basically does a 'more' on the
standard output.

I have written a few lines that just about do it, but it only consists of
pinching the stty rows value from the current terminal, and requesting
stdin once it has printed that many lines.....

However, I find this a little untidy and wondered if anyone had any ideas
or had covered this before......

Email:	djp@sai-baba.demon.co.uk


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

Date: Wed, 21 May 1997 13:44:10 -0700
From: Tom Phoenix <rootbeer@teleport.com>
To: Tim Bird <tbird@caldera.com>
Subject: Re: syntax for subroutine reference with sort
Message-Id: <Pine.GSO.3.96.970521133951.735L-100000@kelly.teleport.com>

On Tue, 20 May 1997, Tim Bird wrote:

> The sort routine can take the a subroutine as its first
> argument.  According to one perl book I have, you can give
> this subroutine parameter by one of a couple of ways:
> 1) as a block
> 2) as a subroutine name
> 3) as a scalar whose value is a subroutine name
> 4) as a scalar whose value is a subroutine reference

I wonder why they say that. In the perl docs and the Camel, I can't find
anything about the last two ways you mention. Maybe you can get your money
back, and use it to buy a Camel.  :-)  But you can do this. 

    sort { &$my_sub_ref } @list;

Hope this helps!

-- Tom Phoenix        http://www.teleport.com/~rootbeer/
rootbeer@teleport.com   PGP  Skribu al mi per Esperanto!
Randal Schwartz Case:     http://www.lightlink.com/fors/



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

Date: Wed, 21 May 1997 15:22:54 -0700
From: Tom Phoenix <rootbeer@teleport.com>
To: Greg <galoi@sdcc13.ucsd.edu>
Subject: Re: system calls
Message-Id: <Pine.GSO.3.96.970521152015.735c-100000@kelly.teleport.com>

On 21 May 1997, Greg wrote:

> I was wondering how to make certain system calls from within a perl
> script.  For example how could I make a call to the unix command
> "date" and store the value returned by "date" in a variable?

Why call on the system? 

   $date = localtime;		# Get today's date

But if you want to call the system for something that you actually need,
there are several ways to do so. Look for backticks (or backquotes),
system, fork and exec, and open (with a "|" character) in the perl
documentation. Hope this helps! 

-- Tom Phoenix        http://www.teleport.com/~rootbeer/
rootbeer@teleport.com   PGP  Skribu al mi per Esperanto!
Randal Schwartz Case:     http://www.lightlink.com/fors/



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

Date: 21 May 1997 17:14:51 GMT
From: adysart@umich.edu (Aidan Dysart)
Subject: Re: Time stamping with perl
Message-Id: <5lvaib$j67$1@newbabylon.rs.itd.umich.edu>

Nicholas Hardgrove (nickh@wind-river.com) wrote:
: Can anyone tell me how to get a time stamp from the system so that I can
: add it into database info that I am working on?

You could always just do

$timestamp = `date`;

which would give you the standard unix date format, which you could then
parse. Or you could do it all in on step like this

$_=`date`;
($day,$month,$date,$time,$time_zone,$year)=split ' ', s/:/ /;

Or you could even parse the time field as well like this:

($day,$month,$date,$hours,$mintues,$seconds,$time_zone,$year)
	=split /:| /, `date`;



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

Date: Wed, 21 May 1997 13:56:51 -0700
From: Tom Phoenix <rootbeer@teleport.com>
To: Raul Almquist <strider@ShadowMAC.org>
Subject: Re: timelocal.pl ?
Message-Id: <Pine.GSO.3.96.970521135504.735O-100000@kelly.teleport.com>

On Tue, 20 May 1997, Raul Almquist wrote:

> #!/usr/local/bin/perl5
> 
> use Time::Local;
> 
> $time = timelocal($sec,$min,$hours,$mday,$mon,$year);

> "Day out of range 1..31 in timelocal.pl at testing.pl line 5"

>   What the heck is going on here?!?  how could it be out of range?

It looks like you're giving timelocal six uninitialized variables. I don't
think you can claim that undef is in the range 1..31. :-)  Hope this
helps!

-- Tom Phoenix        http://www.teleport.com/~rootbeer/
rootbeer@teleport.com   PGP  Skribu al mi per Esperanto!
Randal Schwartz Case:     http://www.lightlink.com/fors/



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

Date: Wed, 21 May 1997 13:05:53 -0700
From: Tom Phoenix <rootbeer@teleport.com>
To: Gerhard Stoizner <stg@adv.magwien.gv.at>
Subject: Re: undef package variables
Message-Id: <Pine.GSO.3.96.970521125140.735D-100000@kelly.teleport.com>

On Tue, 20 May 1997, Gerhard Stoizner wrote:

> How can I 'undef' or 'delete' all variables of a package?
> I have tried (Perl 5.003):
> 
> undef %package::;
> 
> or 
> 
> for (keys %package::) {
>    delete $package{$_};
> }

Those wipe out the symbol table, but any already-compiled references to
those variables will still exist, as near as I can tell. That may be a
bug; you could run perlbug to submit it, and see whether it gets fixed. 
:-) 

You may have to do something like this, but I don't know how you can
delete filehandles, subs, and such.

    for (keys %package::) {
        ${ "package::$_" } = undef;
        @{ "package::$_" } = ();
        %{ "package::$_" } = ();
    }

Hope this helps!

-- Tom Phoenix        http://www.teleport.com/~rootbeer/
rootbeer@teleport.com   PGP  Skribu al mi per Esperanto!
Randal Schwartz Case:     http://www.lightlink.com/fors/



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

Date: 21 May 1997 12:46:43 -0700
From: Russ Allbery <rra@stanford.edu>
Subject: Re: Unusual Sys::Syslog behaviour ?
Message-Id: <m3oha4vc9o.fsf@windlord.Stanford.EDU>

Richard Dows <marius@randomc.com> writes:

> I wanted to use Sys::Syslog, and so I tested it with a small script.  I
> get an error like so:

> Undefined subroutine &Sys::Syslog::hostname called at
> /usr/local/lib/perl5/Sys/Syslog.pm line 92.  BEGIN failed--compilation
> aborted at stest line 3.

This problem is fixed in (the just released) 5.004.

-- 
Russ Allbery (rra@stanford.edu)         <URL:http://www.eyrie.org/~eagle/>


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

Date: 21 May 1997 17:38:56 GMT
From: Sol Lightman <bri@mojo.calyx.net>
Subject: Re: Want perl on Win95 Platform
Message-Id: <5lvbvg$5kt@cdc2.cdc.net>

Zonycat <zonycat@flash.net> wrote:
: Don Botten wrote:
: > 
: > I am running windows 95 and would like to test my perl scripts in my
: > computer.  Up to now I have telneted into my isp and checked them out on
: > unix.  The perl interpreters I have found are for Windows NT or OS2.

Apparently if you compile Perl5.004 under Windows NT, it will also run 
under Windows 95.  See comp.lang.perl.announce

--
Brian S. Julin


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

Date: 21 May 1997 17:21:00 GMT
From: Eli the Bearded <usenet-tag@qz.little-neck.ny.us>
Subject: Re: Year 2000 Issues with Perl5
Message-Id: <5lvats$r26$1@news.netusa.net>

Kerry Schwab <kschwab@nyx10.cs.du.edu> wrote:
>The perl faq's answer is a little incomplete.
>A brief "grep" around my /opt/local/lib/perl finds:
>(Version 5.003_25, not the latest, but pretty recent)
>    my($y,$m,$d) =  (localtime)[5,4,3];
>    $y+=1900;

(plus many other bits of code)

>Now I've not perused these in any great detail and some of it may be just 
>fine, , but it looks to me like several bundled perl .pm and .pl files may 
>have Y2K problems.  At least someone should have a look around before 
>declaring that perl is immune.

Why do you say that? The year, as returned by localtime is specified to
be "the current year minus 1900", so localtime will say the year is 100
2000, and $y+1900 will properly compensate.

The problem comes when people do stupid stuff like:

   $year=1900+((localtime)[5]%100);	   #BAD (saw this advocated once)
   print "Year is 19",(localtime)[5],"\n"; #DUMB (I have seen this in c code)
   ($y,$m,$d)=(localtime)[5,4,3];	   #fine so far
   print "generated $d/$m/$y";		   #INANE (and probably very common)

Elijah
------
"DUMB" comes from the way the ls replacement "sls" works (my copy is fixed)


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

Date: Wed, 21 May 1997 16:32:38 -0400
From: Vincent Kargatis <kargatis@jackaldog.gsfc.nasa.gov>
Subject: yyyymmdd from localtime?
Message-Id: <33835BE6.33@jackaldog.gsfc.nasa.gov>

I want to get a YYYYMMDD from localtime.  Is there a simpler way than
this (I'm just curious from an educational standpoint):

($day,$month,$year)=(localtime)[3,4,5];
$month++;
$month="0"."$month" if length($month)==1;
$date=($year+1900).$month.$day;

Is there a one-line version?

thanks, vince


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

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

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