[13058] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 468 Volume: 9

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Aug 11 19:08:33 1999

Date: Wed, 11 Aug 1999 16:05:09 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Wed, 11 Aug 1999     Volume: 9 Number: 468

Today's topics:
    Re: CGI timeout problem <diggem@cat.com>
    Re: Dereferencing anon hash (Steve Linberg)
        Help with -X (Jason W. Storer)
    Re: HELP (Larry Rosler)
    Re: How to delete an element from an array (Charles DeRykus)
    Re: How to delete an element from an array <Monty.Scroggins@mci.com>
    Re: Making a new web page out of an existing page (Steve Linberg)
        Multi-Page Forms (Wayne)
    Re: Newbie: Looking for help/info on Sockets with Win32 (elephant)
    Re: Newbie: MailTo Script Problem? (Steve Linberg)
    Re: obtaining local IP address in ActivePerl (Charles DeRykus)
    Re: Perl is eating up my memory <cassell@mail.cor.epa.gov>
    Re: Perl Novice needs advice (Steve Linberg)
    Re: PERL on Windows: Print displays only blank lines <laurensmith@sprynet.com>
        printf vs. sprintf: inconsistent? <michael@kbk.org>
    Re: reference to object method (Damian Conway)
    Re: require mylib.pl (Larry Rosler)
    Re: s/// and interpolation (Bill Moseley)
    Re: s/// and interpolation <tchrist@mox.perl.com>
        Stripping quotes only from HTML tags <resource@ERASEjps.net>
    Re: turn $6 into $6000 (Larry Rosler)
    Re: UpperCase first letter of string only. (Larry Rosler)
    Re: working with imagery (Steve Linberg)
        Digest Administrivia (Last modified: 1 Jul 99) (Perl-Users-Digest Admin)

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

Date: Wed, 11 Aug 1999 17:47:55 -0500
From: "Duane G. Meyer" <diggem@cat.com>
Subject: Re: CGI timeout problem
Message-Id: <37B1FD9B.467C2766@cat.com>



Steve Linberg wrote:
> 
> In article <linberg-1108991430220001@ltl1.literacy.upenn.edu>,
> linberg@literacy.upenn.edu (Steve Linberg) wrote:
> 
> > It sounds like you need to learn more about HTTP connections.
> 

This is certainly true. I can always learn more.

> 
> Rereading this, it sounds harsher than I intended.  I apologize if it
> sounded condescending, I didn't mean it that way.

It did.. =) I started to read and went "woof, where's the fire bucket!
douse me please!" 

> Again, apologies if I came off the wrong way.  Good luck.

Appologies accepted. When I put 'little' that was certainly subjective.
I've been searching hi-n-lo for a week or three now. And finally
somebody pointed be at deja.com and I found some examples that should
give me a good start. 

And yes, it's written in perl, but the "work" gets done with a shell
script that's written and run at run time from the perl script. 

My appologies also, I'll be certain to try and be more specific when I
post something to the group. 

Thanks,
Duane


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

Date: Wed, 11 Aug 1999 18:26:27 -0400
From: linberg@literacy.upenn.edu (Steve Linberg)
Subject: Re: Dereferencing anon hash
Message-Id: <linberg-1108991826270001@ltl1.literacy.upenn.edu>

In article <37B1DED6.8017EB7F@lanl.gov>, Josh Goodman <jogoodma@lanl.gov> wrote:

> $test = %{$database{"crd.9.m0"}} ->{"1"};
  ^       ^

Without even looking at your code, it's plain that you have a problem
here.  You're trying to equate a scalar with a hash.  Probably not what
you want.

Remember that the basic way to dereference a hashref is either:

$$hr{"foo"}

-or-

$hr->{"foo"}

Go from there.  Good luck!

-- 
Steve Linberg, Systems Programmer &c.
National Center on Adult Literacy, University of Pennsylvania
Be kind.  Remember, everyone you meet is fighting a hard battle.
print 'Just Another Perl ' . $perl_hierarchy[(USER+EXPERT)/2];


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

