[13036] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 446 Volume: 9

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Aug 10 13:07:18 1999

Date: Tue, 10 Aug 1999 10:05:13 -0700 (PDT)
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, 10 Aug 1999     Volume: 9 Number: 446

Today's topics:
    Re: ActivePerl PerlScript -- funny problems (Matt)
        array and file processing <habfan2@my-deja.com>
    Re: chop? Split? help? (Larry Rosler)
    Re: Date::Manip SLOW (Sean McAfee)
    Re: Date::Manip SLOW <jeffp@crusoe.net>
    Re: Date::Manip SLOW (I R A Darth Aggie)
    Re: Date::Manip SLOW (Matthew Bafford)
    Re: Date::Manip SLOW (Bill Moseley)
    Re: Date::Manip SLOW <pas@unh.edu>
    Re: Date::Manip SLOW (Matthew Bafford)
    Re: exists problem <gene@tekdata.com>
    Re: Fastest way to search a txt file? <aqumsieh@matrox.com>
    Re: Fastest way to search a txt file? (Anno Siegel)
    Re: finding array size <aqumsieh@matrox.com>
    Re: Help - Split Function Blowing My Mind Away!! (Larry Rosler)
        How to create unix install executables? <gregory_guerin@hp.com>
        Illegal division by zero when testing for a directory?? <gregjm@sr.hp.com>
        list length <gmuth@bytecare.com>
    Re: list length (Derek Sherlock)
    Re: Looking for a good Perl Book <aqumsieh@matrox.com>
    Re: Newbie: File I/O & Locking <sariq@texas.net>
    Re: Newbie: File I/O & Locking alexander.zinniker@trivadis.com
        Parse exception chris_bordeleau@lotus.com
        Perl & Oracle in a webserver.... environment variable p lianthe@my-deja.com
        perl on linux <nirl@zoran.co.il>
    Re: perl on linux (I R A Darth Aggie)
    Re: perl on linux <toby@hercules.cas.utk.edu>
    Re: perl script - help (Bill Moseley)
    Re: perldoc and activeperl help (Bill Moseley)
        Digest Administrivia (Last modified: 1 Jul 99) (Perl-Users-Digest Admin)

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

Date: Tue, 10 Aug 1999 16:28:21 GMT
From: mck@iag.net (Matt)
Subject: Re: ActivePerl PerlScript -- funny problems
Message-Id: <37b0528e.8353631@news.iag.net>

On Tue, 10 Aug 1999 10:07:09 +0100, "Nick Liebmann" <Nick@ucecom.com>
wrote:

>You cannot embed perl script into HTML code. It's the other way round, the
>HTML code can be embedde inot the perl and the code cxan then be called up.
>
>You can't use Language= "Perlscript"...

Sure you can, in at least one case. Assuming IIS4 which a safe bet
because ActiveState is a Win32 port, the following links will give
some examples:

http://msdn.microsoft.com/workshop/languages/clinic/scripting012299.asp

http://www.activestate.com/ActivePerl/docs/PerlScript.html




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

Date: Tue, 10 Aug 1999 14:56:02 GMT
From: Teacher Guy <habfan2@my-deja.com>
Subject: array and file processing
Message-Id: <7opehr$dps$1@nnrp1.deja.com>

Another Newbie...... needs help.

Hello and thanks to everyone for help. My next dilemna involves
processing arrays in Perl. I have a database with student names, test
scores and courses. I need to load data into an array, sort the array
on test scores field (without screwing up order of other fields) and
choose only the top ten students. Next, I want to calculate average of
these 10 students and print the results. Here's what I'm trying to do:
$numstuds = 10;
$count = 0;

foreach $i (@indata)
{
#remove hard return character from each record
chop($i);
#split fields on pipe character
#assign a variable name to each of the fields
($student,$testscore,$course) = split(/\|/,$i);

$count = $count + 1;
# ?? Can I do this ??????????????????
%topscore [$i]=('student',$student,'scores',$testscore,'courses',
$course);
# create 1 associative array to handle input and allow for sorting
# all 3 values in correct order

@testscores = $testscore;
@students = $student;
@courses = $course;
# create 3 parallel ordinal arrays for calculating handicap index

#add a new row to the table for each record
print "";
print "$student";
print "$testscore";
print "$course";
print "\n";
#close the loop
}

#close the table
print "";
#close the HTML document

