[9208] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 2803 Volume: 8

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sat Jun 6 22:07:17 1998

Date: Sat, 6 Jun 98 19:00:27 -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           Sat, 6 Jun 1998     Volume: 8 Number: 2803

Today's topics:
    Re: Am I looking at an anonymous array <tchrist@mox.perl.com>
    Re: Best tool? (John Edstrom)
        Copy in Perl... <uday@ionet.net>
    Re: DBD::Oracle: finish doesn't free resources (Gabor)
    Re: Foreach Efficiency <p-fein@uchicago.edu>
    Re: How to make a list of combinations? pehanna@my-dejanews.com
    Re: Idiom for updating file? (Larry Rosler)
    Re: Idiom for updating file? <tchrist@mox.perl.com>
    Re: Idiom for updating file? (Larry Rosler)
    Re: IP to DNS (Larry Rosler)
    Re: IP to DNS <rlogsdon@io.com>
    Re: Is PERL case sensitive? <rlogsdon@io.com>
    Re: Is PERL case sensitive? <rlogsdon@io.com>
    Re: Is PERL case sensitive? <tchrist@mox.perl.com>
    Re: lines of text, inserting spaces <rlogsdon@io.com>
    Re: Looking for upload.pl <rlogsdon@io.com>
    Re: newbie problem opening pipe (Larry Rosler)
    Re: Problem: With the $ENV{'blah'} variable <zeos@gti.com>
        Q: puzzled: regex with inperpolation <xah@best.com>
    Re: Q: puzzled: regex with inperpolation (Ilya Zakharevich)
    Re: Reading a file from the bottom up <rlogsdon@io.com>
    Re: Removing a character from a string <rlogsdon@io.com>
    Re: Saving dynamically created images (Kenny A. Chaffin)
    Re: striphtml program (Larry Rosler)
    Re: Stupid syntax question <rlogsdon@io.com>
    Re: Why is there no "in" operator in Perl? (Greg Andrews)
    Re: Why is there no "in" operator in Perl? (Brandon S. Allbery KF8NH)
        Digest Administrivia (Last modified: 8 Mar 97) (Perl-Users-Digest Admin)

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

Date: 6 Jun 1998 22:55:08 GMT
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: Am I looking at an anonymous array
Message-Id: <6lchcc$vt$1@csnews.cs.colorado.edu>

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

In comp.lang.perl.misc, sommar@algonet.se (Erland Sommarskog) writes:
:If say "ref $x" I might get ARRAY or HASH in return. But can I tell 
:whether this array or hash is a real variable, or just an anonymous
:entity?

No, you can't.

--tom
-- 
    Sorry.  My testing organization is either too small, or too large, depending
    on how you look at it.  :-)
            --Larry Wall in <1991Apr22.175438.8564@jpl-devvax.jpl.nasa.gov>


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

Date: 6 Jun 1998 23:15:58 GMT
From: edstrom@hmsc.orst.edu (John Edstrom)
Subject: Re: Best tool?
Message-Id: <6lcije$o7m$1@news.NERO.NET>

In article <6kui9b$rm6$2@client3.news.psi.net>,
	abigail@fnx.com (Abigail) writes:

> ++ 2) What is the best tool for Web developer?
> 
> The DTDs.
> 

Ah!  I've wondered for a long time why the average web content is so
bad.  Judging by appearances it looked to me as though a lot of
developers were working with the DTs.  Now I see that they've only
been using 2/3rds of the kit all along!

This explains a lot.

> 
> Abigail


	je

---
 John Edstrom | edstrom @ slugo.hmsc.orst.edu

 http://www.hmsc.orst.edu/~edstrom
 "Lurker" at BioMOO (bioinfo.weizmann.ac.il:8888)

 Hatfield Marine Science Center
 2030 S. Marine Science Drive
 Newport, Oregon     97365-5296
 wk: (541) 867 0197
 fx: (541) 867 0138


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

Date: Sat, 06 Jun 1998 19:17:10 -0500
From: Uday Pai <uday@ionet.net>
Subject: Copy in Perl...
Message-Id: <3579DC06.8723A498@ionet.net>

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

I have a file in dir1 and want to copy in dir2. I do not want to make a
system call
like

system("copy C:\sdsd\dir1\file.txt C:\sd\dir2");

