[19012] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 1207 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Jun 27 21:07:56 2001

Date: Wed, 27 Jun 2001 18:05:09 -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: <993690309-v10-i1207@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Wed, 27 Jun 2001     Volume: 10 Number: 1207

Today's topics:
        [ANNOUNCE] Scalar::Properties 0.10 <marcel@codewerk.com>
        Automatic Perl upgrade via CPAN <cshannon@data2design.com>
    Re: Case issue replacing a string with the contents of  (Craig Berry)
    Re: Dijkstra / Graph / SSSP (Zur Aougav)
    Re: expression match help <prariedawn   @hotmail.com>
        How to Build a Perl with Tk Package <rogerhsu2001@yahoo.com>
    Re: How to determine stack depth? (Sweth Chandramouli)
    Re: How to determine stack depth? (Craig Berry)
    Re: How to determine stack depth? sweth+perl@gwu.edu (Sweth Chandramouli0
    Re: How to determine stack depth? (Craig Berry)
        is there a way to look ahead/behind in a foreach (@l)? <nospam@cfl.rr.com>
    Re: is there a way to look ahead/behind in a foreach (@ (Craig Berry)
    Re: is there a way to look ahead/behind in a foreach (@ <wyzelli@yahoo.com>
    Re: New knowledgebase site - looking for authors, artic (Tony L. Svanstrom)
        New to perl (Adam)
        newbie question-- need to do a search and replace of te <stevenb@netvision.net.il>
        Newbie question: What's the opposite of chop? <rwellum@cisco.com>
        Newbie question: What's the opposite of chop? <rwellum@cisco.com>
    Re: Newbie question: What's the opposite of chop? <stevea@wrq.com>
    Re: Newbie question: What's the opposite of chop? <tony_curtis32@yahoo.com>
        PostgreSQL/Perl error (Lisa Koma)
    Re: problam installing JPL (Charles DeRykus)
    Re: Scanning a file in CGI <wyzelli@yahoo.com>
    Re: sorting a hash <troyr@vicnet.net.au>
        Thanks!... <greg_j_miller@agilent.com>
        Trouble with Text::ParseWords.pm <david.j.hutchins@intel.com>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: 27 Jun 2001 22:12:17 GMT
From: Marcel Grunauer <marcel@codewerk.com>
Subject: [ANNOUNCE] Scalar::Properties 0.10
Message-Id: <tjkmntcungtkbd@corp.supernews.com>

NAME
    Scalar::Properties - run-time properties on scalar variables

SYNOPSIS
      use Scalar::Properties;
      my $val = 0->true;
        if ($val && $val == 0) {
        print "yup, its true alright...\n";
      }

      my @text = (
        'hello world'->greeting(1),
        'forget it',
        'hi there'->greeting(1),
      );
      print grep { $_->is_greeting } @text;

      my $l =  'hello world'->length;

DESCRIPTION
    Scalar::Properties attempts to make Perl more object-oriented by taking
    an idea from Ruby: Everything you manipulate is an object, and the
    results of those manipulations are objects themselves.

      'hello world'->length
      -1234->abs
      "oh my god, it's full of properties"->index('g')

    The first example asks a string to calculate its length. The second
    example asks a number to calculate its absolute value. And the third
    example asks a string to find the index of the letter 'g'.

    Using this module you can have run-time properties on initialized scalar
    variables and literal values. The word 'properties' is used in the Perl
    6 sense: out-of-band data, little sticky notes that are attached to the
    value. While attributes (as in Perl 5's attribute pragma, and see the
    `Attribute::*' family of modules) are handled at compile-time,
    properties are handled at run-time.

    Internally properties are implemented by making their values into
    objects with overloaded operators. The actual properties are then simply
    hash entries.

    Most properties are simply notes you attach to the value, but some may
    have deeper meaning. For example, the `true' and `false' properties
    plays a role in boolean context, as the first example of the Synopsis
    shows.

    Properties can also be propagated between values. For details, see the
    EXPORTS section below. Here is an example why this might be desirable:

      pass_on('approximate');
      my $pi = 3->approximate(1);
      my $circ = 2 * $rad * $pi;

      # now $circ->approximate indicates that this value was derived
      # from approximate values

    Please don't use properties whose name start with an underscore; these
    are reserved for internal use.

    You can set and query properties like this:

    `$var->myprop(1)'
        sets the property to a true value.

    `$var->myprop(0)'
        sets the property to a false value. Note that this doesn't delete
        the property (to do so, use the `del_props' method described below).

    `$var->is_myprop', `$var->has_myprop'
        returns a true value if the property is set (i.e., defined and has a
        true value). The two alternate interfaces are provided to make
        querying attributes sound more natural. For example:

          $foo->is_approximate;
          $bar->has_history;

METHODS
    Values thus made into objects also expose various utility methods. All
    of those methods (unless noted otherwise) return the result as an
    overloaded value ready to take properties and method calls itself, and
    don't modify the original value.

  INTROSPECTIVE METHODS

    These methods help in managing a value's properties.

    `$var-'get_props>
        Get a list of names of the value's properties.

    `$var-'del_props(LIST)>
        Deletes one or more properties from the value. This is different
        than setting the property value to zero.

    `$var-'del_all_props>
        Deletes all of the value's properties.

  NUMERICAL METHODS

    `plus(EXPR)'
        Returns the value that is the sum of the value whose method has been
        called and the argument value. This method also overloads addition,
        so:

          $a = 7 + 2;
          $a = 7->plus(2);    # the same

    `minus(EXPR)'
        Returns the value that is the the value whose method has been called
        minus the argument value. This method also overloads subtraction.

    `times(EXPR)'
        Returns the value that is the the value whose method has been called
        times the argument value. This method also overloads multiplication.

    `divide(EXPR)'
        Returns the value that is the the value whose method has been called
        divided by the argument value. This method also overloads division.

    `modulo(EXPR)'
        Returns the value that is the the value whose method has been called
        modulo the argument value. This method also overloads the modulo
        operator.

    `exp(EXPR)'
        Returns the value that is the the value whose method has been called
        powered by the argument value. This method also overloads the
        exponentiation operator.

    `abs'
        Returns the absolute of the value.

    `zero'
        Returns a boolean value indicating whether the value is equal to 0.

  STRING METHODS

    `length', `size'
        Returns the result of the built-in `length' function applied to the
        value.

    `reverse'
        Returns the reverse string of the value.

    `uc', `ucfirst', `lc', `lcfirst', `hex', `oct'
        Return the result of the appropriate built-in function applied to
        the value.

    `concat(EXPR)', `append(EXPR)'
        Returns the result of the argument expression appended to the value.

    `swapcase'
        Returns a version of the value with every character's case reversed,
        i.e. a lowercase character becomes uppercase and vice versa.

    `split /PATTERN/, LIMIT'
        Returns a list of overloaded values that is the result of splitting
        (according to the built-in `split' function) the value along the
        pattern, into a number of values up to the limit.

  BOOLEAN METHODS

    `numcmp(EXPR)'
        Returns the (overloaded) value of the numerical three-way
        comparison. This method also overloads the `<=>' operator.

    `cmp(EXPR)'
        Returns the (overloaded) value of the alphabetical three-way
        comparison. This method also overloads the `cmp' operator.

    `eq(EXPR)', `ne(EXPR)', `lt(EXPR)', `gt(EXPR)', `le(EXPR)', `ge(EXPR)'
        Return the (overlaoded) boolean value of the appropriate string
        comparison. These methods also overload those operators.

    `eqi(EXPR)', `nei(EXPR)', `lti(EXPR)', `gti(EXPR)', `lei(EXPR)',
    `gei(EXPR)'
        These methods are case-insensitive versions of the above operators.

    `is_true', `is_false'
        Returns the (overloaded) boolean status of the value.

EXPORTS
    Three subroutines dealing with how properties are propagated are
    automatically exported. For an example of propagation, see the
    DESCRIPTION section above.

    `pass_on(LIST)'
        Sets (replaces) the list of properties that are passed on. There is
        only one such list for the whole mechanism. The whole property
        interface is experimental, but this one in particular is likely to
        change in the future.

    `passed_on(STRING)'
        Tests whether a property is passed on and returns a boolean value.

    `get_pass_on'
        Returns a list of names of properties that are passed on.

BUGS
    None known so far. If you find any bugs or oddities, please do inform
    the authors.

AUTHORS
    James A. Duncan <jduncan@fotango.com>

    Marcel Grunauer, <marcel@codewerk.com>

COPYRIGHT
    Copyright 2001 Marcel Grunauer, James A. Duncan. All rights reserved.

    This library is free software; you can redistribute it and/or modify it
    under the same terms as Perl itself.

SEE ALSO
    perl(1), overload(3pm), Perl 6's properties.


Marcel

-- 
We are Perl. Your table will be assimilated. Your waiter will adapt to
service us. Surrender your beer. Resistance is futile.
 -- London.pm strategy aka "embrace and extend" aka "mark and sweep"




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

Date: Wed, 27 Jun 2001 20:35:38 -0400
From: "Christopher Shannon" <cshannon@data2design.com>
Subject: Automatic Perl upgrade via CPAN
Message-Id: <9hdu34$l1o$1@news.umbc.edu>

Nowadays whenever I try to install some modules or bundles via the CPAN
shell, like Bundle::libnet for instance, the CPAN interactive shell starts
downloading and installing Perl 5.6!!  I just want the bundle, not a new
version of Perl.

Has anyone out there made a workaround for this?  Or do we "HAVE" to upgrade
if we want to live in peace with the CPAN shell?

- C.




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

Date: Wed, 27 Jun 2001 22:15:32 -0000
From: cberry@cinenet.net (Craig Berry)
Subject: Re: Case issue replacing a string with the contents of a variable.
Message-Id: <tjkmo4d8ktrgbf@corp.supernews.com>

James Anderson (James.2.Anderson@bt.com) wrote:
: Writing a simple program to search for a word and mark every instance
: of it within a document.
: 
: if ($searchstring !~ /\*/) {
:    s/\b$searchstring\b/($searchstring)/gi;
: }
: 
: This is giving me a problem.  I need it to replace the string found
: with the same string in brackets, but at the moment it replaces it
: with the $searchstring variable in brackets.  If $searchstring is
: "this" and the word found is "This", it will replace it with "(this)"
: and not "(This)".
: How do I keep the case when I replace the original word?

  s/\b($searchstring)\b/($1)/gi;

-- 
   |   Craig Berry - http://www.cinenet.net/~cberry/
 --*--  "Magick is the art and science of causing change in conformity
   |   with Will."  - Aleister Crowley


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

Date: 27 Jun 2001 15:11:28 -0700
From: aougav@hotmail.com (Zur Aougav)
Subject: Re: Dijkstra / Graph / SSSP
Message-Id: <bccc87cc.0106271411.1332aec6@posting.google.com>

"JohnShep" <john@princenaseem.com> wrote in message news:<iym_6.298$L41.9347@NewsReader>...
> I am trying to find connections between people using Graph::BFS using a name
> as a vertex and an acquaintance as an edge. Can anyone enlighten me as to
> what %param BFS uses and how to process the resultant search set. E.g. I
> want the path Dave to John => Dave,Mark,Paul,John
> 
> #!/usr/bin/perl -w
> use Graph::Directed;
> use Graph::BFS;
> 
> $G = new Graph::Directed;
> 
> $G = $G->add_edge("dave","mark");
> $G = $G->add_edge("mark","paul");
> $G = $G->add_edge("paul","john");
> 
> # Should I use $G = $G->SSSP_Dijkstra(); here ?
> 
> $set = Graph::BFS->new($G,%param);
> 
> 
> John

To find shortest paths from root to all other nodes:

$G = $G->add_edge("dave","mark");       # "dave" is the root for SSSP_Dijkstra!
$G = $G->add_edge("mark","paul");
$G = $G->add_edge("paul","john");

my $d = $G->SSSP_Dijkstra();   # $d is a graph with "path" and "weight" attributes

foreach my $v ($d->vertices()) {
        print "$v: path is ".join("->",@{$d->get_attribute("path", $v)})."\n";
        print "$v: weight is ".$d->get_attribute("weight", $v)."\n"; # eq 0!
}

Zur


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

Date: Wed, 27 Jun 2001 23:53:21 GMT
From: "Prarie Dawn" <prariedawn   @hotmail.com>
Subject: Re: expression match help
Message-Id: <993686001.932920@atlas.corp.au.home.com>

Stepping away from regex, is it an option to simply match the first =

 ... since this will always be the assignment op?

Just a thought...




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

Date: Wed, 27 Jun 2001 23:09:20 GMT
From: Roger Hsu <rogerhsu2001@yahoo.com>
Subject: How to Build a Perl with Tk Package
Message-Id: <3B3A67C4.76096541@yahoo.com>

Hi all,

When I run my compiled Perl/Tk codes in a Solaris 7 box, I got the
following
error messages:

Can't load module Tk::NBFrame, dynamic loading not available in this
perl.
  (You may need to build a new perl executable which either supports
  dynamic loading or has the Tk::NBFrame module statically linked into
it.)
 at (eval 1) line 3
Compilation failed in require at (eval 1) line 3.
        ...propagated at /usr/local/lib/perl5/5.6.1/base.pm line 62.
BEGIN failed--compilation aborted at
/usr/local/lib/perl5/site_perl/5.6.1/sun4-solaris/Tk/NoteBook.pm line
15.
Compilation failed in require at topstitch.pl line 139.

The binary code was built with Sun's Compiler.  The build and runtime
environment are Solaris 7+ Perl 5.6.1 + Tk 8000.022.

Thanks,

-roger




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

Date: Wed, 27 Jun 2001 22:07:21 GMT
From: sweth+perl@gwu.edu (Sweth Chandramouli)
Subject: Re: How to determine stack depth?
Message-Id: <tOs_6.20237$Ga.2927546@news1.rdc1.md.home.com>

In article <t6c_6.131356$DG1.21774480@news1.rdc1.mi.home.com>,
Clinton A. Pierce <clintp@geeksalad.org> wrote:
>[Posted and mailed]
>
>In article <Nh7_6.17393$Ga.2427112@news1.rdc1.md.home.com>,
>	sweth+perl@gwu.edu (Sweth Chandramouli) writes:
>> 	Is there an easy way to determine how deep in the
>> stack a particular call is?  The only way I can see to do it is to
>> keep calling caller with increasing arguments until it fails to
>> return true, which doesn't seem very efficient.
>
>Just how deep can this stack get?  :)
>
>If this is something that's recursing, you might just want to keep a 
>variable around to keep track of your depth.  If you honestly and 
>truly don't know how deep you're in things, try searching back through
>the stack using sort of an incremental search.  Go back 1 frame, then 2,
>then 4, 8, 16 etc...until you get to the end and search between the last
>two points.
	It's not a recursion issue; I'm actually experimenting
with a new debugging setup.  I usually scatter throughout my scripts
statements that print out debug messages iff some global debug param
is equal to or greater than the debug level I set for that statement.
What I'm trying now is a setup where the debug statements print iff
their stack depth is greater than the debug threshold; that seems to
work pretty well, since I tend to break most of my procedural steps 
up into subroutines, such that the further down in the stack it is
when it is called, the more likely it is to be an implementation
detail that wouldn't be relevant for higher-level debugging.  What
I'm doing now, though, is

sub _debug {
   if ($debug_level > 0) {
      my ($depth) = -1;
      1 while (caller (++$depth));
      if ($debug_level >= $depth) {
         return 1;
      } else {
         return 0;
      };
   } else {
      return 0;
   };
};

	, which seems a little inefficient to me; I was hoping
for some way to determine the stack depth without having to do the
"1 while..." loop.

	-- Sweth.

-- 
Sweth Chandramouli ; <sweth+perl@gwu.edu>


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

Date: Wed, 27 Jun 2001 22:09:19 -0000
From: cberry@cinenet.net (Craig Berry)
Subject: Re: How to determine stack depth?
Message-Id: <tjkmcfmehd1g5b@corp.supernews.com>

Sweth Chandramouli (sweth+perl@gwu.edu) wrote:
: 	Is there an easy way to determine how deep in the
: stack a particular call is?  The only way I can see to do it is to
: keep calling caller with increasing arguments until it fails to
: return true, which doesn't seem very efficient.

That appears to be the only way.  It does make one wish for a new builtin
function, callers(), which would return a list of list refs, each of which
would have the semantics of caller called in array context and with a
frame count argument, in reverse stack order.  Here's an implementation:

  sub callers()
  {
    my (@stack, @frame);
    for (my $depth = 1;
         @frame = caller($depth);
         $depth++) {
      push @stack, [ @frame ];
    }
    return @stack;
  }

-- 
   |   Craig Berry - http://www.cinenet.net/~cberry/
 --*--  "Magick is the art and science of causing change in conformity
   |   with Will."  - Aleister Crowley


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

Date: Wed, 27 Jun 2001 22:29:52 GMT
From: sweth+perl@gwu.edu (Sweth Chandramouli0
Subject: Re: How to determine stack depth?
Message-Id: <A7t_6.20247$Ga.2940184@news1.rdc1.md.home.com>

In article <tjkmcfmehd1g5b@corp.supernews.com>,
Craig Berry <cberry@cinenet.net> wrote:
>That appears to be the only way.  It does make one wish for a new builtin
>function, callers(), which would return a list of list refs, each of which
>would have the semantics of caller called in array context and with a
>frame count argument, in reverse stack order.  Here's an implementation:
>
>  sub callers()
>  {
>    my (@stack, @frame);
>    for (my $depth = 1;
>         @frame = caller($depth);
>         $depth++) {
>      push @stack, [ @frame ];
>    }
>    return @stack;
>  }
	Even discounting the typo in that :) it doesn't make
things any more efficient, however, than just doing a loop around
caller.  A builtin would definitely be better.

	Ah well.  Can't have everything, I suppose.

	-- Sweth.

-- 
Sweth Chandramouli ; <sweth+perl@gwu.edu>


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

Date: Thu, 28 Jun 2001 00:09:30 -0000
From: cberry@cinenet.net (Craig Berry)
Subject: Re: How to determine stack depth?
Message-Id: <tjktdqpk2jlcb0@corp.supernews.com>

Sweth Chandramouli0 (sweth+perl@gwu.edu) wrote:
: In article <tjkmcfmehd1g5b@corp.supernews.com>,
: Craig Berry <cberry@cinenet.net> wrote:
: >That appears to be the only way.  It does make one wish for a new builtin
: >function, callers(), which would return a list of list refs, each of which
: >would have the semantics of caller called in array context and with a
: >frame count argument, in reverse stack order.  Here's an implementation:
: >
: >  sub callers()
: >  {
: >    my (@stack, @frame);
: >    for (my $depth = 1;
: >         @frame = caller($depth);
: >         $depth++) {
: >      push @stack, [ @frame ];
: >    }
: >    return @stack;
: >  }
: 	Even discounting the typo in that :)

What typo?  It was cut-and-pasted from working code, and I just c&p'd it
back from your quoted version and it still works.

: it doesn't make things any more efficient, however, than just doing a
: loop around caller.  A builtin would definitely be better.

I offered it as a reference implementation for how a builtin should
behave.
 
-- 
   |   Craig Berry - http://www.cinenet.net/~cberry/
 --*--  "Magick is the art and science of causing change in conformity
   |   with Will."  - Aleister Crowley


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

Date: Wed, 27 Jun 2001 22:09:47 GMT
From: tuxy <nospam@cfl.rr.com>
Subject: is there a way to look ahead/behind in a foreach (@l)?
Message-Id: <3B3A228F.9E9DC6E9@cfl.rr.com>

I could peek ahead or behind in an old-fashioned loop such as:

  for ($i=2; $i<100; $i++)
   {print 'yikes!' if ($l[$i]> $l[$i-1]);}

is there a way to see other elements of an array in a foreach, as in:
 
  foreach (@l)
    {next unless defined $predecessor;
     print 'yikes!' if ($_ > $predecessor);}

Gracias,
WQ


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

Date: Thu, 28 Jun 2001 00:13:17 -0000
From: cberry@cinenet.net (Craig Berry)
Subject: Re: is there a way to look ahead/behind in a foreach (@l)?
Message-Id: <tjktktagsh3c0d@corp.supernews.com>

tuxy (nospam@cfl.rr.com) wrote:
: I could peek ahead or behind in an old-fashioned loop such as:
: 
:   for ($i=2; $i<100; $i++)
:    {print 'yikes!' if ($l[$i]> $l[$i-1]);}
: 
: is there a way to see other elements of an array in a foreach, as in:
:  
:   foreach (@l)
:     {next unless defined $predecessor;
:      print 'yikes!' if ($_ > $predecessor);}

Not directly.  You can fake it like this:

  my $predecessor;

  foreach (@l) {
    next unless defined $predecessor;
    print 'yikes!' if $_ > $predecessor;
    $predecessor = $_;
  }

-- 
   |   Craig Berry - http://www.cinenet.net/~cberry/
 --*--  "Magick is the art and science of causing change in conformity
   |   with Will."  - Aleister Crowley


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

Date: Thu, 28 Jun 2001 10:11:26 +0930
From: "Wyzelli" <wyzelli@yahoo.com>
Subject: Re: is there a way to look ahead/behind in a foreach (@l)?
Message-Id: <u_u_6.13$HK1.1023@vic.nntp.telstra.net>

"Craig Berry" <cberry@cinenet.net> wrote in message
news:tjktktagsh3c0d@corp.supernews.com...
> tuxy (nospam@cfl.rr.com) wrote:
> : I could peek ahead or behind in an old-fashioned loop such as:
> :
> :   for ($i=2; $i<100; $i++)
> :    {print 'yikes!' if ($l[$i]> $l[$i-1]);}
> :
> : is there a way to see other elements of an array in a foreach, as in:
> :
> :   foreach (@l)
> :     {next unless defined $predecessor;
> :      print 'yikes!' if ($_ > $predecessor);}
>
> Not directly.  You can fake it like this:
>
>   my $predecessor;
>
>   foreach (@l) {
>     next unless defined $predecessor;
>     print 'yikes!' if $_ > $predecessor;
>     $predecessor = $_;
>   }

At what point do you expect $predecessor to become defined? :)

Wyzelli
--
push@x,$_ for(a..z);push@x,' ';
@z='092018192600131419070417261504171126070002100417'=~/(..)/g;
foreach $y(@z){$_.=$x[$y]}y/jp/JP/;print;




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

Date: Wed, 27 Jun 2001 23:15:04 GMT
From: tony@svanstrom.com (Tony L. Svanstrom)
Subject: Re: New knowledgebase site - looking for authors, articles or tips about Perl
Message-Id: <1evotrv.1mnhokc15ji6jgN%tony@svanstrom.com>

Philip Newton <pne-news-20010627@newton.digitalspace.net> wrote:

> On Wed, 27 Jun 2001 04:50:50 -0700, KBaseonline.com
> <info@kbaseonline.com> wrote:
> 
> > We are looking for articles, tips or tutorials on the Perl programming
> > language.  
> 
> Good luck competing against all the other sites trying to offer similar
> services. (And if it's free, I wonder how long you'll stay up, what with
> the ad revenues tanking in the past couple of years.)

Not only the past couple of years, but the past couple of months have
made it far worse.

This guy showed up in an XML-related NG with almost the same posting,
but he never staid to reply to what people said; so on a "how serious is
this guy"-scale I'd rate him as yet another "fame and lots of money
without actually having to do it myself":er.


        /Tony
-- 
the truth is dead, faith is gone, reality killed... ruled by the plastic
laws of modern life we're pushed towards the hell of personal doubt,
betrayal, hate, lust and murder... the now has become an illusion, a
paradise of a dead tomorrow... (c)2000-2001 tony@svanstrom.com


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

Date: 27 Jun 2001 17:05:02 -0700
From: disneyfnatc@msn.com (Adam)
Subject: New to perl
Message-Id: <66690ccf.0106271605.530b975d@posting.google.com>

I downloaded the perl development kit from www.perl.com (the win32
version because I am running windows ME).  How do I load this on my
system there does not seem to be a .exe file and the readme is geared
toward UNIX systems.
Also I am trying to learn this language to get a job writing perl
scripts for sony imageworks how does perl interface with programs such
as 3D Studio Max or Lightwave.

Thanks for any help you can give me.

Adam Olson
disneyfnatc@msn.com


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

Date: Thu, 28 Jun 2001 00:31:51 -0700
From: "Steven Been" <stevenb@netvision.net.il>
Subject: newbie question-- need to do a search and replace of text in files including automatic system date
Message-Id: <9hdjch$inp$1@news.netvision.net.il>

Perl script which does the following (batch mode):
need to search and replace text in files-- replaced text remains constant
but must include system date which changes everyday automatically?
any suggetions greaty appreciated
thanx





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

Date: Wed, 27 Jun 2001 16:53:20 -0700
From: Richard Wellum <rwellum@cisco.com>
Subject: Newbie question: What's the opposite of chop?
Message-Id: <3B3A71F0.2A8DEFE6@cisco.com>

Hi,

I started writing in perl about two days ago - so forgive the simplistic
nature
of this question.....

I used chop after reading a file to an array, to remove the "\n"'s, so I
can process the array:

foreach $all (@raw_data)
    {
 chop($all);
 .......more code;
    }

Now I have finished my manipulation of the array, and want to write this
array back to the file. How to I add "\n"'s back to the end of each line
in my array?

I tried:

 $ctr=0;
 foreach $some (@raw_data)
 {
     @raw_data[$ctr]="$some\n";
     $ctr++;
 }

Which partially works.... But seems to add newlines at the beginning of
each line in the file too. Without the newlines my file is no longer an
array - just a long string...

I figure that this must be done pretty often... Anyone help me out here?

Thanks!



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

Date: Wed, 27 Jun 2001 16:57:38 -0700
From: Richard Wellum <rwellum@cisco.com>
Subject: Newbie question: What's the opposite of chop?
Message-Id: <3B3A72F2.BFD9B4E7@cisco.com>

Hi,

I started writing in perl about two days ago - so forgive the simplistic
nature
of this question.....

I used chop after reading a file to an array, to remove the "\n"'s, so I
can process the array:

foreach $all (@raw_data)
    {
 chop($all);
 .......more code;
    }

Now I have finished my manipulation of the array, and want to write this
array back to the file. How to I add "\n"'s back to the end of each line
in my array?

I tried:

 $ctr=0;
 foreach $some (@raw_data)
 {
     @raw_data[$ctr]="$some\n";
     $ctr++;
 }

Which partially works.... But seems to add newlines at the beginning of
each line in the file too. Without the newlines my file is no longer an
array - just a long string...

I figure that this must be done pretty often... Anyone help me out here?

Thanks!



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

Date: Thu, 28 Jun 2001 00:04:00 GMT
From: Steve Allan <stevea@wrq.com>
Subject: Re: Newbie question: What's the opposite of chop?
Message-Id: <u7kxxzd08.fsf@wrq.com>

Richard Wellum <rwellum@cisco.com> writes:

<snip>
>Now I have finished my manipulation of the array, and want to write this
>array back to the file. How to I add "\n"'s back to the end of each line
>in my array?

I'd just add it in the print call:

   open FH, ">$myfile" or die "Can't open $myfile: $!";
   print FH  "$_\n" foreach @raw_data;
   close FH;

Will that work for you?

>
>I tried:
>
> $ctr=0;
> foreach $some (@raw_data)
> {
>     @raw_data[$ctr]="$some\n";
>     $ctr++;
> }
>
>Which partially works.... But seems to add newlines at the beginning of
>each line in the file too. Without the newlines my file is no longer an
>array - just a long string...
>
>I figure that this must be done pretty often... Anyone help me out here?
>
>Thanks!
>

-- 
-- Steve __


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

Date: 27 Jun 2001 19:05:31 -0500
From: Tony Curtis <tony_curtis32@yahoo.com>
Subject: Re: Newbie question: What's the opposite of chop?
Message-Id: <87r8w5qxis.fsf@limey.hpcc.uh.edu>

>> On Wed, 27 Jun 2001 16:53:20 -0700,
>> Richard Wellum <rwellum@cisco.com> said:

> Hi, I started writing in perl about two days ago - so
> forgive the simplistic nature of this question.....

> I used chop after reading a file to an array, to remove
> the "\n"'s, so I can process the array:

chomp is more usual these days (perl version >= 5)

> foreach $all (@raw_data) { chop($all); .......more code;
> }

You can chomp an array (list) at one go.

> Now I have finished my manipulation of the array, and
> want to write this array back to the file. How to I add
> "\n"'s back to the end of each line in my array?

> I tried:

>  $ctr=0; foreach $some (@raw_data) {
> @raw_data[$ctr]="$some\n"; $ctr++; }

You don't want to put the newline into the data structure
(or at least I strongly doubt it).  The newline is an
artifact of serialising the data structure for permanent
storage in a file (printable record separator).

When you save the data, simply print newlines (\n) as you
normally would (e.g. when printing to stdout).

> @raw_data[$ctr]="$some\n"; $ctr++; }

You meant $raw_data...

You might want to investigate "map",

    perldoc -f map

as your code looks suspiciously C-like :-)

The data structure itself provides you with record
separation (e.g. hash key/value, array index), so you
don't want "punctuation" characters in the data itself,
only in the file where it is represented readably.

hth
t
-- 
Somebody light this monkey.  AAAAGGGHHHH!!  Bad monkey!


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

Date: 27 Jun 2001 18:05:00 -0700
From: zsh99@yahoo.com (Lisa Koma)
Subject: PostgreSQL/Perl error
Message-Id: <d011d382.0106271704.54816c4@posting.google.com>

Running Solaris 8, PostgreSQL-7.1.2, Perl 5.00503

ERROR
at /export/home/httpd/perl/test.pl line 7

[Wed Jun 27 20:45:35 2001] [error] install_driver(Pg) failed: Can't
load '/source/perl5.005_03/lib/site_perl/5.005/sun4-solaris/auto/DBD/Pg/Pg.so'
for module
DBD::Pg: ld.so.1: /source/apache/bin/httpd: fatal: libpq.so: open
failed: No such file or directory at
/source/perl5.005_03/lib/5.00503/sun4-solaris/DynaLoader.pm
line 169. 


Has anyone seen this error?
I installed the required DBD-Pg driver to connect to the database and
I don't seem to figure out why I keep getting this error - ..been
fighting this for a while now. Please HELP.

At Line 7 of my code, I call DBI->connect - ..see below

my $dbh=DBI->connect("dbi:Pg:dbname=seifutest",$username,$password)
        or die "can't connect tp Postgrer database\n";


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

Date: Thu, 28 Jun 2001 00:44:01 GMT
From: ced@bcstec.ca.boeing.com (Charles DeRykus)
Subject: Re: problam installing JPL
Message-Id: <GFM7DD.L3t@news.boeing.com>

In article <010626172753.M0327330@saimpc01.icl.kecl.ntt.co.jp>,
 <okumura@cslab.kecl.ntt.co.jp> wrote:
>HI all.
> I tried to install the JPL with perl5.6.1 on the redhat-linux7.0 and jdk1.3.0.
> I had the following error message when I worked the Sample program of JPL
> and I couldn't work it.
> Do anyone have a idea ?.
>
>//### error message ###
>...
>[root Sample]# java Sample
># # An unexpected exception has been detected in native code outside
> the VM.# Program counter=0x488ec2ab
>#
># Problematic Thread: prio=1 tid=0x804dc10 nid=0x5c3a runnable
>#

Apparently, Jarkko's JPL patch didn't make 5.6.1. The problem
was that jdk's 1.2/1.3 got touchy about other languages tweaking 
the environment via JNI. 

The official patch is somewhere in the Perl kingdom but I can't 
recall where. Here's one Jarkko posted some time ago if you
don't mind patching Perl source:

--
Charles DeRykus



	Duplicate environment for JPL so that JDK 1.2/1.3 don't get upset.

Affected files ...

 ... //depot/perl/perl.c#300 edit
 ... //depot/perl/perl.h#315 edit

Differences ...

==== //depot/perl/perl.c#300 (text) ====
Index: perl/perl.c
--- perl/perl.c.~1~	Wed Feb 14 05:19:55 2001
+++ perl/perl.c	Wed Feb 14 05:19:55 2001
@@ -3257,6 +3257,8 @@
     char *s;
     SV *sv;
     GV* tmpgv;
+    char **dup_env_base = 0;
+    int dup_env_count = 0;
 
     argc--,argv++;	/* skip name of script */
     if (PL_doswitches) {
@@ -3325,6 +3327,23 @@
 	    env = environ;
 	if (env != environ)
 	    environ[0] = Nullch;
+#ifdef NEED_ENVIRON_DUP_FOR_MODIFY
+	{
+	    char **env_base;
+	    for (env_base = env; *env; env++) 
+		dup_env_count++;
+	    if ((dup_env_base = (char **)
+		 safemalloc( sizeof(char *) * (dup_env_count+1) ))) {
+		char **dup_env;
+		for (env = env_base, dup_env = dup_env_base;
+		     *env;
+		     env++, dup_env++)
+		    *dup_env = savepv(*env);
+		*dup_env = Nullch;
+		env = dup_env_base;
+	    } /* else what? */
+	}
+#endif /* NEED_ENVIRON_DUP_FOR_MODIFY */
 	for (; *env; env++) {
 	    if (!(s = strchr(*env,'=')))
 		continue;
@@ -3340,7 +3359,13 @@
 	    (void)PerlEnv_putenv(savepv(*env));
 #endif
 	}
-#endif
+	if (dup_env_base) {
+	    char **dup_env;
+	    for (dup_env = dup_env_base; *dup_env; dup_env++)
+		Safefree(*dup_env);
+	    Safefree(dup_env_base);
+	}
+#endif /* USE_ENVIRON_ARRAY */
 #ifdef DYNAMIC_ENV_FETCH
 	HvNAME(hv) = savepv(ENV_HV_NAME);
 #endif

==== //depot/perl/perl.h#315 (text) ====
Index: perl/perl.h
--- perl/perl.h.~1~	Wed Feb 14 05:19:55 2001
+++ perl/perl.h	Wed Feb 14 05:19:55 2001
@@ -1692,6 +1692,13 @@
 #  define USE_ENVIRON_ARRAY
 #endif
 
+#ifdef JPL
+    /* E.g. JPL needs to operate on a copy of the real environment.
+     * JDK 1.2 and 1.3 seem to get upset if the original environment
+     * is diddled with. */
+#   define NEED_ENVIRON_DUP_FOR_MODIFY
+#endif
+
 #ifndef PERL_SYS_INIT3
 #  define PERL_SYS_INIT3(argvp,argcp,envp) PERL_SYS_INIT(argvp,argcp)
 #endif
End of Patch.


-- 
$jhi++; # http://www.iki.fi/jhi/
        # There is this special biologist word we use for 'stable'.
        # It is 'dead'. -- Jack Cohen


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

Date: Thu, 28 Jun 2001 09:51:14 +0930
From: "Wyzelli" <wyzelli@yahoo.com>
Subject: Re: Scanning a file in CGI
Message-Id: <zHu_6.10$HK1.1070@vic.nntp.telstra.net>

"Philip Newton" <pne-news-20010627@newton.digitalspace.net> wrote in message
news:l0rjjtc799sh8da5p6sh5paroeurg8ojvs@4ax.com...
> On 27 Jun 2001 14:21:20 GMT, anno4000@lublin.zrz.tu-berlin.de (Anno
> Siegel) wrote:
>
> > Just to be difficult, how is its behavior special then?[1]  It splits
> > between any two characters, just like other patterns that (first)
> > match an empty sting.
>
> I suppose in the same way that any pattern matching the null string is a
> little special (and // is extra special for not behaving the same way in
> a split and in a pattern match or substitution).

Yes, the 'something special' I was referring to, in the contect of my reply,
was splitting on character boundaries (matching the null string).  /|/ is a
special case of null string OR null string which I made a poor joke of once
in this group by proposing as an alternative to // in an obfuscating type
solution (something about who could come up with the sillies way of doing
something).  Of course you could always use /||/ etc.

Wyzelli
--
@x='074117115116032097110111116104101114032080101114108032104097099107101114
'=~/(...)/g;
print chr for @x;




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

Date: Thu, 28 Jun 2001 10:23:30 +1000
From: "tez" <troyr@vicnet.net.au>
Subject: Re: sorting a hash
Message-Id: <%Pu_6.13290$qJ4.524609@ozemail.com.au>

Thanks for all the pointers guys/gals :)


"tez" <troyr@vicnet.net.au> wrote in message
news:sbc_6.12345$qJ4.503668@ozemail.com.au...
> Hi there,
>             I'm sure ppl have discussed this one here but i can't remember
> the result of the discussion...
> I'm trying to sort by either 'name' or 'hits'
>
> my %test;
> $test{1}{name}="a group";
> $test{2}{name}="b group";
> $test{3}{name}="c group";
>
> $test{1}{hits}=20;
> $test{2}{hits}=4;
> $test{3}{hits}=14;
>
>
> is this possible to achieve via the sort command? ....checked perldoc -f
> sort but didn't get far
> ie...so would the index #'s 1,2,3 be rearranged or the values within those
> indexes be rearranged
>
> Thanks in advance
>
>
>
>




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

Date: Wed, 27 Jun 2001 16:54:07 -0700
From: Greg Miller <greg_j_miller@agilent.com>
Subject: Thanks!...
Message-Id: <3B3A721F.F5C76C5F@agilent.com>

Yeah this works rather well - better than what I had before for sure.

Thanks again,

Greg

Anthony wrote:

> $_ = "pcamsndt=((nlev==4)*cam4s+(nlev!=5)*cam5s+(nlev>=6)*cam6s)";
> if ( m/([^=!><])=([^=])/ ) {
>      $exp = $2 . $';
> }
> print $exp . "\n";
>
> "Anthony" <hoa@nortelnetworks.com> wrote in message
> news:9hddns$uj$1@bcarh8ab.ca.nortel.com...
> > $n = "pcamsndt=((nlev==4)*cam4s+(nlev!=5)*cam5s+(nlev>=6)*cam6s)";
> > $n =~ s/([^=!><])=([^=])/$1$2/g;
> >
> > "Greg Miller" <greg_j_miller@agilent.com> wrote in message
> > news:3B3A1879.E0940EF7@agilent.com...
> > > I want to match the expression below for "=" but *not* "==", "!=", or
> > > ">="
> > >
> > > pcamsndt =((nlev==4)*cam4s+(nlev!=5)*cam5s+(nlev>=6)*cam6s)
> > >
> > > I've come up with a few ugly expressions but I would like to have a more
> > > elegant way of doing it - any experts out there have a good way?
> > >
> > > Thanks!
> > >
> > > -Greg
> > >
> > >
> >
> >



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

Date: Wed, 27 Jun 2001 18:01:51 -0700
From: "David Hutchins" <david.j.hutchins@intel.com>
Subject: Trouble with Text::ParseWords.pm
Message-Id: <9hdvn0$sbj@news.or.intel.com>

I can't get the ParseWords module work correctly, it always returns an empty
array
as shown in the debugging output below:
======================================
main::update_ptf_file(h:/djhutchi/bin/cc_update_ptf.pl:204):
204:                            @words = &parse_line($delim, 0, $_);
  DB<2> s
Text::ParseWords::parse_line(C:/Perl/lib/Text/ParseWords.pm:54):
54:         my($delimiter, $keep, $line) = @_;
  DB<2>
Text::ParseWords::parse_line(C:/Perl/lib/Text/ParseWords.pm:55):
55:         my($quote, $quoted, $unquoted, $delim, $word, @pieces);
  DB<2> p $delimiter
|
  DB<3> p $line
:VALUE(OPT)   | TOLERANCE(OPT)   | POWER(OPT)   | JEDEC_TYPE(OPT)   |
PART_NUMBER   | PACK_TYPE
  DB<4> p $keep
0
  DB<5> r
list context return from Text::ParseWords::parse_line:
  empty array
======================================
I have tried changnig the delimiter to include quotes, set $keep to both 0 &
1, but nothing works :(
Any hints?





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

Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 6 Apr 01)
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.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 V10 Issue 1207
***************************************


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