[6690] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 315 Volume: 8

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Apr 16 13:17:17 1997

Date: Wed, 16 Apr 97 10:00:25 -0700
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Wed, 16 Apr 1997     Volume: 8 Number: 315

Today's topics:
     Re: "my" variable affects namespace "outside" block? (David Alan Black)
     Re: == equality comparism <ryung@ml.com>
     Adding all possible combinations of list (Susan Starr)
     Another bothersome newbie question (nicholas david pesce)
     Re: Array Elements <tchrist@mox.perl.com>
     Re: associated arrays (ALASTAIR AITKEN CLMS)
     DBM Files dan@akqa.com
     Re: Head of mail.... (Kumar Vadhri-CADENCE)
     More on perl5.003 install <sankar@hscbklyn.edu>
     Re: Number of Array Elements <dsonak@us.oracle.com>
     Re: Ousterhout and Tcl lost the plot with latest paper (Will Duquette)
     Perl & NT & Oracle <stefaanc@sitel-be.com>
     Perl pattern matching question <Hans.Suijkerbuijk@SD.BE>
     Re: Perl pattern matching question (Honza Pazdziora)
     Re: print question (ALASTAIR AITKEN CLMS)
     Problem: hex() and Unsigned vs. Signed <emagnuss@pcocd2.intel.com>
     Processes on WindowsNT (Mathias Scherer)
     Q: equivalent of ctags for perl <Alain_Fargues-R33148@email.sps.mot.com>
     Re: Transliterate from a pattern? (ALASTAIR AITKEN CLMS)
     Re: Transliterate from a pattern? <tchrist@mox.perl.com>
     Re: Transliterate from a pattern? (Mike Stok)
     Re: Unix and ease of use  (WAS: Who makes more ...) (Jettero Heller)
     Re: Unix and ease of use  (WAS: Who makes more ...) (Jettero Heller)
     Re: Unix and ease of use  (WAS: Who makes more ...) (Steve Mading)
     Re: Unix and ease of use  (WAS: Who makes more ...) (Ottavio G. Rizzo)
     Re: Unix and ease of use (WAS: Who makes more ...) (ALASTAIR AITKEN CLMS)
     Digest Administrivia (Last modified: 8 Mar 97) (Perl-Users-Digest Admin)

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

Date: 16 Apr 1997 14:49:09 GMT
From: dblack@icarus.shu.edu (David Alan Black)
Subject: Re: "my" variable affects namespace "outside" block?
Message-Id: <5j2ot5$phf@pirate.shu.edu>

Hello -

(Phil Hanna) writes:

>(The -w switch must be used in order for the error to be duplicated.)

Except the error I wasn't getting wasn't the "uninitialized value"
warning (well, it was, as a secondary matter), but the substantive
error in the output, as per the difference between John's two versions
of his output:

1 file is `one'
Use of uninitialized value at weird.pl line 14.
3 file is `'
1 file is `two/'
2 file is `two/'
1 file is `three'
Use of uninitialized value at weird.pl line 14.
3 file is `'
1 file is `four/'
2 file is `four/'

vs.

1 file is `one'
3 file is `one'  <-- I got this, even with my()
1 file is `two/'
2 file is `two/'
1 file is `three'
3 file is `three' <-- and this
1 file is `four/'
2 file is `four/'

I still haven't researched the history, I'm afraid, but since I'm
using 5.003_95, I'm guessing that it does have something
to do with versions, and that John is using an earlier version.
(Though I'm not sure why John's error was at line 14 - well,
upgrade, everybody :-)

David Black
dblack@icarus.shu.edu


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

Date: Wed, 16 Apr 1997 10:34:13 -0400
From: Robert Yung <ryung@ml.com>
Subject: Re: == equality comparism
Message-Id: <3354E365.7DDC@ml.com>

THIAM YEO wrote:
> 
> Hi there!
> 
>   Does Perl have the opposite of the equality comparism ==? != and <>
> doesn't seems to work.
> 
>   Please advise.
> 
> ==================================================================
> Ervin Yeo Thiam Soon
> Internet : ervinyeo@elf.brisnet.org.au
> Fidonet : 6:600/237.0

To clarify a bit further:

Note that != is opposite of == for numerical comparison ONLY.
Similarly, ne is opposite of eq for string comparison.

Robert Yung


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

Date: 16 Apr 1997 16:26:58 GMT
From: sstarr@skypoint.com (Susan Starr)
Subject: Adding all possible combinations of list
Message-Id: <5j2uki$hb0$1@shadow.skypoint.net>

I'm wondering if anyone knows of an elegant solution to my problem.
 
I need to take a list of numbers and identify the values in the list
that add up to 0.  For example, if I had the following list:
-5.00
-2.50
+3.00
+7.50
+2.20
 
