[6872] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 497 Volume: 8

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon May 19 12:07:29 1997

Date: Mon, 19 May 97 09:00:20 -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           Mon, 19 May 1997     Volume: 8 Number: 497

Today's topics:
     Re: $number = hex("ffff1c20") no work <rootbeer@teleport.com>
     Re: ? about match and rename (Tad McClellan)
     Re: Break command---RTBC (Jahwan Kim)
     Re: cgi security - how to protect data from local cgi-s silex@mindspring.com
     Re: Executing simultaneous commands? (Jordyn A. Buchanan)
     Re: Help: How to Split a file at a Null Line??? (Tung-chiang Yang)
     How do I stop commercial interests from plundering my s <rchurch@wwdc.com>
     Re: idea for new for loop construct (Mark Mills)
     Re: perlipc and multi-threading problem <simonk@telebusiness.co.nz>
     print variable $abc which consist of '$' in it Query?????
     Re: print variable $abc which consist of '$' in it (Nathan V. Patwardhan)
     Re: REQ: Perl obfuscator (Andrew Haveland-Robinson)
     Re: REQ: Perl obfuscator (Abigail)
     Re: Seeding SRAND on WIN32 <mailbox@mongoose.demon.co.uk>
     Small Web DataBase Wanted <umcl1@fang.cs.sunyit.edu>
     Digest Administrivia (Last modified: 8 Mar 97) (Perl-Users-Digest Admin)

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

Date: Sun, 18 May 1997 17:27:34 -0700
From: Tom Phoenix <rootbeer@teleport.com>
To: Tony Whyte <whyte@sector.kodak.com>
Subject: Re: $number = hex("ffff1c20") no work
Message-Id: <Pine.GSO.3.96.970518172047.18750E-100000@kelly.teleport.com>

On 16 May 1997, Tony Whyte wrote:

> Subject: $number = hex("ffff1c20") no work
> 
> My sparc 10 insists that this is negative number and Ill 
> be damned if I can sprintf my way out of it. I want it to 
> interpret it as big unsigned number not negative. 

    use Math::BigInt;
    $n = Math::BigInt->new(hex "ffff");
    $n = $n * 65536 + hex "1c20";
    print "Hooray, it's $n!\n";

It's ugly, but it should work, at least as a start. (Too bad BigInt
doesn't have a hex method. Maybe it should.) 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: Sun, 18 May 1997 18:53:49 -0500
From: tadmc@flash.net (Tad McClellan)
Subject: Re: ? about match and rename
Message-Id: <dq4ol5.ir2.ln@localhost>

Mike Hammernik (mhammer@execpc.com) wrote:
: Hello

Hi.

: I'm attempting to match a word in 1 of 2 XtermLog files and then rename
: the one with the match and then by default name the other one something
: else. 
: I'm using 5.002 on a HP-UX 9.05 machine.

: I confess to all that I'm a newbie and this is my first program.
: I've paged thru the Llama and camel as well as my Learn PERL book.
: I'v also looked thru the FAQ and a collection of articles from this news
: group and I can't find anything close enough to show me the LIGHT!!


Thanks for spending some of your effort before asking for ours.

Showing that you made a good try at solving it yourself is an
extremely effective way to get folks to pay attention to your post.


But, you the list above is missing the very __first place__ to turn
when you have a Perl programming problem. Namely the man pages
(with the *.pod filename extension) that are included with the
perl distribution, see below.



: I have two files   XtermLog.12345  and XtermLog.67890
: inside is a a couple of blank lines and then

: hudson 250
: Date is Sun..........
: Lots of other stuff

: My code is

: #!/usr/bin/perl -w

: $name = getlogin;
: $dir = "/users/$name";
: print "$dir\n";

: @file = glob('XtermLog*');
: foreach (@file) { print "$_\n" };

