[9347] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 2942 Volume: 8

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Jun 23 03:07:28 1998

Date: Tue, 23 Jun 98 00:00:51 -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           Tue, 23 Jun 1998     Volume: 8 Number: 2942

Today's topics:
    Re: after 5 hrs, the beginner beats the s/// <senthilr@Eng.Sun.COM>
        Apology (Cypher)
    Re: case-insensitivity <quednauf@nortel.co.uk>
        Comparing conditional ? with if..else construct <quednauf@nortel.co.uk>
    Re: Comparing conditional ? with if..else construct (Larry Rosler)
    Re: Comparing conditional ? with if..else construct <danboo@negia.net>
    Re: Corrected post (trying to avoid looping through the (Larry Rosler)
    Re: Corrected post (trying to avoid looping through the <danboo@negia.net>
    Re: Finding a string within a string <quednauf@nortel.co.uk>
    Re: first language (David Adler)
    Re: Flames.... <ljz@asfast.com>
    Re: Flames.... (Chip Salzenberg)
    Re: Flames.... (David Adler)
    Re: how do I get directory structure disk space used? (Martien Verbruggen)
    Re: How to find last modified date of a file? <quednauf@nortel.co.uk>
    Re: How to find last modified date of a file? <quednauf@nortel.co.uk>
    Re: More Complete Delete Example (Martien Verbruggen)
    Re: More Complete Delete Example <luckys@geocities.com>
        Oraperl &ora_bind subroutine question (D461-David_F_Haertig(Dave)83040)
    Re: pattern matching with substr (Tad McClellan)
    Re: PERL CGI library path (Martien Verbruggen)
    Re: print and the . operator ?? (Martien Verbruggen)
    Re: Sending files via mail in perl <metcher@spider.herston.uq.edu.au>
    Re: Sick things to do in foreach loops <ajohnson@gpu.srv.ualberta.ca>
    Re: Warnings from environment variables under -w (Tad McClellan)
    Re: Warnings from environment variables under -w (Larry Rosler)
        Digest Administrivia (Last modified: 8 Mar 97) (Perl-Users-Digest Admin)

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

Date: Mon, 22 Jun 1998 23:23:01 -0700
From: Senthilvel Rangaswamy <senthilr@Eng.Sun.COM>
To: Brent Verner <REPLY_TO_damonbrent@earthlink.net>
Subject: Re: after 5 hrs, the beginner beats the s///
Message-Id: <Pine.SOL.3.96.980622232047.12463A-100000@rangas>

On Mon, 22 Jun 1998, Brent Verner wrote:

> hmm...well i feel dummer now...
> 
> $line =~ s/^\s* | *\s*$//g;


>From Perl book:

s/^\s*(.*?)\s*$/$1/;


> 
> does the same thing and looks nicer.
> 
> oh well,
> 
> brent
> 
>     Brent Verner wrote in message <6mmu8h$jhn$1@ecuador.it.earthlink.net>...
>     sorry for wasting the space and time, but i had to celebrate my victory over ONE silly line of code.  i just spent about 5 hours trying to get ONE line of code to do what i needed it to.  i needed to get rid of any  \s  characters at the beginning and end of a $line which needed  \s  chars in the middle ( the line was read from an html page that eventually is placed in a text box to be edited...just a broswer based web-page editor, but a more powerful one than is otherwise available...), so i tried about a million different  s///  lines, but none would work on BOTH ends of the $line.  i ended up with the following line and a bald spot on the side of my head:
>      
>     $line =~ s/^\s+(?=\S*) | *\s*$//g;
>      
>     ok, this line works great, but i'd like a line that was a little easier to understand--being that i am new at this and simple lines are a godsend to the learning process.  is there a more 'clear' way of performing this task?
>      
>     thanks for reading my little story.  i won ---- kind of...
>      
>     brent
>      
>     "ok, so i am ignorant...now i'm free to learn!"
>      
> 
> 

 ..Senthil

DISCLAIMER: The opinions expressed are MINE and NOT my employers'.



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

Date: 23 Jun 98 06:24:40 GMT
From: c_lamson@oz.plymouth.edu (Cypher)
Subject: Apology
Message-Id: <358f4a28.0@news.plymouth.edu>

Please accept my apology for my ignorance in my last post.  I numbly
looked at my "camel" book, and found the $] reference for determining
which version of perl is on my account, and realized how silly of me it
was to ask here a question which had an extremely obvious and easy-to-find
answer.  In the future, I will humbly consult every resource available
before wasting bandwidth and time posting a stupid question.  Thank you. 

--
~Cypher						A.C.S. @Plymouth State
   ****--->finger cypher@mindwarp.plymouth.edu for pgp key<---****
"Any sufficiently advanced technology is indistinguishable from magic."
						--Arthur C. Clarke
-----------------------------------------------------------------------


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

Date: Mon, 22 Jun 1998 09:57:03 +0100
From: "F.Quednau" <quednauf@nortel.co.uk>
Subject: Re: case-insensitivity
Message-Id: <358E1C5F.2CBD5415@nortel.co.uk>

Jonas Kihlsten wrote:
> 
> Does anyone know how to ignore case-sensivity when scaning through a
> textfile?

See eg the perlre page on Perl's regular expressions. The 'i' option stands, I
guess, for insensitive.
-- 
____________________________________________________________
Frank Quednau               
http://www.surrey.ac.uk/~me51fq
________________________________________________


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

Date: Mon, 22 Jun 1998 11:15:59 +0100
From: "F.Quednau" <quednauf@nortel.co.uk>
Subject: Comparing conditional ? with if..else construct
Message-Id: <358E2EDF.46859B37@nortel.co.uk>

I am currently writing a little module, which hopefully eventually can parse
multiple Netscape mailfiles, do searches on them, save single mails to disk, cut
out and properly save attachments, delete whole groups, etc...
So in case the user doesn't provide me with some settings, I want to define some
default ones.

However, I cannot understand why these 2 constructs are different, and I cannot
see ......... Wrong, I just understood! 
(The Mr Spock within me can finally rest!)

  $args->{subjectline} ? $subject = $args->{subjectline} : $subject = ".*";

This doesn't work as expected, $subject will always become '.*' . That would be
a question to ask. The assignment is evaluated in this case. Why?

It seems that the $subject assignment is dealt with out of the conditional
context I was assuming it was in. A silly trap for a newbie, watch out!

If I write

  $subject = $args->{subjectline} ? $args->{subjectline} : ".*";
  
It does the same as:

if ($args->{subjectline}) {
  $subject = $args->{subjectline};
}
else {
  $subject = ".*";
}

So I get what I want, as it says in the perlop - page: 
'If the argument before the ? is true, the argument before the : is returned,
otherwise the argument after the : is returned.'

Just a few Monday morning thoughts for those out there who feel about Monday
like Garfield does.

-- 
____________________________________________________________
Frank Quednau               
http://www.surrey.ac.uk/~me51fq
________________________________________________


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

Date: Mon, 22 Jun 1998 23:44:20 -0700
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: Comparing conditional ? with if..else construct
Message-Id: <MPG.ff8ee9ffba9fc5f9896e9@nntp.hpl.hp.com>

In article <358E2EDF.46859B37@nortel.co.uk>, F.Quednau 
<quednauf@nortel.co.uk> says...
 ...
>   $args->{subjectline} ? $subject = $args->{subjectline} : $subject = ".*";

$args->{subjectline} ? ($subject = $args->{subjectline}) :
    ($subject = ".*");

> This doesn't work as expected, $subject will always become '.*' . That would be
> a question to ask. The assignment is evaluated in this case. Why?

Precedence of = is lower than ?: .

 ...
>   $subject = $args->{subjectline} ? $args->{subjectline} : ".*";

OK, or even nicer:

$subject = $args->{subjectline} || ".*";

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


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

Date: Tue, 23 Jun 1998 02:40:36 -0400
From: Dan Boorstein <danboo@negia.net>
Subject: Re: Comparing conditional ? with if..else construct
Message-Id: <358F4DE4.2F4F2542@negia.net>

F.Quednau wrote:
> 
> If I write
> 
>   $subject = $args->{subjectline} ? $args->{subjectline} : ".*";
> 
> It does the same as:
> 
> if ($args->{subjectline}) {
>   $subject = $args->{subjectline};
> }
> else {
>   $subject = ".*";
> }

so long as i'm just testing the "truth" of the value and not
whether it is defined, i typically use:

$subject = $args->{subjectline} || ".*";

cheers,

-- 
Dan Boorstein   home: danboo@negia.net  work: danboo@y-dna.com

 "THERE IS AS YET INSUFFICIENT DATA FOR A MEANINGFUL ANSWER."
                         - Cosmic AC


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

Date: Mon, 22 Jun 1998 22:29:19 -0700
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: Corrected post (trying to avoid looping through the entire hash)
Message-Id: <MPG.ff8dd0c76568b2b9896e7@nntp.hpl.hp.com>

In article <358F1E6E.FB4@pdq.net>, Tom Kent <tkent@pdq.net> says...
 ...
> sub occurrences {
>   $count{$a} <=> $count{$b};
>  }
> 
>  @array = <SOMEFILE>;
>  
>  foreach $thisline (@array) {
>         ($Fld1) = split (' ',$thisline);
>         push @words, ($Fld1);
>           }
>  
>  foreach $word (@words) {
>    $count{$word} = $count{$word} + 1;
>   }
>  
>       foreach $word (reverse sort occurrences keys %count) {
>         print "$count{$word}        $word\n";
>   }

Unless you need those intermediate arrays, you might try something like 
this:

foreach (<SOMEFILE>) { $count{(split ' ')[0]}++ }

# The slice [0 .. 9] is what you're looking for.
foreach $word ((sort { $count{$b} <=> $count{$a} } keys %count)[0 .. 9])
{
         print "$count{$word}        $word\n";
} 

You might also print using something like this:

printf "%5d\t%s\n", $count{$word}, $word;

to get nice output alignment.

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


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

Date: Tue, 23 Jun 1998 01:39:27 -0400
From: Dan Boorstein <danboo@negia.net>
Subject: Re: Corrected post (trying to avoid looping through the entire hash)
Message-Id: <358F3F8F.62BF3F61@negia.net>

Tom Kent wrote:
> 
>  This script snippet allows me to parse a web server log and tell me
> how> many times   each site was hit. However, I am unable to capture
> just the
>  top ten. Instead, I am only able to go through the entire hash. I've
>  tried counters and for loops in various places with no luck...Any
> ideas?

based on the sample script i am assuming that your log files are not
so large as to dissuade you from reading them into an array all at
once. also, no provisions have been made for frequency ties.

i am not sure exactly what it is you want to avoid, but if you are
looking only for the top 10 "words" the following should work.

for ( map +(split)[0], <SOMEFILE> ) {
  $count{$_}++;
}

@top10keys = grep defined,
         (sort { $count{$b} <=> $count{$a} } keys %count)[0..9];


> sub occurrences {
>   $count{$a} <=> $count{$b};
>  }

i have done away with the sub since it is so simple. i have also 
reversed the $a and $b to do away with the usage of 'reverse'. this
is just my personal preference.

> 
>  @array = <SOMEFILE>;
> 
>  foreach $thisline (@array) {
>         ($Fld1) = split (' ',$thisline);
>         push @words, ($Fld1);
>           }
> 
>  foreach $word (@words) {
>    $count{$word} = $count{$word} + 1;
>   }

the reading of the file, the isolation of the "words" and the frequency
counting have been combined into a single for loop that operates over a
temporary list instead of an array. this may not be appropriate if you
intended to use other parts of the lines in your script.

>       foreach $word (reverse sort occurrences keys %count) {
>         print "$count{$word}        $word\n";
>   }

the finding of the top ten was isolated and combined with the sorting.
basically, the keys are sorted, based on their corresponding values, in
reverse order. then, only a slice of, a t most, 10 elements is taken.
the grep is their in case there are less than 10 elements, and serves
to quiet the warnings from -w.

cheers,

-- 
Dan Boorstein   home: danboo@negia.net  work: danboo@y-dna.com

 "THERE IS AS YET INSUFFICIENT DATA FOR A MEANINGFUL ANSWER."
                         - Cosmic AC


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

Date: Mon, 22 Jun 1998 11:27:42 +0100
From: "F.Quednau" <quednauf@nortel.co.uk>
Subject: Re: Finding a string within a string
Message-Id: <358E319E.D67F6C97@nortel.co.uk>

Azman Shariff wrote:

> if (grep (/$searchstring/,$header){
>    print "$header";
> }

$_ = "Isn't Perl about regular expressions?";

if (/Perl/) {
  print "Oh yes, it is, and you should really read the perlre page!!!\n";
}

-- 
____________________________________________________________
Frank Quednau               
http://www.surrey.ac.uk/~me51fq
________________________________________________


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

Date: 23 Jun 1998 05:56:58 GMT
From: dha@panix.com (David Adler)
Subject: Re: first language
Message-Id: <6mng3a$d0a@news1.panix.com>

On Sun, 21 Jun 1998 21:27:22 GMT, Randal Schwartz <merlyn@stonehenge.com> wrote:
>Me too.  I learned C from K&R (first edition) and the source code to
>Unix (V6 and V7).

Then again, you're nuts. :-) (kidding, kidding!)

-- 
David H. Adler - <dha@panix.com> - http://www.panix.com/~dha/
"We are the Borg. You will be assimilated! Nah, only kidding. We're
just the Sontarans. Care to take part in some 'medical research'?"


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

Date: 23 Jun 1998 01:03:07 -0400
From: Lloyd Zusman <ljz@asfast.com>
Subject: Re: Flames....
Message-Id: <ltk968u2us.fsf@asfast.com>

pudge@pobox.com (Chris Nandor) writes:

> In article <ltvhpsub8e.fsf@asfast.com>, Lloyd Zusman <ljz@asfast.com> wrote:
> 
> # Given that c.l.p.misc is a public, non-moderated newsgroup, I do not
> # believe that anyone has the right to say that it's *their* house.  And
> 
> Sure we do.  People who follow the rules of the newsgroup can say it
> belongs to them.  Else you are saying alt.furry.rabbits people can
> reasonably claim this group as their own, too, which simply is not the
> case.

However, the rules of the newsgroup change over time, as the make-up
of the participants change.  For example, about 4 or 5 years ago, the
people in the comp.lang.perl newsgroup were quite happy to answer "how
to" questions from novices, even repeated questions.  This is back in
the days when the Perl community seemed to be more eager to let the
world know how useful and powerful Perl is.  I even remember that Perl
partisans would repeatedly come into the comp.unix.shell newsgroup
back then and answer "how to" questions there using Perl instead of
one of the *sh shells ... despite the fact that many of the
comp.unix.shell regulars would tell them they were violating the
"rules" and they should get lost.  I even remember that some of the
people who would repeatedly invade comp.unix.shell in that way are
among those who are being a bit less flexible nowadays concerning
c.l.p.misc.

The point of this is that these "rules" change over time as the
realities of the usenet world change.  Now that comp.lang.perl.misc is
being visited by more and more people who are less experienced in
programming than the average reader was 4-5 years ago, the rules here
are slowly changing again.  Witness the fact that c.l.p.moderated
is even being considered at all.  This is a tacit (or not-so-tacit)
admission that the playing field is different today than before.

Therefore, the nature of this "house" is changing.

> # furthermore, given that the "newbies" who come here are human beings
> # like everyone else, I also take strong issue with the insulting
> # characterization of them as "flies".
> 
> Be offended.  Go right ahead.  But realize it is not "newbies" who are
> flies, it is "clueless newbies who would rather waste someone else's time
> than their own."

It has not been established that each person who gets a condescending
or insulting response here is someone who "would rather waste someone
else's time than their own."  In all but a small percentage of the
cases that I see here, the recipient of this kind of treatment has
posted once and only once, with no indication whatsoever whether he or
she is just naive about netiquette, or actually some kind of habitual
freeloader.

It seems to me that the label "clueless newbies who would rather waste
someone else's time than their own" is often being attached to people
without much, if any supporting evidence.  This is one of the things
I am objecting to.

The small percentage of "newbies" and near-"newbies" who willingly
flout the conventions here despite having been repeatedly asked not to
should, in my opinion, be corrected (although I don't believe that
giving insults is a mature way to do that ... nor is it effective at
reducing the signal-to-noise ratio).

> 
> # (1)  ... use killfiles, the 'n', key, etc.  In other words,
> #      ignore it.
> 
> I often do just that.

As do many other people here, as well.  I'm thankful for this in you
and all the others.

> # (2)  ... accept that things have changed and give it no further
> #      thought.
> 
> How fatalistic.  Not in my nature.

And this is not in very many people's nature, either.  This is but one
of four options I mentioned, each of which individually I labeled as
"mature".  Everyone is unique, and different people prefer different
approches.

> # (3)  ... politely and respectfully try to explain the established
> #      patterns to the newcomers, and (still politely and
> #      respectfully) try to persuade them to continue to adhere
> #      to these conventions if they don't initially do that.
> 
> And if you are so offended by the impolite remarks, why not just follow
> your own hypocritical advice in 1 and 2 above?  Hm?

I often do number 1, and like you, I rarely do number 2 ... and for
much the same reason as you.  I'm also in favor of number 5 (starting
a moderated group).  What I also like to do, however, is my version of
number 3: to try to explain the practice of politeness, maturity,
consideration, and respect to those who don't seem to understand the
value of these things, and (still politely and respectfully) to try to
persuade them to continue to adhere to these social conventions if
they don't initially do that.

-- 
 Lloyd Zusman   ljz@asfast.com
 perl -e '$n=170;for($d=2;($d*$d)<=$n;$d+=(1+($d%2))){for($t=0;($n%$d)==0;
 $t++){$n=int($n/$d);}while($t-->0){push(@r,$d);}}if($n>1){push(@r,$n);}
 $x=0;map{$x+=(($_>0)?(1<<log($_-0.5)/log(2.0)+1):1)}@r;print"$x\n"'


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