I would need to identify -5.00, -2.50, and +7.50.  The only way I
can think of to do this is to add up every possible combination of values
and figure out the combo that uses the most numbers that adds up to 0.
The lists of numbers will be small, mostly only involving 3-5 numbers.
 
Any help would be appreciated.
 
Thanks,
 
Sue

--
Good judgement comes with experience,
but experience only comes with bad judgement


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

Date: 16 Apr 1997 11:22:20 -0400
From: pesce@fandango.cis.ohio-state.edu (nicholas david pesce)
Subject: Another bothersome newbie question
Message-Id: <5j2qrcINNfqj@fandango.cis.ohio-state.edu>


Ok here is the story, I need to run another program in perl, that allows
my primary perl shell script to continue, while running this other perl script.

how do I call another perl program in perl that fits these parameters.


Nick Pesce
pesce@cis.ohio-state.edu


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

Date: 16 Apr 1997 15:39:49 GMT
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: Array Elements
Message-Id: <5j2rs5$fa0$4@csnews.cs.colorado.edu>

 [courtesy cc of this posting sent to cited author via email]

In comp.lang.perl.misc, :If you have the array @array, then just say:
:
:print "The number of elements is $#array\n";

You didn't test your solution.   It's wrong.

--tom
-- 
	Tom Christiansen	tchrist@jhereg.perl.com


    "Many folks want nothing more than to live and let learn." --Larry Wall


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

Date: 16 Apr 1997 15:53:32 GMT
From: zpalastair@unl.ac.uk (ALASTAIR AITKEN CLMS)
Subject: Re: associated arrays
Message-Id: <5j2sls$fga@epsilon.qmw.ac.uk>

In article <Z6s9SAAkWoTzEwtk@nght.demon.co.uk>, DJ Morgan <dmorgan@nght.demon.co.uk> writes:
>I'm tring to process two simple flat files and merge them together.
>
>File 1
>
>1234    Field1 Field2 field3
>1234    Field1 Field2 field3
>1234    Field1 Field2 field3
>2222    Field1 Field2 field3
>2222    Field1 Field2 field3
>2222    Field1 Field2 field3
>4444    Field1 Field2 field3
>
>File 2
>
>1234
>2222
>4444
>
>Output required
>
>1234
>Field1
>Field2
>Field3
>
>I want to use associated arrays so that I can look up the values in
>File2 and get the corresponding values from file 1

It looks like file 2 is already in file 1 so I presume file 2 is a filter and
records in file 1 with no correspondence in 2 are to be ignored.  If so:

#! /usr/local/bin/perl	# at a guess

require "5.003";
use strict;

my (%hash, @line);

open (IN1,"/path/to/file1");
while ( <IN1> ) {
    @line = split(' ',$_);	# treats the line as 4 space separated strings
    $hash{$line[0]) = "$line[1] $line[2] $line[3]";
};
close (IN1);
open (OUT,"> /path/to/file3");
open (IN2,"/path/to/file2");
while ( <IN2> ) {
    chop;		# dump the carriage return
    if ($hash{$_}) {
	@recs = split $hash{$_};
	print OUT "$_\n$recs[0]i\n$recs[1]\n$recs[2]\n\n";
    };
};
close (IN2);	# tidy up afterward
close (OUT);	# tidy up afterward
exit 0;


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

Date: Wed, 16 Apr 1997 10:01:33 -0600
From: dan@akqa.com
To: hjparker@mistral.co.uk
Subject: DBM Files
Message-Id: <861202465.18133@dejanews.com>

I am having difficulties getting DBM files to work with
Perl 5 on a Solaris machine.

AnyDBM_File, NDBM_File and so on return the following errors:

fm17% perl -e 'use AnyDBM_File'
AnyDBM_File.pm did not return a true value at -e line 1.
BEGIN failed--compilation aborted at -e line 1.

fm17% perl -e 'use NDBM_File'
Can't load
'/usr/local/lib/perl5.003/sun4-solaris/5.003/auto/NDBM_File/NDBM_File
 .so' for module NDBM_File: ld.so.1: perl: fatal: relocation error: symbol
not fo
und: main: referenced in
/usr/local/lib/perl5.003/sun4-solaris/5.003/auto/NDBM_F
ile/NDBM_File.so at /usr/local/lib/perl5.003/DynaLoader.pm line 140.

I would be very grateful for any pointers on how to fix this problem.

Please reply by email to dan@akqa.com

Thanks,

Dan Norris-Jones.

-------------------==== Posted via Deja News ====-----------------------
      http://www.dejanews.com/     Search, Read, Post to Usenet


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

Date: 16 Apr 1997 14:32:37 GMT
From: kumar@adtaz.sps.mot.com (Kumar Vadhri-CADENCE)
Subject: Re: Head of mail....
Message-Id: <5j2nu5$60h$1@talos4.risc.sps.mot.com>