: foreach $file ( @file ) {
: open (FILE, $file) || die "Could not open $file";
: while (<FILE>) {

You said you have some blank lines at the top of the file,
so when you get one of those, the "else" is executed,
and the file containing "hudson" is now named "troy"...


: if ($_ =~ /hudson/) {
:         print "$_\n";
:         last;
          ^^^^

Exit the loop right now! ie. before the two statements below...

You want the last statement to be, well..., the last statement
in the block ;-)


from the perlfunc man page (I added the underlining):

--------------------------------
=item last LABEL

=item last

The C<last> command is like the C<break> statement in C (as used in
loops); it immediately exits the loop in question.  If the LABEL is
           ^^^^^^^^^^^^^^^^^
omitted, the command refers to the innermost enclosing loop.  The
C<continue> block, if any, is not executed:

    LINE: while (<STDIN>) {
        last LINE if /^$/;      # exit when done with header
        ...
    }
--------------------------------


:         print "$file\n" || die "Can't print what ain't there $!";
:         rename($file, "hudson") || die "No can do $!";
: } else {
: rename("$file", "troy");

If the file not containing "hudson" has 1000 lines in it, then
the rename() above will be executed 1000 times. You have a logic
error here.

You probably want some sort of flag indicating whether hudson
was found or not, then do the rename() once:


:         }
:     }

: }


[ snip ]

: Could someone show me the error of my ways.


UNTESTED!

 ..
$found = 0;
while (<FILE>) {
   if (/\bhudson\b/) {     # \b so it won't match "shudson"
      $found = 1;
      last;
   }
}

if ($found) 
   { rename($file, "hudson") || die... }
else
   { rename($file, "troy") || die... } # don't need quotes around $file...



: Small additional question.

: I appreciate the time people spend to look and help someone like myself
: get better at PERL. Especially when we sometimes ask dumb questions. Is
: it appropriate to send a private e-mail to my mentor and thank him/her.


I appreciate it when that happens, can't speak for others...


: Thanking you in public for now.

You're welcome.


--
    Tad McClellan                          SGML Consulting
    Tag And Document Consulting            Perl programming
    tadmc@flash.net


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

Date: 19 May 1997 06:29:21 GMT
From: jahwan@supernova.math.lsa.umich.edu (Jahwan Kim)
Subject: Re: Break command---RTBC
Message-Id: <slrn5nvsq1.ppr.jahwan@supernova.math.lsa.umich.edu>

