[14005] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 1415 Volume: 9

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Nov 18 14:14:18 1999

Date: Thu, 18 Nov 1999 11:05:27 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <942951925-v9-i1415@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Thu, 18 Nov 1999     Volume: 9 Number: 1415

Today's topics:
    Re: Adding to @INC during perl install (Greg Boug)
    Re: binary database (Kragen Sitaker)
    Re: binary database <jeff@vpservices.com>
    Re: Can open file with Telnet but not browser <amonotod@netscape.net>
    Re: Can open file with Telnet but not browser <amonotod@netscape.net>
    Re: Can open file with Telnet but not browser (Alan Curry)
    Re: Can open file with Telnet but not browser <lr@hpl.hp.com>
    Re: Date localtime help...Newbie <vincent.murphy@cybertrust.gte.com>
        Executeable into a Variable (Kevin)
    Re: FAQ 5.3: How do I count the number of lines in a fi <rick.delaney@home.com>
    Re: FAQ 5.3: How do I count the number of lines in a fi <jkline@one.net>
    Re: FAQ 5.3: How do I count the number of lines in a fi (Sam Holden)
    Re: Fetch Dilbert. (Philip 'Yes, that's my address' Newton)
    Re: Fetch Dilbert. (Philip 'Yes, that's my address' Newton)
    Re: Flat File Searching Problem <kbandes@home.com>
    Re: Generating pi (Jon Bell)
    Re: Generating pi (Peter J. Kernan)
    Re: hash of filehandles <bwalton@rochester.rr.com>
        Help with understanding syntax marius_13@my-deja.com
    Re: Help with understanding syntax (Sam Holden)
    Re: Help with understanding syntax (Brett W. McCoy)
    Re: Help! - grep for x then echo y from a line in a log <rootbeer@redcat.com>
        Help: system() in Perl <dsrinu@acsu.buffalo.edu>
    Re: Help: system() in Perl (Kragen Sitaker)
    Re: Help: system() in Perl <jeffp@crusoe.net>
    Re: how to make perl executable <ritchie@fnal.gov>
        How to make the comparable also hashable? <johnlin@chttl.com.tw>
        Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)

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

Date: 18 Nov 1999 02:21:33 GMT
From: gboug@iona.kau1.kodak.com (Greg Boug)
Subject: Re: Adding to @INC during perl install
Message-Id: <slrn836old.dub.gboug@iona.kau1.kodak.com>

On Tue, 16 Nov 1999 10:30:24 -0500, Tony Demark <tpost@intelihealth.com> wrote:
>This would seem to be an easy question, but I just can't find the answer
>in the FAQ or INSTALL file:
>
>When installing perl (5.005_03), how do I add additional directories to
>@INC?

What you may want is something like this:

#!/usr/bin/env perl -w
BEGIN {
    # Modify @INC to suit your needs here
}

# Program begins here... 

This modifies the @INC before compile time...
Other options are to use -I/path/to/modules on the
Perl line...

Greg
-- 
To reply, remove the uppercase letters in my email address...
Disclaimer: The opinions expressed are purely my own and do not
represent the opinions of my employer...


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

Date: Thu, 18 Nov 1999 03:18:23 GMT
From: kragen@dnaco.net (Kragen Sitaker)
Subject: Re: binary database
Message-Id: <3eKY3.24254$YI2.1056850@typ11.nn.bcandid.com>

In article <80vmrf$s6f$1@ultra.sonic.net>,
Steven Lybeck <alanis@softhome.net> wrote:
>I am in search of a binary database written entirely in perl. I have found
>many flat-file (text-delimated?) database programs, but this is not what I
>am looking for as it will be much to slow if the amount of records to be
>searched is in the hundreds of thousands. Which it will need to be. Also
>nice would be a way to query it with SQL commands. If anyone knows of this,
>or of another solution to my problem, please post it here.

I think you mean "fixed-width-field database", right?  Well, you can
use pack and seek to do a creditable job.  But you'd probably be better
off installing PostgreSQL and using that.
-- 
<kragen@pobox.com>       Kragen Sitaker     <http://www.pobox.com/~kragen/>
The Internet stock bubble didn't burst on 1999-11-08.  Hurrah!
<URL:http://www.pobox.com/~kragen/bubble.html>


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

Date: 18 Nov 1999 03:10:38 GMT
From: Jeff Zucker <jeff@vpservices.com>
Subject: Re: binary database
Message-Id: <38336DE5.AD2883E0@vpservices.com>

Steven Lybeck wrote:
> 
> I am in search of a binary database written entirely in perl. 

What's wrong with a real rdbms like mySQL or PostgreSQL that are freely
available on most platforms and can be easily accessed with Perl DBI
(database interface)?  What reason do you have for wanting the database
itself to be Perl rather than simply the database access mechanism in
Perl and the backend using an rdbms?

-- 
Jeff


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

Date: Thu, 18 Nov 1999 05:38:19 GMT
From: amonotod <amonotod@netscape.net>
Subject: Re: Can open file with Telnet but not browser
Message-Id: <8103cb$3k9$1@nnrp1.deja.com>

  David Cassell <cassell@mail.cor.epa.gov> wrote:
> amonotod wrote:
> [snip]
> X > I don't know of any webservers which use this directory as
> X > the working directory.
Perhaps not, but did you try the script?  Even with any additions you
may care to make?  This is mostly applicable to NT based web-servers, I
don't get this on the Solaris machines we have.  I would like to what
your return was...

> > Ahh, whatever, just run the script...
>
> I'm sorry you're taking this personally.  I'm not trying to
> be difficult.  [I *am difficult, I'm just not trying to be :-]
Point made.  I mean not to take offense.  We are all difficult,
thankfully not all at the same time...

> [snip of comments]
[snip of more of my own inanity...]

> I'm going to agree with you that you do not need every switch
> for your own test scripts.  But when you're writing code for
> a total newbie - code which will be read by a lot more newbies
> who are lurking - you really need to be a stickler.
Again, point made...

> Look at the sort of code that Larry Rosler posts.  Or Jonathan
> Stowe.  Or Uri Guttman.  [Don't look at Abigail's code unless
> you're willing to risk cerebral implosions.]  They are
Whoo-wee, you can say that again... Obfuscated Perl, here we come!

> always careful to show good form, including checking returns
> on open().  I know you've been around here for a while, so I
> just wanted to remind you that those of us who choose to answer
> questions here end up as unintentional 'role models', with
> readers emulating our code.  So quick one-offs which you
> might use for your own private code are potentially a
> problem when given as answers here.
I have learned from the best on here, including you, and always put in
checks on return values... I think.

> I don't want to write your code for you.  But I have confidence
> that you can write model code here.  Please set a good example.
> Be the Brian Wallace of this newsgroup, not the Latrell
> Sprewell.  ;-)
Those names are not familiar to me, but okay...

>
> David, already choking...
After such eloquence, anyone would be!

Somewhat contrite,
amonotod

--
    `\|||/                     amonotod@
      (@@)                     netscape.net
  ooO_(_)_Ooo________________________________
  _____|_____|_____|_____|_____|_____|_____|_____|


Sent via Deja.com http://www.deja.com/
Before you buy.


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

Date: Thu, 18 Nov 1999 05:48:31 GMT
From: amonotod <amonotod@netscape.net>
Subject: Re: Can open file with Telnet but not browser
Message-Id: <8103vf$410$1@nnrp1.deja.com>

  kragen@dnaco.net (Kragen Sitaker) wrote:
> amonotod  <amonotod@netscape.net> wrote:
> >> > print "Content-type: text/html\n\n";
> >> > print "The current dir is $dir\n";
> >> > exit;
> >> This is HTML?
> >No David, it is a _simple_ test, to see if the server works.
> I think the point is that you should say it's text/plain if it's
> text/plain.  *Especially* when you're giving advice to someone else,
> you should make do things correctly.
That line contains what I was taught as the proper beginning to an HTML
file, _any_ HTML file.  Always start with "Content type: text/html"
with two new lines following it. Have you any objections to that?  Oh,
yeah, and the answer is no, it's not HTML.  It's Perl code, even as
sloppy as I was...

> Just post correct answers, or we will have to critique your every
> post.  I don't know about David, but I'm not willing to serve as
> comp.lang.perl.misc moderator -- the majority of things most people
> post are correct.  I don't have time.
Hmm... Seems like I've seen just about everyone (Larry W, Larry R,
David C, Uri, and Abagail) say something about stuff you've posted...
So I guess it's good to have a self-checking community of contributors,
else who know what this newsgroup would be like...

amonotod

--
    `\|||/                     amonotod@
      (@@)                     netscape.net
  ooO_(_)_Ooo________________________________
  _____|_____|_____|_____|_____|_____|_____|_____|


Sent via Deja.com http://www.deja.com/
Before you buy.


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

Date: Thu, 18 Nov 1999 07:07:33 GMT
From: pacman@defiant.cqc.com (Alan Curry)
Subject: Re: Can open file with Telnet but not browser
Message-Id: <VANY3.24520$YI2.1087854@typ11.nn.bcandid.com>

In article <8103vf$410$1@nnrp1.deja.com>,
amonotod  <amonotod@netscape.net> wrote:
>That line contains what I was taught as the proper beginning to an HTML
>file, _any_ HTML file.  Always start with "Content type: text/html"
>with two new lines following it. Have you any objections to that?  Oh,

First of all, it's an HTTP header, not a part of the HTML.
Second, just because you're using CGI doesn't mean you have to output HTML.
If you'd rather just output normal text, you can. That was the point.
-- 
Alan Curry    |Declaration of   | _../\. ./\.._     ____.    ____.
pacman@cqc.com|bigotries (should| [    | |    ]    /    _>  /    _>
--------------+save some time): |  \__/   \__/     \___:    \___:
 Linux,vim,trn,GPL,zsh,qmail,^H | "Screw you guys, I'm going home" -- Cartman


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

Date: Wed, 17 Nov 1999 23:35:07 -0800
From: Larry Rosler <lr@hpl.hp.com>
Subject: Re: Can open file with Telnet but not browser
Message-Id: <MPG.129d4c0260f9fc4698a22c@nntp.hpl.hp.com>

In article <8103vf$410$1@nnrp1.deja.com> on Thu, 18 Nov 1999 05:48:31 
GMT, amonotod <amonotod@netscape.net> says...
>   kragen@dnaco.net (Kragen Sitaker) wrote:
> > amonotod  <amonotod@netscape.net> wrote:
> > >> > print "Content-type: text/html\n\n";
> > >> > print "The current dir is $dir\n";
> > >> > exit;
> > >> This is HTML?
> > >No David, it is a _simple_ test, to see if the server works.
> > I think the point is that you should say it's text/plain if it's
> > text/plain.  *Especially* when you're giving advice to someone else,
> > you should make do things correctly.

> That line contains what I was taught as the proper beginning to an HTML
> file, _any_ HTML file.  Always start with "Content type: text/html"
> with two new lines following it. Have you any objections to that?  Oh,
> yeah, and the answer is no, it's not HTML.  It's Perl code, even as
> sloppy as I was...

You are being deliberately obtuse, I think.  The header line you show 
indicates to the client that what follows is to be interpreted as HTML.  
This means, among other things, that newlines are to be treated as 
simple spaces.  It also implies adherence to a certain format, though 
many browsers are very lenient.  Even though your particular one line of 
text may end up being displayed as you hoped, it is not HTML, so you 
shouldn't tell the server to describe it as HTML.

> > Just post correct answers, or we will have to critique your every
> > post.  I don't know about David, but I'm not willing to serve as
> > comp.lang.perl.misc moderator -- the majority of things most people
> > post are correct.  I don't have time.

> Hmm... Seems like I've seen just about everyone (Larry W, Larry R,
> David C, Uri, and Abagail) say something about stuff you've posted...
> So I guess it's good to have a self-checking community of contributors,
> else who know what this newsgroup would be like...

Larry W almost never posts here, though I am flattered to be named in 
the same sentence with him and those who really do contribute a lot.  
"And gladly wold [w]e lerne and gladly teche."

-- 
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com


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

Date: Thu, 18 Nov 1999 02:14:36 GMT
From: Vincent Murphy <vincent.murphy@cybertrust.gte.com>
Subject: Re: Date localtime help...Newbie
Message-Id: <xjgvh70zgtw.fsf@gamora.ndhm.gtegsc.com>

>>>>> "Marius" == marius 13 <marius_13@my-deja.com> writes:

    Marius> In article <80usjs$7if$1@nnrp1.deja.com>,
    Marius>   crackbaby1@my-deja.com wrote:
    >> I just need to create a varaible with todays date in it...
    >> 
    >> this is what I have:
    >> $updated_on = ???
    >> 
    >> this is what I need:
    >> $updated_on = "19991117"
    >> 
    >> thank you...
    >> 
    >> Sent via Deja.com http://www.deja.com/
    >> Before you buy.
    >> 

    Marius> Try using localtime(time).  It returns several components.

    Marius> Example:

    Marius> ($sec,$min,$hour,$monthdate,$month,$year,$weekday,$yeardate,$daylight) =
    Marius> localtime(time);

perldoc -f localtime

If you use Marius' example you will be 1900 years and 1 month behind. 

--Vinny


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

Date: Thu, 18 Nov 1999 07:53:46 GMT
From: kevinh@inetplus.net (Kevin)
Subject: Executeable into a Variable
Message-Id: <3833b07a.308008317@news2.ase.com>

Question, I am new to Perl and am trying to move some of my bash
scripts to perl. How can I execute a program or another script and put
its output into a Variable?

Kevin


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

Date: Thu, 18 Nov 1999 03:44:28 GMT
From: Rick Delaney <rick.delaney@home.com>
Subject: Re: FAQ 5.3: How do I count the number of lines in a file?
Message-Id: <38337639.81A9D229@home.com>

Larry Rosler wrote:
> 
> In article <38332C61.B89DB66C@cendes.com> on Wed, 17 Nov 1999 22:29:53
> +0000, Jon Erickson <jerickson@cendes.com> says...
> 
> > Tom, why is this better then doing a system call:
> >
> > ex.   system("wc -l", $filename);
> 
> As Tom doesn't play here lately, I'll venture to answer for him.
> 
> 1.  Portability.  Strange as it may seem to you, not every OS has a 'wc'
> command.

That's not so strange.  What I'd like to know is which OS has a "wc -l"
command.

-- 
Rick Delaney
rick.delaney@home.com


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

Date: Wed, 17 Nov 1999 23:35:59 -0500
From: Joe Kline <jkline@one.net>
To: Rick Delaney <rick.delaney@home.com>
Subject: Re: FAQ 5.3: How do I count the number of lines in a file?
Message-Id: <3833822F.93C9E7D7@one.net>

[cc'd and posted]

Rick Delaney wrote:
> 
> Larry Rosler wrote:
> >
> > In article <38332C61.B89DB66C@cendes.com> on Wed, 17 Nov 1999 22:29:53
> > +0000, Jon Erickson <jerickson@cendes.com> says...
> >
> > > Tom, why is this better then doing a system call:
> > >
> > > ex.   system("wc -l", $filename);
> >
<SNIP>
> 
> That's not so strange.  What I'd like to know is which OS has a "wc -l"
> command.

Well, Irix does, as I would imagine and Un*x (or Uni*x-like OS) worth
it's salt.

joe


  -----------== Posted via Newsfeeds.Com, Uncensored Usenet News ==----------
   http://www.newsfeeds.com       The Largest Usenet Servers in the World!
------== Over 73,000 Newsgroups - Including  Dedicated  Binaries Servers ==-----


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

Date: 18 Nov 1999 05:55:11 GMT
From: sholden@pgrad.cs.usyd.edu.au (Sam Holden)
Subject: Re: FAQ 5.3: How do I count the number of lines in a file?
Message-Id: <slrn83756f.gi1.sholden@pgrad.cs.usyd.edu.au>

On Wed, 17 Nov 1999 23:35:59 -0500, Joe Kline <jkline@one.net> wrote:
>[cc'd and posted]
>
>Rick Delaney wrote:
>> 
>> Larry Rosler wrote:
>> >
>> > In article <38332C61.B89DB66C@cendes.com> on Wed, 17 Nov 1999 22:29:53
>> > +0000, Jon Erickson <jerickson@cendes.com> says...
>> >
>> > > Tom, why is this better then doing a system call:
>> > >
>> > > ex.   system("wc -l", $filename);
>> >
><SNIP>
>> 
>> That's not so strange.  What I'd like to know is which OS has a "wc -l"
>> command.
>
>Well, Irix does, as I would imagine and Un*x (or Uni*x-like OS) worth
>it's salt.

None of the Un*x like OSs, in fact more than that none of the computers I
have ever used have come with a command "wc -l". 

Most of them have a command called "wc", which does in fact have a -l
option. 

What does this "wc -l" command that has escaped my attention all these years
do?

As a very off-topic aside, I have only ever seen one program with a space
in its name. And that was "too much" that was a simple shell script that
called more. Of course it didn't come with any OS, it was a play on the
commands more and less. And to save typing there was also a script "too"
which bailed out unless the first argument was "much"... 

-- 
Sam

If your language is flexible and forgiving enough, you can prototype
your belief system without too many core dumps.
	--Larry Wall


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

Date: Thu, 18 Nov 1999 05:41:51 GMT
From: nospam.newton@gmx.li (Philip 'Yes, that's my address' Newton)
Subject: Re: Fetch Dilbert.
Message-Id: <38338f64.382640529@news.nikoma.de>

On 16 Nov 1999 09:05:54 -0800, Carl Johnson <carlj@peak.org> wrote:

>Do either of you know of anything equivalent for getting User Friendly
>also?  I would love to get be able to fetch them automatically, but
>they seem to have randomized the numbers for the GIFs.

I wrote a little one-off script a while back that I can send to you if
you want.

Cheers,
Philip
-- 
Philip Newton <nospam.newton@gmx.li>


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

Date: Thu, 18 Nov 1999 05:41:52 GMT
From: nospam.newton@gmx.li (Philip 'Yes, that's my address' Newton)
Subject: Re: Fetch Dilbert.
Message-Id: <38338fee.382778508@news.nikoma.de>

On 16 Nov 1999 15:55:24 -0600, abigail@delanet.com (Abigail) wrote:

>perldoc@my-deja.com (perldoc@my-deja.com) wrote on MMCCLXVIII September
>MCMXCIII in <URL:news:80s6u1$b23$1@nnrp1.deja.com>:
>[] In article <slrn832jjg.cvu.abigail@alexandra.delanet.com>,
>[]   abigail@delanet.com wrote:
>[] 
>[] > #!/opt/perl/bin/perl -w
>[] 
>[] The "opt" smells of Sun.  I could be wrong.
>
>You are wrong.

HP-UX, then? (What we have at work, and Perl lives happily in
/opt/perl/bin/perl, as well as in /usr/contrib/bin/perl, though the
latter is 4.036...)

Cheers,
Philip
-- 
Philip Newton <nospam.newton@gmx.li>


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

Date: Thu, 18 Nov 1999 02:13:58 GMT
From: Kenneth Bandes <kbandes@home.com>
Subject: Re: Flat File Searching Problem
Message-Id: <38336122.388B1F7A@home.com>

David Cassell wrote:
> > Larry Rosler wrote:
> > > (I've heard of something called PerlScript, but I don't want to upchuck
> > > my breakfast over something like that.)
> >
> > What it isn't:  to Perl as JavaScript is to Java.
> 
> Another "what it isn't":
> to Perl as VBScript is to VB
> 
> I have a VB guy currently asking me for more details about
> what you can and cannot do in PerlScript, since he is so used
> to VBScript doing such a pathetic subset of VB.

Absolutely.  Of course, the whole notion of taking such an already-
broken language as VB and then severely crippling it is so perverse
you have to wonder whether Bill G. has more of a sense of humor
than we give him credit for.

Ken Bandes


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

Date: Thu, 18 Nov 1999 18:09:13 GMT
From: jtbell@presby.edu (Jon Bell)
Subject: Re: Generating pi
Message-Id: <FLEnrE.KBI@presby.edu>

 Anno Siegel <anno4000@lublin.zrz.tu-berlin.de> wrote:
>Peter J. Kernan <pete@theory2.phys.cwru.edu> wrote in comp.lang.perl.misc:
>>
>> [...] or are you speaking of a generator which
>>randomly stops after a possibly infinite time?
>
>How do you stop after infinite time?

You don't need to, of course.  That's the beauty of it!  :-)

-- 
Jon Bell <jtbell@presby.edu>                        Presbyterian College
Dept. of Physics and Computer Science        Clinton, South Carolina USA
        [     Information about newsgroups for beginners:     ]            
        [ http://www.geocities.com/ResearchTriangle/Lab/6882/ ]


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

Date: 18 Nov 1999 04:14:48 GMT
From: pete@theory2.phys.cwru.edu (Peter J. Kernan)
Subject: Re: Generating pi
Message-Id: <slrn836v9o.hss.pete@theory2.phys.cwru.edu>

On 16 Nov 1999 18:11:06 GMT, Ilya Zakharevich <ilya@math.ohio-state.edu> wrote:
 .=You need to refresh your probability concept.  Probability being 0
 .=does not mean that the even is not possible.  ;-)
 .=

  that makes sense for a uniform continuous distribution , but not for a
finite discrete one. or are you saying that the probability of randomly
generating the pi sequence with a truly random digit generator, given
infinite time, is zero (obviously) but possible? i would believe it if
it could be shown that the pi sequence terminated. but i recall, from
8th grade, that it does not. therefore you must have another meaning in
mind.



-- 
  Pete


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

Date: Wed, 17 Nov 1999 23:20:40 -0500
From: Bob Walton <bwalton@rochester.rr.com>
Subject: Re: hash of filehandles
Message-Id: <38337E98.64679600@rochester.rr.com>

"Joel A. Tropp" wrote:
 ...
> The code snippet follows. Thx.
> 
> joel
> 
> * * * * *
> 
> sub prepdata {
> 
> my ($fname) = @_;
> 
> # Open the file and die if there's an error
> 
> die( "$fname is broken." ) if (! open( CURF, "<$fname" ) );
> 
> # For each line in the file...
> 
> while ( $lyne = <CURF> ) {
> 
>     # Divide it into pieces delimited by spaces or commas
>     # The category is the last item on the line
> 
>     $lyne =~ s/,/ /g;
>     @line = split( " ", $lyne );
>     $cat = pop( @line );
> 
>     if ( $cat eq "" ) {
>         # Don't do anything if the category label is empty
> 
>     } elsif ( ! $csize{ $cat } ) {
> 
>         # A new category!
>         # Open a new file for it;
>         # Put that first data point in;
>         # Initialize the count for the category to 1
> 
>         $filez{ $cat } = "feh";                  # Black Magic
what black magic?  This just assigns hash key $cat of hash %filez
to the string 'feh'
>         open( $filez{ $cat }, ">$fname"."_.$cat" );
this opens filehandle 'feh' for output to file "$fname_.$cat".
Note that this filehandle gets reopened every time this statement
is executed, which probably isn't what you want.  Also, be sure
to add " or die" or the equivalent after your open, just in case
it doesn't work.
> 
>         select( $filez{ $cat } );
this selects filehandle 'feh' for subsequent output.
>         print ( join( " ", @line ) . "\n" );
outputs to filehandle 'feh'
>         $csize{ $cat } = 1;
> 
>     } else {
> 
>         # We've already encountered this category,
>         # Add the data point to the category file
>         # And increment the data count for that category
> 
>         select( $filez{ $cat } );
selects filehandle 'feh' for subsequent output
>         print ( join( " ", @line ) . "\n" );
outputs to filehandle 'feh'
> 
>         $csize{ $cat }++;
Note:  the above elsif could be eliminated by simply deleting the
elsif block, retaining the else block.  $csize{$cat}++; will assign 1 
to $csize{$cat} if it is initially empty, and the rest of the code
is identical between the two cases.
>     }
> }
> 
> # Close the pile of files
> 
> foreach $cat ( keys( %filez ) ) {
>     close $filez{ $cat };
this repeatedly closes filehandle 'feh'
> }
> 
> close CURF;
> 
> return ( %csize );
> 
> }

You could try making each of your filehandles unique, maybe by 
making them be the name of the category ($cat, that is).  I'm
sure that was your intention, but not what you actually did.  But
that is frought with danger:  what if the category name is
CURF?  Or STDIN?  And what if the category is "@/:#> $\|%^&" 
(hopefully, I've got something in there that isn't cool in a 
filename in just about every OS)?  And even if you can overcome
that problem by one kludge or another, if you have enough
categories, your OS will eventually barf on too many open files.

You could use just one filehandle, and open for append, write, 
and then close the specific category file each time you need 
to write something to it.  I'm sure that something like that 
was your intent, but not what you actually coded.  Then you 
don't need a hash to save the filehandle name strings, either.
-- 
Bob Walton


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

Date: Thu, 18 Nov 1999 01:56:16 GMT
From: marius_13@my-deja.com
Subject: Help with understanding syntax
Message-Id: <80vmbv$qf7$1@nnrp1.deja.com>

I am a c/c++ developer, and i'm just don't understand the sections in
the2 books that I've read concerning "switch" syntax (case statement).

how would the following c statement be written in perl:

switch(foo)
{
  case 1:
          printf ("case 1\n");
          break;
  case 2:
          printf ("case 2\n");
          break;
  default:
          print ("no match\n");
          break;

}



Thanks,
Brian


Sent via Deja.com http://www.deja.com/
Before you buy.


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

Date: 18 Nov 1999 02:33:02 GMT
From: sholden@pgrad.cs.usyd.edu.au (Sam Holden)
Subject: Re: Help with understanding syntax
Message-Id: <slrn836pbf.f1u.sholden@pgrad.cs.usyd.edu.au>

On Thu, 18 Nov 1999 01:56:16 GMT, marius_13@my-deja.com wrote:
>I am a c/c++ developer, and i'm just don't understand the sections in
>the2 books that I've read concerning "switch" syntax (case statement).

Which two books? What 'switch' syntax? Perl doesn't have a switch statement,
unless you count the one spelt 'for'.

>
>how would the following c statement be written in perl:
>
>switch(foo)
>{
>  case 1:
>          printf ("case 1\n");
>          break;
>  case 2:
>          printf ("case 2\n");
>          break;
>  default:
>          print ("no match\n");
>          break;
>
>}

Why don't you read the documentation yourself?

You have asked a Frequently Asked Question which is answered in the FAQ.

You are meant to read the FAQ before posting, do you violate the conventions
in areas other than usenet?

perldoc -q switch:
=head1 Found in /local/usr/lib/perl5/5.00502/pod/perlfaq7.pod

=head2 How do I create a switch or case statement?

The perlsyn documentation might be useful too, especially the bit 
about 'switch'. You can do a search yourself right?

-- 
Sam

Basically, avoid comments. If your code needs a comment to be
understood, it would be better to rewrite it so it's easier to
understand.	--Rob Pike


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

Date: Thu, 18 Nov 1999 05:08:57 GMT
From: bmccoy@news.lan2wan.com (Brett W. McCoy)
Subject: Re: Help with understanding syntax
Message-Id: <slrn8372ji.5rb.bmccoy@dragosani.lan2wan.com>

Also sprach marius_13@my-deja.com <marius_13@my-deja.com>:

>how would the following c statement be written in perl:
>
>switch(foo)
>{
>  case 1:
>          printf ("case 1\n");
>          break;
>  case 2:
>          printf ("case 2\n");
>          break;
>  default:
>          print ("no match\n");
>          break;
>
>}

SWITCH: for($foo) {
	/1/ && do {
		print "case1\n"; 
		last SWITCH;
		};
	/2/ && do {
		print "case2\n";
		last SWITCH;
		};

	print "Can't find the case!\n";
}

You can get more information by typing 'perldoc -q switch'.

-- 
Brett W. McCoy           
                                        http://www.lan2wan.com/~bmccoy/
-----------------------------------------------------------------------
I have made mistakes but I have never made the mistake of claiming
that I have never made one.
		-- James Gordon Bennett


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

Date: Thu, 18 Nov 1999 10:38:54 -0800
From: Tom Phoenix <rootbeer@redcat.com>
Subject: Re: Help! - grep for x then echo y from a line in a logfile
Message-Id: <Pine.GSO.4.10.9911181031080.16575-100000@user2.teleport.com>

On Thu, 18 Nov 1999, James Nedham wrote:

> What I want my perl script to do is from the line where 2124499062 is on
> tell me whatever machineb is on that line, it could be anything.

Sounds like a job for a pattern match.

> my $hostname = `hostname`;
> chomp($hostname);

Probably better to use Sys::Hostname, in general.

> while (<LOG>){}

What is this doing? Or, what do you think this is doing? 

Cheers!

-- 
Tom Phoenix       Perl Training and Hacking       Esperanto
Randal Schwartz Case:     http://www.rahul.net/jeffrey/ovs/



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

Date: Wed, 17 Nov 1999 21:45:36 -0500
From: Srinivas Dangeti <dsrinu@acsu.buffalo.edu>
Subject: Help: system() in Perl
Message-Id: <Pine.GSO.4.05.9911172138200.15950-100000@penguin.eng.buffalo.edu>

Hi,
I wanted to invoke an executable from perl program. And that executable
prompts the user for input. Is there any way to specify the inputs in the
perl program itself.

e.g.,
read_n_print.exe is an executable which prompts for  a number from STDIN
and prints it to  STDOUT.

system("read_n_print.exe");

But this call waits on the user to give the input. 
How do I go about solving this problem?

Your response will be appreciated.

Thanks
Srinivas Dangeti (dsrinu@eng.buffalo.edu)



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

Date: Thu, 18 Nov 1999 03:54:26 GMT
From: kragen@dnaco.net (Kragen Sitaker)
Subject: Re: Help: system() in Perl
Message-Id: <SLKY3.24343$YI2.1062185@typ11.nn.bcandid.com>

In article <Pine.GSO.4.05.9911172138200.15950-100000@penguin.eng.buffalo.edu>,
Srinivas Dangeti  <dsrinu@acsu.buffalo.edu> wrote:
>I wanted to invoke an executable from perl program. And that executable
>prompts the user for input. Is there any way to specify the inputs in the
>perl program itself.

You want Expect.pm.  Dunno if it works in Win32.
-- 
<kragen@pobox.com>       Kragen Sitaker     <http://www.pobox.com/~kragen/>
The Internet stock bubble didn't burst on 1999-11-08.  Hurrah!
<URL:http://www.pobox.com/~kragen/bubble.html>


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

Date: Wed, 17 Nov 1999 23:05:40 -0500
From: Jeff Pinyan <jeffp@crusoe.net>
Subject: Re: Help: system() in Perl
Message-Id: <Pine.GSO.4.10.9911172304270.24181-100000@crusoe.crusoe.net>

On Nov 18, Kragen Sitaker blah blah blah:

> In article <Pine.GSO.4.05.9911172138200.15950-100000@penguin.eng.buffalo.edu>,
> Srinivas Dangeti  <dsrinu@acsu.buffalo.edu> wrote:
> >I wanted to invoke an executable from perl program. And that executable
> >prompts the user for input. Is there any way to specify the inputs in the
> >perl program itself.
> 
> You want Expect.pm.  Dunno if it works in Win32.

More reliable is IPC::Open2.

  use IPC::Open2;
  open2(\*READ, \*WRITE, "command") or die "can't run command: $!";
  print WRITE "data\n";  # send data
  close WRITE;           # close data pipe
  print <READ>;          # read output
  close READ;

-- 

  MIDN 4/C PINYAN, USNR, NROTCURPI     http://www.pobox.com/~japhy/
  jeff pinyan: japhy@pobox.com     perl stuff: japhy+perl@pobox.com
  "The Art of Perl"               http://www.pobox.com/~japhy/book/      
  CPAN ID: PINYAN  http://www.perl.com/CPAN/authors/id/P/PI/PINYAN/
  PerlMonth - An Online Perl Magazine     http://www.perlmonth.com/



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

Date: Thu, 18 Nov 1999 12:07:07 -0600
From: "David J. Ritchie" <ritchie@fnal.gov>
Subject: Re: how to make perl executable
Message-Id: <3834404B.FF87243E@fnal.gov>

Good question about how to make perl executable.

I have found the ability of Perl on the Mac to save the thing as an executable
useful in some contexts--particularly those in which you want to make it easy for
people to run the thing while making somewhat harder to modify it (accidentally or
otherwise).  Whatever the technique, it doesn't have to be totally  secure to be
useful in such a context; it just has to make it difficult enough to get into the
source so as to raise the bar for those that try.

I wish there were something for this as simple and straight-forward in the Active
State implementation as in the Mac Perl implementation.  Ditto for the nice way
that the MacPerl has an integrated editor, compiler (if that's the right word),
and execution environment.

--David




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

Date: Thu, 18 Nov 1999 11:33:05 +0800
From: "John Lin" <johnlin@chttl.com.tw>
Subject: How to make the comparable also hashable?
Message-Id: <80vs0n$9lo@netnews.hinet.net>

Just like in C++ (STL), we can use map<A>, set<A>
if A::operator<() is defined (overloaded).

In Perl, I have a package A.  I can define their comparison
(overload the '<=>' and 'cmp') but it is difficult to define
string-ifying ('""').  How can I use them as hash keys?

For example:

my $a=new A($foo);  # 'cmp' is overloaded in package A
my $b=new A($bar);  # but '""' is not (because it is difficult)
my %hash;
$hash{$a}=1;      # use object as hash key, not string-ified
$hash{$b}=2;      # suppose $a eq $b
print $hash{$a};  # I need to get '2' here

Thank you.

John Lin

P.S.
    perldoc -q "reference as a hash key"
directed me to Tie::RefHash.  I studied its source code.
It merely stores string-ified references like 'A=SCALAR(0x10c22bc)'.
It is not related to comparison, so it is not suitable here.

I also checked CPAN.  None of the Tie::* module is suitable, either.





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

Date: 16 Sep 99 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 16 Sep 99)
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.  

| NOTE: The mail to news gateway, and thus the ability to submit articles
| through this service to the newsgroup, has been removed. I do not have
| time to individually vet each article to make sure that someone isn't
| abusing the service, and I no longer have any desire to waste my time
| dealing with the campus admins when some fool complains to them about an
| article that has come through the gateway instead of complaining
| to the source.

To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.

To request back copies (available for a week or so), send your request
to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
where x is the volume number and y is the issue number.

For other requests pertaining to the digest, send mail to
perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
sending perl questions to the -request address, I don't have time to
answer them even if I did know the answer.


------------------------------
End of Perl-Users Digest V9 Issue 1415
**************************************


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