[12336] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 5936 Volume: 8

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Jun 9 18:07:27 1999

Date: Wed, 9 Jun 99 15:00:27 -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, 9 Jun 1999     Volume: 8 Number: 5936

Today's topics:
    Re: [Announce] Turbo Perl Shareware (Andrew Allen)
    Re: _Please_ improve localtime! (Andrew Allen)
    Re: _Please_ improve localtime! (Ilya Zakharevich)
    Re: Address Resolution Using Perl to Query Exchange <gellyfish@gellyfish.com>
    Re: Binary File Uploading - Part 2 <dfs@thegrid.net>
    Re: Binary File Uploading - Part 2 (Eric Bohlman)
    Re: Checking symlinks in Perl <jcreed@cyclone.jprc.com>
    Re: Checking symlinks in Perl (Andrew Allen)
    Re: Conditional END blocks (Gregory Snow)
        Eval loading modules <joakim@champion.se>
    Re: Functions <gellyfish@gellyfish.com>
        Generating a checksum... (Jim Matzdorff)
    Re: How do I change my frameset thru perl <shilpa_w@my-deja.com>
    Re: How do I change my frameset thru perl <gellyfish@gellyfish.com>
        How to diagnose/fix internal errors? <zamboni@xnet-a-062.resnet.purdue.edu>
    Re: How to package up perl scripts and interpreter for  <gellyfish@gellyfish.com>
    Re: how to pass a shell command to Perl (Andrew Allen)
        indexing into a hash <jim@sismicro.com>
        invoking a script (not in a subshell) <dshea@taurus.pppl.gov>
    Re: invoking a script (not in a subshell) <zamboni@xnet-a-062.resnet.purdue.edu>
    Re: keys and multilevel hashes and other things <cassell@mail.cor.epa.gov>
    Re: MySQL Placeholders II <gellyfish@gellyfish.com>
    Re: Perl "constructors" zenin@bawdycaste.org
    Re: perl debugging in emacs (Ilya Zakharevich)
    Re: Perl on win32 <gellyfish@gellyfish.com>
        Special: Digest Administrivia (Last modified: 12 Dec 98 (Perl-Users-Digest Admin)

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

Date: 9 Jun 1999 21:09:42 GMT
From: ada@fc.hp.com (Andrew Allen)
Subject: Re: [Announce] Turbo Perl Shareware
Message-Id: <7jml6m$eba$2@fcnews.fc.hp.com>

[this message posted and mailed to Will Smith <turboperl@erols.com>]

Will Smith (turboperl@erols.com) wrote:
: I am glad to announce

:             ============================================
:                            TurboPerl Software Version 1.20
:             ============================================

: You remember when Pascal was turbo-charged, well TurboPerl is a
: turbo-charged interactive Perl programming environment for Windows. Try it,
: you'll like it.

: Beginners will find that TurboPerl's interactive environment makes learning
: Perl easier and faster. It is now easy to modify your perl code and quickly
: see what happens. Experienced Perl programmers will appreciate a quicker
: edit/run cycle.

Pity this isn't written in perl/Tk and portable to many more
platforms. 'Course, my xemacs already does most of what it appears to
do (can't tell, since I have no WinPerl) plus debugging!

What is it written in? VB?

Andrew


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

Date: 9 Jun 1999 21:20:47 GMT
From: ada@fc.hp.com (Andrew Allen)
Subject: Re: _Please_ improve localtime!
Message-Id: <7jmlrf$eba$3@fcnews.fc.hp.com>

Bart Lateur (bart.lateur@skynet.be) wrote:
: Russell Schulz wrote:

: >I agree -- obviously, changing localtime() is a bad idea.
: >
: >But once you write this realtime(), _please_ submit it to perlbug, so it
: >can become part of the standard distribution (helping the poor interface
: >on localtime die an all-too-late death).

: Hah, modernising Perl....

: Why not call the newer version "mytime()"?

And you could call the new gmtime "ourtime". ;)

Andrew


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

Date: 9 Jun 1999 21:38:58 GMT
From: ilya@math.ohio-state.edu (Ilya Zakharevich)
Subject: Re: _Please_ improve localtime!
Message-Id: <7jmmti$hdc$1@mathserv.mps.ohio-state.edu>

[A complimentary Cc of this posting was sent to Andrew Allen
<ada@fc.hp.com>],
who wrote in article <7jmlrf$eba$3@fcnews.fc.hp.com>:
> : Hah, modernising Perl....
> 
> : Why not call the newer version "mytime()"?
> 
> And you could call the new gmtime "ourtime". ;)

"theirtime" or "britime"?

Ilya


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

Date: 9 Jun 1999 20:38:37 -0000
From: Jonathan Stowe <gellyfish@gellyfish.com>
Subject: Re: Address Resolution Using Perl to Query Exchange
Message-Id: <7jmjcd$he$1@gellyfish.btinternet.com>

