[6698] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 323 Volume: 8

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Apr 17 10:19:53 1997

Date: Thu, 17 Apr 97 07:00:32 -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           Thu, 17 Apr 1997     Volume: 8 Number: 323

Today's topics:
     Re:  Split a line on "^M" cirop107@grove.ufl.edu
     Re: "Dummies" book any good? <merlyn@stonehenge.com>
     Re: Adding all possible combinations of list (ALASTAIR AITKEN CLMS)
     Re: Another bothersome newbie question <seay@absyss.fr>
     Re: Array Elements (ALASTAIR AITKEN CLMS)
     Basic search program <cmille31.ford@e-mail.com>
     Re: Can it be done <mcampbel@tvmaster.turner.com>
     Re: CGI scripts (feedme.org/anti-spam.html)
     Change password in /etc/shadow via script (feedme.org/anti-spam.html)
     Compiler compilers in Perl <mcl@cursci.co.uk>
     Re: Good editor for W95? netkid@netcom.com
     Re: HELP:  Redirection with Perl... (Mike Stok)
     How to prevent DOS box from Win32 perl? <levin@mpimg-berlin-dahlem.mpg.de>
     looking for flexible string substitution script <boudreau@hawk.nstn.ca>
     Re: looking for flexible string substitution script (Honza Pazdziora)
     Re: Newbie: Why tr/+/ / Instead of s/+/ / ? <mcampbel@tvmaster.turner.com>
     NT heart characters? (Frank Jendraszak)
     Re: Palindromic words search??? <flg@vhojd.skovde.se>
     Re: Palindromic words search??? (David Alan Black)
     Re: Perl parsing (ALASTAIR AITKEN CLMS)
     Re: Perl pattern matching question (Andy Wardley)
     Re: perl syntax error (ALASTAIR AITKEN CLMS)
     perl types (Was: Kudos to Tom Christiansen and problems <seay@absyss.fr>
     Re: perl types (Was: Kudos to Tom Christiansen and prob (Mike Stok)
     Re: Printing X amount of lines from begining/middle of  (Mike Stok)
     Re: quotewords function - "0" problem (Mike Stok)
     Re: Reply to Ousterhout's reply (was Re: Ousterhout and (David Combs)
     Re: Reply to Ousterhout's reply (was Re: Ousterhout and (Gary D. Duzan)
     Re: Reply to Ousterhout's reply (was Re: Ousterhout and (brech patricia)
     Re: Reply to Ousterhout's reply (was Re: Ousterhout and (Alex Williams)
     Re: Reply to Ousterhout's reply (was Re: Ousterhout and (ozan s. yigit)
     Re: Transliterate from a pattern? (Mike Stok)
     Re: Transliterate from a pattern? (Mike Stok)
     Re: Unexpected Behavior using open () (Tad McClellan)
     Re: Why doesn't until(<FILE> =~ /^\D/) {   work? <merlyn@stonehenge.com>
     Re: Why is $Line=~ s///; erasing = (ash)
     Digest Administrivia (Last modified: 8 Mar 97) (Perl-Users-Digest Admin)

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

Date: Thu, 17 Apr 1997 06:33:18 -0400
From: cirop107@grove.ufl.edu
Subject: Re:  Split a line on "^M"
Message-Id: <Pine.OSF.3.95.970413025043.23163A-100000@birch>

QUN WENG (qxw8184@gamma.uta.edu) wrote:
 
>I use @result=split(/^M/, $need_to_split_line); but failed.
 
  Perl will allow you to specify characters as control characters by
preceding them with a '\c'.  \cM for example.  You're trying to split on a
^ and an M, that's why your split call is not working.
 
This will work:
  @result=split(/\cM/, $need_to_split_line);
 
If you're trying to replace ^M's with \n's, you can do it more efficiently
with code like this:
 
  $need_to_fix_line =~ tr/\cM/\n/;  ### To Replace with newline
  $need_to_fix_line =~ tr/\cM//d;   ### To Delete them
 
tr will operate on $_ unless you bind a string to it with the =~ operator.
 
  Get a copy of Programming Perl by Larry Wall and Randal L. Schwartz by
O'Reilly & Associates, Inc.  It's better than the Bible.  (If you're
really poor, try the Unix man Page for perl.)
 
  - Alex

---
V. Alex Brennen    alexb@nanosource.org    http://www.peoplepage.com/alex/
Technical Director  NanoSource MNT R&D Website  http://www.nanosource.org/
Unix/Web Guru For Hire         http://www.peoplepage.com/alex/consult.html





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

Date: 17 Apr 1997 05:17:11 -0700
From: Randal Schwartz <merlyn@stonehenge.com>
To: jon@amxdigital.com
Subject: Re: "Dummies" book any good?
Message-Id: <8cg1wpalo8.fsf@gadget.cscaper.com>

>>>>> "Jonathan" == Jonathan Peterson <jon@amxdigital.com> writes:

Jonathan> Explaining to a real beginner that:

Jonathan> if ($a == 1) {
Jonathan> 	print ("Whee!");
Jonathan> 	}

Jonathan> is the same as

Jonathan> $a || print ("Whee!");

Jonathan> is not something that you can do in a few sentences. More like a few
Jonathan> chapters.

And will only confuse them (and us) because they aren't the same at all. :-)

Perhaps you meant:

	if ($a) {
		print "Whee!";
	}

and

	$a && print "Whee!";

which *are* the same, except I'd frown a bit on the second form
(personal preference).

print "Just another Perl hacker," # but not what the media calls "hacker!" :-)
## legal fund: $20,495.69 collected, $182,159.85 spent; just 502 more days
## before I go to *prison* for 90 days; email fund@stonehenge.com for details

-- 
Name: Randal L. Schwartz / Stonehenge Consulting Services (503)777-0095
Keywords: Perl training, UNIX[tm] consulting, video production, skiing, flying
Email: <merlyn@stonehenge.com> Snail: (Call) PGP-Key: (finger merlyn@ora.com)
Web: <A HREF="http://www.stonehenge.com/merlyn/">My Home Page!</A>
Quote: "I'm telling you, if I could have five lines in my .sig, I would!" -- me


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

Date: 17 Apr 1997 12:35:00 GMT
From: zpalastair@unl.ac.uk (ALASTAIR AITKEN CLMS)
Subject: Re: Adding all possible combinations of list
Message-Id: <5j55dk$6nn@epsilon.qmw.ac.uk>

In article <5j2uki$hb0$1@shadow.skypoint.net>, sstarr@skypoint.com (Susan Starr) writes:
>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:
>
>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.

If you want the most numbers first try all of them, then all-1 for each in the
set, all-2 etc.  That way you will use the least number of operations to
achieve the result.  Don't forget to terminate the loop when you reach a combo
that fits.

Not perl, general programming.

Alastair.


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

Date: Thu, 17 Apr 1997 14:20:33 +0100
From: Douglas Seay <seay@absyss.fr>
To: nicholas david pesce <pesce@fandango.cis.ohio-state.edu>
Subject: Re: Another bothersome newbie question
Message-Id: <335623A1.277D@absyss.fr>

nicholas david pesce wrote:
> 
> 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.

[posted and mailed]

You leave out a lot of details here.  My advice is to open your camel
and read about fork/exec, open with pipe, backticks, and perhaps system
with "&" for the shell.  After reading about these different ways to
launch processes, think about what you need.  Each has certain
advantages and disadvantages.

If you just want to launch the second one without worrying about silly
little details such as communication, the easiest way would be

	system("second_script &");

note that this works if second_script is a perl program, a compiled C
program, a shell script, or anything else that is normally executable at
the command line.

- doug


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

Date: 17 Apr 1997 12:39:55 GMT
From: zpalastair@unl.ac.uk (ALASTAIR AITKEN CLMS)
Subject: Re: Array Elements
Message-Id: <5j55mr$6nn@epsilon.qmw.ac.uk>

In article <5j1q11$lpq@noc1.gwi.net>, geecee@burbot.netquarters.net (Gary Chambers) writes:
>Can someone confirm the correct method of determining the number of
>elements in an array?  I'm *VERY* new to Perl, and I've looked in the
>Camel book and Llama book and found nothing definitive.  Here's what I
>have been able to gather:

$#array is the last element subscript so ..
$#array++ is the number of elements (but increments the array too) so ..
$elements = $#array++; # which i think doesn't increment the array but
$elements = $#array; $elements++ # definitely doesn't.

This has been well documented since perl2.

Alastair.


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

Date: Thu, 17 Apr 1997 11:40:56 -0700
From: No-way-sis <cmille31.ford@e-mail.com>
Subject: Basic search program
Message-Id: <33566EB8.63E5@e-mail.com>

I'm after a basic search perl program which I can study or modify to
search a report and extract a section of the report relavant to the
search term.

What is the best way of search for characters eg. 'Britain' from a large
amount of data.

Please e-mail me an answer, as I've been trying to use grep, and came to
the conclusion that I'm barking up the wrong tree.
(Flame retardant suit is on)


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

Date: 17 Apr 1997 07:47:19 -0400
From: Mike Campbell <mcampbel@tvmaster.turner.com>
Subject: Re: Can it be done
Message-Id: <r5n2qxkh14.fsf@tvmaster.turner.com>

jhardy@cins.com writes:

> Thanks to Andrew Johnson for all the help with the script. It works
> perfect. It would have took me forever to figure it out, Or I would
> have had to read the entire book.

<horrors>


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

Date: 17 Apr 97 12:38:31 GMT
From: "nozaki@feedME" (feedme.org/anti-spam.html)
Subject: Re: CGI scripts
Message-Id: <335619c7.0@lightning.ica.net>

> Hi!
> Does anyone know of an ISP that is friendly or open to the idea of
> allowing space on their servers for testing CGI's for non-commercial
> use . I'm learning perlI and would like to be able to test my CGI
> scripts . Preferably this ISP would charge nothing or very little for
> this service if I was to use them as my service provider . I live in the
> Toronto, Ontario area .
> Thanks
> Luis
 
  Luis:

  Why don't you install a web server on you machine? If you use Win95, there
is a good server that is free: OmniHTTPd . You can obtain it at
http://www .fas .harvard .edu/~glau/httpd/ . It handles PERL scripts in a very
simple way . You just need to use  .pl as the file extension .
  In case you don't use, Win95, search for another web server to install in
your machine . It's easier .

  Are you from Brazil?

  []'s

---------------------------------------------
       Free ACCCESS to 30,000 Newsgroups     
      Read and Post through a web-site...    
             http://www.feedME.org           
---------------------------------------------



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

Date: 17 Apr 97 12:48:48 GMT
From: "nozaki@feedME" (feedme.org/anti-spam.html)
Subject: Change password in /etc/shadow via script
Message-Id: <33561c30.0@lightning.ica.net>

Does anybody know a PERL script that allows the changing of a user's password
directly in the /etc/shadow file? I need this to create a HTML form for individual
users to change their password without telnet or something like this .

Thanks!

---------------------------------------------
       Free ACCCESS to 30,000 Newsgroups     
      Read and Post through a web-site...    
             http://www.feedME.org           
---------------------------------------------



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

Date: Thu, 17 Apr 1997 13:33:37 +0100
From: Mark Lester <mcl@cursci.co.uk>
Subject: Compiler compilers in Perl
Message-Id: <335618A1.29F8@cursci.co.uk>

I have a program, which I call Stump, which will read an SGML
hierarchy and build a tree of tag nodes. I can then traverse
this tree, and call routines of the same names as the tags
to manipulate the structure. 
Using this technology I have built an HTML templating system, as
well as annihilating just about any "take this half baked SGML
set of files and produce some decent HTML for us to web"
class of task.
I would now like to fit an arbitrary parsing engine on to this,
so I can take non-SGML stuff, as well as being a bit clever
during the parse phase. I am about to write a BNF to LALR rule
set generator, which I am hoping will produce a human readable
file (unlike Yucc) with token names in text, and terminator
rules of the same names as the expression.
This is a great job for some would-be computer science whizz, if
I can convince anyone that Perl isn't just some joke language.
Anyone interested ?


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

Date: Thu, 17 Apr 1997 13:27:02 GMT
From: netkid@netcom.com
Subject: Re: Good editor for W95?
Message-Id: <netkidE8sAp2.2Jn@netcom.com>

In <33554994.60A2@inlink.com>, Benjamin Burack <rascal@inlink.com> writes:
>I'm writing CGI scripts in perl on my W95 machine, and then uploading
>them to the Unix server.  I'm looking for recommendations on good
>editors that can easily save in a Unix format.
>
>Thanks,
>Ben Burack
>rascal@inlink.com

An Ascii FTP transfer should handle the CRLF to LF translation correctly.

---
Jim
Cybernet Connections





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

Date: 17 Apr 1997 12:42:56 GMT
From: mike@stok.co.uk (Mike Stok)
Subject: Re: HELP:  Redirection with Perl...
Message-Id: <5j55sg$kc6@news-central.tiac.net>

In article <5j4e88$9v3@usenet85.supernews.com>,
No Mass Spam E-Mail! <zippidy@do.dah.com> wrote:
>Not quite newbie..
>
>I did it once before, and since have lost my drive, and all my
>development CGI's!
>
>I want to call a url and have the browser load it from Perl.
>
>Also, Iam haveing some trouble with printing " chars.
>
>I tried:
>
>print "<META HTTP-EQUIV=&#34REFRESH&#3 
>CONTENT=&#34URL=http://www.digispec.com/loadthis.htm&#34>";

Maybe you want to say something like

  print '<META HTTP-EQUIV="REFRESH" CONTENT="http://www.digispec.com/loadthis.htm">';

or if you want to do variable interpolation

  print qq{meta http-equiv="refresh" content="$url">};

might be useful.  Check the sections on q and qq in the perlop manual page
or a good perl book (Programming perl, 2nd edition is a good reference)

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: Thu, 17 Apr 1997 15:16:33 +0200
From: lexi <levin@mpimg-berlin-dahlem.mpg.de>
Subject: How to prevent DOS box from Win32 perl?
Message-Id: <335622B0.56D8@mpimg-berlin-dahlem.mpg.de>

Hi
I collect data from a CCD camera with a macro that has recorded 
all mouse events. Within this loop is a short perl script that
converts the data into another format. I run this script from explorer.
Every time the DOS window pops up and my marco fails because the
wanted window is covered.
As the the script must be very fast I would like to know whether there
is a way to prevent the DOS window from appearence or give him his
coordinates where to pop up?

Thanks for your help in advance,
-- 
- LEXI `'~*-,._.,-*~'`^`'~*-,._.,-*~'`^`'~*-,._.,-*~'`^`'~*-,._.,-*~'`

         Alexander Levin, levin@mpimg-berlin-dahlem.mpg.de
 Max-Planck-Institute for Molecular Genetics, Department Dr. Lehrach 
                Ihnestr. 73, D - 14195 Berlin, Germany
        Voice: +49-30-8413.1401      Fax: +49-30-8413.1380 
             http://www.mpimg-berlin-dahlem.mpg.de/~lexi

,-*~'`^`'~*-,._.,-*~'`^`'~*-,._.,-*~'`^`'~*-,._.,-*~'`^`'~*-,._.,-*~'`


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

Date: Thu, 17 Apr 1997 09:29:52 -0300
From: "Yvon Boudreau" <boudreau@hawk.nstn.ca>
Subject: looking for flexible string substitution script
Message-Id: <5j54rl$9t7@news.nstn.ca>

Hi !
I am looking for a script that can do the following:
Basic requirements for existing string specification are:
1. Replacement of a specified literal string by another literal string
2. Replacement of only the content contained between specified beginning
and ending substring by a specified literal string
3. The string substitution range should be a user choice between
a) a single file
b) a list of files
c) a directory
d) a hierarchy of directories including a named directory and all
directories below it to all levels.
If somebody know where I could find such a string please let me know. You
help will be greatly appreciated.
Cheers Yvon.




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