Hi All,'

	I am trying to send an email to someone with some web site addresses.
I also want to create links to thosse websites, so that while the person is
reading my email, all he has to do is to click on them and he can go
to those websites. Do I need to write a perl script for that. If so  how do I
do it. If this question has nothing to do with PERL, please let me know
where I can post this mail

	Thank you for your help
REgards
Kumar



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

Date: Wed, 16 Apr 1997 11:42:32 -0400
From: Sankar Mukhopadhyay <sankar@hscbklyn.edu>
Subject: More on perl5.003 install
Message-Id: <Pine.SOL.3.93.970416113858.27251A-100000@bmec.hscbklyn.edu>

Hi,

	I am trying to install Perl5.003 on a solaris2.4. I am using
	gcc ver 2.5.8. I succeeded in doing this:

	rm -f configure.sh
	sh Configure -Dcc=gcc 
>>> I took all the defaults. According to install, now I should run
make. But I get the following message:

# ./make                                                        
make: Warning: Both `makefile' and `Makefile' exist             
`sh  cflags libperl.a miniperlmain.o`  miniperlmain.c           
          CCCMD =  gcc -c  -O                                   
sh: gcc: not found                                              
*** Error code 1                                                
make: Fatal error: Command failed for target `miniperlmain.o'   

Any ideas? Thanks.

Sankar

***************************************        *********************
Sankar Mukhopadhyay                            
Library Systems
SUNY Health Science Center @ Brooklyn		sankar@hscbklyn.edu

<<< The reverse side has also a reverse side.>>> Japanese Proverb



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

Date: Wed, 16 Apr 1997 09:25:46 -0700
From: "Dipti V. Sonak" <dsonak@us.oracle.com>
Subject: Re: Number of Array Elements
Message-Id: <3354FD8A.5FB@us.oracle.com>

Gary Chambers wrote:
> 
> I'm trying to determine the number of elements in an array.  Is it
> correct to use:
> 
> $elements = @array;
> 
> Any help will be appreciated...  Camel and Llama are unclear to me.
> 
> --
> GeeCee/NQ
> 
> // --------------------------------------
> // Gary Chambers <geecee@netquarters.net>
> // NetQuarters, Incorporated
> // --------------------------------------


This is the program that I have : 

#!/usr/local/bin/perl -w
 
@array = ( 1, 2, 3, 4 );
 
print "@array\n";
 
print "Elements : $#array \n";

__END__

The output is : 

1 2 3 4
Elements : 3 


$#array gives me the "index" of the last element in the array. Indexes
are "zero" based.  

The actual number of elements is : $#array + 1

Dipti


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

Date: 16 Apr 1997 08:48:01 -0700
From: will@peanut.jpl.nasa.gov (Will Duquette)
Subject: Re: Ousterhout and Tcl lost the plot with latest paper
Message-Id: <wbzpuzvuj2.fsf@peanut.jpl.nasa.gov>

In article <5j1ib1$kp3@roar.cs.utexas.edu> wilson@cs.utexas.edu (Paul
Wilson) writes:

   In article <5j12ue$9ib@srv13s4.cas.org>,  <lvirden@cas.org> wrote:
   >
   >I know that I've not tried either of these.  In fact, I've never
   >seen an app that embedded either of these.  however, I've seen
   >several hundred that embedded Tcl - including the latest version of
   >nvi.  Since I prefer to use apps that share the same embedded language
   >when possible, use of tcl works for me at this time.

   Larry,

      This seems like the only reasonable argument that people have raised
   and one I have some grudging respect for.
   <snip>
   Everyone else seems to think it would be nice, including many Tcl users
   who write whole apps, or most of their apps, in Tcl.

Here's what Tcl/Tk buys *me*.

I have no interest in writing large programs solely in Tcl to Tcl/Tk.
There are indeed better languages out there for that purpose.
However, in my work we have a developed a number of APIs for a variety
of obscure tasks.  These are generally coded as C libraries.  By
writing Tcl extensions for these libraries, I get the following
practical advantages:

    1. I can build a Tclsh with my own extensions.

        #1 is crucial.  The libraries I work with use threads.  You can't
        dynamically load a threaded library into a program that's compiled to
        be single-threaded and have it work--not on Solaris at least.  If I
        could not build my own executable, Tcl would be useless to me.

    2. I can write simple programs using these libraries without
       pulling out the compiler, writing Makefiles, and so forth.  
       This is particularly useful for testing.

        Many languages can provide this, I'm sure.

    3. I can exercise these libraries interactively, one command at a
       time, in a shell-like environment.

        Proponents of Scheme and similar languages have pointed out 
        that they can do this in their language as well.  And yet, 
        psychologically anyway, Tcl feels simpler to me.  I'd rather 
        type

                myfunc arg1 arg2

        than

                (myfunc arg1 arg2)

        Moreover, I'd rather tell users of my extended shell to type
        the former rather than the latter.  I guess that's the issue:
        If you want to use a Tcl-based shell as a means of typing
        commands, you can ignore the rest of Tcl; the commands look
        like the kinds of commands you might type into any other
        command-line oriented program.

    4. I'm using a language with sufficient popular support that I
       know I can get help if I need it.  Tcl may never be the most 
       popular language in the world, but it's popular enough that
       it's not going to vanish overnight, either.

        Go look at 
        "http://www.yahoo.com/Computers_and_Internet/Programming_Languages/"
        sometime, and see how many links they list for each language.
        This is at least a rough measure of the current amount of 
        public interest in each language.  I don't claim it measures
        usage, of course. 

You'll notice that I've made no arguments about Tcl as a *language*.
Pragmatically speaking, though, it enables me to get my job done
easily, efficiently, and well.

-- 
--------------------------------------------------------------------------
Will Duquette, JPL  | William.H.Duquette@jpl.nasa.gov
But I speak only    | will@bean.jpl.nasa.gov
for myself.         | It's amazing what you can do with the right tools.


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

Date: 16 Apr 97 14:41:03 GMT
From: "Sitel" <stefaanc@sitel-be.com>
Subject: Perl & NT & Oracle
Message-Id: <01bc4a7f$709a6580$e2ff0a0a@pc2-stefaan.sitel-be.com>

I want to use Perl (DBPerl ?) to manipulate data in Oracle 7 tables on a
Windows NT 4 (using Windows 95 workstations).  

Is it allready possible ?

Thanks
Stefaan Colson
Brussels, Belgium


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

Date: Wed, 16 Apr 1997 17:19:23 -0700
From: Hans Suijkerbuijk <Hans.Suijkerbuijk@SD.BE>
Subject: Perl pattern matching question
Message-Id: <33556C8B.51E2@SD.BE>

Hi,

As I start using perl and used to use Omnimark (an SGML-aware
conversion-tool), my way of converting may be influenced by Omnimark,
but what I want to do is the following:

I want to convert the following string:

<WREF TYPE="INSERT" RB="LAW" RBDATE="22.12.89"></WREF>

to:

<B>INSERTED BY LAW ON 22.12.89</B>

So while converting the string as one pattern, I want to read the
content of the "" in (3) variables. In pseudo-perl-code, it would be
like this:

s|<WREF TYPE=\"(.*?)=$var1\" RB=\"(.*?)=$var2\"
RBDATE=\"(.*?)=$var3\"></WREF>| <B>$var1ED BY $var2 ON $var3</B>|g;

What's the perl solution for my problem?

Thanks a lot!


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

Date: Wed, 16 Apr 1997 16:16:05 GMT
From: adelton@fi.muni.cz (Honza Pazdziora)
Subject: Re: Perl pattern matching question
Message-Id: <adelton.861207365@aisa.fi.muni.cz>

Hans Suijkerbuijk <Hans.Suijkerbuijk@SD.BE> writes:
> 
> I want to convert the following string:
> 
> <WREF TYPE="INSERT" RB="LAW" RBDATE="22.12.89"></WREF>
> 
> to:
> 
> <B>INSERTED BY LAW ON 22.12.89</B>
> 
> So while converting the string as one pattern, I want to read the
> content of the "" in (3) variables. In pseudo-perl-code, it would be
> like this:
> 
> s|<WREF TYPE=\"(.*?)=$var1\" RB=\"(.*?)=$var2\"
> RBDATE=\"(.*?)=$var3\"></WREF>| <B>$var1ED BY $var2 ON $var3</B>|g;
> 
> What's the perl solution for my problem?

s|<WREF TYPE="(.*?)" RB="(.*?)" RBDATE="(.*?)"></WREF>|<B>$1ED BY $2 ON $3</B>|g;

even if you might want to put in \s+ instead of that spaces.

Also, better Subject line would be good.

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: 16 Apr 1997 15:01:32 GMT
From: zpalastair@unl.ac.uk (ALASTAIR AITKEN CLMS)
Subject: Re: print question
Message-Id: <5j2pkc$fga@epsilon.qmw.ac.uk>

In article <335256DE.41C6@tunix.mathematik.uni-stuttgart.de>, Johannes Lipp <lipp@tunix.mathematik.uni-stuttgart.de> writes:

>   #! /usr/bin/perl -w
>   print STDOUT ("whats\n",
>                 "that?\n");
 ...
>   #! /usr/bin/perl -w
>   print ("whats\n",
>          "that?\n");

The parentheses are not necessary and, if ommitted, the compiler will not treat
the second example as a function but as a list operator, as in the first
example.

Alastair.


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

Date: Tue, 15 Apr 1997 17:36:59 -0700
From: Eric Magnusson <emagnuss@pcocd2.intel.com>
Subject: Problem: hex() and Unsigned vs. Signed
Message-Id: <33541F2B.167E@pcocd2.intel.com>

# I am porting a large Perl program from version 4 to version 5.  I
# have found an arithmetic problem that is fatal in my application.  It
# appears in some contexts, that Perl4 is using unsigned integers, and
# Perl5 is using signed integers.  

# Is this a reported bug, with a known work around?

# Are there any ways in Perl5 to force a unsigned/signed context when
# dealing with large integers and the hex() function?

# Here are some results of various experiments.
# It appears that the discrepancy  is observed when performing an
# arithmetic operation on the result of a hex() call.

# This has been observed on Sun, HP, and AIX platforms

# The following table, an entry listed in the +2G column means that
# perl version interpreted the number as an UNsigned integer. -2G means
# that perl version interpreted the number as a SIGNED integer.
#
# In each case I am trying to set bit #31.
#
#   4 = Perl4 (4.0.1.8 pl.36)     5 = Perl5 (5.003 with EMBED)

                              #----+----+
                              # +2G| -2G|
                              #----+----+
&gt0( hex("80") << 24 );      # 4  #  5 #  <== Why the difference?
                              #----+----+  
&gt0( hex("80") * 0x1000000 );# 4  #  5 #  <== Why the difference?
                              #----+----+
&gt0( 0x80000000 );           # 45 #    #
                              #----+----+
&gt0( hex("80000000") );      # 45 #    #
                              #----+----+
&gt0( 0x80 * 0x1000000 );     # 45 #    #
                              #----+----+
&gt0( 0x80000000 << 24 );     #    # 45 #
                              #----+----+
&gt0( 0x80 << 24 );           #    # 45 #
                              #----+----+


sub gt0 {
print "", (0 < $_[0]) ? "Positive\t" : "Negative\t";
}


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

Date: 12 Apr 1997 22:11:52 GMT
From: M.SCHERER@t-online.de (Mathias Scherer)
Subject: Processes on WindowsNT
Message-Id: <5ip1b8$dm3$1@news01.btx.dtag.de>

Mathias Scherer wrote

How can I use the method "Kill" (Perl5 for WIN32) for an active process
on WindowsNT 4.0

Thanks for any response

Mathias

m.scherer@t-online.de


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

Date: Wed, 16 Apr 1997 17:15:16 +0200
From: Alain Fargues <Alain_Fargues-R33148@email.sps.mot.com>
Subject: Q: equivalent of ctags for perl
Message-Id: <3354ED04.5C6E@email.sps.mot.com>

I have to analyze some big perl scripts.

Does anyone wrote an equivalent of 'ctags' command for perl scripts ?

-- 
____________________________________________________________________

         Alain FARGUES            MOTOROLA Semiconductor S.A.
  CACTG Wireless Design Center    Av. du General Eisenhower, BP.1029
     Systems Administrator        31023 TOULOUSE CEDEX FRANCE
Alain_Fargues@email.sps.mot.com   Tel: +33 (0)5 61 19 98 47
alainf@es-tls.sps.mot.com         Fax: +33 (0)5 61 19 10 12
____________________________________________________________________


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

Date: 16 Apr 1997 15:57:21 GMT
From: zpalastair@unl.ac.uk (ALASTAIR AITKEN CLMS)
Subject: Re: Transliterate from a pattern?
Message-Id: <5j2st1$fga@epsilon.qmw.ac.uk>

In article <570ni5.gug.ln@localhost>, tadmc@flash.net (Tad McClellan) writes:
>Jeff Vannest (jefflv@tir.com) wrote:
>: Does anyone know of a method of transliterating a string by a pattern?
>: It's not even really a transliteration; I want to delete leading and
>: trailing spaces from a string.
>
>: The tr// would work except that it deletes ALL spaces in the string
>: and will not recognize the patterns "^ "   (caret +space) or " $"
>: (space+dollar).
>
>$value  =~ /^\s+//; # delete leading spaces
>$value  =~ /\s+$//; # delete trailing spaces
>

in one pattern:

$var =~ s/^\s+|\s+$//;

Alastair.


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

Date: 16 Apr 1997 16:18:44 GMT
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: Transliterate from a pattern?
Message-Id: <5j2u54$hpm$1@csnews.cs.colorado.edu>

 [courtesy cc of this posting sent to cited author via email]

In comp.lang.perl.misc, zpalastair@unl.ac.uk writes:
:in one pattern:
:$var =~ s/^\s+|\s+$//;

Whoops:

    $var = "  front and back   ";

Please try benchmarking these various methods.  You'll be surprised.

--tom
-- 
	Tom Christiansen	tchrist@jhereg.perl.com


Show respect for age.  Drink good Scotch for a change.


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

Date: 16 Apr 1997 16:48:01 GMT
From: mike@stok.co.uk (Mike Stok)
Subject: Re: Transliterate from a pattern?
Message-Id: <5j2vs1$af8@news-central.tiac.net>

In article <5j2st1$fga@epsilon.qmw.ac.uk>,
ALASTAIR AITKEN CLMS <zpalastair@unl.ac.uk> wrote:
>In article <570ni5.gug.ln@localhost>, tadmc@flash.net (Tad McClellan) writes:

>>$value  =~ /^\s+//; # delete leading spaces
>>$value  =~ /\s+$//; # delete trailing spaces
>>
>
>in one pattern:
>
>$var =~ s/^\s+|\s+$//;

The single pattern needs a g modifier to work:

  DB<1> $var = ' foo '; $var =~ s/^\s+//; $var =~ s/\s+$//;       

  DB<2> X var
$var = 'foo'
  DB<3> $var = ' foo '; $var =~ s/^\s+|\s+$//;

  DB<4> X var
$var = 'foo '
  DB<5> $var = ' foo '; $var =~ s/^\s+|\s+$//g;

  DB<6> X var
$var = 'foo'

The new FAQ at http://www.perl.com/FAQ contains:

How do I strip blank space from the beginning/end of a string? 

The simplest approach, albeit not the fastest, is probably like this: 

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

It would be faster to do this in two steps: 

    $string =~ s/^\s+//;
    $string =~ s/\s+$//;

Or more nicely written as: 

    for ($string) {
        s/^\s+//;
        s/\s+$//;
    }

Hope this helps,

Mike


-- 
mike@stok.co.uk                    |           The "`Stok' disclaimers" apply.
http://www.stok.co.uk/~mike/       |   PGP fingerprint FE 56 4D 7D 42 1A 4A 9C
http://www.tiac.net/users/stok/    |                   65 F3 3F 1D 27 22 B7 41
stok@psa.pencom.com                |      Pencom Systems Administration (work)


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