Date: 11 Aug 1999 22:22:31 GMT
From: jstorer@okapi.uvm.edu (Jason W. Storer)
Subject: Help with -X
Message-Id: <7ost37$1efgt$1@swen.emba.uvm.edu>

Hi, I'm writing a program that reads and writes to files and I found the
-e filetest operator.  Using the syntax shown in the perlfunc/_X.html
manpage, I wrote this code:

sub GetBusiness { my($Business)=@_;
	$file="$FilesDirectory/business.dat";
	if -e $file {
		open (bdata, "<$file");
		while (!eof(bdata) && ($Business ne $record[0])) {
			sysread (bdata, $data, 250);
			@record=split('~~', $data);
		}
		close (bdata);
	}

	return @record;
}

It doesn't like the -e.  What am I doing wrong and how can I fix it?
Thanks!  -Jason



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

Date: Wed, 11 Aug 1999 15:34:24 -0700
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: HELP
Message-Id: <MPG.121b9a4995a5eac1989e37@nntp.hpl.hp.com>

In article <772qx@questionexchange.com> on 11 Aug 1999 21:56:39 GMT, 
QuestionExchange <USENET@questionexchange.com> says...
+ > I have a problem on determining a RE:
+ > I use UNPACK function with the format "A11A12A256A12A41A31".
+ > I would like to sum every length field "A" with a RE (for
+ > example, the
+ > result of this format should be 363).
+ > I have tried this but it isn't very powerfull!
+ > ------code-------------------------------------------
+ > #!/usr/bin/perl
+ > $format = "A11A12A256A12A41A31";
+ > @t = split(/A/, $format); $len = 0;
+ > for $x (@t) {$len += $x;}
+ > print "somme=$len\n";
+ > ------code-------------------------------------------
+ > How can I manage this?
+ > Thanks,
+ > Dominique Crétel
+ 
+ your code to the shorter
+ $len = 0;
+ for (split /A/, $format) { $len += $_ }
+ If you don't care about the string
+ remaining as it is, you can of course
+ be really crude:
+ $format =~ s/(\d+)/$len+=$1;$1/ge;
+ or do
+ while($format =~ /(\d+)/g) { $len += $1 }
+ There are always many ways to do it.

When, at least this one is formatted reasonable, even though the blank 
lines are gone.  And the answer is only moderately worse than those 
posted yesterday.  So there is progress!

-- 
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com


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

Date: Wed, 11 Aug 1999 21:51:08 GMT
From: ced@bcstec.ca.boeing.com (Charles DeRykus)
Subject: Re: How to delete an element from an array
Message-Id: <FGBM18.6B6@news.boeing.com>

In article <37b1d968.8951042@news.attcanada.net>,
Dico Reyers <dico@internetworks.ca> wrote:
>Hello there,
>
>Could someone please let me know if it is possible to delete an
>element from an array in perl?
>
>@array = ("one","two and three",4,"five");
>
>how do I delete '4' and be left with...
>
>@array = ("one","two and three","five");
>

@array = map {$_ == 4 ? () : $_} @array; 

hth,
--
Charles DeRykus



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

Date: Wed, 11 Aug 1999 22:34:01 GMT
From: "Monty Scroggins" <Monty.Scroggins@mci.com>
Subject: Re: How to delete an element from an array
Message-Id: <tTms3.1383$8X1.126085@PM01NEWS>



> Could someone please let me know if it is possible to delete an
> element from an array in perl?
>
> @array = ("one","two and three",4,"five");

I think:
splice(@array,3,1);

Monty




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

Date: Wed, 11 Aug 1999 18:27:19 -0400
From: linberg@literacy.upenn.edu (Steve Linberg)
Subject: Re: Making a new web page out of an existing page
Message-Id: <linberg-1108991827190001@ltl1.literacy.upenn.edu>

In article <37b1eddb.102089770@news.cadvision.com>, (Eddie) wrote:

> Is it possible to create a web page by "stealing" certain text
> passages from an existing web page on your web server?  I've never
> used perl before but if it can do this i'd like to start learning it.
> The script would have to search for certain text in a filename and
> then generate a new web page using an existing template.

Yes, Perl is ideal for this kind of task.

-- 
Steve Linberg, Systems Programmer &c.
National Center on Adult Literacy, University of Pennsylvania
Be kind.  Remember, everyone you meet is fighting a hard battle.
print 'Just Another Perl ' . $perl_hierarchy[(USER+EXPERT)/2];


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

Date: Wed, 11 Aug 1999 22:25:08 GMT
From: headdog<no spam>@usa.net (Wayne)
Subject: Multi-Page Forms
Message-Id: <37b7f839.78552459@news.remarq.com>

Can someone tell me what technology (CGI, JavaScript, etc.) is used to make
those multi-form questioners you see around the net. For example, when you
first sign up or place an order at an online store you might be asked for
your name and the username and password you want to use. Once you've finally
found a username that isn't already being used, you're redirected to a form
asking for your address. Then maybe, after filling out your address, your
presented with a credit card form.

Preferably, I'd like to use this in CGI, but anything will do for now. Is
there a certain resource site that I might find cut-n-paste scripts of this
procedure on? I've checked the usual suspects, such as cgi-resources.com
and scriptsearch.com, but I can't seem to find anything like this. Maybe I
just don't know what I'm looking for.

I currently have an extremely long form that people fill out, and are then
presented with a printable form with everything they filled out under the
appropriate categories so that they can snail mail this form in. I'm using
CGI to do this. I basically want to divide the long form up into 2 or 3
different forms so there's not so much scrolling, etc.

I'd appreciate any help on this matter.

Thanks,

Wayne


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

Date: Thu, 12 Aug 1999 09:00:01 +1000
From: elephant@squirrelgroup.com (elephant)
Subject: Re: Newbie: Looking for help/info on Sockets with Win32
Message-Id: <MPG.121cab798f9f07fc989c0d@news-server>

Chris writes ..
>Does anyone know of some "Sockets in Perl for people who don't know
>Sockets" material, or even just some sample source code?

how about the plethora of examples in the perlipc manual ?

  perldoc perlipc

or select 'perlipc' from the menu - under Core Perl Docs - in your 
ActiveState html documentation

you may also want to have a look at the IO::Socket module (included in 
the standard Perl distribution) which wraps socket communication up in 
an object syntax

>                                                         I'd like a
>reminder of what all the functions do, as well as what the Perl
>functions return (for example, it looks like gethostbyname() returns
>for packed ints; sensible, but I'd like to know that sort of thing).

all those functions are documented in perlfunc (a shortenned 
concatenation of "perl functions") .. also in your documentation

  perldoc perlfunc

or from the menu of your ActiveState html documentation

-- 
 jason - elephant@squirrelgroup.com -


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

Date: Wed, 11 Aug 1999 18:19:33 -0400
From: linberg@literacy.upenn.edu (Steve Linberg)
Subject: Re: Newbie: MailTo Script Problem?
Message-Id: <linberg-1108991819330001@ltl1.literacy.upenn.edu>

In article <7osis7$d50$1@garnet.nbnet.nb.ca>, "Yellow Beetle"
<firebrand@mail.usa.com> wrote:

> Hi,
> 
> I have a site at:
> www.skyfamily.com/firebrand
> 
> Now under the "comments" tab you can fill in some
> information, and send it using the "submit" button.
> 
> The problem I have is that when you hit "submit"
> you get a message saying, that this is not encrypted,
> and that you will reveal your e-mail address.

That message is from the client's browser, and depends entirely on how
their browser is configured.  Has nothing to do with anything on your end.

> Is there any way in Perl that I can have it look
> more professional? I really don't like having that pop
> up message.

No.  If the client's browser is set to warn them upon submitting forms,
then there's nothing you can do (unless you can figure a way to submit
data without forms, which can be done in very limited ways).