I want a platform independent solution. Is there no function like copy()
in perl. I
could not find it anywhere.

Thanks

Uday
uday@cyberdude.com

--------------2F1D687417872DB49EF399B6
Content-Type: text/x-vcard; charset=us-ascii; name="vcard.vcf"
Content-Transfer-Encoding: 7bit
Content-Description: Card for Uday Pai
Content-Disposition: attachment; filename="vcard.vcf"

begin:          vcard
fn:             Uday Pai
n:              Pai;Uday
email;internet: uday@ionet.net
title:          CyberDude
note:           URL: http://www.ionet.net/~uday/
x-mozilla-cpt:  ;0
x-mozilla-html: FALSE
version:        2.1
end:            vcard


--------------2F1D687417872DB49EF399B6--



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

Date: 6 Jun 1998 23:54:48 GMT
From: gabor@vmunix.com (Gabor)
Subject: Re: DBD::Oracle: finish doesn't free resources
Message-Id: <slrn6njm7f.n4g.gabor@vnode.vmunix.com>

In comp.lang.perl.misc, Todd Hivnor <hivnor@shore.net> wrote :
#  I'm using perl 5.004_04 with DBI 0.93, DBD:Oracle 0.48, 
# and Oracle 7.3 on Solaris 2.5. 
# 
#   It seems that that the finish method doesn't actually 
# free any resources. Specifically, if I repeatedly prepare, 
# execute, and finish a statement handle, I get an 
# "ORA-01000: maximum open cursors exceeded (DBD: oopen error)" 
# error. 

Couple of things.  DBD::Oracle 0.50 is out.  Subscribe to
dbi-users@fugue.com.

gabor.
--
    You want it in one line?  Does it have to fit in 80 columns? :-)
        -- Larry Wall in <7349@jpl-devvax.JPL.NASA.GOV>


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

Date: Sat, 6 Jun 1998 23:19:24 GMT
From: Peter A Fein <p-fein@uchicago.edu>
Subject: Re: Foreach Efficiency
Message-Id: <87zpfqw22r.fsf@bj2-64.rh.uchicago.edu>

Gellyfish@btinternet.com (Jonathan Stowe) writes:

> When you say:
> 
> >But don't give me a hard time b/c I didn't like your response.
> 
> You are lapsing into a state of mind that will win you few favours.
> These people know of what they speak.

I've seem to have lost my requisite Usenet thick skin some time in the
last few days ... wonder where it went.  Oh well.

-- 
Peter Fein                                                         773-834-6206
1005 E. 60th St.                                              Chicago, IL 60637
p-fein@uchicago.edu                                   http://pfein.home.ml.org/


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

Date: Sun, 07 Jun 1998 00:44:16 GMT
From: pehanna@my-dejanews.com
Subject: Re: How to make a list of combinations?
Message-Id: <6lcnp0$lrq$1@nnrp1.dejanews.com>


> Given a list of n elements, such as qw(A B C D), I need to iterate
> through all possible combinations, starting with the full combination
> of n elements (A B C D), then (in any order) all combinations with
> n-1 elements, such as (A B C), (A B D), (B C D), etc., then all
> combinations with n-2 elements, and so on.

You want the power set of the list, the set of all its subsets.  If there are
n elements, and each element can either be present or absent in some subset,
then there are 2**n possible subsets.  One way to find all of them is:

my @list = qw(A B C D);
my $nsubsets = 1 << @list;
my ($i, $j, @masterList);

#  Iterate through all possible subsets, using the binary value of
#  the subset number to map inclusion (1) or exclusion (0) of
#  elements from the current subset.

for ($i = 0; $i < $nsubsets; $i++) {
   my $mask = $i;
   my @subset = grep (($j = $mask, $mask >>= 1, $j & 1), @list);
   my @copy = @subset;           # Optional -- see below
   push(@masterList, \@copy);    # Optional -- see below
}

#  Sort descending by number of elements so that subsets of the same order
#  are listed together.  You could skip this step and just process the
#  subsets as they are enumerated above if this is not a requirement.

for (sort {@$b <=> @$a} @masterList) {
   my @subset = @$_;
   print "@subset\n";
}

There ought to be a clever way to do this with recursion, but I can't think of
it at the moment.