Date: Thu, 17 Apr 1997 12:32:54 GMT
From: adelton@fi.muni.cz (Honza Pazdziora)
Subject: Re: looking for flexible string substitution script
Message-Id: <hudec.861280374@aisa.fi.muni.cz>

"Yvon Boudreau" <boudreau@hawk.nstn.ca> writes:

> Hi !
> I am looking for a script that can do the following:
> Basic requirements for existing string specification are:
> 1. Replacement of a specified literal string by another literal string

perl -pe 's/specified/another/g'

> 2. Replacement of only the content contained between specified beginning
> and ending substring by a specified literal string

perl -pe 's/beginning specified ending/beginning literal ending/g'

> 3. The string substitution range should be a user choice between
> a) a single file

perl -i -pe ' ... script ... ' file

> b) a list of files

perl -i -pe ' ... script ... ' files

> c) a directory

perl -i -pe ' ... script ... ' directory/*

> d) a hierarchy of directories including a named directory and all
> directories below it to all levels.

perl -i -pe ' ... script ... ' `ls -R`

> If somebody know where I could find such a string please let me know. You
> help will be greatly appreciated.

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: 17 Apr 1997 07:57:33 -0400
From: Mike Campbell <mcampbel@tvmaster.turner.com>
Subject: Re: Newbie: Why tr/+/ / Instead of s/+/ / ?
Message-Id: <r5k9m1kgk2.fsf@tvmaster.turner.com>

tgy@chocobo.org (Tim Gim Yee) writes:

> On 12 Apr 1997 00:54:07 GMT, "Jeff Oien" <jeffo@execpc.com> wrote:
> 
> >
> >Hi,
> >I was wondering why form mail scripts always use
> >tr/+/ /
> >instead of
> >s/+/ /
> >with only one character, wouldn't they be the same?
> 
> s/\+/ /g; # You meant this, right? :)
> 
> Maybe 'tr/+/ /;' is faster.  Maybe the authors all came from a unix
> background and wanted to type as few characters as possible.  Or maybe
> they were just looking to *translate* one character to another.

use Benchmark;

timethese (100000, { "tr" => '$_ = "a+b+c+d"; tr/+/ /;',
                     "s " => '$_ = "a+b+c+d"; s/\+/ /g;'});
    

******************************************************************************

Benchmark: timing 100000 iterations of s , tr...
        s :  5 secs ( 4.14 usr  0.00 sys =  4.14 cpu)
        tr:  0 secs ( 1.01 usr  0.00 sys =  1.01 cpu)


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

Date: 17 Apr 1997 08:34:24 -0500
From: fjj@sashimi.wwa.com (Frank Jendraszak)
Subject: NT heart characters?
Message-Id: <5j58t0$qqf@shoga.wwa.com>

If I do a dump of WINS information, I'll get a file where some entries
contain a ascii heart suit character.

How do I search on this character so that I may replace or remove it with
perl32 on NT 4.0?

Any help would be great.

Thanks,

Frank
-- 
Frank Jendraszak						fjj@wwa.com


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

Date: Thu, 17 Apr 1997 13:09:11 +0200
From: "Fredrik Lindberg" <flg@vhojd.skovde.se>
Subject: Re: Palindromic words search???
Message-Id: <335604b6.0@d2o61.telia.com>

Jong wrote in article <3355E6BC.41C6@mrc-lmb.cam.ac.uk>...
>I am trying to make a program which detects all the palindromic(perfect
>or imperfect palindromes) sequences in any long string.

Hi, How does one define an imperfect palindrome?

Heres a function scanning a string and trying to find all perfect
palindroms.
It saves the result in a list which in turn is printed by the main loop.

No checking is done on the input data, and I dont care about spaces or
things like that.

Sorry for the dots at the beginning of each line, but my stupid newreader
wouldnt let me indent the lines unless I began with a nonwhitespace first.

 . #!/usr/bin/perl -w
 . #
 .
 . my(@palindrom);
 .
 . while(<>) {
 .    chomp;
 .    if (@palindrom = GetPalindrom($_, 2)) {
 .       print "Palindrom: \"@palindrom\"\n";
 .    }
 . }
 .
 . # GetPalindrom. Uses a sort of shrinking window scanning through the
string
 . # looking for matches with itself in reverse.
 . #
 . sub GetPalindrom {
 .    my($string, $min_len) = @_;
 .    my($pos, $len, $str);
 .    my($initial_length);
 .    my(@pals);
 .
 .    $pos = 0;
 .    $len = $initial_length = length($string);
 .
 .    while($len > $min_len) {
 .
 .       do
 .       {
 .          $str = substr($string, $pos, $len); # Extract current string
 .          push(@pals, $str) if ($str eq reverse($str)); # Save it if its a
pal
 .          $pos ++; # Take one step to the right and try another match
 .       }
 .          while ($pos+$len < $initial_length); # until we hit the end of
the string
 .
 .       # Not done yet, make a smaller substring and try again. This loop
will terminate
 .       # when the substring is too small.
 .       $len --;
 .       $pos = 0;
 .    }
 .
 .    return @pals;
 . }
 .
__END__

Hope this helps.

/Fredrik




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

Date: 17 Apr 1997 11:47:53 GMT
From: dblack@icarus.shu.edu (David Alan Black)
Subject: Re: Palindromic words search???
Message-Id: <5j52l9$5cm@pirate.shu.edu>

Hello -

Jong <jong@mrc-lmb.cam.ac.uk> writes:

>Hi,

>I am trying to make a program which detects all the palindromic(perfect
>or imperfect palindromes) sequences in any long string.

Well, here's a start:

if ($string eq reverse ($string)) {
	print "Perfect\n";
}

It gets a bit more involved after that :-)  One approach you might
develop would be to take substrings from the beginning and end of
the string, reverse the latter, split(//) them into characters,
and compare.

David Black
dblack@icarus.shu.edu


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

Date: 17 Apr 1997 12:14:06 GMT
From: zpalastair@unl.ac.uk (ALASTAIR AITKEN CLMS)
Subject: Re: Perl parsing
Message-Id: <5j546e$6nn@epsilon.qmw.ac.uk>

In article <33540245.5632@msp.sc.ti.com>, Jayne Meiners <jayne@msp.sc.ti.com> writes:
>If I am looking for one character out of a string.
>It doesn't matter if it is in the beginning, middle,
>or end.
>All I want to know is if it exists, what is the parsing
>sequence I need.
>
>This is the form I would like to have it:
>
>if (<that_x_character_exists>) {
>
> print "<that_x_character_exists>";
>
>}

if (/<char>/) {
     print "<char> exists\n";
}

All I added to your program were the slashes to denote a pattern.  See the perl
FAQ at www.perl.com/perl/faq/index.html, perlre from the perl man pages and
then, if you're feeling adventurous, read Tom Christiansen's "What Makes Perl's
Regular Expressions Dynamite" at
www.perl.com/perl/everything_to_know/regexps.html.

Alastair.


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

Date: 17 Apr 1997 13:39:46 +0100
From: abw@peritas.com (Andy Wardley)
Subject: Re: Perl pattern matching question
Message-Id: <5j55mi$huf@aoxomoxoa.peritas.com>

Hans Suijkerbuijk  <Hans.Suijkerbuijk@SD.BE> wrote:
>
>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>
>

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

The matches enclosed in parentheses can be referenced using $1, $2, $3
etc.

e.g. s|TYPE=\"(.*?)\"|$1ED|g;


This is described in great detail in the New Camel Book in the section on 
Pattern Matching, page 57 onwards.


A

-- 
Andy Wardley <abw@peritas.com>  **NEW** http://www.peritas.com/~abw 
A responsible and professional individual who has no need for silly 
comments, inane banter or bizarre "in-jokes" in his signature file.  


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

Date: 17 Apr 1997 13:06:27 GMT
From: zpalastair@unl.ac.uk (ALASTAIR AITKEN CLMS)
Subject: Re: perl syntax error
Message-Id: <5j578j$6nn@epsilon.qmw.ac.uk>

In article <33558EC5.1E8F@amd.com>, Syed Babar <syed.babar@amd.com> writes:
>Can any one tell me what is wrong in this :
>
>$ex =`rsh $i 'if ( -e "/etc/lsf.conf") echo 1'` ;
>        if(!$ex) {
>         
>	when i run it i get error:
>"sh: syntax error at line 1: `echo' unexpected"

Yes.  It's not a perl problem, it's a unix shell (sh) problem. Wrong list.

try this:

$ex = `rsh $i 'if [ -f "/etc/lsf.conf" ]; then echo 1; fi;'`;

Note the square brackets, the semicolons and "then".  BTW: my sh didn't
recognise -e as a test. 

Alastair.


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

Date: Thu, 17 Apr 1997 14:34:24 +0100
From: Douglas Seay <seay@absyss.fr>
Subject: perl types (Was: Kudos to Tom Christiansen and problems with OO)
Message-Id: <335626E0.4D8C@absyss.fr>

Devin Ben-Hur wrote:
> 
> Terrence M. Brannon wrote:
> > > Any other jazz pianist Perl types out there besides myself?
> >
> > The only Perl types are scalar, array, and hash. :-)
> 
> What about filehandle and subroutine?

Filehandles and dirhandles are ugly step children kinda like typeglobs. 
They can be useful, but don't mention them in polite company.

What do you mean by a "subroutine type"?  A reference to a sub, that I
understand, but what is sub other than a directive to the interpreter? 
To my way of thinking, a sub isn't a type in Perl.

- doug


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

Date: 17 Apr 1997 13:10:41 GMT
From: mike@stok.co.uk (Mike Stok)
Subject: Re: perl types (Was: Kudos to Tom Christiansen and problems with OO)
Message-Id: <5j57gh$luf@news-central.tiac.net>

In article <335626E0.4D8C@absyss.fr>, Douglas Seay  <seay@absyss.fr> wrote:

>What do you mean by a "subroutine type"?  A reference to a sub, that I
>understand, but what is sub other than a directive to the interpreter? 
>To my way of thinking, a sub isn't a type in Perl.

perkaps type is being used here to say something that's stored in a symbol
table entry.  In the Packages Modules and Object Classes chapter of
Programming Perl (2nd edition) you can find ways of getting at references
to different flavours of thing with the same name (which could be called
types if that fits your way of thinking...)

  *pkg::sym{SCALAR}

and the same for ARRAY HASH CODE GLOB FILEHANDLE (and NAME and PACKAGE
which don't give you references) can all be used in the {}

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: 17 Apr 1997 13:20:22 GMT
From: mike@stok.co.uk (Mike Stok)
Subject: Re: Printing X amount of lines from begining/middle of file. How?
Message-Id: <5j582m$mgr@news-central.tiac.net>

In article <adrade-1604972131360001@pool3-002.wwa.com>,
Adam Levy <adrade@wwa.com> wrote:
>Is it possible to, from a file, print the first 15 lines from the file,
>and in another case, print lines 15-30, etc. in seperate instances? Any
>help is greatly appreciated. If possible, email responses are also
>appreciated.

  perl -ne 'print if 1 .. 15' file
  perl -ne 'print if 15 .. 30' file

might be a place to start.

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: 17 Apr 1997 12:39:01 GMT
From: mike@stok.co.uk (Mike Stok)
Subject: Re: quotewords function - "0" problem
Message-Id: <5j55l5$k3o@news-central.tiac.net>

In article <861229148.8435@dejanews.com>,  <bsautter@get-it.net> wrote:
>I am using the "quotewords" function along with
>some other code to split a CSV file.
>
>Just today I found my script was working. I narrowed
>it down to the quotewords function. Here is a
>snippet of code that shows this problem:

[...]

>It eliminates any zero found at the end of a line!
>Zeros in the middle are not affected as in "string0".
>Only by putting quotes around the last value will it
>keep the zero:

I know that someone's already posted a workaround, this is just an
informational posting...

This is fixed in the betas of what will see daylight as perl 5.004.  Using
the debugger:

  DB<1> use Text::ParseWords

  DB<2> $test="Test,string0,with,stuff,in,it,b0"

  DB<3> @values = quotewords(",", 0==0, $test)

  DB<4> X values
@values = (
   0  'Test'
   1  'string0'
   2  'with'
   3  'stuff'
   4  'in'
   5  'it'
   6  'b0'
)
  DB<5> print $]
5.00397

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: Thu, 17 Apr 1997 11:43:16 GMT
From: dkcombs@netcom.com (David Combs)
Subject: Re: Reply to Ousterhout's reply (was Re: Ousterhout and Tcl ...)
Message-Id: <dkcombsE8s5w5.66q@netcom.com>

> Yes, when I got a copy of SICP last Xmas, I felt I was humouring the

Please, what book title is "SICP"?



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

Date: 17 Apr 1997 12:03:31 GMT
From: gary@wheel.tiac.net (Gary D. Duzan)
Subject: Re: Reply to Ousterhout's reply (was Re: Ousterhout and Tcl ...)
Message-Id: <5j53ij$i1u@news-central.tiac.net>

In article <dkcombsE8s5w5.66q@netcom.com>,
David Combs <dkcombs@netcom.com> wrote:
=>> Yes, when I got a copy of SICP last Xmas, I felt I was humouring the
=>
=>Please, what book title is "SICP"?
=>

   Ah, the joys of cross-posting to a Scheme group. _Structure and
Interpretation of Computer Programs_, by Harold Abelson and Gerald Jay
Sussman with Julie Sussman, recently released in Second Edition.

   http://mitpress.mit.edu/sicp/

                                      Gary D. Duzan
                         Humble Practitioner of the Computing Arts


p.s. I really need to get a copy of the thing. I sold my First Edition
back to the bookstore after the course. (Don't hurt me too badly,
Scheme people; I was an ignorant freshman at the time. I'm better now.)


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

Date: 17 Apr 1997 08:23:16 -0400
From: pbrech1@umbc.edu (brech patricia)
Subject: Re: Reply to Ousterhout's reply (was Re: Ousterhout and Tcl ...)
Message-Id: <5j54nk$fti@umbc10.umbc.edu>

In article <dkcombsE8s5w5.66q@netcom.com>,
David Combs <dkcombs@netcom.com> wrote:
>> Yes, when I got a copy of SICP last Xmas, I felt I was humouring the
>
>Please, what book title is "SICP"?
>

"SICP" is "Structure and Interpretation of Computer Programs" by Abelson,
Sussman and Sussman, MIT Press (2nd Ed recently out).

>From the Scheme FAQ:
  "Starts off introductory, but rapidly gets into powerful Lisp-particular
   constructs, such as using closures, building interpreters, compilers,
   and OO systems...  This is the classical text for teaching program
   design using Scheme, and everybody should read it at least once..."  

prb


-- 
+-------------------------------------------------------------------------+
Patricia Riley Brech (CMSC)   University of Maryland Baltimore County 
pbrech1@gl.umbc.edu           http://www.gl.umbc.edu/~pbrech1


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

Date: 17 Apr 1997 13:16:56 GMT
From: thantos@uxtlaser.alf.dec.com (Alex Williams)
Subject: Re: Reply to Ousterhout's reply (was Re: Ousterhout and Tcl ...)
Message-Id: <5j57s8$nql$1@netnews.alf.dec.com>

In article <mls-1604970159200001@mls.dialup.access.net>,
Michael L. Siemon <mls@panix.com> wrote:
>Try representing the _Iliad_ as either an integer or a list. Just try;
>I want to see what kind of idiocies you will commit. That it is possible
>I willingly acknowledge; that it is sane, I seriously doubt.

Last I checked, the ILIAD was a document and, as such, could be
treated as a /list/ of characters.  Oddly enough, so is a string a
/list/ of characters.  Seems to me, sir, you cannot see the forest for
the trees.

-- 
[  Alexander Williams {thantos@alf.dec.com/zander@photobooks.com}  ]
[ Alexandrvs Vrai,  Prefect 8,000,000th Experimental Strike Legion ]
[	      BELLATORES INQVITI --- Restless Warriors		   ]
====================================================================


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

Date: 17 Apr 1997 09:27:23 -0400
From: oz@ds9.rnd.border.com (ozan s. yigit)
Subject: Re: Reply to Ousterhout's reply (was Re: Ousterhout and Tcl ...)
Message-Id: <x6k9m1wzic.fsf@ds9.rnd.border.com>

Erik Naggum <erik@naggum.no> writes [amongst many other things] in
response to John Ousterhout:

>	...  right now, I'm having the distinct
> impression that you have left yourself in a very unenviable position by
> ridiculing only the most incoherent of your critics, ignoring lots of
> coherent arguments, and then arguing that you're swamped!  by not answering
> technical points and instead turning to rhetorical tricks, you have
> yourself contributed to the voluminous flow of irrelevancy.

it is worth noting that ousterhout did respond over the years to many
pieces of criticism, on usenet and elsewhere. sometimes technical solutions
came as a result; consider the byte-code compiled tcl in 8.0.

people who have strong criticisms [and those who actually understand the
meaning of the word] have the obligation to do some homework and see if such
criticisms have been responded to in the past. life is too short to have to
re-respond to the same old bits again and again, and not everyone has
tom christiansen's stamina. :)

oz


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

Date: 17 Apr 1997 12:13:05 GMT
From: mike@stok.co.uk (Mike Stok)
Subject: Re: Transliterate from a pattern?
Message-Id: <5j544h$ih0@news-central.tiac.net>

In article <5j4vb5$656@epsilon.qmw.ac.uk>,
ALASTAIR AITKEN CLMS <zpalastair@unl.ac.uk> wrote:

>I benchmarked three strings on a sparc 20 server, one processor, 224 MB Ram,
>Solaris 2.5, perl 5.003
>
>$var1 = "   front and back   \n";
>$var2 = "   front only\n";
>$var3 = "back only   \n";
>
>I tried both methods:
>
>1) s/^\s+//;  s/\s+$//;
>2) s/^\s+|\s+$//;
>
>The first method dumped the <CR><LF> in every case and the second dumped it
>only where there was at least one space at the end of the string <b>but none at
>the beginning</b>.
>
>I ran these through time with the same data:
>
>method 1) real	0m0.11s
>	  user	0m0.03s
>	  sys   0m0.07s
>
>method 2) real	0m0.11s
>	  user	0m0.04s
>	  sys	0m0.06s
>
>pretty similar.  I tried it a few times and the results varied slightly but
>were always pretty close.
>
>I never modified the pattern with a g.

Have you checked out the Benchmark module that comes with perl these days?
I tried method 1 and method 2 (I called them front and back 1 and front or
back respectively) like this on my pc:

#!/usr/local/bin/perl -w

use Benchmark;

use vars qw/$var1 $var2 $var3/;

$var1 = "   front and back   \n";
$var2 = "   front only\n";
$var3 = "back only   \n";

timethese (100_000, {
  'front and back 1' => 'foreach ($var1, $var2, $var3) {
                           s/^\s+//;  s/\s+$//;
                         }',
  'front or back'    => 'foreach ($var1, $var2, $var3) {
                           s/^\s+|\s+$//;
                         }',
  'front and back 2' => 'foreach ($var1, $var2, $var3) {
                           s/^\s+|\s+$//g;
                         }',
  'front and back 3' => 'foreach ($var1, $var2, $var3) {
                           s/^\s*(.*?)\s*$/$1/;
                         }',
  }
);

__END__

and it said:

Benchmark: timing 100000 iterations of front and back 1, front and back 2, front and back 3, front or back...
front and back 1: 10 secs ( 9.18 usr  0.00 sys =  9.18 cpu)
front and back 2: 20 secs (18.70 usr  0.00 sys = 18.70 cpu)
front and back 3: 39 secs (38.24 usr  0.01 sys = 38.25 cpu)
front or back: 18 secs (18.55 usr  0.00 sys = 18.55 cpu)

which might be of interest.  

Hope they are,

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: 17 Apr 1997 12:27:53 GMT
From: mike@stok.co.uk (Mike Stok)
Subject: Re: Transliterate from a pattern?
Message-Id: <5j5509$jb5@news-central.tiac.net>

In article <5j4v72$656@epsilon.qmw.ac.uk>,
ALASTAIR AITKEN CLMS <zpalastair@unl.ac.uk> wrote:

>And: eli@NetUSA.Net (Eli The Bearded) wrote @ Wed, 16 Apr 1997 14:10 -0400 (EDT)
>
>> >$var =~ s/^\s+|\s+$//;
>
>> Shouldn't that have a /g on it?
>
>No it shouldn't.  There can only be one beginning and one end to a string.  
>Global substitution is only ever necessary where a pattern might match two or
>more times within a string and you want both occurences to be substituted.
>
>I have tried this and it works without the g modifier.  I think for the above
>reason.

A string has 2 ends and the alternation in /^\s+|\s+$/ matches one of "the
left end of the string followed by 1 or more \w characters" or "1 or more
\w characters followed by the right end of the string" - without the G
then only 0 or 1 substitutions can happen so if there's \w at the left and
right ends of the string then only that at the beginning is removed.  In
most traditional regex implementations the first alternative that works
(working from left to right) is enough to let the group of alternatives be
considered to have succeeded and the engine gives up.  Jeffrey Friedl's
Mastering Regular Expressions covers this in more depth and better than I
copuld ever hope to...

The original requirement was "I want to delete leading and
trailing spaces from a string." and if we were to look at Jeff Vannest's
original code:

  $value  =~ /^ /;
  if ($& eq " ") {
     $value = $';
  }
  $value  =~ / $/;
  if ($& eq " ") {
     $value = $`;
  }

one solution which gets rid of one leading and one trailing space (or
both) might be

  for ($value) {
    s/^ //;
    s/ $//;
  }

or if we took the pluralisation of spaces to mean sewuennces of one or
more spaces then s/^ +//; s/ +$//; might be more in line with what he
wanted.

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: Thu, 17 Apr 1997 05:33:53 -0500
From: tadmc@flash.net (Tad McClellan)
Subject: Re: Unexpected Behavior using open ()
Message-Id: <hau4j5.1n.ln@localhost>

Steve Gunnell (steveg@ccis.adisys.com.au) wrote:

: Tom Christiansen wrote:

: > Because you *told* it to.   Did you read the entry for open in
: > the perlfunc manpage?  Did you read the FAQ?  Here's the FAQ
: > entry for that:
: > 
: >    How come when I open the file read-write it wipes it out?
: > 
: >    Because you're using something like this, which truncates the file
: >    and then gives you read-write access:
: > 
: >        open(FH, "+> /path/name");  # WRONG
: > 
: >    Whoops.  You should instead use this, which will fail if the file
: >    doesn't exist.
: > 

: Jeez Tom,

: Have YOU read the perlfunc manpage? Here's an extract:

:              contains the filename.  If the filename begins with
:              "<" or nothing, the file is opened for input.  If
:              the filename begins with ">", the file is opened for
:              output.  If the filename begins with ">>", the file
:              is opened for appending.  (You can put a '+' in
:              front of the '>' or '<' to indicate that you want
:              both read and write access to the file.)  If the

: Where does it say "truncates the file?


My version of perlfunc (5.003) does not have 'truncate' in it either
(except, of course, for truncate() )
 .
But it does have this:

" '+<' is usually preferred for read/write updates--the '+>'
mode would clobber the file first."

That 'clobber the file' part seems clear to me...


: Stop shooting the bloody messangers and have the guts to accept
: that sometimes the documentation is unclear or missing. Not
: everyone has web access to get to the FAQ list. Lighten up a
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
: bit.


The FAQ is posted to this newsgroup periodically. (though you are
discussing the man pages, not the FAQ ;-)

My guess is that if they can post to c.l.p.m, then they have the
necessary access for reading c.l.p.m.

Yes?

They do not need "web access" in order to do The Right Thing.

-----

The man pages are included with the perl distribution! If they have
perl, then they should have the man pages. If they do not have perl,
then they have no business posting to a perl newsgroup  ;-)

If they have a non-standard, broken, distribution without the man
pages, then they should send ALL of their perl questions to the
non-standard, broken, distributor.

After *they* answer the same question fifty or a hundred times, 
(times dozen of such questions) maybe the distributor will begin to 
see the wisdom of not breaking the distribution in such a manner...

-----

If they do not have access to the FAQ for a newsgroup, then they do
not have the minimum requirements for posting to that newsgroup.

Lightening up would be a disservice to the Perl community.

-----


I will hereby volunteer to email the Perl FAQs to anyone who
sends a request by email.


--
    Tad McClellan                          SGML Consulting
    Tag And Document Consulting            Perl programming
    tadmc@flash.net


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

Date: 17 Apr 1997 05:22:41 -0700
From: Randal Schwartz <merlyn@stonehenge.com>
To: htchapma@vela.acs.oakland.edu (H. Todd Chapman)
Subject: Re: Why doesn't until(<FILE> =~ /^\D/) {   work?
Message-Id: <8cbu7dalf2.fsf@gadget.cscaper.com>

>>>>> "H" == H Todd Chapman <htchapma@vela.acs.oakland.edu> writes:

H> I wanted to use the following:
H> until(<FILE> =~ /^\D/) {        
H> 	($node, $x, $y, $z) = split;
H>         if (exists $nodes_hash{$node}) {
H>                 $nodes_hash{$node} = join ' ', $x, $y, $z;
H>         }
H> }

Let's see, you read a line, tested it for a non-digit, threw it away,
and then went into the body of the loop if it had a non-digit.

H> but htat didn't work, so I tried:

H> until(<FILE> =~ /^\D/) {        
H>         ($node, $x, $y, $z) = split;
H>         if (exists $nodes_hash{$node}) {
H>                 $nodes_hash{$node} = join ' ', $x, $y, $z;
H>         }
H> }

and that's exactly the same code, unless I'm not seeing something... :-)


H> which also failed so I tried:

H> while(<FILE>) {
H>         if (/^\D/) {last;}
H>         ($node, $x, $y, $z) = split;
H>         if (exists $nodes_hash{$node}) {
H>                 $nodes_hash{$node} = join ' ', $x, $y, $z;
H>         }
H> }

which reads a line, puts it into $_, tests that for undef, if not,
goes into the loop body, then tests that $_ for a non-digit, etc etc.

H> Which works, as I expected. Why do the other two methods not woek?

Well, the "other two" are both the same. :-) But the last one works
because the *only* thing inside the parens is the <FILE> line input
operator, and that stuffs the data into $_.  There is *no* implicit
connection between "file reading" and $_, just while (<FOO>) { ... }
and $_.

print "Just another Perl hacker," # but not what the media calls "hacker!" :-)
## legal fund: $20,495.69 collected, $182,159.85 spent; just 502 more days
## before I go to *prison* for 90 days; email fund@stonehenge.com for details

-- 
Name: Randal L. Schwartz / Stonehenge Consulting Services (503)777-0095
Keywords: Perl training, UNIX[tm] consulting, video production, skiing, flying
Email: <merlyn@stonehenge.com> Snail: (Call) PGP-Key: (finger merlyn@ora.com)
Web: <A HREF="http://www.stonehenge.com/merlyn/">My Home Page!</A>
Quote: "I'm telling you, if I could have five lines in my .sig, I would!" -- me


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

Date: 14 Apr 1997 19:40:27 GMT
From: searlea@aston.ac.uk (ash)
Subject: Re: Why is $Line=~ s///; erasing =
Message-Id: <5iu17b$oqk$1@whatsit.aston.ac.uk>

Kevin Swope (obsidian@shore.net) wrote:
: hello,
: 
: why does:
: 
: $Blank_var="";
: 
: $Tag=~ s/$Blank_var//;
: 
: occasionally erase the = from variable $Tag when it contains a =

Because: (from the perlop man page)
" If the pattern evaluates to a null string, the last successfully
  executed regular expression is used instead."

Is there some code anywhere in the program that searches for
an '=' ?


-- 
/*-------------------------------*
 | Ash Searle - ash@innocent.com |    " He's in a box! "
 *-------------------------------*/



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

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

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