> Also, my server doesn't support Perl,
> and I can't move the page. Can I link this information
> toa site that does support Perl?

Your server is lame, then.  And you don't need Perl for anything you've
described.  In fact, you should have posted this to a CGI newsgroup, not
here.

Do you have a Perl question specifically?

-- 
Steve Linberg, Systems Programmer &c.
National Center on Adult Literacy, University of Pennsylvania
Be kind.  Remember, everyone you meet is fighting a hard battle.
print 'Just Another Perl ' . $perl_hierarchy[(USER+EXPERT)/2];


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

Date: Wed, 11 Aug 1999 21:36:57 GMT
From: ced@bcstec.ca.boeing.com (Charles DeRykus)
Subject: Re: obtaining local IP address in ActivePerl
Message-Id: <FGBLDL.517@news.boeing.com>

In article <37B1AD0B.4C65BD49@nih.gov>,
Jonathan Epstein  <Jonathan_Epstein@nih.gov> wrote:
>Given the lack of getnetbyname() on ActivePerl (Win32) and the apparent
>lack of hostname() when running it under Win95, what tricks do people
>use to obtain their local IP address?
>
>Perhaps there's some trick of connecting to a well-known web server, and
>reading back your own IP address from that server?
>
>I'm familiar with the pseudo-IP address 127.0.0.1 which always refers to
>the local host, but that isn't going to cut it in this case ... I need
>the real IP address.
>

You mean the following which works on NT doesn't work on Win32/95...
   
perl -MSocket 'my $ip=gethostbyname("my_host");print inet_ntoa($ip),"\n"'


There's also a command line `ipconfig' though I'm unsure about 
Win32/95 availability.   



hth,
--
Charles DeRykus


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

Date: Wed, 11 Aug 1999 15:44:06 -0700
From: David Cassell <cassell@mail.cor.epa.gov>
Subject: Re: Perl is eating up my memory
Message-Id: <37B1FCB6.72E7FACE@mail.cor.epa.gov>

Chao Fang wrote:
> 
> I used a array to hold 8M of one digit number. However Perl used up to 240M
> of memory and the process is hang up finally.

240M I can believe.  You're probably using an inefficient storage
mechanism.  30 bytes per element is reasonable in that case.

Perhaps you need to look into a better algorithm.  I can't give
much more advice without seeing some code in this newsgroup.
Can you illustrate your problem with less than 40 lines of code?

> I run the script on a SUN Ultra5 with 128M and Solaris. I use 'top' command
> to watch how much memory is used.

Whoa!  You have an Ultra5, and you only have 128M RAM memory?
You ought to have way more than that.  How big is your /tmp
partition?
 
> The script is quite simple and the array is the only main data structure.
> You can try by just filling enough data in an array and watch what is
> happening.
> 
> Is the answer that Perl is not suitable to process great amount of data?

No.  People regularly handle far larger files in Perl.  But
they *don't* try to slurp the whole file in at once before
doing their analyses.  Read up on while and the angle operator,
and see how to read in your file a line at a time for
processing.  It will be a lot easier to adjust your algorithm
than to re-write everything in C.  Well, it would be for me,
anyway.

David
-- 
David Cassell, OAO                     cassell@mail.cor.epa.gov
Senior computing specialist
mathematical statistician


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

Date: Wed, 11 Aug 1999 18:20:44 -0400
From: linberg@literacy.upenn.edu (Steve Linberg)
Subject: Re: Perl Novice needs advice
Message-Id: <linberg-1108991820440001@ltl1.literacy.upenn.edu>

In article <BWks3.3341$Yu4.120917@news2-hme0.mcmail.com>, "Waiman Mak"
<w.mak@cwcom.net> wrote:

> Dear all,
> Is it possible to configure my own PC as a WEB server so that I can create
> and test my own CGI/Perl scripts?

Yes.  How you do this depends on your PC, though.

-- 
Steve Linberg, Systems Programmer &c.
National Center on Adult Literacy, University of Pennsylvania
Be kind.  Remember, everyone you meet is fighting a hard battle.
print 'Just Another Perl ' . $perl_hierarchy[(USER+EXPERT)/2];


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