--
Phil Hanna

-----== Posted via Deja News, The Leader in Internet Discussion ==-----
http://www.dejanews.com/   Now offering spam-free web-based newsreading


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

Date: Sat, 6 Jun 1998 16:00:59 -0700
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: Idiom for updating file?
Message-Id: <MPG.fe36a0813913fef989682@nntp.hpl.hp.com>

In article <6lce2h$rdj$1@marina.cinenet.net>, cberry@cinenet.net says...
 ... 
>   open DB, '+< dbfile' or die $!;
>   flock DB, LOCK_EX;
>   { local $/; $data = <DB>; }
>   # Process data here; external rep lands back in $data.
>   truncate DB, 0;
>   seek DB, 0, 0;
>   print DB, $data;
>   flock DB, LOCK_UN;
>   close DB;
> 
> Does that look like a valid approach?  Is there anything I'm neglecting to
> do, or doing improperly?  Is there a better way?

Gosh, your code looks familiar.  This comes from perlfaq5, with error 
checking snipped so it fits nicely here:

    use Fcntl;
    sysopen(FH, "numfile", O_RDWR|O_CREAT, 0644) or die ...
    flock(FH, 2)                                 or die ...
    $num = <FH> || 0;
    seek(FH, 0, 0)                               or die ...
    truncate(FH, 0)                              or die ...
    (print FH $num+1, "\n")                      or die ...
    # DO NOT UNLOCK THIS UNTIL YOU CLOSE
    close FH                                     or die ...

It is neither necessary nor wise to unlock the file before closing it.  
If there are any data from the 'print' that have not yet been flushed to 
the file (there is no 'select DB; $|=1' in your script, nor should there 
be one), another process might intervene after the unlock, and mess with 
the file before your data get there.  Just closing the file does an 
unlock also, in one atomic operation.

As for whether it is necessary to rewind a file after truncating it to 
zero length, that was discussed here recently -- inconclusively, I 
thought.  At any rate, it can't hurt.

There might be a tiny performance improvement by doing
  truncate DB, length $data;
instead of truncating to zero.  I don't know if it would be perceptible.  
If you do that, you will certainly need the rewind.

-- 
Larry Rosler
Hewlett-Packard Laboratories
lr@hpl.hp.com


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

Date: 6 Jun 1998 23:54:44 GMT
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: Idiom for updating file?
Message-Id: <6lcks4$5q8$1@csnews.cs.colorado.edu>

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

In comp.lang.perl.misc, lr@hpl.hp.com (Larry Rosler) writes:
:>   truncate DB, 0;
:>   seek DB, 0, 0;
:>   print DB, $data;

It would be slightly better to do this:

    open(FH, "+< FILE")                 or die "open: $!";
    flock(FH, 2)			or die "flock: $!";
    @ARRAY = <FH>;
    ##########
    # change ARRAY here
    ##########
    seek(FH,0,0)                        or die "seek: $!";
    print FH @ARRAY                     or die "print: $!";
    truncate(FH,tell(FH))               or die "trunc: $!";
    close(FH)                           or die "close: $!";

Because then you don't first free and then re-allocate the 
datablocks for the file.  And don't mix in syswrite here.

--tom
-- 
    "Help save the world!"              --Larry Wall in README


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

Date: Sat, 6 Jun 1998 18:20:44 -0700
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: Idiom for updating file?
Message-Id: <MPG.fe38ac5f8fb6d8098968c@nntp.hpl.hp.com>

[This followup was posted to comp.lang.perl.misc and a copy was sent to 
the cited author.]

In article <6lcks4$5q8$1@csnews.cs.colorado.edu>, tchrist@mox.perl.com 
says...
>  [courtesy cc of this posting sent to cited author via email]
> 
> In comp.lang.perl.misc, lr@hpl.hp.com (Larry Rosler) writes:
> :>   truncate DB, 0;
> :>   seek DB, 0, 0;
> :>   print DB, $data;
> 
> It would be slightly better to do this:
> 
>     open(FH, "+< FILE")                 or die "open: $!";
>     flock(FH, 2)			or die "flock: $!";
>     @ARRAY = <FH>;
>     ##########
>     # change ARRAY here
>     ##########
>     seek(FH,0,0)                        or die "seek: $!";
>     print FH @ARRAY                     or die "print: $!";
>     truncate(FH,tell(FH))               or die "trunc: $!";
>     close(FH)                           or die "close: $!";
> 
> Because then you don't first free and then re-allocate the 
> datablocks for the file.  And don't mix in syswrite here.

