[13818] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 1228 Volume: 9

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sat Oct 30 03:05:36 1999

Date: Sat, 30 Oct 1999 00:05:12 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <941267111-v9-i1228@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Sat, 30 Oct 1999     Volume: 9 Number: 1228

Today's topics:
        CGI Programming in C/C++ HELP! <doncho@topmachine.com>
    Re: Drop the last item from the Environment string (CGI <wyzelli@yahoo.com>
    Re: Drop the last item from the Environment string (CGI <wyzelli@yahoo.com>
    Re: Drop the last item from the Environment string (CGI <lr@hpl.hp.com>
    Re: FAQ 8.8: How do I get the screen size? (Kragen Sitaker)
    Re: Func works first time but not second <bwalton@rochester.rr.com>
    Re: How do you strip spaces? (Abigail)
    Re: How do you strip spaces? <uri@sysarch.com>
        How should I do this regex? steve@emark.co.nz
    Re: How should I do this regex? (Martien Verbruggen)
    Re: How the heck does this regex match? (John McKown)
    Re: How the heck does this regex match? <lr@hpl.hp.com>
    Re: How to touch a file in perl? <matthew@davin.ottawa.on.ca>
    Re: Makefile.pl modification question <spam@dev.null>
    Re: mod perl anomalies <randy@theoryx5.uwinnipeg.ca>
    Re: perl lang parser (Tad McClellan)
    Re: regex match with empty string (Sharkey (Nick) Moore)
    Re: RFC: Making array using range op and map (Kragen Sitaker)
    Re: simple regex question <bwalton@rochester.rr.com>
    Re: simple regex question (Tad McClellan)
    Re: Stripping live HTML into text <mcgrew@stanfordalumni.org>
        Trying to work this regex out.... steveatemark@my-deja.com
    Re: Trying to work this regex out.... (Martien Verbruggen)
    Re: Why does this print 'bar'? (Martien Verbruggen)
        Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)

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

Date: Fri, 29 Oct 1999 21:52:14 -0700
From: "doncho" <doncho@topmachine.com>
Subject: CGI Programming in C/C++ HELP!
Message-Id: <7vdtlo$a36$1@ash.prod.itd.earthlink.net>

I am currently learning CGI programming. Actually, I am not familiar with
Perl or other languages instead of C/C++.  Are there any sites, books, or
references to learn CGI programming in C/C++, please help me.
Thank you.





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

Date: Sat, 30 Oct 1999 13:46:36 +0930
From: "Wyzelli" <wyzelli@yahoo.com>
Subject: Re: Drop the last item from the Environment string (CGI)
Message-Id: <NiuS3.16$MV2.1942@vic.nntp.telstra.net>

>
> The input is read by:
>
> read(STDIN, $buffer, $ENV{"CONTENT_LENGTH"})
>
Well, here is an answer which I have finally got to after three days of
thinking and reading and playing.

I expect this is all too obvious to most, but I did get a lot from trying to
explain it, and then finding a way.  Hopefully now I'm a bit better than I
was.

anyway...

(just a snippet, comments welcome):

read(STDIN, $names, $ENV{"CONTENT_LENGTH"});
@names= split ('&', $names);
for $x (0 .. ($#names-1)) {
$newnames[$x] = $names[$x];
}
$newnames= join ('&',@newnames);
open (OUTFILE, ">>$outfile") or die "unable to open $outfile $!\n";
print OUTFILE $newnames;
close OUTFILE;

and so off I go...

Basically just a lot cleaner than what I had before.

And I get what  I need.. last environment variable dropped regardless of how
many variables there are.

Wyzelli




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

Date: Sat, 30 Oct 1999 14:40:08 +0930
From: "Wyzelli" <wyzelli@yahoo.com>
Subject: Re: Drop the last item from the Environment string (CGI)
Message-Id: <Q4vS3.17$MV2.2174@vic.nntp.telstra.net>


> >
> read(STDIN, $names, $ENV{"CONTENT_LENGTH"});
> @names= split ('&', $names);
> for $x (0 .. ($#names-1)) {
> $newnames[$x] = $names[$x];
> }
> $newnames= join ('&',@newnames);
> open (OUTFILE, ">>$outfile") or die "unable to open $outfile $!\n";
> print OUTFILE $newnames;
> close OUTFILE;
>

Or maybe this which is even better....

 read(STDIN, $names, $ENV{"CONTENT_LENGTH"});
@names= split ('&', $names);
$submits = pop @names;
$names= join ('&',@names);
open (OUTFILE, ">>$outfile") or die "unable to open $outfile $!\n";
print OUTFILE $names;
close OUTFILE;

 ...do something with $submits...

Wyzelli




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

Date: Fri, 29 Oct 1999 22:58:44 -0700
From: Larry Rosler <lr@hpl.hp.com>
Subject: Re: Drop the last item from the Environment string (CGI)
Message-Id: <MPG.128428eb8673d98898a163@nntp.hpl.hp.com>

In article <Q4vS3.17$MV2.2174@vic.nntp.telstra.net> on Sat, 30 Oct 1999 
14:40:08 +0930, Wyzelli <wyzelli@yahoo.com> says...

 ...

> @names= split ('&', $names);
> $submits = pop @names;
> $names= join ('&',@names);

  ($names, $submits) = $names =~ /(.+)&(.+)/;

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


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

Date: Sat, 30 Oct 1999 04:07:26 GMT
From: kragen@dnaco.net (Kragen Sitaker)
Subject: Re: FAQ 8.8: How do I get the screen size?
Message-Id: <2auS3.8734$23.494891@typ11.nn.bcandid.com>

In article <7vcn4q$1jp$1@news.NERO.NET>,
John Stanley <stanley@skyking.OCE.ORST.EDU> wrote:
>In article <3819d7f8@cs.colorado.edu>,
>Tom Christiansen  <perlfaq-suggestions@perl.com> wrote:
>>    If you have Term::ReadKey module installed from CPAN, you can use
>>    it to fetch the width and height in characters and in pixels:
>
>You can perhaps fetch the width and height in characters of the current
>window, but on modern operating systems with modern windowing systems
>that rarely is the same as the screen size. 

You haven't begun to see the extent of ancient-stuff terminology in
Unix.  Have you ever gotten a "Not a typewriter" error?  

And how about that Emacs?  We have multiple windows on the screen,
which are different from windows (which are panes) and are called
frames instead of windows, and then there are consoles, which are
sometimes also windows.  Control-h invokes help instead of backspacing,
if you're on an ASCII terminal.

Not even mentioning the nomenclature of core files and the output
format of troff.  At least we don't have card images in Unix.  :)

(iow, a window is called a screen.  this is the least of your worries.)
-- 
<kragen@pobox.com>       Kragen Sitaker     <http://www.pobox.com/~kragen/>
Thu Oct 28 1999
12 days until the Internet stock bubble bursts on Monday, 1999-11-08.
<URL:http://www.pobox.com/~kragen/bubble.html>


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

Date: Sat, 30 Oct 1999 00:26:40 -0400
From: Bob Walton <bwalton@rochester.rr.com>
Subject: Re: Func works first time but not second
Message-Id: <381A7380.B53F248E@rochester.rr.com>

Stephen Lee wrote:
 ...
> The subroutine get_pic works on the first call, getting the right URL, but
> not the second.  I think my regexes are correct because if I swap the
> lines marked (1) and (2) it gets the correct link for the first call only
> also.
> 
> Can anybody tell me what is wrong about my script?  I tried printing $url
> and $re in get_pic and they seem to have the right value.
 ...
> Stephen
> 
> #!/usr/bin/perl -Tw
> #=====================================================================
> # forward.pl:
> #=====================================================================
> 
> #=====================================================================
> # Includes
> #=====================================================================
> 
> use strict;
> #$|++;
> #use lib "/home/stephen/lib/perl5";
> use LWP;
> use URI::URL;
> use CGI qw/:html header/;
> use HTML::Entities;
> 
> #=====================================================================
> # Configuration
> #=====================================================================
> 
> my $DILBERT_TOP = "http://www.unitedmedia.com/comics/dilbert/";
> my $DILBERT_PIC_RE = '/comics/dilbert/archive/images/dilbert\d+\.gif';
> 
> my $PEANUTS_TOP = "http://www.unitedmedia.com/comics/peanuts/";
> my $PEANUTS_PIC_RE = '/comics/peanuts/archive/images/peanuts\d+\.gif';
> 
> my $browser = LWP::UserAgent->new(); # create virtual browser
> $browser->agent("Mozilla/4.5 [ja] (WinNT; I)");
> 
> #=====================================================================
> # Subroutines
> #=====================================================================
> 
> # A TD element, centered.
> sub td_center {
>     td({align => "center"}, @_);
> }
> 
> sub get_pic {
>     my $url = $_[0];
>     my $re = $_[1];
> 
>     # make a GET request on the URL via fake browser
>     my $page = $browser->request(HTTP::Request->new(GET => $url));
>     unless ($page->is_success) { # not found
>         die "Cannot get top page";
>     }
> 
>     my ($pic) = $page->content =~ m!($re)!o;

The problem is with the "o" switch in the above regexp match.  The
"o" switch causes the regexp to be evaluated once and then 
remembered rather the reevaluated on the second and subsequent calls.
The the pattern continues to match the first comic rather than the
second or subsequent ones.  Delete the "o", and it should work.  
See perlop for details of the "o" switch.

>     $pic = url($pic, $url)->abs;
> 
>     return $pic;
> }
> 
> #=====================================================================
> #
> #=====================================================================
> 
> print header, start_html("Today's comics"), h1("Today's comics"), "\n";
> 
> my $pic;
> 
> $pic = get_pic($DILBERT_TOP, $DILBERT_PIC_RE);  #(1)
> print table(TR(td_center(encode_entities($pic))) . "\n",
>             TR(td_center(img{-src => $pic})) . "\n");
> 
> $pic = get_pic($PEANUTS_TOP, $PEANUTS_PIC_RE);  #(2)
> print table(TR(td_center(encode_entities($pic))) . "\n",
>             TR(td_center(img{-src => $pic})) . "\n");
> 
> print "\n", end_html;


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

Date: 30 Oct 1999 00:46:34 -0500
From: abigail@delanet.com (Abigail)
Subject: Re: How do you strip spaces?
Message-Id: <slrn81l1gq.66b.abigail@alexandra.delanet.com>

Uri Guttman (uri@sysarch.com) wrote on MMCCL September MCMXCIII in
<URL:news:x7ogdhdds3.fsf@home.sysarch.com>:
// >>>>> "A" == Abigail  <abigail@delanet.com> writes:
// 
//   A>     s/ (.*)/;
//   A>     local $_ = $1;
//   A>     y; ;;d;
//   A>     $_;
//   A>     /xs;
//           ^^
// 
// shouldn't the modifier be sex?


No. But it should be 'es'.



Abigail
-- 
perl -we 'print q{print q{print q{print q{print q{print q{print q{print q{print 
               qq{Just Another Perl Hacker\n}}}}}}}}}'    |\
perl -w | perl -w | perl -w | perl -w | perl -w | perl -w | perl -w | perl -w


  -----------== Posted via Newsfeeds.Com, Uncensored Usenet News ==----------
   http://www.newsfeeds.com       The Largest Usenet Servers in the World!