Date: Wed, 11 Aug 1999 14:50:01 -0700
From: "Lauren Smith" <laurensmith@sprynet.com>
Subject: Re: PERL on Windows: Print displays only blank lines
Message-Id: <7osr69$tbg$1@brokaw.wa.com>

netnews.msn.com wrote in message ...
>The basic Print command
>doesn't work NT - Is there any environement setup that needs to be
done?
>Thx -Sputnik-

Assuming that you mean 'print()' function, the answer is yes.  You do
need to have Perl installed on your system.
You can get the latest from www.activestate.com

Lauren




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

Date: Wed, 11 Aug 1999 18:36:15 -0400
From: "Michael B. Klein" <michael@kbk.org>
Subject: printf vs. sprintf: inconsistent?
Message-Id: <7ostuo$7b0$1@autumn.news.rcn.net>

I've discovered what I'll call an "understandable but inconsistent" behavior
in Perl, involving the printf and sprintf functions.  Take the following
code:

--snip--
@array = ("%2.2f", 1);

printf @array;
print "\n";
print sprintf @array;
print "\n";
print sprintf $array[0], @array[1..$#array];
print "\n";
--snip--

The first and last calls do what they should -- print the formatted string.
The second, however, simply prints the number of elements in @array.  Why is
@array passed to printf in array context, but sprintf in scalar context?  Am
I missing something?

Michael





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

Date: 11 Aug 1999 22:23:27 GMT
From: damian@cs.monash.edu.au (Damian Conway)
Subject: Re: reference to object method
Message-Id: <7ost4v$nj6$1@towncrier.cc.monash.edu.au>

gbacon@itsc.uah.edu (Greg Bacon) writes:

>C<use strict 'methods'> anyone?  Breakage bad, progress good.

Nice. Off by default under plain C<use strict>, of course.

Damian


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

Date: Wed, 11 Aug 1999 15:17:51 -0700
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: require mylib.pl
Message-Id: <MPG.121b966ed039e645989e35@nntp.hpl.hp.com>

[Posted and a courtesy copy mailed to the answer 'bot'.]

In article <7os4t4$p30$1@lublin.zrz.tu-berlin.de> on 11 Aug 1999 
15:29:40 -0000, Anno Siegel <anno4000@lublin.zrz.tu-berlin.de> says...
> QuestionExchange  <USENET@questionexchange.com> wrote, quoting a
> nicely formatted posting:
> 
> >> The perl cookbook would lead me to believe that perhaps I
> >> should learn how  to write a module because the notion of
> >> libraries is quickly becoming obsolete, however, all I want to
> >> do is store a mass of strings...  const.pl:    $const_str1 =
> >> 'this is string1';    $const_str2 = 'this is string2';     1;
> >> #// const.pl  mytest.pl    #!/usr/bin/perl -w     require
> >> 'const.pl';     print "$const_str1\n";    print
> >> "$const_str2\n";  #// mytest.pl  Now, if there is anything that
> 
> Eeeek.
> 
> Anno

Well, finally someone besides me has spoken up about this, though 
minimally.

I'm sure there's no objection to these answers, except that:

1.  They are anonymous, so there's no one to respond to but an apparent 
bot.

2.  The questions are quoted in full (but before the response, Deo 
gratias for little favors!).

3.  The questions and the answers are unreadably unformatted.

Unless fixed, this will become my first-ever plonkee, because there is 
no chance that I will read another one of them formatted the way they 
are.

-- 
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com


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

Date: Wed, 11 Aug 1999 15:29:33 -0700
From: moseley@best.com (Bill Moseley)
Subject: Re: s/// and interpolation
Message-Id: <MPG.121b9924e1e73ff89896a6@nntp1.ba.best.com>

Steve Linberg (linberg@literacy.upenn.edu) seems to say...
> # ***************************************
> # * *********************************** *
> # * * DANGEROUS: DON'T USE THIS CODE! * *
> # * *********************************** *
> # ***************************************

Thank you.  I was just trying to figure that out.

Is (can) the expressions in your example be somehow pre-compiled to make 
them faster?

I've got a script that makes substitutions in a bunch of files.  I've 
got a hash where the keys/values are the parts of s///.

First, with Larry's and perlfaq6's help, I build a search string to make 
the searching for lines to modify quicker.

my %replace = (
    '(t)(h)(e)'  => '$3$2$1',  # reverse the word 'the'
    'old text'  => 'next text',
);

my $match = build_re_match( keys %replace );  # from perlfaq6

And, with your help, I build the substitutions strings:

my @substitutions = map { "s/$_/$replace{$_}/g" } keys %replace;

Then in my code:

$^I = '.bak';

while (<>) {
    if ( &$match ) {  # check line against all patterns at once

        # at least one matched.  Try all substitutions

        foreach my $expr ( @substitutions ) {
            $changed_lines++ if eval $expr;
        }

    }
            
    print $_;
}

My question is, should (can) the @substitutions expressions be pre-
compiled?  Any other pointers on speeding this up?


-- 
Bill Moseley mailto:moseley@best.com
pls note the one line sig, not counting this one.


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

Date: 11 Aug 1999 16:46:42 -0700
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: s/// and interpolation
Message-Id: <37b1fd52@cs.colorado.edu>

     [courtesy cc of this posting mailed to cited author]

In comp.lang.perl.misc, 
    moseley@best.com (Bill Moseley) writes:
:My question is, should (can) the @substitutions expressions be pre-
:compiled?  Any other pointers on speeding this up?

Here's something from the PCB draft source.

    Program: fixstyle

    Imagine you have a table containing both old strings and new
    strings, such as this:

        Old Words   New Words
        ---------   ---------
        bonnet      hood
        rubber      eraser
        lorrie      truck
        trousers    pants

    The following program is a filter that changes all occurrences
    of the first set to the corresponding version in the second
    set.

    When called without filename arguments, the program acts as a
    simple filter. If files are supplied on the command line, an
    in-place edit leaves the new version in the old names, with
    the original versions safely saved away to a file with a
    `".orig"' appended to it. This is described in ``Modifying a
    File in Place with -i Switch''. A -v command-line option
    enables notification of each change out standard error.

    The table of original strings and their replacements is stored
    below `__END__' in the main program as described in ``Storing
    Files Inside Your Program Text''. Each pair of strings is
    converted into carefully escaped substitutions and accumulated
    into the $code variable like the *popgrep2* program in
    ``Speeding Up Interpolated Matches''.

    A `-t' to test for an interactive run check tells whether
    we're expecting to read from the keyboard in case no arguments
    are supplied. That way if the user forgets to give any
    arguments, they don't sit there wondering why the program
    appears to be hung.

        #!/usr/bin/perl -w
        # fixstyle - switch first set of <DATA> strings to second set
        #   usage: $0 [-v] [files ...]
        use strict;
        my $verbose = (@ARGV && $ARGV[0] eq '-v' && shift);

        if (@ARGV) {
            $^I = ".orig";          # preserve old files
        } else {
            warn "$0: Reading from stdin\n" if -t STDIN;
        }

        my $code = "while (<>) {\n";
        # read in config, build up code to eval
        while (<DATA>) {
            chomp;
            my ($in, $out) = split /\s*=>\s*/;
            next unless $in && $out;
            $code .= "s{\\Q$in\\E}{$out}g";
            $code .= "&& printf STDERR qq($in => $out at \$ARGV line \$.\\n)" 
                                                                if $verbose;
            $code .= ";\n";
        }
        $code .= "print;\n}\n";

        eval "{ $code } 1" || die;

        __END__
        analysed        => analyzed
        built-in        => builtin
        chastized       => chastised
        commandline     => command-line
        de-allocate     => deallocate
        dropin          => drop-in
        hardcode        => hard-code
        meta-data       => metadata
        multicharacter  => multi-character
        multiway        => multi-way
        non-empty       => nonempty
        non-profit      => nonprofit
        non-trappable   => nontrappable
        pre-define      => predefine
        preextend       => pre-extend
        re-compiling    => recompiling
        reenter         => re-enter
        turnkey         => turn-key

    One caution: This program is pretty fast, but doesn't scale if
    you need to make hundreds of changes. The more lines of change
    pairs in the DATA section, the slower it takes. This isn't
    noticeable with only a few dozen changes, and in fact, the
    version given in the solution is faster for that case. But if
    you run the program on a hundred times that many pairs, you'll
    see it bog down.

    Here's a version that doesn't have that's slower for few
    changes, but faster when there are a lot of them.

        #!/usr/bin/perl -w
        # fixstyle2 - like fixstyle but faster for many many matches
        use strict;
        my $verbose = (@ARGV && $ARGV[0] eq '-v' && shift);
        my %change = ();
        while (<DATA>) { 
            chomp;
            my ($in, $out) = split /\s*=>\s*/;
            next unless $in && $out;
            $change{$in} = $out;
        }

        if (@ARGV) { 
            $^I = ".orig";
        } else { 
            warn "$0: Reading from stdin\n" if -t STDIN;
        }

        while (<>) { 
            my $i = 0;
            s/^(\s+)// && print $1;         # emit leading whitespace
            for (split /(\s+)/, $_, -1) {   # preserve trailing whitespace
                print( ($i++ & 1) ? $_ : ($change{$_} || $_));
            } 
        }

        __END__
        analysed        => analyzed
        built-in        => builtin
        chastized       => chastised
        commandline     => command-line
        de-allocate     => deallocate
        dropin          => drop-in
        hardcode        => hard-code
        meta-data       => metadata
        multicharacter  => multi-character
        multiway        => multi-way
        non-empty       => nonempty
        non-profit      => nonprofit
        non-trappable   => nontrappable
        pre-define      => predefine
        preextend       => pre-extend
        re-compiling    => recompiling
        reenter         => re-enter
        turnkey         => turn-key

    This second version breaks up each line into chunks of
    whitespace and words, which isn't a fast operation. But then
    it uses those words to look up their replacements in a hash,
    which is much faster than a substitution. So the first part is
    slower and the second faster. How much difference this makes
    depends on the number of matches.

    If we didn't care so much about not changing the amount of
    whitespace separating each word, the second version can run as
    fast as the first one even for few changes. If you know a lot
    about your input, you can just collapse white space into
    single blanks by plugging in this loop instead:

        # very fact, but whitespace collapse
        while (<>) { 
            for (split) { 
                print $change{$_} || $_, " ";
            } 
            print "\n";
        }

    That leaves an extra blank at the end of each line. If that's
    a problem, you could use the technique from ``Postprocessing
    Output'' to introduce an output filter that fixes that, too.
    Place the following code in front of the previous `while' loop
    above that's collapsing whitespace:

        my $pid = open(STDOUT, "|-");
        die "cannot fork: $!" unless defined $pid;
        unless ($pid) {             # child
            while (<STDIN>) {
                s/ $//;
                print;
            } 
            exit;
        } 


I keep thinking someone will use this as a basis for the
http://language.perl.com/misc/geekspeak.html contest.

--tom
-- 
    Although the Perl Slogan is There's More Than One Way to Do It, I hesitate
    to make 10 ways to do something.  :-)
            --Larry Wall in <9695@jpl-devvax.JPL.NASA.GOV>


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

