[13630] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 1040 Volume: 9

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Oct 11 14:06:43 1999

Date: Mon, 11 Oct 1999 11:05:15 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <939665114-v9-i1040@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Mon, 11 Oct 1999     Volume: 9 Number: 1040

Today's topics:
    Re: alarm and eval (M.J.T. Guy)
    Re: AV,HV,SV <-> XML? <ken@bitsko.slc.ut.us>
        Case Question. <kevinm@papillonres.com>
    Re: character count (Craig Berry)
    Re: character count (Craig Berry)
    Re: Debugger and "O LineInfo=..." (Chris Fedde)
        DESTROY method: can't get to data? (Jack Applin)
    Re: Expiring Pages (I.J. Garlick)
    Re: File upload problem <@mdo.net>
        FTP SERVER in Perl <paymerich@snet.net>
    Re: I need some Perl help (Larry Rosler)
    Re: Installing Fly on remote server <ages@stones.com>
    Re: Is $$variable allowed like in PHP ? (M.J.T. Guy)
    Re: Is there an easy Perl equivalent to SSIs including  <dwozmak@rational.com>
        JPL jbell@263.net
        New Perl Email List <mmenninger@sric.sri.com>
    Re: Opening files on Windows NT (Larry Rosler)
    Re: Opening files on Windows NT (Clinton Pierce)
    Re: parenthesizing arguments to grep - BLOCK form jrw32982@my-deja.com
    Re: parenthesizing arguments to grep - BLOCK form (Alan Curry)
    Re: Passing unknown filenames as arguments to another p (Randal L. Schwartz)
        Question: How do I get the length of a string in PERL? <x@x.com>
        Question: How do I get the length of a string in PERL? <x@x.com>
    Re: Question: How do I get the length of a string in PE <dtbaker_@busprod.com>
    Re: Question: How do I get the length of a string in PE (Larry Rosler)
    Re: Question: How do I get the length of a string in PE <wcollins@cableworks.org>
        Reference of instance method xca1019@my-deja.com
        search engine!! (Daniel Lee)
    Re: Simple flock question <jeff@vpservices.com>
        solution: howto load modules to an ISP website? dtbaker_dejanews@my-deja.com
    Re: Sort one array by contents of another (M.J.T. Guy)
    Re: Sort one array by contents of another (Larry Rosler)
    Re: We do complex Perl Programming at very competetive  (Craig Berry)
        Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)

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

Date: 11 Oct 1999 17:42:01 GMT
From: mjtg@cus.cam.ac.uk (M.J.T. Guy)
Subject: Re: alarm and eval
Message-Id: <7tt7h9$8h1$1@pegasus.csx.cam.ac.uk>

In article <7tsue1$uli$1@nnrp1.deja.com>,  <mbarieux2225@my-deja.com> wrote:
>I'm trying timing out an operation. I did the following :
>
>$SIG{ALRM} = sub { die "alarm" };
>eval
>{
>alarm (1);
># Operation here
>alarm (0);
>};
>warn "$@";
>if ($@)
>{
>	warn "timeout";
>	die $@;
>}
>
>I did the warn "timeout" to see if ti really times out, and the warn
>"$@" to see what's in it. It seems that the operation times out,
>because it is not executed when alarm is on 1 but it is when alarm is
>on 3600 for example. The strange thing is that it doesn't go in the if
>and the warn "$@" delivers:
>warning: something's wrong at test.pl line 62

That's what you get from warn() with no argument (or with a null string
as argument.    See  perldoc -f warn.

So that's exactly what I would expect if the operation didn't time out,
and didn't die() in any other way.


Mike Guy


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

Date: Mon, 11 Oct 1999 16:22:07 GMT
From: Ken MacLeod <ken@bitsko.slc.ut.us>
Subject: Re: AV,HV,SV <-> XML?
Message-Id: <m3wvsteusl.fsf@biff.bitsko.slc.ut.us>

yacob@rcn.com writes:

>   I am working on a problem where it would be *nice* if I could send
> an SV and HV data structure from a client to a broker and back to an
> adapter to recover into Perl name space intact (reblessed and ready
> to go) on the receiving end.
> 
>   Assuming closely related versions of Perl on either end, the dirty
> work I expect would be chasing pointers and copying data into an SV
> payload (XML seemed to be a good choice).
> 
>   Is there some traditional means by which to do this?

Are you looking for serialization, RPC, or both?

For serialization, Data::Dumper, XML::Dumper, FreezeThaw, and the
Marshal::* modules should maintain Perl structures intact.  Start with
Data::Dumper and look at XML::Dumper if you really want XML.

For RPC, you can look at plRPC in the RPC module directory on CPAN.