In comp.lang.perl.misc Sitaram Chamarty <sitaram@diac.com> wrote:
> On Mon, 7 Jun 1999 16:18:14 -0500, Michael J. McKinlay
> <Mike.McKinlay@hboc.com> wrote:
>>I've seen some hints and ideas floating around -- is there anyone actually
>>using perl LDAP to query an Exchange server to resolve an address?
> 
> I use "ldapsearch", a neat little command line thingie, to grab
> all the email addresses every Monday morning and populate my email
> client (mutt)'s aliases file.  Works great.
> 
>>We have an app on IIS that can generate SMTP mail, but you have to know the
> 
> Aaah!  Now I see what you mean.  Perhaps ldapsearch and its
> associated tools will compile on NT...?
> 

one might be able to use Net::LDAP on NT - Cant recall ever having seen
it in the Activestate repository though.

/J\

-- 
Jonathan Stowe <jns@gellyfish.com>
Some of your questions answered:
<URL:http://www.btinternet.com/~gellyfish/resources/wwwfaq.htm>
Hastings: <URL:http://www.newhoo.com/Regional/UK/England/East_Sussex/Hastings>


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

Date: Wed, 09 Jun 1999 20:01:09 GMT
From: "Ryan" <dfs@thegrid.net>
Subject: Re: Binary File Uploading - Part 2
Message-Id: <01beb2b3$a9032bc0$3830a2d1@ryano-ke>



Hi,

Yeah, I have fatalsToBrowser in the script and only receive the 500 error.
I will try to find information on the warn feature in the docs..

Anybody else have an idea? BTW, my comments do not wrap like they are shown
in the post.

C-ya
Ryan

I.J. Garlick <ijg@csc.liv.ac.uk> wrote in article
<FD2DC2.JKE@csc.liv.ac.uk>...
> In article <01beb265$2fc60460$f031a2d1@ryano-ke>,
> "Ryan" <dfs@thegrid.net> writes:
> > 
> > Ok, I thought I had it worked out with the help of Will Smith (Thanks
for
> > your time Will!)
> > 
> > I am trying to get a web based binary (.jpg) file upload script to
work.
> > Unfortunately, I do not have access to the server logs. I am receiving
a
> > 500 internal error and I am hoping someone can look at these two snips
and
> > see what is wrong..
> > 
> 
> Not sure, and without error logs it gets real fun real quick (not to
> mention tedious).
> 
> So have you tried something like this
> 
> 	use CGI::Carp 'fatalsToBrowser';
> 
> Hopefully this will print any errors to your browser. I think there is a
> way of doing it for warn as well. At any rate you will see what the die
is
> returning (assuming it is the die that causes it to stop prematurely).
> 
> > 
> > Humbly spoken...Help!? <G>
> > Thanks for your time
> > Ryan
> 
> -- 
> -- 
> Ian J. Garlick
> ijg@csc.liv.ac.uk
> 
> The function of the expert is not to be more right than other people,
> but to be wrong for more sophisticated reasons.
>                 -- Dr. David Butler, British psephologist
> 
> 


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

Date: Wed, 9 Jun 1999 20:21:45 GMT
From: ebohlman@netcom.com (Eric Bohlman)
Subject: Re: Binary File Uploading - Part 2
Message-Id: <ebohlmanFD2tw9.Mrq@netcom.com>

Ryan (dfs@thegrid.net) wrote:
: Yeah, I have fatalsToBrowser in the script and only receive the 500 error.

That suggests that either your server is failing to call your script at 
all, or that your script is bombing out with a compilation error rather 
than run-time error.

: I will try to find information on the warn feature in the docs..

In this case, that won't help, since it sounds like your script is never 
running.


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

Date: 09 Jun 1999 16:33:33 -0400
From: Jason Reed <jcreed@cyclone.jprc.com>
Subject: Re: Checking symlinks in Perl
Message-Id: <a1r9nljeqq.fsf@cyclone.jprc.com>

Jaap Keuter <jak@knoware.nl> writes:

> Hi all,
> 
> I'm using Perl on HP-UX 10 and I'm looking for a way to check if the file a
> symlink points to has gone. This is to be used in a script that checks all
> symlinks in a directory and if a symlinks points to nothing it is removed.
-e readlink $symlinkname
?

---Jason


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

Date: 9 Jun 1999 21:01:23 GMT
From: ada@fc.hp.com (Andrew Allen)
Subject: Re: Checking symlinks in Perl
Message-Id: <7jmkn3$eba$1@fcnews.fc.hp.com>

Jaap Keuter (jak@knoware.nl) wrote:
: Hi all,