Date: Mon, 22 Jun 1998 22:54:59 GMT
From: chip@mail.atlantic.net (Chip Salzenberg)
Subject: Re: Flames....
Message-Id: <6mmneu$89v$1@cyprus.atlantic.net>

According to ilya@math.ohio-state.edu (Ilya Zakharevich):
>On system with *really helping* help/doc systems
>there is no need for a *user* to search filesystem

Oh?  I know OS/2 has a great help facility (I used OS/2 for a while),
but that won't help you find all the occurrences of SVf_READONLY in
the Perl sources.  Grepping (with whatever too) *is* a necessary
computer survival skill.  That's just more true for programmers than
others.
-- 
Chip Salzenberg                - a.k.a. -               <chip@pobox.com>
"I brought the atom bomb.  I think it's a good time to use it."  //MST3K
           ->  Ask me about Perl training and consulting  <-
     Like Perl?  Want to help out?  The Perl Institute: www.perl.org


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

Date: 23 Jun 1998 06:37:14 GMT
From: dha@panix.com (David Adler)
Subject: Re: Flames....
Message-Id: <6mnieq$ek5@news1.panix.com>

On Tue, 23 Jun 1998 02:31:32 GMT, birgitt@my-dejanews.com
<birgitt@my-dejanews.com> wrote:

>But they would stop asking if they didn't get an answer and at the
>same time are almost 'forced' to read these subject lines:
>
>     "WHY YOU DON'T GET AN ANSWER TO YOUR QUESTION"
>     "WE EXPECT YOU TO HELP YOURSELF AND READ THE DOCS"

I actually think this *could* be helpful.  But... they would need to
sort towards the top.  Can we assume that such people as we are
targeting here sort their usenet alphabetically?  If so... subjects
beginning with "W" aren't going to cut it.

-- 
David H. Adler - <dha@panix.com> - http://www.panix.com/~dha/
"Perhaps the Monty Python Scholar in America today"
	-New Yorker magazine 13mar89


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

Date: 23 Jun 1998 04:50:47 GMT
From: mgjv@comdyn.com.au (Martien Verbruggen)
Subject: Re: how do I get directory structure disk space used?
Message-Id: <6mnc77$mb7$2@comdyn.comdyn.com.au>

In article <358F351E.55F8EEB3@bwsd.com>,
	Beck Web Servers & Design <admin@bwsd.com> writes:
> Hi:
> 
> I'm trying to a directory structure -> disk space used script.  I

What?

> haven't the foggiest where to start.  I can do stuff with files, but
> have never attempted directories.  I know what I need...just don't know
> how....read directory and all directories under and get running total of
> bytes in the directories...I know there must be an easy way to do this.