Who would do that? :-)

We agree that truncating the file before printing is less efficient than 
printing first then truncating.  And now I see a bug in what I proposed:

print DB, $data;
truncate DB, length $data;

On systems where "\n" is multi-byte externally, this would lop data off 
the end of the file -- a definite no-no.  Your 'truncate FH, tell FH' 
always gives the right result.  (As for the use of $data instead of 
@ARRAY, that was the submitter's choice, which he is entitled to.)   

Not losing data is certainly 'slightly better'!  I assume that's what you 
meant.

-- 
Larry Rosler
Hewlett-Packard Laboratories
lr@hpl.hp.com


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

Date: Sat, 6 Jun 1998 16:23:12 -0700
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: IP to DNS
Message-Id: <MPG.fe36f3dd6a29bc5989684@nntp.hpl.hp.com>

In article <35798FFC.24D8869E@jaske.com>, stathy@jaske.com says...
> Hi,
>         I currently have my httpd log files logging the
> visiting
> clients ip address.  Some of my clients would like these to be
> the domain names for there use.  I would not like this to be
> done on the server end (slow down) but would instead like to
> write a script which parses the information (ip addresses) and
> converts them to domain names.  I am stuck on that part.  Am
> currently trying to use the function gethostbyaddr() but am
> unable to determine how to convert the ip addresses into a
> format that gethostbyaddr() can use.
> 
> Any suggestions?
> 

This has always worked for me:

gethostbyaddr(pack('C4', split /\./, $ip_addr), 2)

If you are fastidious, you can use a symbolic constant for that '2'.

There has been lots of talk here about IP addresses that do not comprise 
four octets, but to me they are like purple cows -- I've never seen one 
(except in those discussions, of course :-).

-- 
Larry Rosler
Hewlett-Packard Laboratories
lr@hpl.hp.com


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

Date: Sat, 6 Jun 1998 19:58:06 -0500
From: REUBEN LOGSDON <rlogsdon@io.com>
To: Stathy Touloumis <stathy@jaske.com>
Subject: Re: IP to DNS
Message-Id: <Pine.BSI.3.96.980606195111.639D-100000@pentagon.io.com>

it has to get packed into some binary format:

$IP = '140.140.1.1';
if ($IP =~ m!^(\d+)\.(\d+)\.(\d+)\.(\d+)$!) {
        $addr = (gethostbyaddr((pack('C4',$1,$2,$3,$4)),2))[0];
	print $addr;
        }

$addr will return null if resolution fails

Regards,
Reuben Logsdon


On Sat, 6 Jun 1998, Stathy Touloumis wrote:

> Hi,
>         I currently have my httpd log files logging the
> visiting
> clients ip address.  Some of my clients would like these to be
> the domain names for there use.  I would not like this to be
> done on the server end (slow down) but would instead like to
> write a script which parses the information (ip addresses) and
> converts them to domain names.  I am stuck on that part.  Am
> currently trying to use the function gethostbyaddr() but am
> unable to determine how to convert the ip addresses into a
> format that gethostbyaddr() can use.
> 
> Any suggestions?
> 
> stathy@jaske.com
> 
> 



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

Date: Sat, 6 Jun 1998 19:29:25 -0500
From: REUBEN LOGSDON <rlogsdon@io.com>
To: Marc Day <mnd02@keele.ac.uk>
Subject: Re: Is PERL case sensitive?
Message-Id: <Pine.BSI.3.96.980606192904.639A-100000@pentagon.io.com>

perl is case sensitive, so yeah that might be a problem

Regards,
Reuben Logsdon


On Thu, 4 Jun 1998, Marc Day wrote:

> I am writing a PERL script that parses information. I have a problem
> in the fact that it will not write the information to the email. I
> think my problem may be that I am using a command that uses $FORM in
> one part of the script and $Form in another part. Does this matter? Is
> this the answer to my three week nightmare????
> 
> Thanx in advance
> 
> Marc
> mnd02@keele.ac.uk
> 
> 



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

Date: Sat, 6 Jun 1998 19:38:19 -0500
From: REUBEN LOGSDON <rlogsdon@io.com>
To: Martien Verbruggen <mgjv@comdyn.com.au>
Subject: Re: Is PERL case sensitive?
Message-Id: <Pine.BSI.3.96.980606193640.639B-100000@pentagon.io.com>

On 5 Jun 1998, Martien Verbruggen wrote:

> Subject: Is PERL case sensitive?
> 
> Depends what you mean. 
> 
> It is perl for the program, Perl for the language. Never PERL. 
> 
> That is case sensitive. The program perl, and the language Perl are
> both case sensitive as well. I don't really know about PERL.

PERL is an acroynm for "Practical Extraction and Report Language".  It's
common practice to capitalize acronyms.

Regards,
Reuben Logsdon       


> Martien
> -- 
> Martien Verbruggen                  | 
> Webmaster www.tradingpost.com.au    | 
> Commercial Dynamics Pty. Ltd.       | Curiouser and curiouser, said Alice.
> NSW, Australia                      | 
> 
> 



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

Date: 7 Jun 1998 00:39:07 GMT
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: Is PERL case sensitive?
Message-Id: <6lcnfb$7p4$1@csnews.cs.colorado.edu>

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

In comp.lang.perl.misc, 
    REUBEN LOGSDON <rlogsdon@io.com> writes:
:PERL is an acroynm for "Practical Extraction and Report Language".  It's
:common practice to capitalize acronyms.

You're embarrassing yourself with ignorance of the culture, and
of its history.

--tom
-- 
    "That which does not kill me makes me stranger." --Larry Wall


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

Date: Sat, 6 Jun 1998 20:38:49 -0500
From: REUBEN LOGSDON <rlogsdon@io.com>
To: plener@ibm.net
Subject: Re: lines of text, inserting spaces
Message-Id: <Pine.BSI.3.96.980606203550.639I-100000@pentagon.io.com>

yeah, so you have a big <FILE> and wnat spaces at arbitrary points (say
10th and 20th spots?

open(F,"<in");
open(F2,">out");
while (<F>) {
	if (m!^(\.{10})(\.{10})(.*)$!) {
		print F2 "$1 $2 $3"; # <- spaces now
		}
	else {
		print F2;
		print "uhoh pattern failed on $_\n";
		}
	}
close(F); close(F2)

Regards,
Reuben Logsdon


On Sat, 6 Jun 1998 plener@ibm.net wrote:

> newbie needs some help on inserting spaces in lines of continuous
> text--fi;e is 250 megs of text data and each line is erminated by a
> carrage return
> data looks like this 112121821745647263562393434941947 ......cr
> i need to insert spacea at certain positions
> so data looks like this
> 1212 1218 45678 7677767 121212..
> please note that the above data is just examples
> i need to insert the space to act as a deliminater for a statistical
> data file
> can you help?
> i have looked in the books and kind of got some idea on how to do it
> but really need a little basic help
> could you  please also email me your answer?
> plener@ibm.net
> 
> 
> 



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

Date: Sat, 6 Jun 1998 20:30:06 -0500
From: REUBEN LOGSDON <rlogsdon@io.com>
To: Jim Fritz <jimfritz@softhouse.com>
Subject: Re: Looking for upload.pl
Message-Id: <Pine.BSI.3.96.980606202927.639H-100000@pentagon.io.com>

saw one at http://terminalp.com/scripts/

Regards,
Reuben Logsdon


On Sat, 6 Jun 1998, Jim Fritz wrote:

> I am looking for a perl script to allow users to upload small text files
> from their browsers.  I have seen mention of a script called upload.pl;
> but I am sure there are many more out there.  However I haven't as of
> yet been able to find any.  If anyone could point me in the right
> direction I would really appreciate it.
> 
> Jim Fritz
> -- 
>  F&H SoftHouse, Inc.   jimfritz@softhouse.com
>  39 West 32nd Street   Holland, MI 49423-5061
>  Phone: (616) 395-9556    Fax: (616) 395-9557
>          http://www.SoftHouse.com/
> 
> 



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

Date: Sat, 6 Jun 1998 16:40:00 -0700
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: newbie problem opening pipe
Message-Id: <MPG.fe3732b513c130c989685@nntp.hpl.hp.com>

In article <6lbva1$mq4$1@nnrp1.dejanews.com>, sweth@my-dejanews.com 
says...
> I have a bunch of shell-script-based cgi pages that I'm trying to convert to
> perl, to which I am very new.  One of the pages keeps exiting with a syntax
> error on line 26 (below, along w/ line 27) that I can't figure out.  I'm
> trying to mail the output of a subroutine using mailx; the line in question
> is copied straight from the camel book's section on anonymous pipes, with a
> different filehandle name and a different command after the pipe (obviously).
>  what am i missing here?
> 
> 26: open MAILER, "| /usr/bin/mailx -s 'SMTP Registration Submitted' $NOTIFY"
> 27:    or die "$REGFAIL" ;

Often compilers like Perl will become aware of a syntax error on the line 
*after* the one in which the error actually occurs.  You have not shown 
line 25, which may well be where the actual error lies.

-- 
Larry Rosler
Hewlett-Packard Laboratories
lr@hpl.hp.com


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

Date: Sat, 06 Jun 1998 20:21:38 -0400
From: David Wasserstrum <zeos@gti.com>
To: Jonathan Stowe <Gellyfish@btinternet.com>
Subject: Re: Problem: With the $ENV{'blah'} variable
Message-Id: <3579DD12.C94CA6C3@gti.com>

as you suggested I tried calling my CGI from the command line and it returned
with the correct output (that being all my environmental settings.)  It
still, however, does not work from my web server.  I have this odd feeling
that my Windows Apache server is not setting the environmental variables
before calling perl.exe.  I'm not quite sure how to fix that though...

Jonathan Stowe wrote:

> On Sat, 06 Jun 1998 15:30:24 -0400, David Wasserstrum wrote :
>
> >I just installed a Windows Apache server and am having problems with
> >perl CGI programing.  Programs that are simple such as print "Hello";
> >run just fine.  Programs, however, that require ENV variables are not
> >working...
> >
>
> Eh,oh
>
> >recently I tried the following:
> >
> >#!perl.exe
> >print "\n";
> >while (($key,$value) = each %ENV) {
> >   print "$key=$value\n";
> >}
> >
> >   but I did not recieve any output.  This leads me to conclude that for
> >
>
> Of course you deliberately omiitted the :
>
> print "Content-type:  text/html\n\n";
>
> didnt you ?
>
> >some reason my apache web server is not creating any enviromental
> >variables before calling perl.exe.  Is this correct???  (i'm not a great
> >
>
> Of course there is wealth of fine documentation available to you
> regarding the module CGI.pm and there is also a vast  wealth of
> documentation regarding CGI in particular and so and and so forth...
>
> >perl programer so I'm not sure if my source code is correct.)
> >
> >Thanks for your time,
> >   David wasserstrum
>
> No problem
>
> /J\
> Jonathan Stowe
> Some of your questions answered:
> <URL:http://www.btinternet.com/~gellyfish/resources/wwwfaq.htm>





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

Date: Sat, 06 Jun 1998 18:17:43 -0700
From: "Xah" <xah@best.com>
Subject: Q: puzzled: regex with inperpolation
Message-Id: <6lcpbh$rn5$1@nntp2.ba.best.com>

I'm puzzled by this one. The puzzle is: When a regex is using interpolation,
it doesn't match, but if the string literal is used, it matches.

#!/usr/local/bin/perl -w
use strict;
my $str = 'shouldMatch.m';
my $patternString = q{(\Q.m\E|\Q.nb\E)$};
# if ($str =~ m/(\Q.m\E|\Q.nb\E)$/) {print 'matched';} else {print 'just say
no.';};
  if ($str =~ m/${patternString}/) {print 'matched';} else {print 'just say
no.';};
__END__

In the above code, it'll print no. But if the commented line is switch,
it'll print yes. The answer is probably some obscurity about regex with
interpolation that I forgot.

 Xah, xah@best.com
 http://www.best.com/~xah/Wallpaper_dir/c0_WallPaper.html
 "I heart Dvorak keyboard."


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

Date: 7 Jun 1998 01:23:02 GMT
From: ilya@math.ohio-state.edu (Ilya Zakharevich)
Subject: Re: Q: puzzled: regex with inperpolation
Message-Id: <6lcq1m$jo9$1@mathserv.mps.ohio-state.edu>

[A complimentary Cc of this posting was sent to Xah
<xah@best.com>],
who wrote in article <6lcpbh$rn5$1@nntp2.ba.best.com>:
> I'm puzzled by this one. The puzzle is: When a regex is using interpolation,
> it doesn't match, but if the string literal is used, it matches.
> 
> #!/usr/local/bin/perl -w
> use strict;
> my $str = 'shouldMatch.m';
> my $patternString = q{(\Q.m\E|\Q.nb\E)$};
> # if ($str =~ m/(\Q.m\E|\Q.nb\E)$/) {print 'matched';} else {print 'just say
> no.';};
>   if ($str =~ m/${patternString}/) {print 'matched';} else {print 'just say
> no.';};
> __END__
> 
> In the above code, it'll print no. But if the commented line is switch,
> it'll print yes. The answer is probably some obscurity about regex with
> interpolation that I forgot.

\Q and \E work during interpolation, they have nothing to do with RE
engine.  m// implies interpolation.  Both 

    $var = q{FOO}; 

and 

    m/$var/ 

do not interpolate FOO (first since you explicitly asked for it,
second - since this would be *double* interpolation).

A new qr// (Quote-as-in-Re) operator would have been available now,
except for the strike of Perl developers.  Then you could have used it
instead of your q//.

Hope this helps,
Ilya


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

Date: Sat, 6 Jun 1998 20:15:53 -0500
From: REUBEN LOGSDON <rlogsdon@io.com>
To: Tan <tan@jettech.dircon.co.uk>
Subject: Re: Reading a file from the bottom up
Message-Id: <Pine.BSI.3.96.980606201207.639F-100000@pentagon.io.com>

On Sat, 6 Jun 1998, Tan wrote:
> Is there a way to read files starting from the end?

yea

this reads the file lien-by-line:
open(F,"<file");
foreach (<F>) {
	$myLine = $_;
	&doSomethingWith($myLine);
	}

this reads file line-by-line from last line to first line:
open(F,"<file");
foreach (reverse <F>) {
	$myLine = ..etc
	}

Regards,
Reuben Logsdon


> Data coming in from a switch appends to a file so that the most recent
> records are at the end of the file. To reduce processing time I would like
> to start searching for the most recent data and so would like to start
> reading from the end of the file to the beginning in order to cut processing
> time down.
> 
> Any help would be gratefully appreciated.
> 
> Regards
> Tan
> 
> 
> 
> 
> 
> 



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

Date: Sat, 6 Jun 1998 20:17:50 -0500
From: REUBEN LOGSDON <rlogsdon@io.com>
To: Martine Habib <mhabib@microsoft.com>
Subject: Re: Removing a character from a string
Message-Id: <Pine.BSI.3.96.980606201656.639G-100000@pentagon.io.com>

yea

$string = 'this&that';
$string =~ s/\&//g; # substitute "&" with null globally
print $string; # -> 'thisthat'



Regards,
Reuben Logsdon


On Fri, 5 Jun 1998, Martine Habib wrote:

> If I have a string $string = "this&that";
> I want to remove the ampersand, and end up with $string = "thisthat";
> 
> How can I do this in perl ?
> Thanks for any help,
> 
> Martine
> 
> 
> 
> 



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

Date: Sun, 07 Jun 1998 00:03:26 GMT
From: kenny@kacweb.com (Kenny A. Chaffin)
Subject: Re: Saving dynamically created images
Message-Id: <MPG.fe384ac5bc621d8989f3c@news.dimensional.com>

In article <3579A3F5.AAACC02D@jaske.com>, stathy@jaske.com says...
> Hmmm, sounds like stealing to me . . .
> 
> Why not just use the <IMG SRC> call from their site?
> 
> Derrick Lathem wrote:

> > Basically, I am trying to display a weathermap as a .gif or .jpg on my
> > site but the site that displays the current map dynamically creates
> > the image, so the name is not consistent.  I don't want to link to
> > their site or anything easy either.
> > 
> > I want to hit their site via a script in cron, parse out the image
> > name, "grab" that image (save it on my webserver), and save it as a
> > certain name.  This script is actually running on a webserver.

Agreed, unless you have arranged with the site to use there data - which 
is wbat the map they are generating is, then you probably shouldn't be 
doing it. There have been numerous cases of people getting into legal 
trouble by doing what you describe.
It would be relatively simple to do, but probably not legal unless you 
have their approval.

-- 
KAC
Website Design, Programming, Graphics --> http://www.kacweb.com
kenny@kacweb.com


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

Date: Sat, 6 Jun 1998 17:43:29 -0700
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: striphtml program
Message-Id: <MPG.fe3820a3545febb989687@nntp.hpl.hp.com>

In article <1998060617153300.NAA21782@ladder01.news.aol.com>, 
bbirthisel@aol.com says...
> Hi Jonathan:
 ...
> >This snippet contains a modified version of the regular expression in
> >question that does work:
> >
> >#!perl 
> >while(<>)
> >{
> >s/(?:<[^>'"]*|".*?"|'.*?')+>//gs;
> >print;
> >}
> >
> >>Does anybody have any idea what has changed between 5.002 (called for
> >>in the program) and perl 5.004 to cause this error?  
> 
> Without looking up the entire original expression, I'm going to guess that it
> provided for multi-line matches (the last "s" in your snippet). Since MS-DOS
> like OSs use CRLF, that's a place to look.

Odd that the regex provides for multi-line matches, while it is executed 
in a single-line-at-a-time loop.  Better to read the whole file into a 
scalar before applying the regex.

And then the peculiarities of how various OSs represent end-of-line 
externally are irrelevant, because Perl translates all such 
representations to and from the single character represented by \n, which 
is not matched by /./ unless the 's' modifier is used (which the above 
regex correctly demands to handle multi-line HTML tags).

-- 
Larry Rosler
Hewlett-Packard Laboratories
lr@hpl.hp.com


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

Date: Sat, 6 Jun 1998 20:10:36 -0500
From: REUBEN LOGSDON <rlogsdon@io.com>
To: gateway <betabeta@geocities.com>
Subject: Re: Stupid syntax question
Message-Id: <Pine.BSI.3.96.980606200930.639E-100000@pentagon.io.com>

you are forgiven   :)

my @array = ('foo','bar');
$i =0;
foreach (@array) {
	print "this is element $i: ";
	print "$_\n";
	$i++;
	}

Regards,
Reuben Logsdon


On Sat, 6 Jun 1998, gateway wrote:

>     I just started learning Perl, so forgive me if this is stupid. I can't
> seem to get the syntax right. what I want to do is use a loop to cycle
> through all elements in an array, one at a time, using a variable as the
> array index (ie &array[$counter]). can someone clear this up for me.
> I'm sorry if this sounds simple, but I've tried everything I can think of.
> 
> Zen
> 
> 
> 
> 



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

Date: 6 Jun 1998 23:45:20 GMT
From: gerg@shell. (Greg Andrews)
Subject: Re: Why is there no "in" operator in Perl?
Message-Id: <6lckag$3pd$3@news.ncal.verio.com>

glengk@mindspring.com (Glen Koundry) writes:
>
>Actually the point to my question was not "what is the fastest way to
>search a list?".  I think an "in" operator would make the code a lot
>easier to write (and to read as well).
>

So would good comments on the line(s) above the search code.

  -Greg


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

Date: 6 Jun 1998 20:55:43 -0400
From: allbery@kf8nh.apk.net (Brandon S. Allbery KF8NH)
Subject: Re: Why is there no "in" operator in Perl?
Message-Id: <6lcoef$hpq$1@rushlight.kf8nh.apk.net>

Also sprach gerg@shell. (Greg Andrews) (<6lckag$3pd$3@news.ncal.verio.com>):
+-----
| glengk@mindspring.com (Glen Koundry) writes:
| >search a list?".  I think an "in" operator would make the code a lot
| >easier to write (and to read as well).
| So would good comments on the line(s) above the search code.
+--->8

Aside from which, if readability is such a concern, you probably are asking at
the wrong window.  :-)

-- 
brandon s. allbery	   [team os/2][linux][japh]	 allbery@kf8nh.apk.net
system administrator, ece facilities			   allbery@ece.cmu.edu
carnegie mellon university			   (bsa@kf8nh is still valid.)


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

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

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