if ($count > 9)
{
@thebest = sort values %topscore;
# see p.77 of Rob's Perl for above
# all items must sort in sych
foreach $i (keys %topscore)
# foreach (@thebest)
# need to limit this to 10 times only
{

$total = $total + $topscore{'testscore'};
# top ten students

print "$topscore{'testscore'} and loop value is $i";
print "$total";
print "";
# check values
last if $i > 9;
}
# end of foreach


$ave = $total/$numstuds;


I'm not sure whether I should be using parallel ordinal arrays or an
associative array. Can I use a subscript with an associative array?

Thanks in advance for your insights!



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


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

Date: Tue, 10 Aug 1999 09:26:16 -0700
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: chop? Split? help?
Message-Id: <MPG.1219f273293e728d989e17@nntp.hpl.hp.com>

In article <7op5ln$n3k$1@lublin.zrz.tu-berlin.de> on 10 Aug 1999 
12:24:23 -0000, Anno Siegel <anno4000@lublin.zrz.tu-berlin.de> says...
 ... 
> The standard idiom to remove a file extension ( the last dot and
> everything that follows) is s/\.[^.]*$//.

That depends on your definition of a file extension.  Does changing 
'.foobar' to '.' or changing 'foobar.' to 'foobar' remove a file 
extension or just mangle a filename that has no extension?

Assuming, as your regex does, that there are no newlines in filenames 
(an assumption I, for one, find very easy to live with), I think the 
proper regex is what I posted last week (as I recall):

    s/(.)\..+$/$1/

or for those who like positive look-behind:

    s/(?<=.)\..+$//

Adjustments for dain-bramaged newlined file names (what a wonderful way 
to screw up an idiom like `ls | wc -l`) are obvious:

    s/(.)\..+\z/$1/s
    s/(?<=.)\..+\z//s

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


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

Date: Tue, 10 Aug 1999 15:38:20 GMT
From: mcafee@waits.facilities.med.umich.edu (Sean McAfee)
Subject: Re: Date::Manip SLOW
Message-Id: <MHXr3.1075$J72.156986@news.itd.umich.edu>

In article <7opbv7$br3$1@nnrp1.deja.com>, Stone Cold  <paulm@dirigo.com> wrote:
>I'm using the Date::manip module to print a range of dates (e.g. Jan-
>99, Feb-99, Mar-99, etc).  I'm finding, though, that this modules
>really slowed down my CGI program.  Before I started using the module,
>my output would come up in browser pretty fast.

>So, does anyone know how to speed up the date::manip module?

Have you tried A) using Devel::DProf to profile your code and locate the
bottlenecks, or B) contacting the module's author with your concerns?

-- 
Sean McAfee                                                mcafee@umich.edu
print eval eval eval eval eval eval eval eval eval eval eval eval eval eval
q!q@q#q$q%q^q&q*q-q=q+q|q~q:q? Just Another Perl Hacker ?:~|+=-*&^%$#@!


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

Date: Tue, 10 Aug 1999 12:14:07 -0400
From: Jeff Pinyan <jeffp@crusoe.net>
Subject: Re: Date::Manip SLOW
Message-Id: <Pine.GSO.4.10.9908101212090.5367-100000@crusoe.crusoe.net>

[posted & mailed]

On Aug 10, Stone Cold blah blah blah:
> I'm using the Date::manip module to print a range of dates (e.g. Jan-
> 99, Feb-99, Mar-99, etc).  I'm finding, though, that this modules
> really slowed down my CGI program.  Before I started using the module,
> my output would come up in browser pretty fast.

From the 'purl' bot on #perl on EFnet:
	Rumour has it Date::Manip is cool, but has two drawbacks.  1) It
	reads a config file, so -T is going to whine loudly.  2) It's big,
	you'll notice that in startup time.

	Everything plus the kitchen sink.

 	Date::Calc is better.

	ONLY TO BE USED if Date::Calc doesn't do the trick.

Oh well. :)  Try Date::Calc.

--
jeff pinyan    japhy@pobox.com  japhy+perl@pobox.com  japhy+crap@pobox.com
japhy's little hole in the (fire) wall:       http://www.pobox.com/~japhy/
japhy's perl supposit^Wrepository:       http://www.pobox.com/~japhy/perl/
The "CRAP" Project:                 http://www.pobox.com/~japhy/perl/crap/
CPAN ID: PINYAN           http://www.perl.com/CPAN/authors/id/P/PI/PINYAN/




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

Date: 10 Aug 1999 16:00:35 GMT
From: fl_aggie@thepentagon.com (I R A Darth Aggie)
Subject: Re: Date::Manip SLOW
Message-Id: <slrn7r0j95.6po.fl_aggie@thepentagon.com>

On Tue, 10 Aug 1999 14:12:02 GMT, Stone Cold <paulm@dirigo.com>, in
<7opbv7$br3$1@nnrp1.deja.com> wrote:

+ So, does anyone know how to speed up the date::manip module?

Not use it? It is a fairly large chunk of code. Perhaps there are ways
of importing only a relative subset of the code. I'd consult the
documentation, but it isn't installed on my machine...

James - that's a 'whoopsie'...

-- 
Consulting Minister for Consultants, DNRC
The Bill of Rights is paid in Responsibilities - Jean McGuire
To cure your perl CGI problems, please look at:
<url:http://www.perl.com/CPAN/doc/FAQs/cgi/idiots-guide.html>


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

Date: Tue, 10 Aug 1999 16:31:22 GMT
From: *@dragons.duesouth.net (Matthew Bafford)
Subject: Re: Date::Manip SLOW
Message-Id: <slrn7r0kb6.bfl.*@dragons.duesouth.net>

[A courtesy copy was sent to paulm@dirigo.com]

And so it happened, on Tue, 10 Aug 1999 14:12:02 GMT, Stone Cold
<paulm@dirigo.com> typed random characters into perl, and ended up with
the following posted to comp.lang.perl.misc: 
: I'm using the Date::manip module to print a range of dates (e.g. Jan-
: 99, Feb-99, Mar-99, etc).  I'm finding, though, that this modules
: really slowed down my CGI program.  Before I started using the module,
: my output would come up in browser pretty fast.

man Date::Manip:
 ...
       Date::Manip is written entirely in perl.  It's the most powerful of the date
       modules.  It's also the biggest and slowest.
 ...
       The downside is that Date::Manip is slow.  The much simpler Date modules listed
       above are all faster (usually be a significant amount).  Although I am working on
 ...
       Date::Manip is slow
           The reasons for this are covered in the SHOULD I USE DATE::MANIP section above.

           Some things that will definitely help:
 ...
           Business date calculations are extremely slow.  You should consider
           alternatives if possible (i.e. doing the calculation in exact mode and then
 ...

: So, does anyone know how to speed up the date::manip module?

Perhaps Data::Manip is not the best tool for the job?

It's hard to tell from your description above, though.

Hope This Helps,

: Paul R. Mesker

--Matthew


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

Date: Tue, 10 Aug 1999 09:32:00 -0700
From: moseley@best.com (Bill Moseley)
Subject: Re: Date::Manip SLOW
Message-Id: <MPG.1219f3d9ca2755fc9896a0@nntp1.ba.best.com>

> On Aug 10, Stone Cold blah blah blah:
> > I'm using the Date::manip module to print a range of dates (e.g. Jan-
> > 99, Feb-99, Mar-99, etc).  I'm finding, though, that this modules
> > really slowed down my CGI program.  Before I started using the module,
> > my output would come up in browser pretty fast.

A lot is going on between the program an the browser.

Jeff Pinyan (jeffp@crusoe.net) then says...
> 	2) It's big,
> 	you'll notice that in startup time.

I use this to bring it in when needed:

use autouse 'Date::Manip' => qw( ParseDate );

It's worth the wait for how flexible it is in interpreting dates of 
various formats.  I wonder if you could auto split it.


-- 
Bill Moseley mailto:moseley@best.com
pls note the one line sig, not counting this one.


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

Date: 10 Aug 1999 16:36:02 GMT
From: Paul A Sand <pas@unh.edu>
Subject: Re: Date::Manip SLOW
Message-Id: <7opkdi$qrh$1@tabloid.unh.edu>

Stone Cold <paulm@dirigo.com> writes:

>I'm using the Date::manip module to print a range of dates (e.g. Jan-
>99, Feb-99, Mar-99, etc).  I'm finding, though, that this modules
>really slowed down my CGI program.  Before I started using the module,
>my output would come up in browser pretty fast.

>So, does anyone know how to speed up the date::manip module?

Date::Manip is big and hairy; probably needs to be for what it does.
Calling it inside a loop (as your post seems to imply you are) would be
bad. If you're just using it to format your output as Mmm-yy (as your
post seems to imply you are), look into strftime instead:

    use POSIX strftime;

    [...]

    print strftime("%b-%y\n", localtime($unixsecs));

If Date::Manip is unavoidable, but you use it for the same dates over
and over, you might try caching its results in a persistent tied-hash
file; only call the Date::Manip routines if the answer isn't in the
cache.

-- 
-- Paul A. Sand                 | This is so utterly trivial and inconsequential 
-- University of New Hampshire  | a point that your opponents, giving you the 
-- pas@unh.edu                  | benefit of the doubt, assumed that you could 
-- http://pubpages.unh.edu/~pas | not be making it. More fools they. (B Vogt)


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