Oh! You want to count the number of bytes in a directory? Be aware
that there is no unambiguous answer to that question. There was quite
a thread on this exact subject a while ago on this group. you'll be
able to find it on www.dejanews.com (It's in the old archive, Subject
"best way to find disk space for a directory", and I am sure there was
another thread) There are lots of issues you need to be aware of,
which I won't mention here.

A start:

# perldoc -f opendir
# perldoc -f readdir
# perldoc -f closedir
# perldoc -f stat

# perldoc File::Find

Martien
-- 
Martien Verbruggen                  | 
Webmaster www.tradingpost.com.au    | 
Commercial Dynamics Pty. Ltd.       | What's another word for Thesaurus?
NSW, Australia                      | 


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

Date: Mon, 22 Jun 1998 11:31:58 +0100
From: "F.Quednau" <quednauf@nortel.co.uk>
Subject: Re: How to find last modified date of a file?
Message-Id: <358E329E.F9809E9@nortel.co.uk>

Richard G. Coleman wrote:
> 
> Hi
> 
> Can anyone help with a Perl problem I have.
> 
> How do I extract the last modified date / time of a file eg a data file
                                ^
                                |
TMTOWTDI:      _________________/

use File::stat;
$status = stat($file) or die "Darn, that didn't work:$!";
$lastmodtime = localtime($status->mtime);