Date: 16 Apr 1997 14:08:40 GMT
From: heller@nacs.net (Jettero Heller)
Subject: Re: Unix and ease of use  (WAS: Who makes more ...)
Message-Id: <5j2mh8$q0f@tracy.nacs.net>

Ell (ell@access5.digex.net) wrote:
: jason olmsted (olmstj@phat-media.com) wrote:
: :
: : My point is that just because code is released without comments does
: : not mean that it doesn't exist somewhere else with it.  For the
: : majority of instances, the intened audience of comments is yourself.
: : Are you going to know what the hell your were thinking two years ago
: : or even two months ago?
: 
: Isn't that part of the reason for comments, so that you can recall what
: sections of code are about?

Yup. exactly. And I agree. But if, as the programmer, I can remember
what the section of code was about then, I don't need to comment.
And someone who says "all programmers who release code must comment"
is saying, "I don't think you can remember what you were thinking
when you look at this next". Bad news. I have very little problem
remembering what I was doing in a program several years later. 'tis
the nature of my memory. If I happen upon some code that I know is
going to be hard to rememember, I put in a line of comment.

But don't tell me that because I didn't comment the code I did a
poor job of writing it. . .

** Heller

-- 
                 http://www.nacs.net/~heller/funny
Can you imagine having an implant so the government can track you anywhere
you go? It's coming and we're bringing it to you, AT&T.
OK, not AT&T but: http://www.acsp.uic.edu/TechNews/9605002.htm



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