------== Over 73,000 Newsgroups - Including  Dedicated  Binaries Servers ==-----


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

Date: 30 Oct 1999 01:51:41 -0400
From: Uri Guttman <uri@sysarch.com>
Subject: Re: How do you strip spaces?
Message-Id: <x7emedcs5u.fsf@home.sysarch.com>

>>>>> "A" == Abigail  <abigail@delanet.com> writes:

  A> Uri Guttman (uri@sysarch.com) wrote on MMCCL September MCMXCIII in
  A> <URL:news:x7ogdhdds3.fsf@home.sysarch.com>:
  A> // >>>>> "A" == Abigail  <abigail@delanet.com> writes:
  A> // 
  A> //   A>     s/ (.*)/;
  A> //   A>     local $_ = $1;
  A> //   A>     y; ;;d;
  A> //   A>     $_;
  A> //   A>     /xs;
  A> //           ^^
  A> // 
  A> // shouldn't the modifier be sex?


  A> No. But it should be 'es'.

i knew the e was missing. but i can see why x is not needed though you
made it look like it would be. the regex itself has no extra chars while
the replacement is multiple lines of code. 

uri

-- 
Uri Guttman  ---------  uri@sysarch.com  ----------  http://www.sysarch.com
SYStems ARCHitecture, Software Engineering, Perl, Internet, UNIX Consulting
The Perl Books Page  -----------  http://www.sysarch.com/cgi-bin/perl_books
The Best Search Engine on the Net  ----------  http://www.northernlight.com


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