: I'm using Perl on HP-UX 10 and I'm looking for a way to check if the file a
: symlink points to has gone. This is to be used in a script that checks all
: symlinks in a directory and if a symlinks points to nothing it is removed.

It's almost perl poetry:

  opendir MYDIR,"." or die "Can't open .: $!";
  unlink foreach grep {-l && !-e} readdir MYDIR;
  closedir MYDIR;

Andrew


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

Date: 9 Jun 1999 19:53:59 GMT
From: snow@biostat.washington.edu (Gregory Snow)
Subject: Re: Conditional END blocks
Message-Id: <7jmgon$rta$1@nntp6.u.washington.edu>

In article <375EB8B4.DA37889E@mathworks.com>,
Craig Ciquera  <craig@mathworks.com> wrote:

>2. may be your best bet.  The Camel book has the following to say
>about END blocks:
> 
>Your END blocks should not assume that any or all of your main code
>ran.  (They shouldn't do this in any event, since the interpreter
>might exit early from an exception.)  This is not a bad problem in
>general.  At worst it means you should test for the "definedness" of a
>variable before doing anything rash with it.  In particular, before
>saying something like:
> 
>  system "rm -rf '$dir'"
> 
>you should always check that $dir contains something meaningful,
>whether or not your doing it in an END block.

Yes, reading that was what made me test before trusting the simple
approach. 


>In any case, the following does what you want -- I think:
>
>#!/home/bin/perl -w
>
>my $temp=0;
>
>sub test {
>  print "in sub\n";
>
>      END { print "ending stuff: $temp\n" if ( $temp ); }
>}
>
>
>if ($temp) {
>  test();
>}

That works as long as $temp does not change after the conditional and
before the end of the script.  Inserting "my $temp = $temp;" as the first
line of the sub fixes that (aren't lexicals great :-).

This is my method 1, it has the (dis)?advantage of running the END
block at most once even if the sub runs more than once.  

An interesting aside, my test showed that while the END block runs
only once (as it should), when the sub "test" is run 2 times with
$temp having different values each time. The END block reports the
value from the first run of "test" rather than the last.  Is this
documented somewhere?, why the first rather than last?, could this
change?  The end block is kind of like a closure, but only gets
created the first time the function runs.  Interesting

A better version of the above code (assuming you only want at most
one final print statement if the sub runs multiple times) is:

sub test {
	my $test_ran = 1;  #something that evals to true
	print "in sub\n";  
	END {print "ending stuff: $temp\n" if $test_ran; }
}

That way $temp can change, but the END block still runs, plus the sub
doesn't need to know what conditions control it's running (i.e. if
($temp || $othercondition){test()} ).

I still think I like my #2 best, because I probably want an equivalent
of an END block for each time the subroutine runs, but your post
solidified my thoughts on using the inner lexical variable (and there
will probably be other situations where I want to use this one),
Thanks.

-- 
-------------------------------------------------------------------------------
     Gregory L. Snow         |   Imagination is the one weapon in the
     (Greg)                  |  war against reality.
snow@biostat.washington.edu  |                -- Jules de Gaultier


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

Date: Wed, 09 Jun 1999 23:40:06 +0200
From: Joakim Mared <joakim@champion.se>
Subject: Eval loading modules
Message-Id: <375EDF36.DC653F0A@champion.se>

I've run in to something i can't really understand, and would greatly
appreciate an explanation or a reference to some document that could
explain why my code behaves like this.

imagine that i want a conditional loading of a module, ie. if we have
the module, use it, if we don't have it use another way, but don't die.
'ayrnieu, EFnet, #perl' suggested this:

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

if (eval 'use MyModule', $@ eq '') {
    print "We have our module\n";
} else {
    print "We don't have our module\n";
}

this did not work, the module was never really 'used', but this approach
works:

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

if (eval 'use MyModule', $@ eq '') {
    use MyModule;
    print "We have our module\n";
} else {
    print "We don't have our module\n";
}

so, now to the question, why doesn't the eval statement in example one
load the module?

//Joakim Mared//



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

Date: 9 Jun 1999 19:47:59 -0000
From: Jonathan Stowe <gellyfish@gellyfish.com>
Subject: Re: Functions
Message-Id: <7jmgdf$fc$1@gellyfish.btinternet.com>

On Wed, 9 Jun 1999 12:44:50 -0400 Bob Perini wrote:
> I'm trying to include a file(which has a function) into my program, and
> can't seem to get it to work.
> 
> File1
> seems to include the function properly but here is my "include" lines:
> 
> Line8:   @INC="c:/InetPub/scripts/jeopardyalpha/addtoDB/";
> Line9:   require "c:/InetPub/scripts/jeopardyalpha/addtoDB/addtodb.pl";
> 

You probably want to do:

  use lib 'C:/InetPub/scripts/jeopardyalpha/addtoDB';
  require 'addtidb.pl';

As what you are doing will trash your @INC thus rendering the use of
any standard libraries rather difficult.

> File 2
> 
> sub addtodb
> {
>     do stuff
>     return 0;
> }
> 
> Now the error that I get is:
> 
> c:/InetPub/scripts/jeopardyalpha/addtoDB/addtodb.pl did not return a true
> value at C:\InetPub\scripts\jeopardyalpha\addtodb\addtodbInter.pl line 9.
> 
> Line 9 is the one that i labeled above..
> 

You should put

'I am the lord of hell fire';

as the last line of your library file.

perldoc -f require

/J\
-- 
Jonathan Stowe <jns@gellyfish.com>
Some of your questions answered:
<URL:http://www.btinternet.com/~gellyfish/resources/wwwfaq.htm>
Hastings: <URL:http://www.newhoo.com/Regional/UK/England/East_Sussex/Hastings>


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

Date: 9 Jun 1999 14:05:47 -0700
From: syran@best.com (Jim Matzdorff)
Subject: Generating a checksum...
Message-Id: <7jmkvb$q47$1@shell18.ba.best.com>

Hello all,

I am trying to generate a checksum for an ICMP packet, which basically
states that the checksum is the 16-bit one's complement of the one's
completment sum of th whole IGMP message (direct from the RFC!).  The
checksum computes on every 2 bytes in the message.

My problem is that I am unsure of how to get a one-complement in perl,
as I can't use unsigned values and do bit-wise shifts (this would be
easy to do in C).  My code is based on how you would do it in C.