Date: Wed, 11 Aug 1999 15:19:00 -0700
From: Warren Bell <resource@ERASEjps.net>
Subject: Stripping quotes only from HTML tags
Message-Id: <37B1F6D4.3EDB38DF@ERASEjps.net>

I have a messageboard script that I want to strip the quotes out of
anything within HTML tags that is entered in the text area.  If a quote
is entered as text like: try the command "foo -a" it woulden't get
stripped. But anything in between < and > gets the quotes stripped from
it.

Is there a way to do this with a simple substitution like:

$message =~ s/?/?\g;

Any help much appreciated,
Warren Bell

-- 
####### Remove ERASE to reply #######


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

Date: Wed, 11 Aug 1999 15:06:26 -0700
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: turn $6 into $6000
Message-Id: <MPG.121b93bb59f9e745989e34@nntp.hpl.hp.com>

In article <slrn7r34j0.dc3.fl_aggie@thepentagon.com> on 11 Aug 1999 
15:08:13 GMT, I R A Darth Aggie <fl_aggie@thepentagon.com> says...
> On Wed, 11 Aug 1999 07:49:23 -0700, Larry Rosler <lr@hpl.hp.com>, in
> <MPG.121b2d413991c4ca989e30@nntp.hpl.hp.com> wrote:
> + But that solution is only O(N).  Surely you can do worse.
> 
> Worse? sure.
> 
> perl -e '$bucks=0; foreach (0..5999) { $bucks+=1;} print "\$$bucks\n";'
> 
> If I'm remembering things correctly, there's the time/space required to
> generate a list of (0..5999), of course looping iteratively just to add
> a constant isn't particularly efficient. No, just like the subject, this
> is a terrible way to get to $6000.