> and print it on an html page.
                       ^
                       |
CGI.pm is dead cool for this undertaking.
 

-- 
____________________________________________________________
Frank Quednau               
http://www.surrey.ac.uk/~me51fq
________________________________________________


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

Date: Mon, 22 Jun 1998 14:26:35 +0100
From: "F.Quednau" <quednauf@nortel.co.uk>
Subject: Re: How to find last modified date of a file?
Message-Id: <358E5B8B.9C391D39@nortel.co.uk>

Richard G. Coleman wrote:
> 

> 
> I don't know how to include this in the script.
> >
Amazingly I've got a script which does exactly that. I know, I am being a very
bad teacher, but there U get your fish, use the fishing rod the next time!

opendir(CB,"$cbdir") || die "Cannot opendir:$!";
foreach $file (sort readdir(CB)) {
  push (@files, $file);
}
closedir(CB);

splice (@files, 0, 3);

open(BLA, $explan_file);
  @blabla = <BLA>;
close(BLA);

$i = 0;

print header;

print $layout->start_html(-title=>'Bliblablo', -BGCOLOR=>'white');
print h1("$title");
print "<table width=100%>";
print "<tr><td><b>Filename:</b><hr noshade></td><td><b>Description
(Owner):</b><hr noshade></td>";
print "<td><b>Last modified:</b><hr noshade></td></tr>";
foreach $file (@files) {
  $status = stat($cbdir."/".$file) or die p("Darn, that didn't work:$!");
  $time = localtime($status->mtime);
  $file =~ /(1401)|(1415)/ ? 
  print "<tr><td><a href='/some_other_path/$file'>",$file,"</a></td>" :
  print "<tr><td><a href='$url_path$file'>",$file,"</a></td>";
  print "<td>",$blabla[$i],"</td>";
  print "<td>",$time,"</td></tr>";
  $i++;
}
print "</table>";
print end_html;