Date: 16 Apr 1997 14:04:07 GMT
From: heller@nacs.net (Jettero Heller)
Subject: Re: Unix and ease of use  (WAS: Who makes more ...)
Message-Id: <5j2m8n$q0f@tracy.nacs.net>

Tim Behrendsen (tim@a-sis.com) wrote:
: Jettero Heller <heller@nacs.net> wrote in article <5j06j7$hoh@tracy.nacs.net>...
: > Tim Behrendsen (tim@a-sis.com) wrote:
: > : I don't accept excuses for my employees, I don't accept excuses
: > : for myself, and I don't accept them for Larry Wall.  There is no
: > : excuse for code without comments.  Period.
: > 
: > Oh yes there is. If the code is written for the author only (as is
: > the case with perl) then he/she *does not* need to comment didly!
: > Don't try to push *your* personal coding beliefs on other people.
: > If you can't accept other peoples coding styles, then don't look at
: > their code! Larry Wall, Brian Kernighan, or myself *DO NOT* answer
: > to you in regards to our code, so basically we don't care what you
: > want us to do!
: 
: I hope this was a joke.
: 
: If not, whether you answer to me or not is irrelevent.  Of course
: you can do whatever you want with your code.  That doesn't change
: the fact that uncommented code released publically for a significantly
: complex program is shamefully bad engineering.
:
: And I'm not claiming perfection, either.  I have made many style
: changes over the years when I've noticed that others didn't seem to
: be able to follow what I was doing well.  I didn't whine and whimper
: and get defensive about it.  Being a good engineer means evolving
: through experience, and screaming "Wahh!  Don't criticize my code!"
: does not do much for self-improvement.