This is what I have currently, but (obviously) it doesn't work -- 
help?

        my ($hex_string) = "12 00 00 00 e0 0c 17 22";
        my (@hexes) = split /\s/, $hex_string;
        for ($on_hex = 0; $on_hex < scalar(@hexes); $on_hex++)
        {
		# get the 2 byte equivalent HEX
                push @hex_vals, "0x" . $hexes[$on_hex++] .  $hexes[$on_hex];
        }
        foreach (@hex_vals)
        {
		# convert the hex number to decimal to do addition
                $number = hex($_);
                $total += $number;
		# try and flip it if the one's complement is set
                if ($total & 0x80000000)
                {
                   $total = ( $total & 0xFFFF) + ($total >> 16);
                }  
        }       
        while ( $total >> 16)
        {
                $total =  ( $total & 0xFFFF) + ($total >> 16);
        }       

-- 
--
One tequila, two tequila, three tequila, floor.


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

Date: Wed, 09 Jun 1999 20:10:14 GMT
From: Shilpa <shilpa_w@my-deja.com>
Subject: Re: How do I change my frameset thru perl
Message-Id: <7jmhmv$tn4$1@nnrp1.deja.com>

In article <7jm3ke$nll$1@nnrp1.deja.com>,
  mikecard@my-deja.com wrote:
> In article <7jlv01$lfu$1@nnrp1.deja.com>,
>   shilpa_w@my-deja.com wrote:
> > My web application has a window that has 3 frames.
> > When the user clicks on the submit button in the
> > form in one of the frames, a perl program is
> > executed that gets the data from the server. I
> > want to display this data in a new framset that
> > has only 2 frames.
>
> when the user submits the form make sure the result TARGET=_top.
> have your cgi create the new 2 frame frameset.  for the frame that you
> want the user submitted data to be displayed have the framesource go
> back to the cgi with a query string (the query string being the info
the
> user submitted)  when the program recieves a query string make it
create
> an html document based on that information...hope that isn't too
> confusing,  i'm sure there's an easier way but that's what i came up
> with
>
> mike cardeiro
>
> Sent via Deja.com http://www.deja.com/
> Share what you know. Learn what you don't.
>
Mike
I tried the solutions you offered and it worked great. Thanks a lot for
your help.  But I have one more question.
Here is my code
print <<mult;
<HTML>
<HEAD><TITLE>NorthStar 2000</TITLE> </HEAD>
<FRAMESET COLS="27%,*">
<FRAME NAME="left" SRC="left.htm" SCROLLING="no" MARGINWIDTH="5"
MARGINHEIGHT="0" BORDER="5" >
   <FRAMESET ROWS="85%,*">
     <FRAME NAME="body"
SRC="/test/cgi-bin/contents.pl?process=contents&class=None"
MARGINWIDTH="5" MARGINHEIGHT="12">
     <FRAME NAME="lowerbody" SRC="lowerbody.htm" SCROLLING="no"
MARGINWIDTH="5" MARGINHEIGHT="12">
   </FRAMESET>
</FRAMESET>
</HTML>
mult

If I have a .pl file as framesource for one of the frames, do the other
frames need only pl files as source? Becuase in this case I am getting
internal error for the left and lowerbody frames and if I replacethem w/
pl files they work fine.

--
Shilpa