Date: Sat, 30 Oct 1999 04:14:45 GMT
From: steve@emark.co.nz
Subject: How should I do this regex?
Message-Id: <7vdrbk$t8g$1@nnrp1.deja.com>

Can you help me? I'm very new to Perl.

I need to replace all occurences of the string 'emark' with another
string, except where it appears in words like 'trademark', e-mail
addresses and URL's.

eg: In 'emark trademark test@emark.co.nz www.emark.co.nz', only the
first occurence would be altered.

Thank you for your help!

Steve



Sent via Deja.com http://www.deja.com/
Before you buy.


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

Date: 30 Oct 1999 04:43:30 GMT
From: mgjv@wobbie.heliotrope.home (Martien Verbruggen)
Subject: Re: How should I do this regex?
Message-Id: <slrn81ku1g.jvv.mgjv@wobbie.heliotrope.home>

On Sat, 30 Oct 1999 04:14:45 GMT,
	steve@emark.co.nz <steve@emark.co.nz> wrote:
> Can you help me? I'm very new to Perl.
> 
> I need to replace all occurences of the string 'emark' with another
> string, except where it appears in words like 'trademark', e-mail
> addresses and URL's.
> 
> eg: In 'emark trademark test@emark.co.nz www.emark.co.nz', only the
> first occurence would be altered.

