[6329] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 951 Volume: 7

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Feb 14 16:17:23 1997

Date: Fri, 14 Feb 97 13:00:36 -0800
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Fri, 14 Feb 1997     Volume: 7 Number: 951

Today's topics:
     Re: '--' on command line (Honza Pazdziora)
     Re: Case insensitive comparison (Brian L. Matthews)
     DATA MASTERS--Your source for permanent or contract pos bsartin@softscience.com
     finding full path to file name <toddl@net.com>
     glob behavior with nonexistent directories (glob is not (KF6IIU)
     Re: How to impliment AnsiColor in perl? (Honza Pazdziora)
     Re: HOW TO SPLIT A SIMPLE STRING (Dave Thomas)
     Re: HOW TO SPLIT A SIMPLE STRING (Brian L. Matthews)
     Re: HOW TO SPLIT A SIMPLE STRING (David  Bell)
     Re: Is there a better way to return this reference? (Honza Pazdziora)
     Re: MLDBM issues - is it transparent? (Gurusamy Sarathy)
     Re: on the fly graphs <paul.joslin@sdrc.com>
     Path to a file handle <toddl@net.com>
     Re: pattern matching of sorts (Honza Pazdziora)
     perl5.003 "make test" error (Jerry L. Kazdan)
     Digest Administrivia (Last modified: 8 Jan 97) (Perl-Users-Digest Admin)

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

Date: Fri, 14 Feb 1997 20:05:27 GMT
From: adelton@fi.muni.cz (Honza Pazdziora)
Subject: Re: '--' on command line
Message-Id: <adelton.855950727@aisa.fi.muni.cz>

bill@medtechnet.com (Bill Hliwa) writes:

> I have a number of cgi scripts.  Most begin with:
>  
>     #!/usr/bin/perl
>  
> There are some, however, that will not run unless '--' is appended to this
> line, as:
>  
>     #!/usr/bin/perl --
>  
> I can't seem to find a reference to this.  What does the '--' command line
> argument do?

Page 330 of the Camel book:

-- Terminates switch processing, even if the next argument starts with
   a minus. It has no other effect.

So it really makes sense only with -s switch. What does it mean "will
not run"? What are the error messages?

--
------------------------------------------------------------------------
 Honza Pazdziora | adelton@fi.muni.cz | http://www.fi.muni.cz/~adelton/
                   I can take or leave it if I please
------------------------------------------------------------------------


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

Date: 14 Feb 1997 11:04:15 -0800
From: blm@halcyon.com (Brian L. Matthews)
Subject: Re: Case insensitive comparison
Message-Id: <5e2cvf$8a6$1@halcyon.com>

In article <slrn5g8sik.lak.dave@fast.thomases.com>,
Dave Thomas <Dave@Thomases.com> wrote:
|On Fri, 14 Feb 1997 01:16:55 -0800, Rupesh Kapoor <rupesh@whowhere.com> wrote:
|> Its probably an easy question. What is the operator/function to compare
|> two strings in a case insensitive way
|  print "*match*\n" if ($str1 =~ m/^$str2$/i);

Unless $str2 could contain regexp metacharacters, in which case you'll
need something like:

print "*match*\n" if $str1 =~ m/^\Q$str2\E$/i;

Of course this is a fair bit slower than just lower-casing everything:

use Benchmark;

$str1 = 'A(b)c';
$str2 = 'a(B)c';

timethese (100000,
    {
	'RE' => '$str1 =~ m/^\Q$str2\E$/i',
	'RE const' => '$str1 =~ m/^a\(b\)c$/i',
	'lc' => 'lc $str1 eq lc $str2',
	'lc const' => '\'a(b)c\' eq lc $str2'
    });

Benchmark: timing 100000 iterations of RE, RE const, lc, lc const...
        RE: 23 secs (20.08 usr  0.57 sys = 20.65 cpu)
  RE const: 20 secs (10.62 usr  0.88 sys = 11.50 cpu)
        lc: 12 secs ( 6.43 usr  0.47 sys =  6.90 cpu)
  lc const: 11 secs ( 3.77 usr  0.38 sys =  4.15 cpu)

Brian
-- 
Brian L. Matthews				Illustration Works, Inc.
	For top quality, stock commercial illustration, visit:
		  http://www.halcyon.com/artstock


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

Date: Fri, 14 Feb 1997 14:30:58 -0600
From: bsartin@softscience.com
Subject: DATA MASTERS--Your source for permanent or contract positions!
Message-Id: <3304CB81.61FA@softscience.com>

Hello,
If you are a programmer or network administrator interested in a quality
permanent or contract position, contact DATA MASTERS
(http;//www.datamstrs.com).  Let them find the ideal opportunity for
you!


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

Date: Thu, 13 Feb 1997 07:47:11 -0800
From: Todd Lowpensky <toddl@net.com>
Subject: finding full path to file name
Message-Id: <3303377F.6A60@net.com>

I'm being passed a file name to work on, and I need to
figure out the entire path of the file.  The string passed
to me may be "../../../motive/file", so it would require
a fair amount of work to reconstruct it from the current
directory.

I'm using PERL 5 in Solaris.  Any ideas?
thanks
-- 

-TL
toddl@net.com


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

Date: Fri, 14 Feb 1997 20:35:08 GMT
From: spammers@must.die.com (KF6IIU)
Subject: glob behavior with nonexistent directories (glob is not find)
Message-Id: <wsandersE5M16L.310@netcom.com>

I suppose glob is not really designed to be a replacement for "find":

perl -e 'print join("\n",glob("/*"))'
/TT_DB
/bin
/cache
/dev  [etc]

If I put a bogus directory in the "path":

perl -e 'print join("\n",glob("/bleah/* /*"))'
{nothing}

perl -e 'print join("\n",glob("/* /bleah/*"))'
{nothing}

Is this supposed to happen? I checked the FAQ and didn't find
anything. This behavior is actually consistent with "ls", which returns
and no such file error givne the same arguments.

I think this is of interest because I have seen a fair number of
perl-isms where glob (or <>) is used to "find" a list of files. Guess
not. Glob is more like "ls", no "find".

If this has been beaten to death already in this group, never mind.

This is perl, version 5.003 with EMBED
	built under solaris at Sep 26 1996 16:36:59
	+ suidperl security patch

Thanks,
-w


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

Date: Fri, 14 Feb 1997 19:56:33 GMT
From: adelton@fi.muni.cz (Honza Pazdziora)
Subject: Re: How to impliment AnsiColor in perl?
Message-Id: <adelton.855950193@aisa.fi.muni.cz>
Keywords: Ansicolor

lstanl01@fiu.edu writes:

> Well, hi.  This is my first time sending a post to this newsgroup, so
> don't really know all the protocols.  But, anyway.  I have been trying to
> get ansicolor into my client, and I thought it would be just like
> everything else, be it VAX, DOS, or Unix with escape sequences.  perhaps I
> am doing it wrong. 
> 
> $blink = "\c[[5m";  # This will blink the current text color I thought.
> 		    # I don't filter out escape sequences, yet this
> 		    # doesn't work

The problem will probably be with your terminal not understanding the
excape sequence you are sending to it. Anyway, this

perl -e ' print "\c[[1mBold\c[[0m\033[4mUnderline\e[0m\n"; '

works just fine with my xterm to make it bold and underline. Or am I
answering something completely different?

> 
> I was also told that I could do this too:
> 
> $blink = "\27[5m"; 

This should read "\33[5m" because you are specifying an octal number.

Hope this helps.

--
------------------------------------------------------------------------
 Honza Pazdziora | adelton@fi.muni.cz | http://www.fi.muni.cz/~adelton/
                   I can take or leave it if I please
------------------------------------------------------------------------


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

Date: 14 Feb 1997 18:47:44 GMT
From: dave@fast.thomases.com (Dave Thomas)
Subject: Re: HOW TO SPLIT A SIMPLE STRING
Message-Id: <slrn5g9clb.m88.dave@fast.thomases.com>

On 14 Feb 1997 16:50:19 GMT, Adam M. Donahue <donahue@acf2.nyu.edu> wrote:
> Hi!
> 
> OK, how does one accomplish this?  I have a a six character string,
> say 012345, that I want to split into three variables, $one, $two, $three
> that would then have 01, 23, 45.  The original string has no
> delimiters, though.
>   

split won't do what you want. You can either use s///, substr or
(preferably) unpack:

   my ($one, $two,$three) = unpack('a2 a2 a2', "012345");
   print "$one - $two - $three\n";
   
Dave


-- 

 _________________________________________________________________________
| Dave Thomas - Dave@Thomases.com - Unix and systems consultancy - Dallas |
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


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

Date: 14 Feb 1997 11:11:50 -0800
From: blm@halcyon.com (Brian L. Matthews)
Subject: Re: HOW TO SPLIT A SIMPLE STRING
Message-Id: <5e2ddm$8jn$1@halcyon.com>

In article <5e254b$to6$1@news.nyu.edu>,
Adam M. Donahue <donahue@acf2.nyu.edu> wrote:
|OK, how does one accomplish this?  I have a a six character string,
|say 012345, that I want to split into three variables, $one, $two, $three
|that would then have 01, 23, 45.  The original string has no
|delimiters, though.

Check out unpack in perlfunc.

Brian
-- 
Brian L. Matthews				Illustration Works, Inc.
	For top quality, stock commercial illustration, visit:
		  http://www.halcyon.com/artstock


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

Date: 14 Feb 1997 12:51:08 -0700
From: dbell@azstarnet.com (David  Bell)
Subject: Re: HOW TO SPLIT A SIMPLE STRING
Message-Id: <5e2fnc$lvt@web.azstarnet.com>

In article <slrn5g9clb.m88.dave@fast.thomases.com>,
Dave Thomas <Dave@Thomases.com> wrote:
>On 14 Feb 1997 16:50:19 GMT, Adam M. Donahue <donahue@acf2.nyu.edu> wrote:
>> Hi!
>> 
>> OK, how does one accomplish this?  I have a a six character string,
>> say 012345, that I want to split into three variables, $one, $two, $three
>> that would then have 01, 23, 45.  The original string has no
>> delimiters, though.
>>   
>
>split won't do what you want. You can either use s///, substr or
>(preferably) unpack:
>
(unpack example deleted)

unpack seems like the most reasonable way to do it, but you can use 
split if you throw away some elements:

	$original = '012345';

	($one, $two, $three) = grep /../, split (/(..)/, $original);


m//g works also:

	($one, $two, $three) =  ($original =~ m/../g);

Dave


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

Date: Fri, 14 Feb 1997 20:37:28 GMT
From: adelton@fi.muni.cz (Honza Pazdziora)
Subject: Re: Is there a better way to return this reference?
Message-Id: <adelton.855952648@aisa.fi.muni.cz>

> This works, but I have a strong sensation that I am not doing this in
> the best way possible.  If I use the obvious syntax "$main::$x",  I get

You probably want a $main::x instead of $main::$x.
> a 
> "Scalar found where operator expected at ....(Missing operator before
> $x?)" message.
--
------------------------------------------------------------------------
 Honza Pazdziora | adelton@fi.muni.cz | http://www.fi.muni.cz/~adelton/
                   I can take or leave it if I please
------------------------------------------------------------------------


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

Date: 14 Feb 1997 20:07:36 GMT
From: gsar@engin.umich.edu (Gurusamy Sarathy)
Subject: Re: MLDBM issues - is it transparent?
Message-Id: <5e2gm8$4tm$1@news.eecs.umich.edu>

   [ mailed and posted ]

In article <ken-1302971826130001@news.swarthmore.edu>,
Ken Williams <ken@forum.swarthmore.edu> wrote:
>(1) Is it efficient?  What I mean is, how fast can I open up databases? 
>My fear is that MLDBM stores a data structure to disk, and then whenever I
>open up that structure again, via a tie(), it reads the ENTIRE data
>structure into memory.

First, you shouldn't be using *any* TIE mechanism if you're after
efficiency, since all C<tie> does is act as sugar for some method calls.
Using those method calls would save you at least 1/2 the number of
overall method calls (which can be a considerable saving, depending on
where you're using the tied hash).  The added value is pure convenience.

One would think that a great reason to use C<tie>s would be to try out
various different hashing implementations (SubstrHash, DB_File-BTREE) 
and see if any one is better for the job, without changing the code
you may have already written for an in-memory hash.  Unfortunately,
that tack won't quite work if you're using multidimensional hashes.

Because the TIEHASH interface is *broken* when it comes to mdim
hashes.  This is where MLDBM comes in.  It serves as an interface
to TIEHASH packages so you may use multidimensional ties (with
some restrictions).  The restriction is that you cannot *store*
a nested element transparently without making a temporary first.
i.e.:

    # won't work
    $tiedhash{f}[0]{o} = 'bar';

    # must do this instead
    { my $tmp = $tiedhash{f}; $tmp->[0]{o} = 'bar'; $tiedhash{f} = $tmp; }

Fetches are still ok:

    # this *will* work
    print $tiedhash{f}[0]{o};

I know this limitation is *awful* and all that, but there's no way
around it currently.  Core support may be forthcoming in the future though.

You can see from the above that MLDBM has to cache an entire *record*
in memory (not the entire hash).  Depending on how humoungous your
records are, this may or may not be an efficient approach.

>(2) How come the each() function doesn't seem to work like I thought it
>would?  Here's some code:
> while(($k, $v) = each %{$db{'002340'}}) {

Similar issue as above.  That will refetch the $db{'002340'} record
*every* time through the loop, so that record will always start out
at the first element => infinite loop.  You must again use a temporary:

  my $rec = $db{'002340'};
  while(($k, $v) = each %$rec) { ...

to both work and be efficient.

>(3) What plans are being made for a more seamless storage implementation
>of multidimensional data structures?

I've been making some noises about this on perl5-porters list (but that's
all it is at this point. Noise.).  I'll implement it when I find the time
(or when the mood is upon me).  Feel free to try and post patches to
perlbug@perl.com.

>Thanks for your time,
>      Ken Williams
>      ken@forum.swarthmore.edu

And thanks for your feedback.

 - Sarathy.
   gsar@umich.edu


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

Date: 14 Feb 1997 13:29:07 -0500
From: Paul Joslin <paul.joslin@sdrc.com>
Subject: Re: on the fly graphs
Message-Id: <y4dafp7fdho.fsf@heimdall.sdrc.com>

"Richard S. Boswell" <sboswell@tamu.edu> writes:

> 
> I'm trying to write a program that will generate gifs of graphs on the fly
> for web publishing.  I need to generate simple graphs (line,bar,pie) for a
> simulation model.  There is the possibility of thousands of graphs, so to
> conserve disk space, we only want to generate graphs that are needed by a
> certain user.

Someone solved the problem for bar graphs in websar.pl.  Search for
it; it should also be at <URL http://www.samag.com>.

-- 
Paul R. Joslin		paul.joslin@sdrc.com		+1 513 576 2012
I guess we were all guilty, in a way. We all shot him, we all skinned
him, and we all got a complimentary bumper sticker that said, "I
helped skin Bob."	-- Jack Handey


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

Date: Tue, 11 Feb 1997 17:49:56 -0800
From: Todd Lowpensky <toddl@net.com>
Subject: Path to a file handle
Message-Id: <330121C4.111B@net.com>

I'm trying to find the complete path to a specific
file handle that I am operating on.  I am using Solaris,
and Perl 5.  The STATS command appears to give me everything
I might possibly want about a file EXCEPT the path.

Any suggestions?
thanks
-- 

-TL
toddl@net.com


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

Date: Fri, 14 Feb 1997 20:44:41 GMT
From: adelton@fi.muni.cz (Honza Pazdziora)
Subject: Re: pattern matching of sorts
Message-Id: <adelton.855953081@aisa.fi.muni.cz>

"D. M. Johnson" <ez045864@peseta.ucdavis.edu> writes:

> I need to take a scalar variable and determine how many alphanumeric
> characters and non-alphanumeric characters it contains.  I have tried a
> for loop but that resulted in an infinite loop.  Any help would be greatly
> appreciated.  Thanks.

Yes, it's rather easy to make an infinite loop and it's hard to debug,
if you do not send the source code. But:

$w = 0;
while ($data =~ /\w/g) { $w++; }
print $w, "\n";
print length($data) - $w, "\n";

prints

18
3

on $data = "No manual entry found";
which sound pretty much like what you wanted.

Hope this helps.

--
------------------------------------------------------------------------
 Honza Pazdziora | adelton@fi.muni.cz | http://www.fi.muni.cz/~adelton/
                   I can take or leave it if I please
------------------------------------------------------------------------


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

Date: 14 Feb 1997 19:23:49 GMT
From: kazdan@hans.math.upenn.edu (Jerry L. Kazdan)
Subject: perl5.003 "make test" error
Message-Id: <5e2e45$jdb@netnews.upenn.edu>

I have perl5.003 running on a NeXT computer running NeXTSTEP 3.2 and
want to also have it running on an identical NeXT computer (NeXTSTEP 3.2).

Thus I tarred the entire src/perl5.003/ tree (this had been compiled)
and copied it to the other computer.  I untarred it. I ran
	make test
but then one test failed
		   lib/dirhand....FAILED on test 0

("make test" gave no errors on the first computer).

	Any hints? Is this serious?

	Jerry  (e-mail reply is best)


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

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

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 V7 Issue 951
*************************************

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