Sent via Deja.com http://www.deja.com/
Share what you know. Learn what you don't.


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

Date: 9 Jun 1999 20:00:06 -0000
From: Jonathan Stowe <gellyfish@gellyfish.com>
Subject: Re: How do I change my frameset thru perl
Message-Id: <7jmh46$fn$1@gellyfish.btinternet.com>

On Wed, 09 Jun 1999 14:50:46 GMT shilpa_w@my-deja.com wrote:
> My web application has a window that has 3 frames.
> When the user clicks on the submit button in the
> form in one of the frames, a perl program is
> executed that gets the data from the server. I
> want to display this data in a new framset that
> has only 2 frames. How can I do this?
> 

If you are using the module CGI.pm then you should read the documentation:

  perldoc CGI

There is a section entitled:

  WORKING WITH NETSCAPE FRAMES

You will also want to look at the CGI FAQ:

  <http://www.webthing.com/tutorials/cgifaq.html>

Almost certainly this kind of question is more appropriately asked in 
the group comp.infosystems.www.authoring.cgi

/J\
-- 
Jonathan Stowe <jns@gellyfish.com>
Some of your questions answered:
<URL:http://www.btinternet.com/~gellyfish/resources/wwwfaq.htm>
Hastings: <URL:http://www.newhoo.com/Regional/UK/England/East_Sussex/Hastings>


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

Date: 09 Jun 1999 16:09:53 -0500
From: Diego Zamboni <zamboni@xnet-a-062.resnet.purdue.edu>
Subject: How to diagnose/fix internal errors?
Message-Id: <cwogip13oe.fsf@xnet-a-062.resnet.purdue.edu>

Hi,

I am in the process of porting a set of fairly large modules/programs
written in Perl from Solaris 2.5.1 on Sparc (where they were written)
to Linux. I am using RedHat 5.1 with a 2.0.34 kernel and Perl
5.004_05, running on a Pentium machine.

Being Perl, there was really no much porting necessary, except for the
following weird problem. There are two different (but I think related)
parts to the problem.

Part 1:
-------

When the program exits, I get the following errors:

Attempt to free unreferenced scalar during global destruction.
Attempt to free unreferenced scalar during global destruction.
<final program output>
Can't upgrade that kind of scalar during global destruction.

According to perldiag(1), the first message is an optional warning
(I am using -w), and the last one is an "internal error you should
never see". Ouch.

The first two messages occur during the last phases of execution of
the program (I know this because the program still prints a message
after those two first warnings), so my guess is that they occur
during the destruction of some of the internal objects used by the
program, but I have not been able to diagnose which ones.

The last message appears when the main program executes "exit(0)" to
terminate. I have no idea of how to even start diagnosing this.

Part 2:
-------

My program reads instructions from STDIN, and I have two ways of
stopping it: either by closing the input (CTRL-D if I'm running it
interactively) or by typing a "STOP" command.

The program behaves as described in Part 1 if I use the STOP command.
However, if I use CTRL-D, I get the following:

Attempt to free unreferenced scalar during global destruction.
Attempt to free unreferenced scalar during global destruction.
Segmentation fault (core dumped)

No final output, and a core dump. I have sprinkled debugging messages
throughout my code to see where the crash is occurring, but it seems
to occur semi-randomly (e.g., I see it occurs at a certain statement,
comment it out, only to have it occur later in the program).
My guess is that is has something to do with the fact that STDIN
is closed, although my program does not try to read from STDIN
after it detects it has been closed.



None of the errors (both parts) occur if I execute the program from
the debugger.  Also, none of the errors occur in Solaris. They only
appear in Linux. Also, other than printing the errors (and dumping
core in case 2), the program runs just fine.

Any ideas on how to go about finding what could be causing these
problems will be very welcome. Could it be something in my program?
Something in Linux? Something in the Linux port of Perl?

Thanks a lot for any help,
--Diego Zamboni


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

Date: 9 Jun 1999 20:33:53 -0000
From: Jonathan Stowe <gellyfish@gellyfish.com>
Subject: Re: How to package up perl scripts and interpreter for shipping
Message-Id: <7jmj3h$hb$1@gellyfish.btinternet.com>

On 7 Jun 1999 19:29:02 GMT lvirden@cas.org wrote:
> 
> Has anyone a technique for determining the minimal libraries to ship
> along with the interpreter?  Is there perhaps a technique which
> would create a single executable perl interpreter which was completely
> self-contained (had no dependencies on additional runtime components
> other than the perl script one wanted to run)?

You can print out the keys and values of the %INC hash after you have done
all of your use'ing to determine all of the files that have been used
by use,require or do ...

/J\
-- 
Jonathan Stowe <jns@gellyfish.com>
Some of your questions answered:
<URL:http://www.btinternet.com/~gellyfish/resources/wwwfaq.htm>
Hastings: <URL:http://www.newhoo.com/Regional/UK/England/East_Sussex/Hastings>


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