A couple of problems here.

1.  It is still O(N).

2.  It doesn't get from '$6' to '$6000', but from 0 (or '$0').  
Abigail's ++ solution works, though.  '++' is not the same as '+= 1',

> Somehow:
> 
> perl -e '$bucks=0; foreach (0..6000) { $bucks+=$_;} print "\$$bucks\n";'
> 
> has a much prettier result. But just as inefficient... ;)

Prettier if it's my bank balance.  But still only O(N).  Try harder!

-- 
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com


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

Date: Wed, 11 Aug 1999 15:23:13 -0700
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: UpperCase first letter of string only.
Message-Id: <MPG.121b97b0c341bb5b989e36@nntp.hpl.hp.com>

In article <brian-ya02408000R0908992043080001@news.panix.com> on Mon, 09 
Aug 1999 20:43:08 -0400, brian d foy <brian@pm.org> says...
> In article <7onqqe$qvv$0@216.39.133.155>, "Bart Simpson" <phony@nospam.com> posted:
> 
> > my $mystring='hello';
> > 
> > How would I go about changing $mystring so it contains 'Hello'? I have a
> > script where names are entered, and would like to make sure the first letter
> > is capitalized.
> 
> ucfirst() would work, even though it is cryptically named.

You of all people might have mentioned that this action might be 
contrary to the wishes of the persons whose names are entered.