This is all nice. . .but irrellavent to the point. The point is:
Since he is not programming this for *anyone* but himself, he *does
not* have to abide by anyone elses coding style. You saying "He
should comment it" *does not* mean that he has to comment it. Just
cuz you say it is bad engineering does not make it so. The only
thing that not commenting code makes it is: not commented.

Why is it that because *you* insist that he must comment his code,
and he does not, it is bad engineering? You seem to think that it is
a "fact" that releasing uncommented code is bad engineering. Sorry
buddy, that is an opinion. not a fact. Until you accept that, you
aren't going to get far in talking to other people about coding.
Releasing code that doesn't work, is bad engineering. . .
Releasing working code is not. . .

** Heller

-- 
                 http://www.nacs.net/~heller/funny
Can you imagine having an implant so the government can track you anywhere
you go? It's coming and we're bringing it to you, AT&T.
OK, not AT&T but: http://www.acsp.uic.edu/TechNews/9605002.htm



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

Date: 16 Apr 1997 10:14:33 -0500
From: madings@earth.execpc.com (Steve Mading)
Subject: Re: Unix and ease of use  (WAS: Who makes more ...)
Message-Id: <5j2qcp$ble$1@earth.execpc.com>

Tim Behrendsen (tim@a-sis.com) wrote:
: Steve Mading <madings@earth.execpc.com> wrote in article
: <5j071r$530$1@earth.execpc.com>...
: > 
: > Extract one file without streaming the whole thing:  How do you know
: > that pkzip does this?  all you know is that you ask for a particular
: <[snip]