On Fri, 9 May 1997 16:51:47 GMT, Jacob Salomon <jake@apparel.net> wrote:
[snip]
> I did this all to experiment with the 'break' command, which is
> available in awk.  I could not find 'break' in the index of the perl
> book I'm using to learn.  The break command above did not incur a
> compile error but neither did it break me out of the loop; it continued
> to accept input until I entered an empty line.
> 
> Am I misusing the break command?  How would I leave a loop if not with
> break? (Please don't suggest goto.)

    Read The Blue Camel.  From Blue Camel p.533 (C Traps):
    
    The break and continue keywords from C become in Perl last and next,
resp.  Unlike in C, these do not work within a do {} while construct.

Jahwan



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

Date: Tue, 20 May 1997 03:54:48 GMT
From: silex@mindspring.com
Subject: Re: cgi security - how to protect data from local cgi-server shell users?
Message-Id: <3381206b.9706437@news.mindspring.com>

testing...


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

Date: Sun, 18 May 1997 20:42:07 -0400
From: jordyn@bestweb.net (Jordyn A. Buchanan)
Subject: Re: Executing simultaneous commands?
Message-Id: <jordyn-ya02408000R1805972042070001@nntp.bestweb.net>

Dianne <Dianne@spamfree.com> wrote:

> I was wondering if it is possible to execute a subroutine or a command
> line program and move on to the next line in the script without waiting
> for the subroutine/command to finish.  I am not having much luck.  Any
> suggestions?

Look into fork() or multithreading.

|---------------------------------------------------------------|
|Jordyn A. Buchanan                           jordyn@bestweb.net|
|Bestweb Corporation                      http://www.bestweb.net|
|Senior System Administrator                     +1.914.271.4500|
|---------------------------------------------------------------|


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

Date: Mon, 19 May 1997 06:13:49 GMT
From: tcyang@netcom.com (Tung-chiang Yang)
Subject: Re: Help: How to Split a file at a Null Line???
Message-Id: <tcyangEAEzz2.1JJ@netcom.com>

(untested)

#!/usr/local/bin/perl

open(FILE1,">file1") or die "Cannot open FILE1\n";
open(FILE2,">file2") or die "Cannot open FILE2\n";

while (<STDIN>){
   last if /^\n$/;
   print FILE1;
}

while (<STDIN>){
   print FILE2;
}

close(FILE1);
close(FILE2);

# I still wonder if it is necessary to test whether the close's succeed.

==========================================
j,u?OE" (swsung.bbs@cis.nctu.edu.tw) wrote:
: Hi,

: I have a file and there is a blank line amid this file.

: How can I split the file into two file at the blank line?

: Any answers will be highly appreciated.



--
Tung-chiang Yang                       tcyang@netcom.com

soc.culture.taiwan, soc.culture.china (by SCC FAQ Team) FAQ's:
   http://www.clever.net/tcyang/Taiwan_faq.shtml, China_faq.shtml


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

Date: Sun, 18 May 1997 19:16:43 -0400
From: Richard Church <rchurch@wwdc.com>
Subject: How do I stop commercial interests from plundering my site?
Message-Id: <337F8DDB.3E66@wwdc.com>

Hello,

I have a public website that that is very content rich, containing
links to thousands of other sites on the Web.

My question is as follows:

Is there a way for me to limit or prevent others from downloading
my extensive list of links and yet still provide people access to
those same links? I want people to be able to link to these websites,
but I don't want commercial interest taking, in a blink of the eye,
a list that essentially took me hundreds of hours to compile.

So, again, is there a CGI function that could either hide the
URL for each link, or, at the very least, limit what the user
can see to one URL at a time? I want to give free access to my
list but I don't want to give away the underlying proprietary
structure of my list.

Thanking you in advance for your input.

Richard

rchurch@wwdc.com


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

Date: Mon, 19 May 1997 01:47:05 GMT
From: mark@ntr.net (Mark Mills)
Subject: Re: idea for new for loop construct
Message-Id: <337fa74a.7724569@news.ntr.net>

On 17 May 1997 15:04:47 GMT, Ronald.J.Kimball@dartmouth.edu (Chipmunk)
wrote:

>In article <337ad07f.21110859@news.ntr.net>
>mark@ntr.net (Mark Mills) writes:
>
>> On Wed, 14 May 1997 14:38:22 -0700, Trenton Lipscomb
>> <trenton@ssil.uoregon.edu> wrote:
>> 
>> >    for(1 .. 5){
>> 
>> >    for $it (1 .. $count){
>> 
>> >However, there is a construct that seems natural to me, but is not
>> >recognized by the interpreter.  It is:
>> 
>> >       for(4 x){
>> 
>> >and, similiarly:
>> 
>> >       for $it (4 x){
>> 
>> >where $it would be assigned the value of the current iteration of the
>> >loop.
>> 
>> Hmm...  
>> howz about:
>>       for($i=0; $i<4; $i++) { print $i,"\n"; }
>> 
>> that would have a conflict with above, since what you were doing
>> was really the foreach (LIST) [perl has been taking care of you]
>
>How would that have a conflict?
>One is:
>for (EXP; EXP; EXP) { COMPOUND-STMT }
>and the other is:
>for VAR (EXP x) { COMPOUND-STMT }
>
>On the other hand, the construction
>for $foo (4 x)
>doesn't really seem intuitive to me.
>
>I would use either:
>for $foo (1 .. 4)
>or
>for ($foo=1; $foo<=4; ++$foo)
>
>BTW, according to Camel 1, "The 'foreach' keyword is actually identical
>to the 'for' keyword, so you can use 'foreach' for readability or 'for'
>for brevity."
>
>Chipmunk

Also from Camel 1, same page, next line...
(The crucial difference between the normal _for_ loop and the
_foreach_ loop is the presence or absence of semicolons)

using BNCish markup...
for ( SIDE_EFFECT ; EXPR ; SIDE_EFFECT ) BLOCK (? CONT ?)
foreach (? SCALAR ?) (LIST) { COMPOUND-STMT } BLOCK (? CONT ?)


where SIDE_EFFECT is EXPR or EXPR MOD_OP EXPR.

The keywords can be the same because the parser can clearly tell the
difference from the semi-colons (and maybe the SCALAR).

Also from Camel 1 (sorry 2 is at work)

Note that LIST and EXPR are syntactically the same.  We distinguish
between them only to document whether the operator in question
supplies an array context or a scalar context. The comma in EXPR is
like the C comma operator, the comma in LIST is not.

See the parser (yacc?) treats the loop structure different from the
it's innards.  The innards are processed just as they would be any
where else.

You would now get a new treatment ONLY inside a FOR type operator
(where it will be fairly hard to parse differently than EXPR)?  Hmm.

for (? SCALAR  ?) (EXPR x) { COMPOUND-STMT } BLOCK (? CONT ?)

And all of that for some thing that can be done another way already.

On the other hand I got to learn BNCish grammar and read most of the
yacc man pages  :> it was worth it.

-- 
[Hopper, Dennis]: There's mines over there, there's mines over 
there, and watch out those goddam monkeys bite, I'll tell ya.
==Apocalypse Now==


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

Date: 19 May 1997 01:17:35 GMT
From: "Simon Kitching" <simonk@telebusiness.co.nz>
Subject: Re: perlipc and multi-threading problem
Message-Id: <01bc63f3$0d616260$cbe824ca@simonk>



swarren@pdc.com wrote in article <5lio60$fbq@drn.zippo.com>...
> I am trying to get this multi-threaded control program to work
> and having no luck.

I have discovered this in the past, and couldn't resolve the problem
either. Hope someone out there can!
I get exactly the same results on an IBM RS6000 running AIX.

By the way, as far as I am aware, the tem "multi-threading" is reserved for
multiple threads of execution running **in the same address space**.
Perhaps the correct term for the example app is "multi-processing"?



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

Date: 19 May 1997 01:35:18 GMT
From: Query?????
Subject: print variable $abc which consist of '$' in it
Message-Id: <5loaom$as4@triton.np.ac.sg>

Hi,
   
    how do I print a variable which consist of "$" in it.
    Any pointers would be appreciated.

Thanks.






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

Date: 19 May 1997 02:09:03 GMT
From: nvp@shore.net (Nathan V. Patwardhan)
Subject: Re: print variable $abc which consist of '$' in it
Message-Id: <5locnv$q25@fridge-nf0.shore.net>

Query????? wrote:

:     how do I print a variable which consist of "$" in it.
:     Any pointers would be appreciated.

Is this what you were looking for?

perl -e '$val = "\$foo"; print $val,"\n";'

--
Nathan V. Patwardhan
nvp@shore.net



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

Date: Sun, 18 May 1997 22:46:59 GMT
From: andy@osea.demon.co.uk (Andrew Haveland-Robinson)
Subject: Re: REQ: Perl obfuscator
Message-Id: <337f8312.128888331@news.demon.co.uk>

On 17 May 1997 14:54:29 GMT, Ronald.J.Kimball@dartmouth.edu (Chipmunk) wrote:

>I suppose the only real way to handle all the possibilities would be to
>write a full-fledged compiler from perl to obfuscated perl.  But that
>wouldn'tbe as much fun.  :-)

Theoretically, this shouldn't be too difficult for the right person, as the
parser is aleady there... (and no, don't look at me!)
Web providers have access to all our hard work, an obfuscator is the next best
thing to a compiler.

Andy.
(Latest creation: http://www.domnames.com/cgi-bin/life-cgi/dnr.cgi?10101010
Registers .com .org .net domain names almost painlessly!)

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Haveland-Robinson Associates, 17 Williams Way, Fleet, Hants, GU13 9EU England.
Tel. +44 (0)1252-811670       Fax +44 (0)1252-811714       Mobile: 0585-052583
Web: http://www.osea.demon.co.uk


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

Date: Mon, 19 May 1997 03:20:14 GMT
From: abigail@fnx.com (Abigail)
Subject: Re: REQ: Perl obfuscator
Message-Id: <EAErxr.DqL@nonexistent.com>

On Sun, 18 May 1997 22:46:59 GMT, Andrew Haveland-Robinson wrote in
comp.lang.perl.misc URL: news:337f8312.128888331@news.demon.co.uk:
++ On 17 May 1997 14:54:29 GMT, Ronald.J.Kimball@dartmouth.edu (Chipmunk)
++ wrote:
++ 
++ >I suppose the only real way to handle all the possibilities would be to
++ >write a full-fledged compiler from perl to obfuscated perl.  But that
++ >wouldn'tbe as much fun.  :-)
++ 
++ Theoretically, this shouldn't be too difficult for the right person, as the
++ parser is aleady there... (and no, don't look at me!)
++ Web providers have access to all our hard work, an obfuscator is the next
++ best
++ thing to a compiler.


Djee, you got the Internet for free, you got HTTP for free, you got
HTML for free, you got CGI for free and you got Perl for free, and
now you are worried a web provider might see your puny cgi-program.

I guess you want the obfuscator and the upcoming compiler for free too?



Abigail


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

Date: Mon, 19 May 1997 05:26:53 +0100
From: Joshua <mailbox@mongoose.demon.co.uk>
To: Bill Banyai <banyai@llnl.gov>
Subject: Re: Seeding SRAND on WIN32
Message-Id: <337FD68D.EE8@mongoose.demon.co.uk>

Bill Banyai wrote:
> 
> Is there a good way to seed the random number generator on a WIN32
> platform?
> 

Perl's time function works on win32, so

  srand(time + $$);

still works.

> An associated question is how to retrieve the time; in particular, how
> to deal with the prompt that follows the display of the time.
> 
> For example:
> 
> c:\time
> c:\Current time is 12:06:42.47p
> c:\Enter new time:
> 
> I can extract the time to, in theory, seed SRAND, but how do I supply a
> carriage return to kill the program.
> 
> Thanks

You do not need to invoke command.com's time command for this, as
stated above, but you can if you want to:

   my $localtime = `echo.|time`;

This will get a string equivalent to

  "Current time is 12:06:42.47p\nEnter new time:\n"

--
Joshua Swink
joshua@mongoose.demon.co.uk


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

Date: Mon, 19 May 1997 02:19:07 -0500
From: Michael Lament <umcl1@fang.cs.sunyit.edu>
Subject: Small Web DataBase Wanted
Message-Id: <337FFEEB.63AC@fang.cs.sunyit.edu>

All,

	I am really into designing Web Pages and I have access to a PERL
Interpreter
via my CGI-BIN.  I am looking to see if anyone has a PERL script that
would interact
with a Web Page and act a  database.  Just a small type of database
where I can manipulate
the code for the exact types of fields but I would like to have deletion
capability.   

	I am hoping some dedicated PERL hacker would have any types of script
like this
that I could have.  This could also be helpful in learning this great
language and 
understanding it better.

	Well, if you can help , I would appreciate it.  Thanks in advance

Mike Lament


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

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

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