You especially, but perhaps also Ludwig von Beethoven, e e cummings, and 
innumerable others.

-- 
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com


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

Date: Wed, 11 Aug 1999 18:20:06 -0400
From: linberg@literacy.upenn.edu (Steve Linberg)
Subject: Re: working with imagery
Message-Id: <linberg-1108991820070001@ltl1.literacy.upenn.edu>

In article <37B1D793.4B05105B@ccrs.nrcanDOTgc.ca>, Tom Kralidis
<tom.kralidis@ccrs.nrcanDOTgc.ca> wrote:

> Hi,
> 
> Does anyone have any info, links, etc. on using Perl for images
> (properties, cell values, etc.)?

Start, as always, at www.perl.com, and browse through the CPAN archives.

-- 
Steve Linberg, Systems Programmer &c.
National Center on Adult Literacy, University of Pennsylvania
Be kind.  Remember, everyone you meet is fighting a hard battle.
print 'Just Another Perl ' . $perl_hierarchy[(USER+EXPERT)/2];


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

Date: 1 Jul 99 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 1 Jul 99)
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" from
almanac@ruby.oce.orst.edu. The real FAQ, as it appeared last in the
newsgroup, can be retrieved with the request "send perl-users FAQ" from
almanac@ruby.oce.orst.edu. 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" from
almanac@ruby.oce.orst.edu. 

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 V9 Issue 468
*************************************


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