Date: Tue, 10 Aug 1999 17:03:10 GMT
From: *@dragons.duesouth.net (Matthew Bafford)
Subject: Re: Date::Manip SLOW
Message-Id: <slrn7r0m2s.c6k.*@dragons.duesouth.net>

[Courtesy copy sent to paulm@bass.dirigo.com]

[Brought back to clpm]

From paulm@bass.dirigo.com  Tue Aug 10 12:25:04 1999:
! sub nextFiveMonths {
! 
!    $date = shift;                            		# get date from @_
!    ($month,$year) = split (/-/,$date);       		# parse out month and year
!    $date = ParseDate("$month-01-$year") || die; 	# now date is in
! Date::Manip
!                                                 	# format
! 
!    @fiveMonths = ();
! 
!    for $i (0..5) {
!       $delta = ParseDateDelta ("+$i months");  		# no. of months to add to
! date
!       $newdate = DateCalc($date, $delta);      		# add delta and date
!       $fnewdate = UnixDate($newdate, "%b-%Y"); 		# format date to "month-yy"
! 
!       push @fiveMonths, $fnewdate;             		# put into array
!    }
!    return @fiveMonths;
! 
! }

Well, how about:

> cat next_five
#!/usr/bin/perl -w

use Date::Calc qw(Add_Delta_YMD Month_to_Text Today);

my ( $year, $month, $day ) = Today();

for my $i ( 1..5 ) {
    my ( $year, $month, $day ) = Add_Delta_YMD($year, $month, $day, 0, $i, 0);

    printf "+$i: %s %d, %d\n", Month_to_Text($month), $day, $year;
}
__END__
> time ./next_five
+1: September 10, 1999
+2: October 10, 1999
+3: November 10, 1999
+4: December 10, 1999
+5: January 10, 2000
0.19user 0.01system 0:00.19elapsed 100%CPU (0avgtext+0avgdata 0maxresident)k
0inputs+0outputs (300major+122minor)pagefaults 0swaps
>

HTH,

--Matthew


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

Date: Tue, 10 Aug 1999 11:42:56 -0500
From: Gene LeFave <gene@tekdata.com>
Subject: Re: exists problem
Message-Id: <37B05690.BE1EFB8C@tekdata.com>

Anno,

The program works on my machine and on some of our customers.  It fails
at only one site so far.  That's why I think it is a version specific
problem, and if so is there a work around.

Gene

Anno Siegel wrote:
> 
> Gene LeFave  <gene@tekdata.com> wrote in comp.lang.perl.misc:
> >Tom,
> >
> >Thanks for your reply.   I finally located the error log and perl gives
> >a message about illegal tokens  exists $in
> 
> Could you reproduce the error message exactly?  "token" appears
> exactly once in perldiag, and not in a message.
> 
> >Is it possible that the exists function doesn't exist in earlier
> >versions?   Since I found it in a perl book on version 5 I thought it
> >would work on all 5.x versions.
> 
> It's been around far longer than perl5.
> 
> >This is only one line in pages of perl code so I can't really change the
> >way $in is used.   It is created by a cgi library script.  I have
> >searched numerous books, online samples, etc.  and I can't find any
> >other way to do this.  The problem is that I need to distinquish between
> >the Econf parameter being present or not.  If it is present a null value
> >is perfectly acceptable.   In other places in the source the phrase:
> >
> >     $something  = $in {'something'}
> >is used frequently.    I originally used this but there is no
> >distinction that I can be find between   $in{'something'} =  ""    and
> >$in{'something'} being undefined.
> 
> With respect to hashes, you can distinguish three situations. This is
> explained in perldoc -f exists.  To quote:
> 
>     print "Exists\n"    if exists $array{$key};
>     print "Defined\n"   if defined $array{$key};
>     print "True\n"      if $array{$key};
> 
> So you can tell the difference between a '' value and an undefined
> value.
> 
> >Since the script is in an application that we supply to hundreds of
> >customers, it is extremely desirable that it works in all 5.x perls'. So
> >I'm looking for a version insensitive way to do this.
> 
> It's certainly not the perl version that is the problem, except
> you have a buggy build (*very* unlikely).
> 
> Anno


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

Date: Tue, 10 Aug 1999 15:36:23 GMT
From: @l@ <aqumsieh@matrox.com>
Subject: Re: Fastest way to search a txt file?
Message-Id: <7opgtm$fmq$1@nnrp1.deja.com>

In article <7op9ni$a0s$1@nnrp1.deja.com>,
  srhadden@my-deja.com wrote:

> The code I'm working on now takes the file and redefines $/, which
> allows a chunk of the file to be extracted, and then has perl search
the
> entire chunk for one of the keywords. If a keyword is detected in the
> chunk, then the chunk is split into lines and each line is examined
for
> the information and certain count variables are updated depending on
how
> many lines contain a keyword.

Something like:

{
	local $/ = ''; # paragraph mode for example
	while (<F>) {  # I assume file is already open
		if (/error|warning/i) {
			my @lines = split "\n";
			# now search your lines here
		}
	}
}


--Ala


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


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

Date: 10 Aug 1999 16:02:14 -0000
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Fastest way to search a txt file?
Message-Id: <7opie6$ngl$1@lublin.zrz.tu-berlin.de>

 <srhadden@my-deja.com> wrote in comp.lang.perl.misc:
>Hi, I hope I don't get roasted for asking this...
>
>I was wondering what would be a very efficient (fast) way to examine a
>text file line by line to search for keywords, such as "error", or
>"warning".
>
>The code I'm working on now takes the file and redefines $/, which
>allows a chunk of the file to be extracted, and then has perl search the
>entire chunk for one of the keywords. If a keyword is detected in the
>chunk, then the chunk is split into lines and each line is examined for
>the information and certain count variables are updated depending on how
>many lines contain a keyword.
>
>I suppose some issues are that maybe the file doesn't contain any
>keywords at all.  Would it be too slow to have perl search the entire
>file for a keyword?  Is it quicker to search the file chunk by chunk
>rather than just search the entire file once for a keyword?

Only you can decide what performance is acceptable.  There is no
absolute "too slow" in the computer world.  You'll have to try
and see what happens.

Even the question which search strategy is quicker can't be answered
without knowing your data:  size of file, how many chunks, how many
patterns, are all the patterns fixed strings, do they change during
a program run, and probably other parameters I haven't thought of.

Make a few test runs using various searching techniques and see which
on give you good-enough performance.  The Benchmark module may
come in handy.

Anno



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

Date: Tue, 10 Aug 1999 09:39:55 -0400
From: Ala Qumsieh <aqumsieh@matrox.com>
Subject: Re: finding array size
Message-Id: <x3yu2q77o0k.fsf@tigre.matrox.com>


Margaret Escherich <glasscat@shell7.ba.best.com> writes:

> It's easy to find the size (in bytes) of a file with -s.
> 
> How do you find the size of an array or a splice?  how could I, for
> example, take 400 bytes of an array?

Now this is a question you don't see everyday!
Why would you want 400 bytes of an array? AFAIK, Perl's arrays (unlike
C's) do not occupy contiguous memory locations. So it is very hard to
manipulate arrays in Perl by indexing their memory locations.

Perhaps your question is not posed properly. Would care to explain
what is it exactly that you are looking for?

Ala



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

Date: Tue, 10 Aug 1999 09:37:08 -0700
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: Help - Split Function Blowing My Mind Away!!
Message-Id: <MPG.1219f513be75f141989e18@nntp.hpl.hp.com>

In article <7op9q6$n84$1@lublin.zrz.tu-berlin.de> on 10 Aug 1999 
13:35:02 -0000, Anno Siegel <anno4000@lublin.zrz.tu-berlin.de> says...
> Larry Rosler <lr@hpl.hp.com> wrote in comp.lang.perl.misc:
> 
> >Write that line thus:
> >
> >     @record = split(/\|/, $_[0]);
> >
> >And all will be well.  (This is on my Top Ten list of Perl surprises for 
> >beginners.  The vertical bar is a popular field separator!)
> 
> A case of "Ceci n'est pas une pipe"?

You bet it isnt.  It is ASCII VL (vertical line).  Calling it a 'pipe' 
(as the poster did, and which I refused to echo) boggles one's mind with 
irrelevant semantics from an unrelated domain.

As Freud (might have) said, 'Not every cigar is a phallic symbol.'

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


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

Date: Tue, 10 Aug 1999 10:24:48 -0600
From: Greg Guerin <gregory_guerin@hp.com>
Subject: How to create unix install executables?
Message-Id: <37B05250.FE0FEEAD@hp.com>

I am trying to write an application that will work on hpux 10.x -11.x
and
solaris 2.51 - 2.70.  Is there a package builder that will enable me to
install perl scripts to work on these machines without having to install
Perl itself on every machine I was them to run on?   Thank you in
advance!

please mailto:gregory_guerin@hp.com




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

Date: Tue, 10 Aug 1999 09:27:25 -0700
From: Greg Miller <gregjm@sr.hp.com>
Subject: Illegal division by zero when testing for a directory??
Message-Id: <37B052ED.82073C25@sr.hp.com>

Hi,

This morning I came in to see that my nightly tests reported
the following error:

Illegal division by zero at runsession.pl line 968, chunk 1.

Hmmm....Here is the line that it choked on:
------------------------------------------

if (-d "$LOC_DIR/actual/$PLATFORM/logs")
{$LOGSDIR="$LOC_DIR/actual/$PLATFORM/logs";}


How in the heck could this produce the division by zero?..Must be some
kind of NFS issue?...

-Greg




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

Date: Tue, 10 Aug 1999 16:20:40 +0100
From: Gerhard Muth <gmuth@bytecare.com>
Subject: list length
Message-Id: <37B04348.EFE9315D@caci.co.uk>


Simple Question:

Is there a way to get the number of elements of a list WITHOUT 
assigning it to a variable?

e.g. Thread->list gives a list of Threads. This works fine but is
not what I want:

@l = Thread->list;
print $#l." threads in list";

I looked to a lot documentation as well as faqs but could not
find a method or function to get the number of elems of the list.

I would expect something like Thread->list->length or
length(Thread->list)
or anything else.

Cheers,
Gerhard


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

Date: Tue, 10 Aug 99 16:03:47 GMT
From: derek_sherlock@hp.com (Derek Sherlock)
Subject: Re: list length
Message-Id: <rr0jb3.7hpqa2@bogomip.fc.hp.com>


Hi,

If you access a list in a scalar context, you get the number of elements.  In a list
context, you get the elements themselves.

You can force a scalar context with the "scalar" operator if necessary.

For example:

@a = qw(aa ab ac q1 q2 q3);
print scalar grep m/a./,@a;
print "\n";                                          

The print operator provides a list context to its expression.  The scalar operator
coeerces it into a scalar context.  The grep returns a 3 element list which, in the
scalar context, evalutaes to the number 3.

Derek



Nearly 934384840 seconds after the Epoch, Gerhard Muth <gmuth@bytecare.com> wrote:
> 
> Simple Question:
> 
> Is there a way to get the number of elements of a list WITHOUT 
> assigning it to a variable?
> 
> e.g. Thread->list gives a list of Threads. This works fine but is
> not what I want:
> 
> @l = Thread->list;
> print $#l." threads in list";
> 
> I looked to a lot documentation as well as faqs but could not
> find a method or function to get the number of elems of the list.
> 
> I would expect something like Thread->list->length or
> length(Thread->list)
> or anything else.
> 
> Cheers,
> Gerhard



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

Date: Tue, 10 Aug 1999 09:33:50 -0400
From: Ala Qumsieh <aqumsieh@matrox.com>
To: Michael Prendergast <mprender@virtualis.com>
Subject: Re: Looking for a good Perl Book
Message-Id: <x3ywvv37oaq.fsf@tigre.matrox.com>


[posted and CCed]

Michael Prendergast <mprender@virtualis.com> writes:

> I'm looking for a good Perl book to learn from. I do have programming
> experience and I was wondering if any of you have a suggestion as to
> which is a good book to introduce me to the Perl language. I'm not
> *just* looking for an intro book though, I mean one with depth also, and
> some assignments/quizzes also.

Ok. The best book for beginners would be "Learning Perl" (aka the
Llama) written by R. Schwartz and T. Christiansen, published by
O'Reilly.

The best reference on Perl would be "Programming Perl" (aka the Camel)
written by L. Wall, T. Christiansen and R. Shwartz, published by
O'Reilly.

If you want to get the most out of Perl, then I suggest 3 more books:

1) The Perl Cookbook (aka the Ram) by T. Christiansen and
   N. Torkington, published by O'Reilly.

2) Advanced Perl Programming (aka the Panther) by S. Srinivasan,
   published by O'Reilly.

3) Mastering Regular Expressions (aka the Owl) by J. Friedl, published
   by O'Reilly.

(do you see a pattern here?)

Another useful book that I learnt a great deal from (too bad it has
many typos) is the Perl5 Interactive Course, by J. Orwant, published
by Waite Group. It contains some nice quizzes that aided my
understanding greatly.

> Plus, does anyone know of a good online school to learn Perl/Unix?
> Preferably one with begginer and advanced Perl courses.

My only advice here is to read the online docs that come with every
Perl distribution. Perl's docs are complete, up-to-date, free, and your
best source of quick solutions for over 90% of your problems with
Perl.

Just type 'perldoc perldoc' at the command prompt (assuming Perl is
properly installed), and enjoy :)

As for learning Unix, then I say:
1) get Linux
2) install it
3) get any unix book from O'Reilly
4) Enjoy Your Freedom (tm).

HTH,
Ala



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