This isn't exactly clear, but let me try:

You only want emark to be changed when it appears between whitespace
and/or the beginning or end of a string? Things like:

"this sentence contains emark, and I don't want that changed"

for example.. Do you want it changed? Would the definition become 'at
least whitespace on one side?

Perl regexps have the \b special character, which matches the boundary
between a word and non-word character, where a word character is
alphanumeric plus _.

$str =~ s/\bemark\b/foo/g;

But that will change the emarks in the email address as well.

If you only want whitespace or the start/end of a line, you could do
something like

$str =~ s/(\A|\s)emark(\s|\z)/$1foo$2/g;

But that won't grab emark when followed or preceded by punctuation.

If you want to only exclude '.' and '@', you could do something like:

$str =~ s/(?<![@.])\bemark\b(?![@.])/foo/g;

But this one would also leave emark at the end of a sentence alone
(since it would be followed by a '.').

Since you've been a bit vague in your description, I can't really
tell. You don't even mention how restrictive the string is. Is it some
free text? Is it formatted stuff?

Did your company name change and you suddenly need to change all
documents that mention it? :)

I'd probably pick one of the above,run it over the text, and then grep
for the leftovers (ambiguous ones) and do them by hand.

It would be beneficial to you if you looked at the perlre documentation,
and tried to understand most of that (and yes, I know it's hard to get
REs at first).

# perldoc perlre

Martien
-- 
Martien Verbruggen              | 
Interactive Media Division      | I'm just very selective about what I
Commercial Dynamics Pty. Ltd.   | accept as reality - Calvin
NSW, Australia                  | 


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

Date: Fri, 29 Oct 1999 23:33:59 +0000
From: joarmc@linux2.johnmckown.net (John McKown)
Subject: Re: How the heck does this regex match?
Message-Id: <slrn81kbn6.pp.joarmc@linux2.johnmckown.net>