ObPlug: LDO <http://casbah.org/LDO/> is intended to support both
serialization and RPC modules for Perl, as well as being a general
purpose framework for client/server communication.

-- 
  Ken MacLeod
  ken@bitsko.slc.ut.us


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

Date: Mon, 11 Oct 1999 12:50:02 -0400
From: Kevin McCluskey <kevinm@papillonres.com>
Subject: Case Question.
Message-Id: <3802153A.B42F440@papillonres.com>

I am trying to check a variable against an array of keywords and cannot
get it to ignore the case.
This is what I have:

 $kw_len = @keywords;

sub keytest {
        for($i=0;$i<$kw_len;$i++)
          {
              if ($word eq $keywords[$i]){
    return 1;}
          }
    }

If I do: $word eq /$keywords[$i]/i
I don't get a compare.

Any ideas ? is it that the "eq" operator does not work right with /i ?

Thanks
Kevin.



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

Date: Mon, 11 Oct 1999 17:47:10 GMT
From: cberry@cinenet.net (Craig Berry)
Subject: Re: character count
Message-Id: <s048kut7h1s74@corp.supernews.com>

hakanogren@my-deja.com wrote:
: I need help to count the number of times a certain letter appears in a
: string.
: For example if a have a string "HELLO WORLD" i want to know how many
: L's there are in the string.

Example of one technique:

  my $teststr = 'La La WeLL Lots of Ls';
  my $count   = $teststr =~ tr/L//;
  print "L count is $count\n";

-- 
   |   Craig Berry - cberry@cinenet.net
 --*--    Home Page: http://www.cinenet.net/users/cberry/home.html
   |      "There it is; take it."  - William Mulholland


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

Date: Mon, 11 Oct 1999 17:59:39 GMT
From: cberry@cinenet.net (Craig Berry)
Subject: Re: character count
Message-Id: <s049cblgh1s56@corp.supernews.com>

Jason P Tribbeck (jtribbeck@argogroup.com) wrote:
: However, I've never done any speed tests to see which is faster. The
: first one is, in theory, slower, because there's more intepretation of
: the code, but the second does write back to the original string. Also,
: the latter may not be as understandable.

Each variant can be made nondestructive.  Benchmarking is useful:

#!/usr/bin/perl -w
# charcount - benchmark various ways to count occurrences of
#             a single character in a string.
# Craig Berry (19991011)

use Benchmark;

$str = 'La La HELLO WORLD Lots of Ls';