Don't worry about <BLA>, it contains a list of explanations to the file. Don't
worry about the 1401|1415 conditional, I needed different URL's for those two
files. Don't worry about splice, it cuts of '.', '..' and the first file of the
listing.


-- 
____________________________________________________________
Frank Quednau               
http://www.surrey.ac.uk/~me51fq
________________________________________________


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

Date: 23 Jun 1998 04:44:36 GMT
From: mgjv@comdyn.com.au (Martien Verbruggen)
Subject: Re: More Complete Delete Example
Message-Id: <6mnbrk$mb7$1@comdyn.comdyn.com.au>

In article <358F268A.4435@geocities.com>,
	Luckys <luckys@geocities.com> writes:

> What I specificly want to know is how does one DELETE() from a DMB file
> with regards to associative arrays?

(It's DBM, and delete)

Same way you'd do it for any hash

# perldoc -f delete
# perldoc -f dbmopen

In which way isn't the sentence from the documentation: 'Deleting from
a hash tied to a DBM file deletes the entry from the DBM file' clear?

#!/usr/local/bin/perl -w
use strict;
my %dbm;

dbmopen(%dbm, 'test_dbm', 0644) || die "Cannot open dbm file: $!";

$dbm{foo} = 'foobar';
$dbm{bar} = 'also foobar';
foreach (keys %dbm) { print "$_ : $dbm{$_}\n" }

print "deleting\n";
delete $dbm{bar};
foreach (keys %dbm) { print "$_ : $dbm{$_}\n" }

dbmclose(%dbm);

OUTPUT:
foo : foobar
bar : also foobar
deleting
foo : foobar

Martien
-- 
Martien Verbruggen                  | 
Webmaster www.tradingpost.com.au    | If at first you don't succeed, try
Commercial Dynamics Pty. Ltd.       | again. Then quit; there's no use being
NSW, Australia                      | a damn fool about it.


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

Date: Tue, 23 Jun 1998 02:32:35 -0400
From: Luckys <luckys@geocities.com>
To: Martien Verbruggen <mgjv@comdyn.com.au>
Subject: Re: More Complete Delete Example
Message-Id: <358F4C03.48E1@geocities.com>

It may delete the input from the associative array but it doesn't seem
to delete it from the dbm file.  Why?  This is my question.  (Your
example below doesn't seem to even write the associative array to the
dbm file.)


Martien Verbruggen wrote:
> 
> In article <358F268A.4435@geocities.com>,
>         Luckys <luckys@geocities.com> writes:
> 
> > What I specificly want to know is how does one DELETE() from a DMB file
> > with regards to associative arrays?
> 
> (It's DBM, and delete)
> 
> Same way you'd do it for any hash
> 
> # perldoc -f delete
> # perldoc -f dbmopen
> 
> In which way isn't the sentence from the documentation: 'Deleting from
> a hash tied to a DBM file deletes the entry from the DBM file' clear?
> 
> #!/usr/local/bin/perl -w
> use strict;
> my %dbm;
> 
> dbmopen(%dbm, 'test_dbm', 0644) || die "Cannot open dbm file: $!";
> 
> $dbm{foo} = 'foobar';
> $dbm{bar} = 'also foobar';
> foreach (keys %dbm) { print "$_ : $dbm{$_}\n" }
> 
> print "deleting\n";
> delete $dbm{bar};
> foreach (keys %dbm) { print "$_ : $dbm{$_}\n" }
> 
> dbmclose(%dbm);
> 
> OUTPUT:
> foo : foobar
> bar : also foobar
> deleting
> foo : foobar
> 
> Martien
> --
> Martien Verbruggen                  |
> Webmaster www.tradingpost.com.au    | If at first you don't succeed, try
> Commercial Dynamics Pty. Ltd.       | again. Then quit; there's no use being
> NSW, Australia                      | a damn fool about it.

-- 
Gary C. New
gnew@southernvirginia.edu
Wedding: http://www.erols.com/gnew/wedding/
Resume:  http://cgibin.erols.com/gnew/cgi-bin/resume/index.cgi


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

Date: Tue, 23 Jun 1998 06:39:22 GMT
From: dfh@dwroll.lucent.com (D461-David_F_Haertig(Dave)83040)
Subject: Oraperl &ora_bind subroutine question
Message-Id: <EuzrtM.5yM@drnews.dr.lucent.com>
Keywords: Oraperl ora_bind


Hi -

When you open a cursor with bind variables, is there some limit
to the number of times you can bind to it before you should
close/reopen the cursor?

Specific code example:

$DB = &ora_login("", "uid/password\@sid", "");
die "$ora_errstr\n" if $ora_errno;
$InsertCursor = &ora_open($DB, <<EOF);
	insert into newtable
		(select * from oldtable
		 where serial_number = :1)
EOF
die "$ora_errstr\n" if $ora_errno;
$DeleteCursor = &ora_open($DB, <<EOF);
	delete from oldtable
	where serial_number = :1
EOF
die "$ora_errstr\n" if $ora_errno;

while (... a REALLY long loop, millions and millions of iterations) {
	$SuccessCnt = 0;
	# Does this BINDBLOCK error checking look bulletproof?
	BINDBLOCK:
	{
		$RtnIns = &ora_bind($InsertCursor, $Something);
		last BINDBLOCK unless $RtnIns;
		last BINDBLOCK if $RtnIns eq "OK";
		$SuccessCnt++;
		$RtnDel = &ora_bind($DeleteCursor, $Something);
		last BINDBLOCK unless $RtnDel == $RtnIns;
		last BINDBLOCK if $RtnDel eq "OK";
		$SuccessCnt++;
	}
	if ($SuccessCnt != 2) {
		&ora_rollback($DB);
		next;
	}
	&ora_commit($DB);
}

# These cursors may have been bound to millions of times prior to
# these &ora_close() calls.  Is this OK?  If not, how about a
# counter inside the while() loop that forces close/reopen every
# so often?  How often?
&ora_close($InsertCursor);
&ora_close($DeleteCursor);

&ora_commit($DB);
&ora_logoff($DB);


Thanks,    (email replies preferred)
--
Dave Haertig
haertig@lucent.com
-- 
Dave Haertig
haertig@lucent.com


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

Date: Mon, 22 Jun 1998 23:31:05 -0500
From: tadmc@flash.net (Tad McClellan)
Subject: Re: pattern matching with substr
Message-Id: <92bnm6.glb.ln@localhost>

Juli@my-dejanews.com wrote:
: $rep_last = "cones III";

: $second = substr($rep_last,index($rep_last," "),4);


   $second = (split /\s+/, $rep_last)[-1]; # grab all chars after the
                                           # last space

   OR

   ($second = $rep_last) =~ s/.* //;  # delete everthing up to the last space



: Please email me at juli@my-dejanews.com.  Thanks!


Why?

We wouldn't want answers to Perl questions to be hoarded.

Let's just put them here in the newsgroup so everyone can
benefit. Much less selfish that way.


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


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

Date: 23 Jun 1998 06:04:14 GMT
From: mgjv@comdyn.com.au (Martien Verbruggen)
Subject: Re: PERL CGI library path
Message-Id: <6mnggu$mmq$2@comdyn.comdyn.com.au>

In article <358EBCD4.4E064040@ams.org>,
	Dan Pelton <dnp@ams.org> writes:
> The PERL5LIB environment variable would work except that there is no
> way to set it when using perl as a cgi.

What about putting a different PERL5LIB in the environment of your
sever, before you start it up? Wether this is possible with your
particular OS and Web server is a different issue, and doesn't belong
in this group.

Martien
-- 
Martien Verbruggen                  | 
Webmaster www.tradingpost.com.au    | The number of the beast is not 666. The
Commercial Dynamics Pty. Ltd.       | number is 95, and it's awake.
NSW, Australia                      | 


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

Date: 23 Jun 1998 05:58:58 GMT
From: mgjv@comdyn.com.au (Martien Verbruggen)
Subject: Re: print and the . operator ??
Message-Id: <6mng72$mmq$1@comdyn.comdyn.com.au>

[There really was no need to post this message 4 times]

In article <6mn8i4$4sa$1@duke.squonk.net>,
	"Eschult" <eschult.NOSPAM@squonk.net> writes:
> $line includes the line termination character, which you are appending to
> $grades{student}.  The print is printing it, yielding the extra blanks in
> your output.
> 
> Try adding 'chop $line;' as your first line after the 'while ($line......)
> {' line.

chomp is safe than chop. Only use chop if you really want to chop off
the last character. Use chomp if you are trying to get rid of line
endings (as defined by $/)

Martien
-- 
Martien Verbruggen                  | 
Webmaster www.tradingpost.com.au    | 
Commercial Dynamics Pty. Ltd.       | Curiouser and curiouser, said Alice.
NSW, Australia                      | 


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

Date: Tue, 23 Jun 1998 15:59:51 +1000
From: Jaime Metcher <metcher@spider.herston.uq.edu.au>
Subject: Re: Sending files via mail in perl
Message-Id: <358F4456.4DA53D57@spider.herston.uq.edu.au>

Zenin wrote:
> 
<snip>
> 
>         Yes, there are ways to work around systems lacking an MTA.  If you
>         must work in suck conditions and want to stay at all portable at
>         least use a best method test:
<snip>

My system *does* have an MTA, but you don't get to it by calling
sendmail.  You get to it using SMTP.  And it *is* local, but it's on the
*Local* Area Network, not on this machine.  Doesn't everyone on a LAN do
it this way?  The Unix philosophy of a complete toolbox on every machine
is great for flexibility, but unless you like applying security patches
I can't see any earthly reason for having 500 copies of *any* demon
running on a LAN (actually, I can, but in general most of these things
are a waste of space).

You're right about the portability hit, but in real life there *isn't* a
general way to find an MTA, and no amount of wishing the world ran
(properly configured) Unix will change that.

-- 
Jaime Metcher


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

Date: Tue, 23 Jun 1998 01:13:22 -0500
From: Andrew Johnson <ajohnson@gpu.srv.ualberta.ca>
Subject: Re: Sick things to do in foreach loops
Message-Id: <358F4782.C40C25@gpu.srv.ualberta.ca>

Michael D. Schleif wrote:
!
! Am I the only mere mortal sinner who finds this amusing?
! 
! Question: Should ALL Perl users, god and novitiate alike, be at
! 5.004_67 so that we will be at the same FAQing level?
!
! Tom Christiansen wrote:
! >     psf@euclid.jpl.nasa.gov (Peter Scott) writes:
! > :Er - WHICH perlsyn?  Not the one that came with the Perl 5.004_04
! >
! > The one at 5.004_67.

No, this is plain silliness. One should not quote modified
'developmental' versions of the docs without explicitly stating
such when doing so (especially given a recent thread regarding
access to developmental versions of perl).

I may have access to perl-5.004_67 and its docset ... but I don't
think one should throw quotes from it without explicit mention,
anymore than one should advocate using feature X (where X is
unique to some version++ later than CPAN's "latest.tgz"). Up to
date on clpm is not the same as up to date on p5p.
 
regards
andrew


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

Date: Mon, 22 Jun 1998 23:22:57 -0500
From: tadmc@flash.net (Tad McClellan)
Subject: Re: Warnings from environment variables under -w
Message-Id: <1janm6.2kb.ln@localhost>

Stephan Carydakis (steph@hotkey.net.au) wrote:

: My Problem:

: I am writting a simple search engine script under use strict and -w.
                                              ^^^^^^^^^^^^^^^^^^^^^^^

Most excellent!


: I am declaring subs and vars with 'use vars qw' and 'use subs qw' or
: with 'my' where appropriate. I am getting warnings(uninitialised value)
: from references to environment variables. 


Care to share some such reference with us?

Many of us are not psychic...


: I wish to rid myself of these
: warnings :]. I have tried including both %ENV and individual environment
: variables in the 'use vars qw' list but this doesn't work.

: 1). Is there a way to get rid of these warnings caused by environment
                                                  ^^^^^^^^^
: variables?

We can't really tell what they were caused by because you haven't
shown us what you are doing that caused them.

So...  we get to guess  ;-)


My guess is that you are referring to env vars that are not defined.

So, check to see if they are defined before you use them:

   if (defined $ENV{somevar}) {
     # do interesting stuff
   }
   else {
     # complain loudly
   }


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


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

Date: Mon, 22 Jun 1998 22:44:53 -0700
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: Warnings from environment variables under -w
Message-Id: <MPG.ff8e0b17ea50c729896e8@nntp.hpl.hp.com>

In article <1janm6.2kb.ln@localhost>, Tad McClellan <tadmc@flash.net> 
says...
> Stephan Carydakis (steph@hotkey.net.au) wrote:
 ...
> : 1). Is there a way to get rid of these warnings caused by environment
>                                                   ^^^^^^^^^
> : variables?
 ...
> So, check to see if they are defined before you use them:
> 
>    if (defined $ENV{somevar}) {
>      # do interesting stuff
>    }
>    else {
>      # complain loudly
>    }

Sorry, this 'defined' is not needed and has nothing to do with the 
reported warnings.  As Martien Verbruggen demonstrates in another post in 
this thread, a simple boolean test on an undefined variable or a 
nonexistent hash member returns FALSE, without a warning.

I also have been unable to identify the source of these reported 
warnings.
 
-- 
Larry Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com


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

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

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