On Thu, 28 Oct 1999 20:15:25 +1000, Douglas Garstang 
<dgarstan@nsw.bigpond.net.au> wrote:
]>#!/usr/bin/perl
]>
]>$a = "[ sdt_shel ]";
]>$b = "dtlogin";
]>
]>if ( $b =~ $a ) {
]>        print "YES\n";
]>}
]>
]>... That returns true!
]>*is blown away*
]>
]>How can this be true?
]>
]>(something to do with the []'s getting in the way?)

In a regular expression, the [] enclose a list of characters. The regular
expression is matched if the string matches any ONE of the characters
enclosed within the []. If you need to match a literal set of [], then
you must "escape" both the [ and ] with a \ (backslash). However, due
to weird syntax, you must also escape the backlash in the assignment.
So you most likely what something like:

$a="\\[ sdt_shel \\]"

I assume you're trying to match the string '[ sdt_shel ]' where the
[] are literal characters, not metacharacters? If so, try the
assignment above and see if it works for you.

John


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

Date: Fri, 29 Oct 1999 23:19:18 -0700
From: Larry Rosler <lr@hpl.hp.com>
Subject: Re: How the heck does this regex match?
Message-Id: <MPG.12842dc436caf69c98a164@nntp.hpl.hp.com>

In article <slrn81kbn6.pp.joarmc@linux2.johnmckown.net> on Fri, 29 Oct 
1999 23:33:59 +0000, John McKown <joarmc@linux2.johnmckown.net> says...

 ...

> In a regular expression, the [] enclose a list of characters. The regular
> expression is matched if the string matches any ONE of the characters
> enclosed within the []. If you need to match a literal set of [], then
> you must "escape" both the [ and ] with a \ (backslash).

Not the ']'.  The only time that ']' must be escaped is to include it as 
a member of a character class, as any other than the first character in 
the class.  Escaping it elsewhere doesn't hurt, but 'must "escape"' is 
too strong.

>                        However, due
> to weird syntax, you must also escape the backlash in the assignment.

Not 'weird syntax' -- the wrong choice for quotes.

> So you most likely what something like:
> 
> $a="\\[ sdt_shel \\]"

  $a = '\[ sdt_shel ]';

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


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

Date: 30 Oct 1999 06:02:18 GMT
From: Matthew Darwin <matthew@davin.ottawa.on.ca>
Subject: Re: How to touch a file in perl?
Message-Id: <7ve1la$s2v$2@caribou.davin.ottawa.on.ca>

Well, the camel tells us now if we had just looked in the right place:


sub touch {
        my $now = time;
	local (*TMP);
        foreach my $file (@_) {
                utime ($now, $now, $file)
                || open (TMP, ">>$file")
                || warn ("Couldn't touch file: $!\n");
        }
}  



M.J.T. Guy <mjtg@cus.cam.ac.uk> wrote:
> Matthew Darwin  <matthew@davin.ottawa.on.ca> wrote:
>>What's a safe way to touch a file in perl?
>>
>>`touch $filename` is not the solution I'm looking for but it does do what
>>I want. The complete perl solution should handle files or directories on a
>>Unix system.

> You're pointing in the right direction, but ...

>>open HANDLE, ">$filename" || die;
>># do something?
>>close HANDLE

> Oooooooooooo!   Ouch!    You've just destroyed that pre-existing file.

> And you've got a precedence problem  -  that die will never happen,
> as it parses as

>  open HANDLE, (">$filename" || die);

> Try instead

>  open HANDLE, ">>$filename" or die "touch $filename: $!\n";
>  close HANDLE;

> See       perldoc -f open
>           perldoc perlopentut


> Mike Guy


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

Date: Sat, 30 Oct 1999 04:47:12 GMT
From: Steve <spam@dev.null>
Subject: Re: Makefile.pl modification question
Message-Id: <kLuS3.152$rK2.6845@ptah.visi.com>

Owen Brydon <owen@vvl.co.uk> wrote:
> The Crest Hotel wrote:
>> 
>> Sorry, I'm running on a UNIX platform, btw =)
>> 
>> In article <7uds4q$ljm$1@nnrp1.deja.com>,
>>   info@cresthotel.bc.ca wrote:
>> > I'm trying to build and install a 3rd party Perl module but I don't
>> > have rights to "make install" in the standard directories. I have my
>> > own personal /lib folder that I want to install into. How do I modify
>> > Makefile.pl to make this happen? Or do I modify the Makefile directly?
>> > Your time is greatly appreciated.
> [snip]

> FAQ:

> perldoc perlfaq8: How do I keep my own module/library directory?

This doesn't work for me.

I've attempted to build libnet-1.0607.tar.gz using a line similar to:

perl Makefile.PL PREFIX=/home/me/lib/perl

and the 'make install' continues to try to write files to where my account
does not have permissions.  The same is true when I try to use the CPAN
module for downloading & installing modules.

I'm using 5.005_03 included with freebsd 3.3.  Thanks for any help.


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

Date: 30 Oct 1999 04:58:42 GMT
From: Randy Kobes <randy@theoryx5.uwinnipeg.ca>
Subject: Re: mod perl anomalies
Message-Id: <7vdtu2$i3j$1@canopus.cc.umanitoba.ca>

In comp.lang.perl.misc, Thomas Nunn <tom@tnunn.demon.co.uk> wrote:
> In article <MPG.1282888e78e7a224989824@nntp1.ba.best.com>, Bill Moseley
> <moseley@best.com> writes
>>Thomas Nunn (tom@tnunn.demon.co.uk) seems to say...
>>> >> However every so often when I submit the form, the record that is added
>>> >> to the file is actually a repetition of a record added a few submits
>>> >> before.
>>
>>Have you run the server with -X?
>>
> Not entirely sure what that means, I'll try it as soon as I find out how
> to do it.

Hi,
   This is for running in single process mode (start it as 'httpd -X'),
so that no children are forked. It's useful for debugging some
things, but of course won't show up problems that arise from
variables apparently "shared" across children.

best regards,
Randy Kobes


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

Date: Fri, 29 Oct 1999 18:07:21 -0400
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: perl lang parser
Message-Id: <pq5dv7.s71.ln@magna.metronet.com>

Scott Lanning (slanning@bu.edu) wrote:

: -- 
: qualification: I'm a dimwit according to someone who emailed me


   I have received correspondence from that person as well.


   It's a small world, huh?


--
    Tad McClellan                          SGML Consulting
    tadmc@metronet.com                     Perl programming
    Fort Worth, Texas


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

Date: 30 Oct 1999 04:05:13 GMT
From: sharkey@ee.mu.oz.au (Sharkey (Nick) Moore)
Subject: Re: regex match with empty string
Message-Id: <7vdqpp$lfd$1@mulga.cs.mu.OZ.AU>

sholden@pgrad.cs.usyd.edu.au (Sam Holden) writes:

>Or even :
>if (//) {print "1$_\n";} else { print "0$_\n";}

Or even:
print 1*//.$_;


Xah,
	what exactly do you hope to acheive by annoying everyone?

	I'm assuming what you're trying to do is really /$foo/,
for empty $foo. You can always do one of:

		if ($foo eq '' or /$foo/) ...
		if (/$foo.?/) ...

	Of course if what you really want to do is something like

		/complicatedregex/

		foreach (@foo) {
			if (//) ...
		}

	Then bear in mind that its the last _successful_ match that
counts, so make sure it does, or if you want the default match anything
behaviour just do a /^/ first.

	My personal opinion is that the documentation is excellent,
compared with many commercial offerings.

-----sharks.		"What would Larry do?"

---___------------------------------------------------------------------
  /   \  Nick "Sharkey" Moore,   /   "Assembly of Japanese bicycle 
  \   /  sharkey@ee.mu.oz.au    /      require great peace of mind"
   0.0   XLV750R | CB250RS     /                  -----ZatAoMM
-- ^^^ -----------------------------------------------------------------   



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

Date: Sat, 30 Oct 1999 04:17:03 GMT
From: kragen@dnaco.net (Kragen Sitaker)
Subject: Re: RFC: Making array using range op and map
Message-Id: <3juS3.8742$23.496405@typ11.nn.bcandid.com>

In article <7vd78r$g1p$1@nnrp1.deja.com>,  <louhevly@my-deja.com> wrote:
>My goal is to produce a single array of numbers from 50,000 to 200,000
>in increments of 10,000; then from 225,000 to 600,000 in increments of
>25,000. So the array would go:
>50,000, 60,000, 70,000, etc. up to 200,000, then 225,000, 250,000,
>275,000 etc. up to 600,000.
>
>Here's my code; I would be grateful for any suggestions to improve it.
>
>#!/usr/bin/perl -w
>use strict;
>
>my @price = ( [5..20], [20..60] );
>@{$price[0]} = map {$_ * 10} @{$price[0]};
>@{$price[1]} = grep /[5|0]$/, @{$price[1]};
>@{$price[1]} = map {$_*10,  $_*10+25} @{$price[1]};
>shift @{$price[1]}; pop @{$price[1]};
>my @final = map { map {$_*1000} @{$_} } @price;
>print "$_\n" for @final;

The APL/Lisp style of manipulating lists is usually shorter and
sometimes clearer than the imperative style.  This may not be one of
those times; Uri's suggestion to use a C-style loop is a good one.

If you absolutely must use a functional style, you could write a
function range:

sub range { 
	my ($min, $max, $step) = @_;
	return map {$min + $step * $_} (0..($max-$min)/$step);
}
# 
my @final = (range (50_000, 200_000, 10_000), 
             range (225_000, 600_000, 25_000));
print "$_\n" for @final;

-- 
<kragen@pobox.com>       Kragen Sitaker     <http://www.pobox.com/~kragen/>
Thu Oct 28 1999
12 days until the Internet stock bubble bursts on Monday, 1999-11-08.
<URL:http://www.pobox.com/~kragen/bubble.html>


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

Date: Sat, 30 Oct 1999 00:05:09 -0400
From: Bob Walton <bwalton@rochester.rr.com>
Subject: Re: simple regex question
Message-Id: <381A6E75.C8A64C2F@rochester.rr.com>

"Philip A. Viton" wrote:
> 
> If I do
> 
>   s|c:\\|d:\\|;
> 
> within a script, I can change c:\  to d:\ .  I'd like to generalize this, so I
> can pass the two strings to a script in the command line. But if I pass, eg
> 
>   myroutine.pl myfile.txt c:\\  d:\\
> 
> and do
> 
>    s|$ARGV[1]|$ARGV[2]|;
> 
> c:\  gets changed to d:\\  (ie with an extra \). Can anyone see what I'm doing
> wrong?
 ...
> ----------------
> Philip A. Viton
> City & Regional Planning, OSU, 190 W. 17th Avenue, Columbus OH 43210
> pviton@magnus.acs.ohio-state.edu

Philip, from perlop:


perlop>?RE?, /RE/, m/RE/, s/RE/foo/,
perlop>
perlop>          Processing of \Q, \U, \u, \L, \l and interpolation
happens (almost) as
perlop>          with qq// constructs, but the substitution of \
followed by RE-special
perlop>          chars (including \) is not performed!  
perlop>...
perlop>Note that absence of processing of \\ creates specific
restrictions on
perlop>          the post-processed text: if the delimiter is /, one
cannot get the
perlop>          combination \/ into the result of this step: / will
finish the regular
perlop>          expression, \/ will be stripped to / on the previous
step, and \\/ will be
perlop>          left as is.


Note that patterns receive an extra level of interpolation (from
perlop again):

perlop>Patterns are subject to an additional level of interpretation as
a regular expression.
perlop>This is done as a second pass, after variables are interpolated,
so that regular
perlop>expressions may be incorporated into the pattern from the
variables. If this is not
perlop>what you want, use \Q to interpolate a variable literally. 
perlop>
perlop>Apart from the above, there are no multiple levels of
interpolation.


That last sentence applies to replacement strings, since they are
not regexp's.  So the replacement string gets one interpolation.
If it is d:\\, it becomes d:\.  If it is $ARGV[2] and $ARGV[2]
is d:\\, it becomes d:\\.

For a more useable program, try:

s|\Q$ARGV[1]\E|$ARGV[2]|

and lose the double backslashes in the arguments.  Then the program:

open IN,"$ARGV[0]" or die "Couldn't open file $ARGV[0], $!\n";
while(<IN>){
	chomp;
	$s=$_;
	$s=~s|\Q$ARGV[1]\E|$ARGV[2]|;
	print "s=$s\n";
}
close IN or die "Couldn't close file $ARGV[0], $!\n";

applied to the file:

c:\whatever
c:\blah\blah

with the command:

perl junk69.pl junk69.txt c:\ d:\

results in:

H:\Bob\junk>perl junk69.pl junk69.txt c:\ d:\
s=d:\whatever
s=d:\blah\blah

H:\Bob\junk>

at least on Win32.  In Unix, you will need to quote the backslashes
on the command line, as the shell will interpret them if they
are not quoted (possibly dependent upon what shell you are using).

Then in Unix, the call would be:

junk69.pl junk69.txt 'c:\' 'd:\'

or

junk69.pl junk69.txt c:\\ d:\\

depending on your favorite shell quoting method.
-- 
Bob Walton


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

Date: Fri, 29 Oct 1999 21:01:42 -0400
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: simple regex question
Message-Id: <m1gdv7.9m1.ln@magna.metronet.com>


[ Please limit your line lengths to the customary 70-72 characters.
  Else they get hard to read after being quoted a few times.
]


Philip A. Viton (pviton@magnus.acs.ohio-state.edu) wrote:

: If I do

:   s|c:\\|d:\\|;

: within a script, I can change c:\  to d:\ .  I'd like to generalize this, so I 
: can pass the two strings to a script in the command line. But if I pass, eg 

:   myroutine.pl myfile.txt c:\\  d:\\

: and do

:    s|$ARGV[1]|$ARGV[2]|;

: c:\  gets changed to d:\\  (ie with an extra \). 


: Can anyone see what I'm doing 
: wrong?


   Backslashes are also "special" in most shells.

   Your shell is probably eating one.

   How to make it not eat it depends on which shell you use.


   In most Unix-like shells you can either escape the escapes (yuk!)

      myroutine.pl c:\\\\  d:\\\\ myfile.txt

   or, make the backslashes not special by putting them in single quotes

      myroutine.pl 'c:\\'  'd:\\' myfile.txt

   (I can't bring myself to write the filenames then the args,
    so I changed it to a more conventional order.
   )



--
    Tad McClellan                          SGML Consulting
    tadmc@metronet.com                     Perl programming
    Fort Worth, Texas


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

Date: 30 Oct 1999 06:45:19 GMT
From: Darin McGrew <mcgrew@stanfordalumni.org>
Subject: Re: Stripping live HTML into text
Message-Id: <7ve45v$bv6$1@samba.rahul.net>

Ryan <ryan_richards_2000[NOSPAM]@yahoo.com> wrote:
> I need to come up with a solution to strip text from an html page and place
> it in a file on the local machine. I was thinking Java, Javascript, PERL
> etc. Any ideas would be most welcome!

I usually use the "Save As..." function of my browser (Opera), then I
specify that I want to save it as a "Text File".  The FAQ
<http://www.htmlhelp.com/faq/html/media.html#strip-html> describes other
methods as well.
-- 
Darin McGrew, mcgrew@stanfordalumni.org, http://www.rahul.net/mcgrew/
    Web Design Group, darin@htmlhelp.com, http://www.htmlhelp.com/

"A little neglect may breed great mischief."  -- Benjamin Franklin


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

Date: Sat, 30 Oct 1999 04:01:34 GMT
From: steveatemark@my-deja.com
Subject: Trying to work this regex out....
Message-Id: <7vdqit$sk2$1@nnrp1.deja.com>

I'm very new to CGI/Perl, and I need some help
with this problem.

$e = '<font color="#003366">emark</font>';
$c = 'emark trademark test@emark.co.nz
www.emark.co.nz emark';
$c =~ s/\b(emark)\b/$e/ig;

I'd like to replace all occurences of the
string 'emark' with another string, except in
words like 'trademark' and email addresses and
URLs.

So in the above example, only the first and last
occurences should be replaced.

Can anyone please help me? I'd be very grateful!

Thanks,

Steve


Sent via Deja.com http://www.deja.com/
Before you buy.


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

Date: 30 Oct 1999 04:48:53 GMT
From: mgjv@wobbie.heliotrope.home (Martien Verbruggen)
Subject: Re: Trying to work this regex out....
Message-Id: <slrn81kubj.jvv.mgjv@wobbie.heliotrope.home>

On Sat, 30 Oct 1999 04:01:34 GMT,
	steveatemark@my-deja.com <steveatemark@my-deja.com> wrote:
> I'd like to replace all occurences of the
> string 'emark' with another string, except in
> words like 'trademark' and email addresses and
> URLs.

This post is much, much better than your other one, that I just replied
to. At least in this one you show us what you tried, and that you read
the documentation. And the above description is much clearer. 

'Everywhere, except in ...'

If you want to do that with a single regex you're going to have some
troubles, but if you can bear the occasional emark at the end of a
sentence to be skipped, and do those manually, then my reply to your
other post should help.

Of course, it isn't that hard to come up with a full solution. I
probably wouldn't do it with a single regex, but even that probably
would be possible with a few longer lookahead and behind expressions
that make sure you're not in a hostname or in an email address. The more
precise you can define those excepts, the easier the problem gets.

Martien
-- 
Martien Verbruggen              | 
Interactive Media Division      | If it isn't broken, it doesn't have
Commercial Dynamics Pty. Ltd.   | enough features yet.
NSW, Australia                  | 


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

Date: 30 Oct 1999 04:21:26 GMT
From: mgjv@wobbie.heliotrope.home (Martien Verbruggen)
Subject: Re: Why does this print 'bar'?
Message-Id: <slrn81kso2.jvv.mgjv@wobbie.heliotrope.home>

On Wed, 27 Oct 1999 23:04:46 -0700,
	Larry Rosler <lr@hpl.hp.com> wrote:
> In article <RZOR3.185$z73.4674@nsw.nnrp.telstra.net> on Thu, 28 Oct 1999 
> 02:58:57 GMT, Martien Verbruggen <mgjv@comdyn.com.au> says...

[discussion about parentheses in ?:]

> > Two reasons why I always include them:
> > 
> > 1) It's visually much clearer what is going on
> 
> I was triggered in my gripe by an article on precedence and parentheses 
> by mjd in TPJ #15, which I just read today.

agreed with the examples, except

>     $s = ($n == 1) ? 'foo' : 'bar';

I just do not feel that

$s = $n == 1 ? 'foo' : 'bar';

is clear enough. It's almost like

if $n == 1 {
	blabla
}

Even if that was allowed, I would never even think of doing that. In
these cases I do really believe that extra parentheses make it much
clearer what exactly the condition is.

> On the other hand, expressions using << or >> or & or | get me to 
> parenthesize, because of a lack of certainty about the precedence rules.

It depends a bit. I will parenthesise these in conditionals, but almost
never in simple assignments.

> > 2) I program a lot in C. They're mandatory there
> 
> Gosh, that's news to me.  And I thought I knew C a lot better than I 
> know Perl.

You are right. I have no idea at all why I was absolutely convinced that
the brackets were mandatory in C, but it'll teach me to test everything
I say :)

But it does go to show that in all the years of programming C I never
even _considered_ trying this without parentheses. I honestly can't
remember whether I first thought they were mandatory, and therefore
never tried to leave them off, or whether I started to think they were
mandatory because I never left them off.

Martien
-- 
Martien Verbruggen              | 
Interactive Media Division      | We are born naked, wet and hungry.
Commercial Dynamics Pty. Ltd.   | Then things get worse.
NSW, Australia                  | 


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

Date: 16 Sep 99 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 16 Sep 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.  

| NOTE: The mail to news gateway, and thus the ability to submit articles
| through this service to the newsgroup, has been removed. I do not have
| time to individually vet each article to make sure that someone isn't
| abusing the service, and I no longer have any desire to waste my time
| dealing with the campus admins when some fool complains to them about an
| article that has come through the gateway instead of complaining
| to the source.

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

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

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


------------------------------
End of Perl-Users Digest V9 Issue 1228
**************************************


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