Date: 9 Jun 1999 21:45:46 GMT
From: ada@fc.hp.com (Andrew Allen)
Subject: Re: how to pass a shell command to Perl
Message-Id: <7jmnaa$eba$4@fcnews.fc.hp.com>

ZENG (zeng@haas.Berkeley.EDU) wrote:
: I need to write a Perl program, which take a shell command and process it.
: For example, let me call my program 'sw'. So I can use it like the
: following:

: 1. sw ls
: 2. sw ls -l
: 3. sw who
: 4. sw more file

: You got the idea. This is easy to do because I can use the @ARGV and pass
: it to my program to 'sw'. 

: Now it is the hard part. What if I want to do the following:

: sw ls -l | grep Jun

: The command runs but not what I want. The shell understands this as
: process 'sw ls -l' first then pipe to 'grep Jun'. What I really want is
: pass the whole command 'ls -l | grep Jun' to 'sw.

This is a shell issue, not a perl issue. I'd do it like:

  sw ls -l \| grep Jun

<snip>

: sw 'more file | grep 'Inter*st' '
: or
: sw 'more file | egrep 'good | bad' > newFile'

for the readability impaired, there's always:

  sw 'more file | egrep '\''good | bad'\'' > newFile'

or the simpler

  sw "more file | egrep 'good | bad' > newFile"

(but then you have to watch out for shell double-quote expansion).
 
Andrew


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

Date: Wed, 09 Jun 1999 15:19:15 -0600
From: Jim Keefer <jim@sismicro.com>
Subject: indexing into a hash
Message-Id: <375EDA53.2FD8C1C7@sismicro.com>

Since perl implements a hash as two parallel arrays, is there a way I
can index into a hash?

I need the speed of a hash key look up, but I also need to be able to
get the hash key from an integer index.  Currently, I have a hash with a
string key and integer (index) value, and an array based on these
indexes which also stores the string.  This gives me the fuctionality I
want.  But I have some pretty large arrays of strings, which I am
storing twice because of this arrangement.  It would save time and a lot
of space if I could store it once in a hash, but still be able to access
the hash either by string key to get the index, or get the hash key by
using an integer index.

Email me with any suggestions.
Thanks!

--
_________________________________________________________________________
Jim Keefer        SIS Microelectronics, Inc.,   An ASPEC Technology Co.
|
jim@sismicro.com  1831 Lefthand Circle Suite E  Longmont, CO 80501     
|
303.776.1667x272  http://www.sismicro.com       FAX: 303.776.5947      
|


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

Date: Wed, 9 Jun 1999 16:42:17 -0400
From: Dan Shea <dshea@taurus.pppl.gov>
Subject: invoking a script (not in a subshell)
Message-Id: <Pine.SO4.4.05.9906091636001.25055-100000@taurus.pppl.gov>


Hi,

I've read the perl faq, which re-directs me to the comp.unix.questions
faq, which points to a non-existant ftp site in the attempt to answer the
following question.

I have a perl script which needs to look at users environment variables,
strip out duplicate instances of paths: 

e.g. 

$PATH = .:/bin:/usr/bin:/usr/bin

would become

$PATH = .:/bin:/usr/bin


Now, what I am trying to figure out is how I can force my Perl script to
run in the current shell, instead of forking a subshell.

Any suggestions are appreciated.


Dan Shea
Disclaimer:
My opinions do not reflect those of my employer.



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

Date: 09 Jun 1999 16:49:46 -0500
From: Diego Zamboni <zamboni@xnet-a-062.resnet.purdue.edu>
Subject: Re: invoking a script (not in a subshell)
Message-Id: <cwn1y911tx.fsf@xnet-a-062.resnet.purdue.edu>

Dan Shea <dshea@taurus.pppl.gov> writes:
> I have a perl script which needs to look at users environment variables,
> strip out duplicate instances of paths: 
> [...]
> Now, what I am trying to figure out is how I can force my Perl script to
> run in the current shell, instead of forking a subshell.

One thing you could do is have the Perl script output shell commands that
set the variables, and eval it from the shell. So have your Perl script
output something like this (assuming it is to be run from a Bourne-like
shell such as sh, ksh or bash):

PATH=.:/bin:/usr/bin; export PATH

and then from your shell script do:

eval `perlscript.pl`

--Diego



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

Date: Wed, 09 Jun 1999 14:28:25 -0700
From: David Cassell <cassell@mail.cor.epa.gov>
To: Steve Vertigan <vertigan@bigfoot.com>
Subject: Re: keys and multilevel hashes and other things
Message-Id: <375EDC79.DF8E0BEE@mail.cor.epa.gov>

[courtesy cc to poster]