Date: Tue, 10 Aug 1999 10:04:05 -0500
From: Tom Briles <sariq@texas.net>
Subject: Re: Newbie: File I/O & Locking
Message-Id: <37B03F65.71D30540@texas.net>

Chris wrote:
> 
> Hey all,
> 
> Is
> there some package that offers file locking? If not, do I just do
> something like
> 
>         while (!open(OUT,  "> common.txt"))
>         {
>                 # Loop until the file is free
>         }
> 
> without getting laughed at?

perlfaq5

- Tom


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

Date: Tue, 10 Aug 1999 15:23:52 GMT
From: alexander.zinniker@trivadis.com
Subject: Re: Newbie: File I/O & Locking
Message-Id: <7opg5q$f4p$1@nnrp1.deja.com>

In article <37aedf53.8159617@news.swbell.net>,
  chrisl@hamptons.com (Chris) wrote:
> Hey all,
>
> I have some simple CGI scripts I have to write. They're going to be
> reading and writing a common file, so I need some synchronization. Is
> there some package that offers file locking? If not, do I just do
> something like
>
> 	while (!open(OUT,  "> common.txt"))

on a unix system this would always overwrite an existing file.
You could probably use flock() - see manpages. or "programming perl"

> 	{
> 		# Loop until the file is free
> 	}
>
> without getting laughed at?
>
> Thanks a lot,
> Chris
>
> P.S. Happy 30th to me!!!
>


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


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

Date: Tue, 10 Aug 1999 15:48:42 GMT
From: chris_bordeleau@lotus.com
Subject: Parse exception
Message-Id: <7ophkm$g7g$1@nnrp1.deja.com>

Hi,
   I am writing a perl extension to call functions in a DLL. I am able
to compile it fine but when I run "nmake test" I get :
---------------------------------------------------------------------
w32 [G:\CVS] nmake test

Microsoft (R) Program Maintenance Utility   Version 6.00.8168.0
Copyright (C) Microsoft Corp 1988-1998. All rights reserved.

        E:\Devel\Perl\bin\perl.exe -Iblib\arch -Iblib\lib -
IE:\Devel\Perl\lib -I
E:\Devel\Perl\lib test.pl
1..1
Error: Parse exception
NMAKE : fatal error U1077: 'E:\Devel\Perl\bin\perl.exe' : return
code '0xfffffff
f'
Stop.
---------------------------------------------------------------------
From looking on the web I have found that this error should only occur
when there is a mismatch between the version of perl being used and the
one the extension was compiled for... Here is the test script :
---------------------------------------------------------------------
BEGIN { $| = 1; print "1..1\n"; }
END {print "not ok 1\n" unless $loaded;}

use CVS;

$loaded = 1;
print "ok 1\n";
CVS::ccCVSTablePath("cvstable.tlb");
---------------------------------------------------------------------
I wrote a simple dll with a hello world function in it and it run fine.

Any help on why this would be happening would be appreciated...

Thanks

Chris bordeleau


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


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

Date: Tue, 10 Aug 1999 15:23:01 GMT
From: lianthe@my-deja.com
Subject: Perl & Oracle in a webserver.... environment variable problems
Message-Id: <7opg46$f4a$1@nnrp1.deja.com>

I'm using Perl5 and Oracle (through DBD/DBI) to modify some cgi programs
to write to a database.  In Netscape Suitespot webserver on Solaris, the
scripts do not work.  I've tracked it down to the missing environment
variables ORACLE_HOME and LD_LIBRARY_PATH.  I tried setting
$ENV{LD_LIBRARY_PATH} and $ENV{ORACLE_HOME}, but that only helps in a
subshell, not in the current shell.  I was able to "kludge" my test
script by writing a wrapper around it that set these variables, but that
won't really work for my real project (and it's a performance hit as
well).

I've tried many things:
* the webmaster account (that the script runs as) has the right vars set
* the default .profile has the right vars in
* the vars are set and exported in the server's start script
* I don't see anywhere in the webserver setup to set the vars

Any other things I can try?  There's got to be a way to do this?

Thanks,
Kevin


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


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

Date: Tue, 10 Aug 1999 17:24:26 +0300
From: Nir Leshem <nirl@zoran.co.il>
Subject: perl on linux
Message-Id: <37B0361A.5E07CD97@zoran.co.il>

hi all...