: It has a directory structure.  It's not possible with tar|gzip
: because the directory is compressed along with the data.

Apparently you missed the part of my post where I said you *could*
do it with tar/gzip.  I HAVE done it with tar/gzip.  BTW the 
functionality is in tar, not gzip.  'tar' can extract specific
files or trees of files, like so:

   % gunzip --stdout foo.tar.gz | tar xvf - filename_i_want

With the above example, only 'filename_i_want' gets extracted, no
matter what else is in the archive.  If filename_i_want is a
directory, then everthing from that point down in the 'tree' in
the archive is extracted.

: > Oh, and can pkzip archive to tape or other non-disk devices?  With
: > Unix's everything-is-a-file sytesm, 'tar' can.  I even remember
: >[snip]

: Well, that's a property of Unix, not the tool necessarily.  I
: like Unix, don't get me wrong. :-)

If PKware ported pkzip to Unix, then we could compare.  :-)

I think PKware realizes that in Unix, they'd have no market
because of tar/gzip.

: > : And it's also extremely fragile.  One corrupted byte and the
: > : rest of the file is trash.  With a reasonable tool like pkzip,
: > 
: > This I admit is true.  Never had it happen though.  But to be fair,
: > the messed up bit has to be in just the right spot.  Otherwise
: > you only corrupt that file in the extraction.  The real problem comes
: > when bytes are missing or extra bytes are added.  This is what
: > hoses a tar file, because the tar format uses the filesize in bytes
: > to determine where the next file in the archive starts.

: No, one bit and entire rest of the compression stream is trash,
: which means all of the rest of the files are trash.

Ah.  Sorry.  I was thinking of the 'tar' part - you were thinking of
the 'gzip' part.  I'll concede this point, since I don't know gzip's
internals enough to argue about them.

: > : you can often access files even if part of it is corrupt, and
: > : sometimes even rebuild the directory structure.
: > 
: > : Or how about self-extracting archives?
: > 
: > A nice thing if you don't mind limiting yourself to one machine
: > archetecture.  (Imagine trying to run a self-extracting exe on
: > Windows NT on a non-intel box like Alpha.)  The Unix community
: > does not want this feature since the Unix community has zillions
: > of different archetectures to pass files between.  Since gzip
: > came from Unixy people - it has no self-extracting exe format.
: > This has nothing to do with it being free and everything to do
: > with it being from Unix.

: I must admit this a good point.  It would an interesting project
: to write a very small extracter in C that could be imbedded with
: the binary data, and all that wrapped in a shell script.  The
: shell script could create the binary file and a .c file, compile
: it, and then do the extraction.  Of course, not all Unix hosts
: have C compilers, so this still wouldn't be a perfect solution.