Steve Vertigan wrote:
> 
> Is there a way, that I've missed, to run through a multilevel hash, similar
> to this...
> 
> foreach $key (keys %HASH) {
>     foreach $key2 (keys $HASH{$key}) { }
                                       ^^^
        you need to do *something* here |
>     }

BTW, please use a lower-case or title-case name for your
variables.  It's better Perlstyle to use upper-case for
filehandles, dirhandles, and constants only.  [See the
perlstyle manpage, using man or perldoc or ...]

This is *almost* the right form for accessing a hash of hashes, 
which was just what you were hoping for.  But, if you had stopped
and read the perldsc pages on your system, you would already
know this, and you would know that you can do a little
better by sorting so that your keys come out in a prettier
order:

foreach $key1 (sort keys %hash) {
    foreach $key2 (sort keys %{ $hash{$key1} }) {
        print "$key2 = $hash{$key1}{$key2}\n";
    }
}
 
> So I could get all the $HASH{$key}{'whatever'} values?  I achieved what
> needed to be done using Symbolic References and one level hashes but this
> would seem a better way to go if it could be done.

Yes.  Using symbolic references is, umm, deprecated.  To
put it another way, they are A Bad Thing.. as has been pointed
out in this newsgroup at least weekly for the past umpteen
months.

> Another question if I may, on hashes vs array.  When working on a flat file
> database would it be more efficient to load everything into an @array or to
> to stick each line in a $DATA{$primary_key} = $restofline; structure?  It
> would obviously be easier to work with the hash but I wonder if that would
> mean a tradeoff in program speed and memory usage.  Most of my perl
> programming is currently CGI scripts which sit on other people's hosts so
> I'm always looking for the (quickest|best) way to do things.

Okay, given your issues, I would suggest that you make the
array/hash decision based on data needs instead of speed and
memory usage.  If you're going to be using your data structure
to search or look up or check for inclusion, then you should
probably be using a hash for handy searching.  Make the data
structure so that it answers your problem for you.  Then your
code will be a heck of a lot simpler.

And, since you're using Perl on your ISP's system, you'll
want to acquire your very own personal copy of the docs.
I'm guessing based on your newsreader that you're using a
win32 box yourself.  So go to www.activestate.com and
download your own copy of Perl.  It will install on its own,
and place a fairly complete set of docs in an HTML tree on
your disk, along with a button on your Start menu for easy
access.  Then go and look in there.  Perl comes with enough
info to answer all your questions for some time, including
the FAQ and the win32 FAQ.  You'll want to go straight to
the perldsc section to see what you can do with a hash-of-
hashes like you have here.
 
> And while we're talking about perl and CGI I'll re-ask a question which has
> gone unanswered in a CGI group even though it's more appropiate there, so
> feel free to ignore it. :-)
> 
> I know this is really dependant on various factors but, as a general rule,
> what's the largest size text-based datafile you can safely load into memory
> when running as a CGI script?  Or at what point does it become preferable to
> use an SQL solution.  The most likely scenario for failure that I can think
> of would be running under a CGI wrapper like CGIWrap that has imposed memory
> or CPU-usage limits on the script in which case I presume the script would
> be killed or encounter an error trying to read the file.  Has anyone
> experienced hitting such a limit and have wisdom to share?
> 
> Anyways this post is getting far longer than it should so I'll give it a
> rest here.
> 
> Ciao,
> --Steve