does anybody know why my linux shell doesnt recognize the 'shebang' notation (#!/usr/..../perl

 im surly using the correct path, and chmod my script to +x

and also encountered no problems running my script via the shell (i.e. perl foo.pl)

help....

nir.

--------------------------------------------------------------------
Nir Leshem
VLSI group                                     E-mail nirl@zoran.co.il
ZORAN Microelectronics LTD                     Tel : 972-4-8545911
Advanced Technology Center                       Fax : 972-4-8551550
P.O.B. 2495, Haifa 31204, Israel       www : http://www.zoran.com
--------------------------------------------------------------------





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

Date: 10 Aug 1999 16:08:38 GMT
From: fl_aggie@thepentagon.com (I R A Darth Aggie)
Subject: Re: perl on linux
Message-Id: <slrn7r0jo9.6po.fl_aggie@thepentagon.com>

On Tue, 10 Aug 1999 17:24:26 +0300, Nir Leshem <nirl@zoran.co.il>, in
<37B0361A.5E07CD97@zoran.co.il> wrote:

+ does anybody know why my linux shell doesnt recognize the 'shebang'
+ notation (#!/usr/..../perl

What sort of error are you getting?

+  im surly using the correct path, and chmod my script to +x

% ./foo.pl

Does this give you a "no such file or directory" error? then your #! line
isn't right.

+ and also encountered no problems running my script via the shell
+ (i.e. perl foo.pl)

% which perl

% perl -v 

James

-- 
Consulting Minister for Consultants, DNRC
The Bill of Rights is paid in Responsibilities - Jean McGuire
To cure your perl CGI problems, please look at:
<url:http://www.perl.com/CPAN/doc/FAQs/cgi/idiots-guide.html>


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

Date: Tue, 10 Aug 1999 12:10:59 -0400
From: toby <toby@hercules.cas.utk.edu>
Subject: Re: perl on linux
Message-Id: <37B04F13.E2A7984F@hercules.cas.utk.edu>



Nir Leshem wrote:

> hi all...
>
> does anybody know why my linux shell doesnt recognize the 'shebang' notation (#!/usr/..../perl
>
>  im surly using the correct path, and chmod my script to +x
>
> and also encountered no problems running my script via the shell (i.e. perl foo.pl)
>
> help....
>
> nir.

shell>which perl

this would give you the correct shebang. Also try

shell>./foo.pl

and/or

shell>chmod 755 foo.pl

Please give the error messages next time for a better answer. Hope this helps...

Toby



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

Date: Tue, 10 Aug 1999 08:01:21 -0700
From: moseley@best.com (Bill Moseley)
Subject: Re: perl script - help
Message-Id: <MPG.1219de9a239f546098969e@nntp1.ba.best.com>

Abigail (abigail@delanet.com) seems to say...
> Bill Moseley (moseley@best.com) wrote on MMCLXX September MCMXCIII in
> <URL:news:MPG.12196263903f96de98969d@nntp1.ba.best.com>:
> || Abigail (abigail@delanet.com) seems to say...
> || > perl -walne '$_{$F[0]}->{$F[3]}++;
> || >              END{map{print"For word $_ I found:";%_=%{$_{$_}};
> || >                  map{print"    $_{$_} instances of $_"}keys%_}keys%_}' file
> || 
> || I love well documented code.
> 
> 
> It's self documenting. Only obscure code needs comments.

Say I wanted to find out more about using %_.

62) /usr/local/perl5.005/lib/5.005/pod %grep '%_' *
perlguts.pod:    L        (none)              Debugger %_<filename
perlguts.pod:    l        vtbl_dbline         Debugger %_<filename 

Oh.  Not what I had wished for.

Pardon me, but which exit to I take for nirvana?


Thanks,

-- 
Bill Moseley mailto:moseley@best.com
pls note the one line sig, not counting this one.


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

Date: Tue, 10 Aug 1999 08:10:22 -0700
From: moseley@best.com (Bill Moseley)
Subject: Re: perldoc and activeperl help
Message-Id: <MPG.1219e0bbc3a41ee498969f@nntp1.ba.best.com>

Eric Bohlman (ebohlman@netcom.com) seems to say...
> It doesn't work under Win95.  The problem seems to be that perldoc is 
> implemented as a batch file, and under some circumstances the STDOUT of 
> a program called from a batch file doesn't get redirected or piped.  If I 
> invoke it as 'perl \perl\5.00502\bin\perldoc.bat -f substr | more' it 
> works properly.

And THAT doesn't work for me, either, under Win98.  But, say, 'perldoc 
CGI' will work.  It's really a pain, considering how often we are 
suppose to use it.

-- 
Bill Moseley mailto:moseley@best.com
pls note the one line sig, not counting this one.


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

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

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" from
almanac@ruby.oce.orst.edu. The real FAQ, as it appeared last in the
newsgroup, can be retrieved with the request "send perl-users FAQ" from
almanac@ruby.oce.orst.edu. 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" from
almanac@ruby.oce.orst.edu. 

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


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