: Or write the extractor using the bourne-shell ... ugh.

Actually, if you are willing to assume the target system has
gzip and tar in the $PATH, you can do it in a script - but
you have to use something better then the archaic Bourne.
Here's a Korn example (works also in Bash):

# A self extracting shell script, sort of:
( gunzip | tar xvf - ) <<END_OF_ARCHIVE_BYTES
---- Here would be a stream of gibberish characters that are actually
---- the contents of the tar/gzip file pasted into this script.
---- Be careful to use a text editor that won't try to interpet
---- these characters and mungle them when you write this file.
---- Alternately you could add a uuencode/uudecode to the pipe,
---- and put the uuencoded stuff here - but since this is an
---- attempt to do file compression - uuencoding it would be
---- counter-productive unless you had to.
END_OF_ARCHIVE_BYTES

This uses a 'here document' to read in the text of the script
itself as stdin to the ( gunzip | tar xvf - ) command.

(Okay, so I admit - it's not very simple :-) )



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

Date: 16 Apr 1997 11:34:54 -0400
From: otto@jacobi.math.brown.edu (Ottavio G. Rizzo)
Subject: Re: Unix and ease of use  (WAS: Who makes more ...)
Message-Id: <sf67xnx9pd.fsf@jacobi.math.brown.edu>

"Tim Behrendsen" <tim@a-sis.com> writes:

> > : And it's also extremely fragile.  One corrupted byte and the
> > : rest of the file is trash.  With a reasonable tool like pkzip,
> > 
> > This I admit is true.  Never had it happen though.  But to be fair,
> > the messed up bit has to be in just the right spot.  Otherwise
> > you only corrupt that file in the extraction.  The real problem comes
> > when bytes are missing or extra bytes are added.  This is what
> > hoses a tar file, because the tar format uses the filesize in bytes
> > to determine where the next file in the archive starts.
> 
> No, one bit and entire rest of the compression stream is trash,
> which means all of the rest of the files are trash.
> 

This is a trade-off with better compression, since you're first packing
things up, and then compressing them. You might use first gzip on each
file, and then tar the result: not as good, but a bad byte would trash
just one file, as in pkzip
-- 
Ottavio G. Rizzo                          diceno `e nuje ca nun c'e' maje
Dep. of Maths, box 1917                   piaciuto `e fatica' \\ pecche' `o
Brown University, Providence RI USA       tiempo e' vita e vulimmo campa'
Phone +401 863 7957 Fax: +401 863 9013                    Almamegretta
otto@math.brown.edu                 


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

Date: 16 Apr 1997 14:50:16 GMT
From: zpalastair@unl.ac.uk (ALASTAIR AITKEN CLMS)
Subject: Re: Unix and ease of use (WAS: Who makes more ...)
Message-Id: <5j2ov8$fga@epsilon.qmw.ac.uk>

In article <33512BA5.23BEA30D@jrchaff.seanet.com>, John Chaffer <jrchaff@jrchaff.seanet.com> writes:
>That kind of puerile comment shows how ignorant socialists really,
>really are. The total, utter failure of socialism to provide
>anything but bankruptcy, chaos and finally, collapse has been
>illustrated over and over, not least by your own nation. Certainly
>you were aware (or were you) that the Soviet Union is no more?
>
>What planet do you live on?

i thought i was in comp.lang.perl.misc

not in a programming list please

Alastair.


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

Date: 8 Mar 97 21:33:47 GMT (Last modified)
From: Perl-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 8 Mar 97)
Message-Id: <null>


Administrivia:

The Perl-Users Digest is a retransmission of the USENET newsgroup
comp.lang.perl.misc.  For subscription or unsubscription requests, send
the single line:

	subscribe perl-users
or:
	unsubscribe perl-users

to almanac@ruby.oce.orst.edu.  

To submit articles to comp.lang.perl.misc (and this Digest), send your
article to perl-users@ruby.oce.orst.edu.

To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.

To request back copies (available for a week or so), send your request
to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
where x is the volume number and y is the issue number.

The Meta-FAQ, an article containing information about the FAQ, is
available by requesting "send perl-users meta-faq". The real FAQ, as it
appeared last in the newsgroup, can be retrieved with the request "send
perl-users FAQ". Due to their sizes, neither the Meta-FAQ nor the FAQ
are included in the digest.

The "mini-FAQ", which is an updated version of the Meta-FAQ, is
available by requesting "send perl-users mini-faq". It appears twice
weekly in the group, but is not distributed in the digest.

For other requests pertaining to the digest, send mail to
perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
sending perl questions to the -request address, I don't have time to
answer them even if I did know the answer.


------------------------------
End of Perl-Users Digest V8 Issue 315
*************************************

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