[Another of my annoying nitpicks: it's usually a good idea to
post different questions in different posts, instead of lumping
them all together.  Here's why:]

This question I can't answer effectively.  But I can tell you this.
Perl trades off memory to gain speed.  So a hash of lines from
a file will take up more space than an array of those lines, which
will take up more space than slurping all those lines into one
[possibly unusable] scalar variable.  The amount of space you'd
have for your file will depend a lot on external factors: what
else is running in your space; what Perl modules you have 'use'd;
how long your program is; how effectively you have coded your
HTML; ...  My suggestion is to try it out.  Fake a series of
data files which increase in size by a factor of 2 [or 10],
starting with something reasonable like a 2K file.  See where
the system munches you.  Then go ask your ISP for more memory.
Or go to a real database, which Perl can handle even better,
using the DBI and DBD::* modules.

Arrevederci,
David
-- 
David Cassell, OAO                     cassell@mail.cor.epa.gov
Senior computing specialist
mathematical statistician


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

Date: 9 Jun 1999 19:51:46 -0000
From: Jonathan Stowe <gellyfish@gellyfish.com>
Subject: Re: MySQL Placeholders II
Message-Id: <7jmgki$fg$1@gellyfish.btinternet.com>

In comp.lang.perl.misc Clinton Gormley <clint@drtech.co.uk> wrote:
> Sorry, another placeholder issue
> 
> I'm trying to do this :
> SELECT * FROM Table WHERE Id IN (1,2,3,4)
> 
> I'd like to replace the 1,2,3,4 with a place holder, but it looks like I
> would have to do this :
> SELECT * FROM Table WHERE Id IN (?,?,?,?)
> 
> Only problem is, I don't know how many numbers I will have beforehand.
> 

Use the 'power of Perl' to dynamically build your query string before you
prepare it.

/J\
-- 
Jonathan Stowe <jns@gellyfish.com>
Some of your questions answered:
<URL:http://www.btinternet.com/~gellyfish/resources/wwwfaq.htm>
Hastings: <URL:http://www.newhoo.com/Regional/UK/England/East_Sussex/Hastings>


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

Date: 09 Jun 1999 20:03:37 GMT
From: zenin@bawdycaste.org
Subject: Re: Perl "constructors"
Message-Id: <928958797.413894@localhost>

armchair@my-deja.com wrote:
	>snip<
: What pages of the standard Perl documentation, in your opinion, best
: demonstrate it's higher level language status versus C++?

	perl*

	Your definition of HLL seems to stem directly from total LOC.  By
	this definition Perl is about as high level a language as one can
	get, typically weighing in at 1/10 to 1/20 the LOC of C/C++ for a
	given task.

-- 
-Zenin (zenin@archive.rhps.org)         Caffeine...for the mind.
                                        Pizza......for the body.
                                        Sushi......for the soul.
                                             -- User Friendly


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

Date: 9 Jun 1999 21:36:15 GMT
From: ilya@math.ohio-state.edu (Ilya Zakharevich)
Subject: Re: perl debugging in emacs
Message-Id: <7jmmof$har$1@mathserv.mps.ohio-state.edu>

[A complimentary Cc of this posting was sent to Tom Phoenix 
<rootbeer@redcat.com>],
who wrote in article <Pine.GSO.4.02A.9906091232100.26349-100000@user2.teleport.com>:
> > When ever I redirect stdin to a file, the debugger still
> > reads from the keyboard.
> 
> I'm not completely sure, never having needed it, but I think you want the
> noTTY option described in the perldebug manpage. Good luck!

Then the debugger will not take any command input.

But Emacs should have redirected the current TTY to "Emacs window".
Smells like under-ported Emacs on something fishy, like Win*.

Since it is absolutely unclear what the original poster wanted to
achieve, guessing is moot.

Ilya


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

Date: 9 Jun 1999 21:25:55 -0000
From: Jonathan Stowe <gellyfish@gellyfish.com>
Subject: Re: Perl on win32
Message-Id: <7jmm53$tm$1@gellyfish.btinternet.com>

On 9 Jun 1999 10:25:40 GMT Steffen Beyer wrote:
> In article <7jjtcv$v68$1@nnrp1.deja.com>, RoLm <rolm@my-deja.com> wrote:
> 
>> try the following:
> 
>> 1. Start->Settings->Control Panel->System
>> 2. Click the Environment tab
>> 3. in the Variable field, type PATHEXT
>> 4. in the Value field, type .COM;.EXE;.BAT;.CMD;.plx
>> 5. Click Set, then Apply, then OK
>> 6. Enjoy!
> 
> This works great!
> 
> But is there another way, apart from a "$dummy = <STDIN>;" statement at
> the end of the script, to avoid the automatic closing of the MSDOS window
> after the script terminated (on Windows NT 4.0)?
> 

If you make your script into a batch file using pl2bat then you will be
able to change the 'Close on exit' property in the properties item of
the right mouse menu.  You can only do this with DOS programs and batch
files - Activeperl doesnt count as DOS program.

/J\
-- 
Jonathan Stowe <jns@gellyfish.com>
Some of your questions answered:
<URL:http://www.btinternet.com/~gellyfish/resources/wwwfaq.htm>
Hastings: <URL:http://www.newhoo.com/Regional/UK/England/East_Sussex/Hastings>


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

Date: 12 Dec 98 21:33:47 GMT (Last modified)
From: Perl-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Special: Digest Administrivia (Last modified: 12 Dec 98)
Message-Id: <null>


Administrivia:

Well, after 6 months, here's the answer to the quiz: what do we do about
comp.lang.perl.moderated. Answer: nothing. 

]From: Russ Allbery <rra@stanford.edu>
]Date: 21 Sep 1998 19:53:43 -0700
]Subject: comp.lang.perl.moderated available via e-mail
]
]It is possible to subscribe to comp.lang.perl.moderated as a mailing list.
]To do so, send mail to majordomo@eyrie.org with "subscribe clpm" in the
]body.  Majordomo will then send you instructions on how to confirm your
]subscription.  This is provided as a general service for those people who
]cannot receive the newsgroup for whatever reason or who just prefer to
]receive messages via e-mail.

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

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