timethese(10000, {
  translate  => sub { $count = $str =~ tr/L//; },
  substitute => sub { $count = $str =~ s/L/L/g; },
  match      => sub { $count = () = $str =~ m/L/g; },
  loop_match => sub { $count = 0;
                      while ($str =~ m/L/g) {
                        $count++;
                      }
                    }
});
__END__


Benchmark: timing 10000 iterations of loop_match, match, substitute,
translate...
loop_match:  9 secs ( 6.25 usr  0.00 sys =  6.25 cpu)
     match:  9 secs ( 6.58 usr  0.00 sys =  6.58 cpu)
substitute:  2 secs ( 3.19 usr  0.00 sys =  3.19 cpu)
 translate:  1 secs ( 1.85 usr  0.00 sys =  1.85 cpu)


Not surprisingly, 'translate' is the clear winner.  tr/// is almost always
the best choice when it can be applied to a given problem.

-- 
   |   Craig Berry - cberry@cinenet.net
 --*--    Home Page: http://www.cinenet.net/users/cberry/home.html
   |      "There it is; take it."  - William Mulholland


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

Date: Mon, 11 Oct 1999 16:59:36 GMT
From: cfedde@fedde.littleton.co.us (Chris Fedde)
Subject: Re: Debugger and "O LineInfo=..."
Message-Id: <YHoM3.80$F3.135467008@news.frii.net>

In article <7tqkvt$jf9$1@charm.magnus.acs.ohio-state.edu>,
Ilya Zakharevich <ilya@math.ohio-state.edu> wrote:
>[A complimentary Cc of this posting was sent to Chris Fedde
><cfedde@fedde.littleton.co.us>],
>who wrote in article <BVUL3.59$F3.172436480@news.frii.net>:
>> Now if I start perl -d t.pl and set "O LineInfo=|catit" at the

[...]

>
>This looks like a difference in program-oriented output and
>Human-oriented one.  Piping lineinfo switches to program-oriented
>output.  Creating interactive prompt switches to human-oriented one.
>Which one do you *want*?
>
>[ Hmm, I checked and the proper answer happens to be RTFM! ]
>
>This behaviour probably may be changed by an assignment to
>$DB::emacs.  Make an alias if you need to do this often.
>
>Do people want to have the style of the output settable from `O'?
>

The manual page says:

       LineInfo                File or pipe to print line number
                               info to.  If it is a pipe (say,
                               |visual_perl_db), then a short,
                               "emacs like" message is used.

Specifically it does not mention that there is a difference between
the behavior when set interactively vs when set out of PERLDB_OPTS.
I don't know about "people" in general, but I'd like a way to insure
that when LineInfo goes to a pipe, the pipe always gets the same
data.  I need to check the output for invisible characters. The
thought that this might occur did not cross my mind.  If this is
indeed the case then it amounts to a third format.

chris

BTW Please don't take this as a criticism of the Perl debugger.  I think
that it is a fantastic system and is one of three features that make Perl
far and away the most convenient prototyping environment.


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

Date: 11 Oct 1999 16:44:47 GMT
From: neutron@fc.hp.com (Jack Applin)
Subject: DESTROY method: can't get to data?
Message-Id: <7tt45v$fvq$1@fcnews.fc.hp.com>

Consider this stripped-down code:

	#! /usr/bin/perl -w

	package Simple;
	use strict;
	use IO::File;

	sub new {
		my $fh = new IO::File ">value" or die;
		return bless {FH => $fh};
	}

	sub DESTROY {
		my ($self) = @_;
		my $fh = $self->{FH};
		print "fh=$fh\n";
	}

	package main;
	no strict;

	$foo = new Simple;
	print "foo=$foo\n";

When I run it, I get this really quite helpful message:

	foo=Simple=HASH(0x4001d034)
	Use of uninitialized value during global destruction.
	fh=

If I make $foo a lexical variable with "my $foo = new Simple;",
I get this, which I like:

	foo=Simple=HASH(0x4001d034)
	fh=IO::File=GLOB(0x4001d01c)

I don't understand why the filehandle seems to be vanishing.
Does this have something to do with order of destructors?
I hope that File::IO's destructor wouldn't get called until everybody's
finished with it, and there's still a use in that hash.

perl -v says: This is perl, version 5.005_02 built for PA-RISC1.1


						-Jack Applin
						 neutron@fc.hp.com


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

Date: Mon, 11 Oct 1999 16:04:55 GMT
From: ijg@connect.org.uk (I.J. Garlick)
Subject: Re: Expiring Pages
Message-Id: <FJG4o7.63@csc.liv.ac.uk>

In article <rvvlbtamh1s45@news.supernews.com>,
<gus@asus.net> writes:
> How do I expire a page once it has loaded.  I do not want people to be able
> to refresh the page...
> 
> 
> I tried inserting an expire html header tag.  But it does nothing..
> 
> Is it my server?  I am on NT4 with IIS

No it's your browser. Which makes this.... bet you can't guess?

Duh duherr. Nope the answer is "not a perl question".


-- 
Ian J. Garlick
ijg@csc.liv.ac.uk

A computer scientist is someone who fixes things that aren't broken.



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

Date: Mon, 11 Oct 1999 12:33:37 -0400
From: "CS" <@mdo.net>
Subject: Re: File upload problem
Message-Id: <ZgoM3.5782$UG5.399187@typ11.nn.bcandid.com>

It won't work on version 5.003, which is a few years old.  I've tried it,
and it just won't get along with it.

Besides, CGI.pm (if you're using that) requires version 5.004

Regards, CS

>is running perfectly on the NT server which has Perl 5.004
>
>However, the same script is not running with perl 5.003 build
>300 series - if the perl file is called from a form then it gives
>an error that the document contains no data.




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

Date: Mon, 11 Oct 1999 13:41:13 -0400
From: "Pablo Aymerich" <paymerich@snet.net>
Subject: FTP SERVER in Perl
Message-Id: <7tt7ds$pes$1@ffx2nh5.news.uu.net>

Does any one have a FTP SERVER written in Perl ??

or even a simple file transfer client/server in Perl ??

thanks in advance

Pablo




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

Date: Mon, 11 Oct 1999 10:38:12 -0700
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: I need some Perl help
Message-Id: <MPG.126bc05cee91e23198a06d@nntp.hpl.hp.com>

In article <slrn803gvm.gep.abigail@alexandra.delanet.com> on 11 Oct 1999 
06:03:32 -0500, Abigail <abigail@delanet.com> says...

 ...

> @@ >%% Actually, if they're not chomped, the printed output will include 
> @@ >%% extraneous newlines after each key printed, won't it?
> @@ >
> @@ >Not if you don't print the "\n" ....
> @@ 
> @@ It changes *where* the newline is printed. If you do
> @@ 
> @@ 	print "$_: $hash{$_}"; 
> 
> Oh. Don't do that then. ;-)
> 
>         print "$hash{$_}: $_\n";

Which then produces two newlines on each output string.  :-)

What a lot of fuss about just simply chomping the input, without carping 
about doing that!

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


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

Date: Mon, 11 Oct 1999 10:45:20 -0700
From: "ages" <ages@stones.com>
Subject: Re: Installing Fly on remote server
Message-Id: <7tt7n3$ol5@masters0.InterNex.Net>

>Alternatively, is there an 'Installing Fly on webprovider's server for
>dummies' type page somewhere on the web?


http://www.unimelb.edu.au/fly/




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

Date: 11 Oct 1999 17:37:20 GMT
From: mjtg@cus.cam.ac.uk (M.J.T. Guy)
Subject: Re: Is $$variable allowed like in PHP ?
Message-Id: <7tt78g$8dv$1@pegasus.csx.cam.ac.uk>

Martien Verbruggen <mgjv@comdyn.com.au> wrote:
>
>Only in my very first beginning perl years, somewhere in 92 or 93, I
>felt the urge to use symbolic references, and that was because back
>then, there were no hard ones. Since hard references were introduced in
>perl, I never use symrefs anymore.

But hard and symbolic references were introduced at the same time,
with perl5.    I suspect your recollections are of the disgusting
things one had to do aliasing typeglobs in perl4 in order to make
anything resembling a data structure.


Mike Guy


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

Date: Mon, 11 Oct 1999 13:15:05 -0400
From: David Wozmak <dwozmak@rational.com>
Subject: Re: Is there an easy Perl equivalent to SSIs including some HTML ?
Message-Id: <38021B19.F48CFE61@rational.com>



Stuart Wright wrote:
> 
> Jonathan Stowe <gellyfish@gellyfish.com> wrote in message
> > Yes it usually involves opening the file and printing its contents.
> >
> In my original post I wrote that I had considered this - but not being a
> Perl expert (actually it baffles me - I tend to copy existing Perl and hope
> it works without knowing how), opening a file and printing it's contents is
> not *necessarily* a quick solution for some people.
> But thanks anyway.

well...what do you think happens when you do an Server-Side-Include? 
The file is opened and read, and it's contents(or results) are printed. 
This is a trivial operation.  in fact, it is a simple four liner
(although it could have even been done in two):

#---------------------------------------------
#code snippet:
#
sub include_this_file {
	my $include_file = @_;    # get the name of the file
	open (INCLUDE, "$include_file") or print "couldn't open $include_file,
error: $!\n"; 
	while (<INCLUDE>) {print;}   # read each line from the file and print
it.
	close (INCLUDE);  # be nice and close the file yourself, 
                          #even though perl will eventually do it for
you
}
#---------------------------------------------

This code snippet is called a "subroutine". You cut and paste this into
your script at the end, and in the main body of your code, any time you
want to include a file, you put this line in your code:

&include_this_file("somePath/myfile.htm");

where you change "somePath/myfile.htm" to be the name of the file you
want to include.

so, in the main body of your script, it reduces to a single simple line
of code, just as simple as any server-side-include!

The main body of your code could look like this:


____________________________________________
#! usr/bin/perl

use Strict;
{
&include_this_file("header.htm");
&include_this_file("top_navbar.htm");
&include_this_file("body.htm");
&include_this_file("footer.htm");
1
}
#---------------------------------------------
sub include_this_file {
	my $include_file = @_;    # get the name of the file
	open (INCLUDE, "$include_file") or print "couldn't open $include_file,
error: $!"; 
	while (<INCLUDE>) {print;}   # read each line from the file and print
it.
	close (INCLUDE);  # be nice and close the file yourself, 
                          #even though perl will eventually do it for
you
}
#---------------------------------------------
____________________________________________

So...if you considered this and decided not to do it, what other options
do you have?  I'm curious, because there really isn't any simpler way to
do it in PERL.  

I'm also curious about your other statement...that you "hope it works,
without knowing how..."  Does that mean you really could give a rat's
a** about learning perl, and just want someone to do the real work for
you?  If this is for a company website, I must ask how you can sleep at
night, not really knowing what all that code you use does.  Do you just
blindingly trust that the code is doing what you want it to do, and
nothing more? People like you build websites that are known as
"cracker's delights", because they're so full of bugs and backdoors.  

Think of that.  I could have "given" you a twenty-line code snip that
opened a file and printed it, and also sent me all your customer
information, set up any subsequent page to redirect through my server so
I could steal your form data, wipe out your filesystem, give myself
remote access to your server, and lots of other really fun stuff.

I, of course, have no need for your information, so the code above is
probably safe to use.  But there's lots of bored young programmers that
would do malicious things just for a lark.

How would you know?

If this is something you might have to do *several times* in the future,
wouldn't it be *quicker* to spend an hour learning it the first time, so
that it becomes a quick little 5 minute thing NEXT time and the NEXT
NEXT time?

Perhaps you're better suited to using VBscript, a Microsoft scripting
language in which difficult things are sometimes easy to do, and simple
things are seldom easy to do. VBscript has a command that works just
like SSI "include", in fact it's called "include".  Imagine that. 

dwoz

hope this helped.


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

Date: Mon, 11 Oct 1999 17:50:20 GMT
From: jbell@263.net
Subject: JPL
Message-Id: <7tt80m$6at$1@nnrp1.deja.com>

Hi, all,

I run into a bunch of problems when running JPL.
Where can I get support or discussion on this issue?

Thanks!

--
JB


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


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

Date: Mon, 11 Oct 1999 10:40:58 -0700
From: "Marc R. Menninger" <mmenninger@sric.sri.com>
Subject: New Perl Email List
Message-Id: <7tt78i$o06$1@unix.sri.com>

I just created the Perl for NT Admins email list.

Description: The Perl for NT Admins mail list is for NT administrators who
want to automate tasks and procedures with Perl scripts. Subscribers include
Perl beginners and experts. Discuss useful scripts and helpful coding
techniques.

To subscribe, send an email to perl-ntadmins-subscribe@topica.com or go to
http://www.topica.com/lists/perl-ntadmins

Hope to see you there!

Marc R. Menninger, Consultant
SRI Consulting
333 Ravenswood Avenue #AH332, Menlo Park, CA 94025
http://www.sriconsulting.com/ipas/ics/infosec.html
Voice: 650.859.5309 Fax: 650.859.5092
"There is a difference between knowing the path, and walking the path."
Morpheus, The Matrix




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

Date: Mon, 11 Oct 1999 09:08:49 -0700
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: Opening files on Windows NT
Message-Id: <MPG.126bab699214db1998a06b@nntp.hpl.hp.com>

In article <jakem-1110991643350001@dialup-sa-1-315.uni.camtech.net.au> 
on Mon, 11 Oct 1999 16:43:35 +0930, jakal <jakem@camtech.net.au> says...
> I have done a little programming in Perl, mostly on my Macintosh.
> I am trying to port a script to a Windows NT machine, and am having
> trouble accessing files. my code looks like this:
> 
>   open(TEST, ">>test.txt")|| die "can't open test.txt";
> 
> and the program dies at this point (the first time I try to access a file).
> 
> Is this something to do with file permissions or is it a syntax problem??

Some might consider it rude to post essentially the same question twice 
within an hour.  Everyone would consider it impatient and inappropriate.

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


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

Date: Mon, 11 Oct 1999 15:34:14 GMT
From: cpierce1@ford.com (Clinton Pierce)
Subject: Re: Opening files on Windows NT
Message-Id: <38020343.514250973@news.ford.com>

[poster cc'd in e-mail]

On Mon, 11 Oct 1999 16:43:35 +0930, jakem@camtech.net.au (jakal) wrote:
>I have done a little programming in Perl, mostly on my Macintosh.
>I am trying to port a script to a Windows NT machine, and am having
>trouble accessing files. my code looks like this:
>
>  open(TEST, ">>test.txt")|| die "can't open test.txt";
>
>and the program dies at this point (the first time I try to access a file).

 ...yeah

>Is this something to do with file permissions or is it a syntax problem??

If you had printed the value of $! in the die message, you would know
this!



-- 
Clinton A. Pierce       "If you rush a Miracle Man, you get rotten
clintp@geeksalad.org        Miracles."  -- Miracle Max, The Princess Bride
http://www.geeksalad.org


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

Date: Mon, 11 Oct 1999 15:58:07 GMT
From: jrw32982@my-deja.com
Subject: Re: parenthesizing arguments to grep - BLOCK form
Message-Id: <7tt1e6$15e$1@nnrp1.deja.com>

In article <MPG.126867ddf1a96fde98a065@nntp.hpl.hp.com>,
  lr@hpl.hp.com (Larry Rosler) wrote:

> > [] There are situations where one must disambiguate an anonymous
> > hashref
> > [] from a block by prefixing the former with unary plus.  I don't
> > know any
> > [] syntax to do the opposite, to designate a block.
> >
> >
> >   {;
>
> So now I know.  Very cool.  That must be the most trenchant two-
> character answer ever!
>
> I just found both of these in perlref:
>
> Note how the leading +{ and {; always serve to disambiguate the
> expression to mean either the HASH reference, or the BLOCK.
>
> So you could have answered 'RTFM', but your answer was half as long as
> that.  :-)

Thanks for all the replies!  (And I did RTFM, but just couldn't find
this one).

Unfortnately, {; doesn't solve my problem.
   grep({; -d $_} @ARGV);
still generates a syntax error.  So, I guess this is a bug.  Do I need
to report it? (never done that before)

To answer Uri's earlier question about why someone would want to
parenthesize a call to grep:

My philosophy on syntax says that consistency is almost always a good
thing.  For example, I see no point in randomly parenthesizing some
calls to print() and not others.  There must be a good reason to do
things one way sometimes and another way other times.  Otherwise, you
should do things the same way all the time.  Therefore, I'm currently
experimenting with always parenthesizing all function calls (as in many
other languages), trying to find a good rule about when function calls
should be parenthesized.  Just because you don't *have* to parenthesize
a function call, doesn't necessarily mean you shouldn't do it.

Knowing that print(STDOUT ...) works was exactly what caused me to post
my question, as well as the prelude to Camel chapter 3 which explicitly
states that "The functions described in this chapter may be used either
with or without parentheses around their arguments."  Otherwise, I would
have just given up, assuming you couldn't parenthesize a call to a
function whose first argument was one of those weird thingies that you
don't put a comma after.

BTW, what do you call those thingies and what exactly is their syntactic
status.  I haven't seen much discussion in the manual about them.  How
do you search for something like that?

--
John Wiersba


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


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

Date: Mon, 11 Oct 1999 17:19:51 GMT
From: pacman@defiant.cqc.com (Alan Curry)
Subject: Re: parenthesizing arguments to grep - BLOCK form
Message-Id: <X_oM3.5896$UG5.406627@typ11.nn.bcandid.com>

In article <7tt1e6$15e$1@nnrp1.deja.com>,  <jrw32982@my-deja.com> wrote:
>To answer Uri's earlier question about why someone would want to
>parenthesize a call to grep:
>
>My philosophy on syntax says that consistency is almost always a good
>thing.

Consistency? Heh heh heh.

>Knowing that print(STDOUT ...) works was exactly what caused me to post
>my question, as well as the prelude to Camel chapter 3 which explicitly
>states that "The functions described in this chapter may be used either
>with or without parentheses around their arguments."  Otherwise, I would
>have just given up, assuming you couldn't parenthesize a call to a
>function whose first argument was one of those weird thingies that you
>don't put a comma after.
>
>BTW, what do you call those thingies and what exactly is their syntactic
>status.  I haven't seen much discussion in the manual about them.  How
>do you search for something like that?

In the case of grep, it's an anonymous sub. The same thing you can use on
your own subs by prototyping them with a &. See perlsub(1):

       An & requires an anonymous subroutine, which, if passed as
       the first argument, does not require the "sub" keyword or a
       subsequent comma.  A * does whatever it has to do to turn
       the argument into a reference to a symbol table entry.

The filehandle with no comma immediately after print is referred to in some
parts of the documentation as an "indirect object".

Happy grepping.
-- 
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: 11 Oct 1999 09:26:42 -0700
From: merlyn@stonehenge.com (Randal L. Schwartz)
Subject: Re: Passing unknown filenames as arguments to another program
Message-Id: <m1r9j1zwvx.fsf@halfdome.holdit.com>

>>>>> "Abigail" == Abigail  <abigail@delanet.com> writes:

Abigail> Assuming blastcl3 can take multiple arguments:

Abigail>      ls *.seq | xargs blastcl3

Fails if any *.seq are directories.  Nearly useless use of ls there.

  blastcl3 *.seq

would be closer.

-- 
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!


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

Date: Mon, 11 Oct 1999 19:00:24 +0200
From: "Zak Keith" <x@x.com>
Subject: Question: How do I get the length of a string in PERL?
Message-Id: <7tt59h$br5$1@cubacola.tninet.se>

Question: How do I get the length of a string in PERL?




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

Date: Mon, 11 Oct 1999 19:01:40 +0200
From: "Zak Keith" <x@x.com>
Subject: Question: How do I get the length of a string in PERL?
Message-Id: <7tt5bu$bsb$1@cubacola.tninet.se>

Question: How do I get the length of a string in PERL?

Thanks!

Newbie, of course




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

Date: Mon, 11 Oct 1999 12:33:06 -0500
From: Dan Baker <dtbaker_@busprod.com>
Subject: Re: Question: How do I get the length of a string in PERL?
Message-Id: <38021F52.4463F428@busprod.com>



Zak Keith wrote:
> 
> Question: How do I get the length of a string in PERL?
--------------
http://www.perl.com/CPAN-local/doc/FAQs/FAQ/PerlFAQ.html

is a great place to start for online docs.

Dan


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

Date: Mon, 11 Oct 1999 10:31:52 -0700
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: Question: How do I get the length of a string in PERL?
Message-Id: <MPG.126bbedfa044db0398a06c@nntp.hpl.hp.com>

In article <7tt5bu$bsb$1@cubacola.tninet.se> on Mon, 11 Oct 1999 
19:01:40 +0200, Zak Keith <x@x.com> says...
> Question: How do I get the length of a string in PERL?

The Perl language has many builtin functions that respond to common 
programming needs.

At the command line, type `perldoc perlfunc` to see the documentation of 
these functions.

Then type `perldoc -f length`, and guess what you will find?

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


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

Date: Mon, 11 Oct 1999 13:44:42 -0400
From: Wayne Collins <wcollins@cableworks.org>
Subject: Re: Question: How do I get the length of a string in PERL?
Message-Id: <38022209.F41AEBFF@cableworks.org>

This is a multi-part message in MIME format.
--------------47F023DB20E776F7BDCF2718
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit

Zak Keith wrote:

> Question: How do I get the length of a string in PERL?
>
> Thanks!
>
> Newbie, of course

$number = length $something
See perldoc -f length


--------------47F023DB20E776F7BDCF2718
Content-Type: text/x-vcard; charset=us-ascii;
 name="wcollins.vcf"
Content-Transfer-Encoding: 7bit
Content-Description: Card for Wayne Collins
Content-Disposition: attachment;
 filename="wcollins.vcf"

begin:vcard 
n:Collins;Wayne
tel;work:(905)575-1212 x3226
x-mozilla-html:FALSE
org:Mohawk College of Applied Arts and Technology;Computer Science and Information Technology
version:2.1
email;internet:collinw@mail.mohawkc.on.ca
title:Professor
adr;quoted-printable:;;Fennell Campus=0D=0AP.O. box 2034=0D=0AL8N 3T2;Hamilton;Ontario;;
x-mozilla-cpt:;-1
fn:Wayne Collins
end:vcard

--------------47F023DB20E776F7BDCF2718--



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

Date: Mon, 11 Oct 1999 17:37:23 GMT
From: xca1019@my-deja.com
Subject: Reference of instance method
Message-Id: <7tt78i$5p3$1@nnrp1.deja.com>

Hi all,
I want to make a call to a function.
One parameter of the called function should
be an reference to a function or instance
method:

$oFh=FagMods::DM::File_Log->new();

$rfRef=\&Print;         ### Reference to function
$sRc=Test($rfRef);      ### ==> This works

$rfRef=\&{$oFh->Write}; ### Reference to method
$sRc=Test($rfRef);      ### ==> Doesnt work :-(

sub Test($)
{
 ...
}

sub Print($)
{
 ...
}

What is wrong in my syntax?
Many thanks for any reply


Kind Regards
Daniel


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


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

Date: Mon, 11 Oct 1999 18:03:08 +0100 (BST)
From: daniel_lsl@go.com (Daniel Lee)
Subject: search engine!!
Message-Id: <1999Oct11.170309.27625@leeds.ac.uk>

Hi I'm currently doing a project on web search engine.  I'm contemplating on  
whether to use Java or Perl.  Can anyone out there advice me on which language 
to use.  Which is more efficient, easy,...... Thanks 

Daniel



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

Date: 11 Oct 1999 15:42:52 GMT
From: Jeff Zucker <jeff@vpservices.com>
Subject: Re: Simple flock question
Message-Id: <38020533.19F9694C@vpservices.com>

[posted and emailed]

"M.J.T. Guy" wrote:
> 
> Jeff Zucker <jeff@vpservices.com> wrote: 
> >
> >use constant HAS_FLOCK => eval { flock STDOUT, 0; 1 };
> >...
> >if( HAS_FLOCK ) {
> >    # do flock stuff
> >}
> 
> But note that there are circumstances where that doesn't work.   There
> was a previous thread here discussing this   -   I forget the details
> but I think the platform was DOS or one of the older Windows.    It
> seems that HAS_FLOCK will be true although an attempt to flock()
> subsequently will fail.    Or something.

Mike, unless you are referring to something else, that previous thread
was a discussion between you and me -- we emailed back and forth several
times and then you sent some stuff to p5p.  You had suggested a slightly
different version of the constant test (using $0 instead of STDOUT, I
think)  and when I tested it on win95 it gave a false positive, but this
version I posted above does work AFAIK:  it gives false on win95 and
true on solaris.  It is not the same solution we were discussing that
was broken on win95.

-- 
Jeff


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

Date: Mon, 11 Oct 1999 17:17:02 GMT
From: dtbaker_dejanews@my-deja.com
Subject: solution: howto load modules to an ISP website?
Message-Id: <7tt61v$4rd$1@nnrp1.deja.com>

I finally got this all working, so thought I would document in one
posting in case someone else uses dejanews in the future with the same
issue.

My basic question was how to install an optional CPAN module like
Image/Size.pm in a case where you want to use it on a remote host like
a dial-up ISP, and they wont load the module in the system library.

The answer is that you can create your own library, in your cgi-bin dir
for instance. The basic process is the same as installing a module to a
local distribution of perl, but you define a path to your target lib
instead of the "regular" /usr site lib. The you just have to add a line
to your scripts to tell perl where to look for the new lib.

Thought I'd make a quick step-by-step of the install. Details are
available in the perldoc faq section 8.

- download the <whatever>.gz from CPAN
- upload to a temp dir at your ISP
- telnet to the temp dir on your ISP and unpack the file, build the
  makefile, and run the make. probably look like this:

      $tar -zxvf <whatever>.gz
      $perl Makefile.PL LIB=/home/your_account/cgi-bin/your_module_dir
      $make install

- add a line to scripts requiring the module BEFORE you require the
module like this (or you can explicitly add to the @INC ):

      use lib '/path/to/your_module_dir' ;
      use SOME::MODULE ;
      ...rest of your code...

Hope this helps someone else out in the future.....

Dan


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


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

Date: 11 Oct 1999 17:34:13 GMT
From: mjtg@cus.cam.ac.uk (M.J.T. Guy)
Subject: Re: Sort one array by contents of another
Message-Id: <7tt72l$847$1@pegasus.csx.cam.ac.uk>

In article <01bf13d9$b9205c80$da76549e@w-skefford.uk.sequent.com>,
David Bown <nospam-dbown@sequent.com> wrote:
>Hi,
>
>is there a simple way to sort the contents of two arrays into the same
>order using only one of the arrays for comparison?

The standard way is to sort the set of indices:

   my @index = sort { $first[$a] cmp $first[$b] } 0..$#first;
   @first = @first[@index];
   @second = @second[@index];


Mike Guy


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

Date: Mon, 11 Oct 1999 10:52:18 -0700
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: Sort one array by contents of another
Message-Id: <MPG.126bc3b091113f1398a06e@nntp.hpl.hp.com>

In article <7tt077$72$1@nnrp1.deja.com> on Mon, 11 Oct 1999 15:37:13 
GMT, jboes@my-deja.com <jboes@my-deja.com> says...
> In article <01bf13d9$b9205c80$da76549e@w-skefford.uk.sequent.com>,
>   "David Bown" <nospam-dbown@sequent.com> wrote:
> > is there a simple way to sort the contents of two arrays into the same
> > order using only one of the arrays for comparison?

 ...

> If I understand, what you have are two arrays which are correlated:
> 
> @emp_name = ('Sandy','Fred','Percy');
> @emp_code = ('111','333','222');
> 
> So you want to sort @emp_code, and have @emp_name end up in the same
> order. This is probably a data structure mistake, as you may have
> wanted a hash instead:
> 
> %emp = ('111' => 'Sandy', '333' => 'Fred', '222' => 'Percy');
> 
> and then this becomes trivial to process by the key.

Perhaps, but this doesn't generalize well to more than two arrays.  A 
more appropriate data structure would be an array of array references.  
See perllol and perldsc.
 
> If you really do have two arrays, and you want to end up with two
> arrays, then you can either (a) use a temporary hash to get from point
> A to point B, or (b) write your own sort routine based on a standard
> algorithm, and exchange elements of both arrays when you make a
> comparison.

Neither of these approaches is as effective as using an 'index sort'.  
Sort the indexes of one array, then use the sorted indexes to sort each 
of the arrays.

Using your example:

> @emp_name = ('Sandy','Fred','Percy');
> @emp_code = ('111','333','222');
> 
> print join(',', @emp_code), "\n";
> print join(',', @emp_name), "\n";

my @indexes = sort { $emp_code[$a] <=> $emp_code[$b] } 0 .. $#emp_code;

@emp_code = @emp_code[@indexes];
@emp_name = @emp_name[@indexes];

> print join(',', @emp_code), "\n";
> print join(',', @emp_name), "\n";

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


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

Date: Mon, 11 Oct 1999 17:08:06 GMT
From: cberry@cinenet.net (Craig Berry)
Subject: Re: We do complex Perl Programming at very competetive rates
Message-Id: <s046bm50h1s38@corp.supernews.com>

harris_m@my-deja.com wrote:
: Kraigen should get at least $20/hr from this company for doing
: "detailed" non Perl related QA.

Amen.

: By the way how does the company display their Perl expertise on Web a
: page? By puting some irrelavent source code for "something" written in
: Perl?

Typically, by providing links to sites created by the company which do
interesting server-side things.  There's no way to prove these things are
being done in Perl, of course, but if the company can do interesting
server-side things, one can presume they (probably) aren't lying about the
choice of implementation language.

-- 
   |   Craig Berry - cberry@cinenet.net
 --*--    Home Page: http://www.cinenet.net/users/cberry/home.html
   |      "There it is; take it."  - William Mulholland


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

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


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