[19973] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 2168 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Nov 21 00:05:47 2001

Date: Tue, 20 Nov 2001 21:05:07 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <1006319107-v10-i2168@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Tue, 20 Nov 2001     Volume: 10 Number: 2168

Today's topics:
    Re: Can I avoid 2 passes? <echang@netstorm.net>
    Re: Can I avoid 2 passes? <uri@stemsystems.com>
    Re: Can I avoid 2 passes? <uri@stemsystems.com>
    Re: Can I avoid 2 passes? <godzilla@stomp.stomp.tokyo>
    Re: EOF testing <ahamm@programmer.net>
    Re: has anyone tried activestate perl under solaris? <uri@stemsystems.com>
    Re: help w/ error: 'package does not return true' <mgjv@tradingpost.com.au>
        help with member program <hoss@chungk.com>
    Re: help with member program <mgjv@tradingpost.com.au>
    Re: how to calculate the CRC of a string... <bart.lateur@skynet.be>
    Re: how to calculate the CRC of a string... <mgjv@tradingpost.com.au>
    Re: how to calculate the CRC of a string... <bart.lateur@skynet.be>
    Re: how to calculate the CRC of a string... <mgjv@tradingpost.com.au>
        need help with a seemingly simple regex <t.s.spencer@n2.com>
    Re: need help with a seemingly simple regex <mnemotronic@mind\no-spam/spring.com>
    Re: need help with a seemingly simple regex <godzilla@stomp.stomp.tokyo>
    Re: need help with a seemingly simple regex <mgjv@tradingpost.com.au>
    Re: need help with a seemingly simple regex <godzilla@stomp.stomp.tokyo>
        Overwriting a part of text using a perl script! (Kevin VAZ)
    Re: result pages (10 by 10) <bart.lateur@skynet.be>
    Re: Template System <gamu829@yahoo.com>
    Re: using sendmail from perl (Alan Barclay)
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Wed, 21 Nov 2001 02:30:26 GMT
From: "E.Chang" <echang@netstorm.net>
Subject: Re: Can I avoid 2 passes?
Message-Id: <Xns915FDBD79BCF7echangnetstormnet@207.106.93.86>

Uri Guttman <uri@stemsystems.com> wrote in
news:x7bshxdx1t.fsf@home.sysarch.com: 

>>>>>> "EC" == E Chang <echang@netstorm.net> writes:
>   EC> my ($user, $rest) = split (/:/, $_, 2);
>   EC> $users{$user} = $rest;
> 
> even simpler:
> 
>      %users = map split (/:/, $_, 2), <PW> ;
 
Sweet.  I was hoping someone would point out a compact improvement like 
that.

-- 
EBC


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

Date: Wed, 21 Nov 2001 04:36:33 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: Can I avoid 2 passes?
Message-Id: <x7r8qsd9ir.fsf@home.sysarch.com>

>>>>> "G" == Godzilla!  <godzilla@stomp.stomp.tokyo> writes:

  G> Uri Guttman wrote:
  >> Dale Henderson wrote:
  >> > Drew Myers wrote:

  G> (snipped)

  >> and make sure you read bart's reply to moronzilla. you will learn why
  >> she should be ignored here. first she says use associative arrays over
  >> hashes which is plain stupid. then she says use arrays over hashes which
  >> for this problem (indexing by user names from /etc/passwd) is plain
  >> wrong. so which is she, stupid or wrong?


  G> Will you forgive me for being a more talented
  G> Perl programmer than you? I just cannot help it.
  G> Truly, it is not my fault nor intentional.

i forgive you for your stupidity. we are all stupid sometimes. but i
don't forgive you for your constant thickheadedness. you never seem to
grasp that hashes ARE associative arrays by another name and they are
NOT arrays. but then you won't look back on your recent posts and
realize that mistake. but it is good that you make such dumb mistakes in
public for even newbies will know that you don't know anything about
perl. as for your being a better programmer, i let you win that
battle. i will not fight the lame, the sick, or the mentally
handicapped.

uri

-- 
Uri Guttman  ------  uri@stemsystems.com  -------- http://www.stemsystems.com
-- Stem is an Open Source Network Development Toolkit and Application Suite -
----- Stem and Perl Development, Systems Architecture, Design and Coding ----
Search or Offer Perl Jobs  ----------------------------  http://jobs.perl.org


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

Date: Wed, 21 Nov 2001 04:41:05 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: Can I avoid 2 passes?
Message-Id: <x7oflwd9b5.fsf@home.sysarch.com>

>>>>> "G" == Godzilla!  <godzilla@stomp.stomp.tokyo> writes:

  G> Martien Verbruggen wrote:
  >> Godzilla!  wrote:
  >> > Bart Lateur wrote:
  >> > > Godzilla! wrote:

  >> No one claimed an array was the same thing as a hash.


  G> Bart did.

bart said:

	You stupid person. A "hash" is simply another shorter name for an
	"associative array". Technically, they're the same thing.

he was correct in all three statements.


  G> Beneath my signature, you will find an associative array
  G> and a hash. Based on your statements and high logic, which
  G> is no different than Bart's nor Uri's, hmm.. are you boys
  G> lovers are just the same person? Anyhow, based on your
  G> flawless logic, my script will exhibit identical prints,
  G> with typical Godzilla perfection.


  G> @Associative_Array = qw (user1:pass1:uid1:gid1:gecos1:home1:shell1
  G>                          user2:pass2:uid2:gid2:gecos2:home2:shell2);

that is an ARRAY. not an ASSOCIATIVE ARRAY. note the adjective
ASSOCIATIVE which modifies the word ARRAY. perl4 had ASSOCIATIVE
ARRAYs. perl5 renamed them HASHES

  G> $Hash{user1} = "pass1:uid1:gid1:gecos1:home1:shell1";
  G> $Hash{user2} = "pass2:uid2:gid2:gecos2:home2:shell2";

  G> for (@Associative_Array)
  G>  { print "Array: $_\n"; }

  G> print "\n\n";

  G> for (%Hash)
  G>  { print "Hash: $_\n"; }

notice how the ARRAY doesn't print any of the user keys? BECAUSE IT
ISN'T ASSOCIATIVE. it doesn't ASSOCIATE keys with values.

i hope all you newbies read this and learn how dumb she is.

uri

-- 
Uri Guttman  ------  uri@stemsystems.com  -------- http://www.stemsystems.com
-- Stem is an Open Source Network Development Toolkit and Application Suite -
----- Stem and Perl Development, Systems Architecture, Design and Coding ----
Search or Offer Perl Jobs  ----------------------------  http://jobs.perl.org


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

Date: Tue, 20 Nov 2001 20:56:11 -0800
From: "Godzilla!" <godzilla@stomp.stomp.tokyo>
Subject: Re: Can I avoid 2 passes?
Message-Id: <3BFB33EB.733E6677@stomp.stomp.tokyo>

Uri Guttman wrote:
 
> Godzilla! wrote:
 
> > Uri Guttman wrote:
> > > Dale Henderson wrote:
> > > > Drew Myers wrote:
 
>  > Will you forgive me for being a more talented
>  > Perl programmer than you? I just cannot help it.
>  > Truly, it is not my fault nor intentional.

> i forgive you for your stupidity. we are all stupid sometimes. but i
> don't forgive you for your constant thickheadedness. you never seem to
> grasp that hashes ARE associative arrays by another name and they are
> NOT arrays. but then you won't look back on your recent posts and
> realize that mistake. but it is good that you make such dumb mistakes in
> public for even newbies will know that you don't know anything about
> perl. as for your being a better programmer, i let you win that
> battle. i will not fight the lame, the sick, or the mentally
> handicapped.


Oh shoot Uri, this is no battle. My being a better
Perl programmer than you, is just the way it is.


You know Uri, I wouldn't pull stunts like this if
you and the other boys here didn't constantly and
continuously harass me, insult me and troll me.

You boys always start this. You boys are stalking
me through four different Perl groups.

You boys are not having much fun.

I am having a lot of fun.

Do you want to have fun?

Just a matter of knocking off all the childish
crap, don't you think?


Do so and I may be motivated to stop munching your minds. 


Godzilla!


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

Date: Wed, 21 Nov 2001 14:07:10 +1100
From: "Andrew Hamm" <ahamm@programmer.net>
Subject: Re: EOF testing
Message-Id: <3bfb1ac5_2@news.iprimus.com.au>

Joe Schaefer wrote in message ...
>"Andrew Hamm" <ahamm@programmer.net> writes:
>
>> if($line) { WORK }
>>
>> will do the trick.
>
>Careful-
>
>  % echo -ne "\000" | perl -wle '$_ = <>; print ord if $_'
>  0
>  % echo -ne "\060" | perl -wle '$_ = <>; print ord if $_'
>  %
>

;-)
I'm assuming Erik isn't doing anything that hairy, since he asked a simple
question.

Ass = u = me. But not for beginners questions about text files (I know,
another assumption;-)

--
Space Corps Directive #723
Terraformers are expressly forbidden from recreating Swindon.
    -- Red Dwarf





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

Date: Wed, 21 Nov 2001 04:43:54 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: has anyone tried activestate perl under solaris?
Message-Id: <x7lmh0d96g.fsf@home.sysarch.com>

>>>>> "a" == aaa  <nobody@nowhere.com> writes:

  a> Hi just wondering about people's opinion of activestate's perl
  a> distribution for solaris?
  a> If you've tried it, let me know what you like and dont like about
  a> it.....

why would i try it? perl builds fine under solaris. and you can get
prebuilt binaries from sunfreeware.com. there is no need for
activestate's solaris perl.

uri

-- 
Uri Guttman  ------  uri@stemsystems.com  -------- http://www.stemsystems.com
-- Stem is an Open Source Network Development Toolkit and Application Suite -
----- Stem and Perl Development, Systems Architecture, Design and Coding ----
Search or Offer Perl Jobs  ----------------------------  http://jobs.perl.org


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

Date: Wed, 21 Nov 2001 02:25:41 GMT
From: Martien Verbruggen <mgjv@tradingpost.com.au>
Subject: Re: help w/ error: 'package does not return true'
Message-Id: <slrn9vm455.isv.mgjv@verbruggen.comdyn.com.au>

[Non existing group comp.lang.perl removed]

On Tue, 20 Nov 2001 22:29:54 GMT,
	Brice Ruth <brice@webprojkt.com> wrote:
> I'm trying to create a simple package (class) that will hold some variables
> for me. Unfortunately, when I try to 'use' this package, Perl keeps giving
> me an error about the package not returning true.  I have the line '1;' at
> the end of the package file ... I've read through the applicable section in
> the camel book and followed its directions - no go.

[snip]

> I'm running perl 5.6.0 on darwin 1.4.1 (Mac OS X v10.1.1).

Does your file have the correct line endings?  Mac OSX is the
Unix-like Os, right? If you use an editor that puts MacOS line endings
in that file, then it'll end up being a single line as far as Perl is
concerned. A comment anywhere in that file could make everything after
it a comment, including the 1;.

Martien
-- 
                                | 
Martien Verbruggen              | If at first you don't succeed, try
Trading Post Australia Pty Ltd  | again. Then quit; there's no use
                                | being a damn fool about it.


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

Date: Wed, 21 Nov 2001 03:44:31 GMT
From: "Devon Perez" <hoss@chungk.com>
Subject: help with member program
Message-Id: <zqFK7.1193975$si5.46768572@typhoon.kc.rr.com>

hi,
im creating a service.. and lets say its a counter service

i want each member to be able to log in and edit their counters.

how can i do this without having to put a whole other counter managment
program in every member directory??

i just want one counter managment program, with multiple users able to edit
their counter.

any help? suggestions?

thanks




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

Date: Wed, 21 Nov 2001 03:57:47 GMT
From: Martien Verbruggen <mgjv@tradingpost.com.au>
Subject: Re: help with member program
Message-Id: <slrn9vm9hr.isv.mgjv@verbruggen.comdyn.com.au>

On Wed, 21 Nov 2001 03:44:31 GMT,
	Devon Perez <hoss@chungk.com> wrote:
> hi,
> im creating a service.. and lets say its a counter service

A counter service? What are you counting?

> i want each member to be able to log in and edit their counters.

ok.

> how can i do this without having to put a whole other counter managment
> program in every member directory??

Put one in a place where all "members" can access it.

> i just want one counter managment program, with multiple users able to edit
> their counter.

ok.

> any help? suggestions?

Yeah...

If you're looking for a complete piece of software, try the Web, or
hire a programmer. If you want to write a solution to your problem in
Perl, write it, and feel free to ask for help to specific problems
here. If you have problems with how your OS operates, ask in an OS
specific group. If this is in some way a HTTP server/CGI question, ask
in one of the comp.infosystems.www.* groups.

if it is indeed a Perl problem you are having:

Restate your problem in such a way that it actually specifies what it
is you want to do, and state it in technical terms. Provide code that
shows that you've tried to solve the problem.

Martien
-- 
                                | 
Martien Verbruggen              | 
Trading Post Australia Pty Ltd  | Curiouser and curiouser, said Alice.
                                | 


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

Date: Wed, 21 Nov 2001 02:24:17 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: how to calculate the CRC of a string...
Message-Id: <bl3mvto79ivaql7kcol3sv4ih7q9qk2kcb@4ax.com>

MAGiC MANiAC^mTo wrote:

>How can I calculate the CRC of a string?...
>(it doesn't matter if it is a crc16 or crc32)

The modules String::CRC and String::CRC32, which exist for Windows Perl
to on Activestate's site (start browing in the
<http://www.activestate.com/PPMpackages/> directory).

And as a sidenote: the module Digest::MD5 can be used for many of the
same purposes, but with a much smaller chance of clashes, because the
result contains a lot more bits: 128 instead of 16 or 32.

-- 
	Bart.


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

Date: Wed, 21 Nov 2001 02:39:37 GMT
From: Martien Verbruggen <mgjv@tradingpost.com.au>
Subject: Re: how to calculate the CRC of a string...
Message-Id: <slrn9vm4va.isv.mgjv@verbruggen.comdyn.com.au>

On Wed, 21 Nov 2001 02:24:17 GMT,
	Bart Lateur <bart.lateur@skynet.be> wrote:
> MAGiC MANiAC^mTo wrote:
> 
>>How can I calculate the CRC of a string?...
>>(it doesn't matter if it is a crc16 or crc32)
> 
> The modules String::CRC and String::CRC32, which exist for Windows Perl
> to on Activestate's site (start browing in the
><http://www.activestate.com/PPMpackages/> directory).

No need to download a module. unpack can do this:

$ perldoc -f unpack
[snip]
               In addition to fields allowed in pack(), you may
               prefix a field with a %<number> to indicate that
               you want a <number>-bit checksum of the items
               instead of the items themselves.  Default is a
               16-bit checksum.  Checksum is calculated by sum­
               ming numeric values of expanded values (for string
               fields the sum of "ord($char)" is taken, for bit
               fields the sum of zeroes and ones).
[snip]

> And as a sidenote: the module Digest::MD5 can be used for many of the
> same purposes, but with a much smaller chance of clashes, because the
> result contains a lot more bits: 128 instead of 16 or 32.

Good advice. I don't know what the largest number of bits for unpack's
checksum is, but I doubt it's 128 or larger.

Martien
-- 
                                | 
Martien Verbruggen              | That's funny, that plane's dustin'
Trading Post Australia Pty Ltd  | crops where there ain't no crops.
                                | 


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

Date: Wed, 21 Nov 2001 03:46:53 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: how to calculate the CRC of a string...
Message-Id: <6r7mvtc5uu3cdr9k49a3fqdv0pn0biist1@4ax.com>

Martien Verbruggen wrote:

>$ perldoc -f unpack
>[snip]
>               In addition to fields allowed in pack(), you may
>               prefix a field with a %<number> to indicate that
>               you want a <number>-bit checksum of the items
>               instead of the items themselves.  Default is a
>               16-bit checksum. 

A checksum is not a CRC. For example, "ab" and "ba", i.e. two bytes
swapped, return the same checksum. All anagrams return the same
checksum.

By contrast, for a n-bit CRC you need at least (or more than) n bits to
be changed before there's a chance that two strings return the same
result (IIRC). A simple byte swap won't trigger that. 

Now, if only there was a quick way to verify that... (URL?
<http://www.cs.williams.edu/~tom/courses/336/outlines/lect7_2.html>
looks like a good starting point... scroll down to point 6)

-- 
	Bart.


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

Date: Wed, 21 Nov 2001 03:53:46 GMT
From: Martien Verbruggen <mgjv@tradingpost.com.au>
Subject: Re: how to calculate the CRC of a string...
Message-Id: <slrn9vm9aa.isv.mgjv@verbruggen.comdyn.com.au>

On Wed, 21 Nov 2001 03:46:53 GMT,
	Bart Lateur <bart.lateur@skynet.be> wrote:
> Martien Verbruggen wrote:
> 
>>$ perldoc -f unpack
>>[snip]
>>               In addition to fields allowed in pack(), you may
>>               prefix a field with a %<number> to indicate that
>>               you want a <number>-bit checksum of the items
>>               instead of the items themselves.  Default is a
>>               16-bit checksum. 
> 
> A checksum is not a CRC. For example, "ab" and "ba", i.e. two bytes
> swapped, return the same checksum. All anagrams return the same
> checksum.

Ack. You're right. The accuracy of posts is obviously inversely
proportional to the amount of urgency one feels for getting out of the
office for a late lunch.

Martien
-- 
                                | 
Martien Verbruggen              | Useful Statistic: 75% of the people
Trading Post Australia Pty Ltd  | make up 3/4 of the population.
                                | 


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

Date: Tue, 20 Nov 2001 18:39:54 -0800
From: "Travis Spencer" <t.s.spencer@n2.com>
Subject: need help with a seemingly simple regex
Message-Id: <ECEK7.251$bt3.236773@news.uswest.net>

Hello,

I am stuck on a regular expression that seems as though it should be pretty easy, but I can't seem
to get it.

I am trying to search for all JPG files used in a certain Web page.  The img elements looks like
this:

<img src="images/large/0010.jpg">
<img src="images/large/0102.jpg">
<img src="images/large/0215.jpg">
etc.

But the problem is that there are many referenced to JPGs that are prefixed with the string "tn_" in
the same page.  For instance:

<img src="images/tn/tn_0010.jpg">
<img src="images/tn/tn_0102.jpg">
<img src="images/tn/tn_0215.jpg">

This is what I have tried so far, but the negation doesn't help at all.

[^tn_[0-9]+.jpg)][0-9]+.jpg

Any help would be much appreciated.

Regards,

Travis Spencer
Portland, OR USA




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

Date: Tue, 20 Nov 2001 20:17:02 -0700
From: pt <mnemotronic@mind\no-spam/spring.com>
Subject: Re: need help with a seemingly simple regex
Message-Id: <3BFB1CAE.C6A46BDA@mindspring.com>



Travis Spencer wrote:

> Hello,
>
> I am stuck on a regular expression that seems as though it should be pretty easy, but I can't seem
> to get it.
>
> I am trying to search for all JPG files used in a certain Web page.  The img elements looks like
> this:
>
> <img src="images/large/0010.jpg">
> <img src="images/large/0102.jpg">
> <img src="images/large/0215.jpg">
> etc.
>
> But the problem is that there are many referenced to JPGs that are prefixed with the string "tn_" in
> the same page.  For instance:
>
> <img src="images/tn/tn_0010.jpg">
> <img src="images/tn/tn_0102.jpg">
> <img src="images/tn/tn_0215.jpg">
>
> This is what I have tried so far, but the negation doesn't help at all.
>
> [^tn_[0-9]+.jpg)][0-9]+.jpg
>

    Do you want just the filename, the full path, the filename plus extension?

    Here's something that will give just the filename part, and how I arrived at it :
    Search for "<IMG"
    followed by 1 or more whitespace
    followed by "SRC"
    followed by 0 or more whitespace
    followed by "="
    followed by 0 or more whitespace
    followed by 1 or more of any char
    followed by "/" or "\" (if delim is always "/" drop "\")
    followed by 1 or more anything that isn't "." (CAPTURE)
    followed by ".JPG"
    make it case insensitive so that we can use "IMG" and "SRC"
    in the regexp to distinguish those chars from stuff like "\s"

    /<IMG\s+SRC\s*=\s*.*\/|\\([^.]+)\.JPG/i

    Most of the work is in differentiating image tags from something else that might have a
'src="file/blah/blah/'.  This might be more safety than is needed, and there's probably a module that
will parse HTML files for you, but re-inventing the wheel *CAN* be a good exercise.



>
> Any help would be much appreciated.
>
> Regards,
>
> Travis Spencer
> Portland, OR USA


Remove the obvious anti-spam to reply.


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

Date: Tue, 20 Nov 2001 19:40:53 -0800
From: "Godzilla!" <godzilla@stomp.stomp.tokyo>
Subject: Re: need help with a seemingly simple regex
Message-Id: <3BFB2245.36F2B2DB@stomp.stomp.tokyo>

Travis Spencer wrote:

(snipped)

> I am trying to search for all JPG files used in a certain Web page.
> The img elements looks like this:
 
> <img src="images/large/0010.jpg">
> <img src="images/large/0102.jpg">
> <img src="images/large/0215.jpg">
 
> But the problem is that there are many referenced to JPGs that are
> prefixed with the string "tn_" in the same page.  For instance:

> <img src="images/tn/tn_0010.jpg">
> <img src="images/tn/tn_0102.jpg">
> <img src="images/tn/tn_0215.jpg">
 
> This is what I have tried so far, but the negation doesn't help at all.
 
> [^tn_[0-9]+.jpg)][0-9]+.jpg
 
> Any help would be much appreciated.


A presumption is made you are working with an average
size web page and reading it in as a single string.

I have two methods to exemplify for you which should
prove to be relatively quick and efficient compared
to a standard regex method.

You have data perfect for a split. Looks like you are
working with thumbnails and full size images. For each
full size image, your url contains "large" as part of
your path. This is adaptable to a split / array method.

Same word can be used for a do / until loop action.

Look over my methods within my test script and decide
if these are adaptable to your needs.


Godzilla!
--

#!perl

$string = 'GARBAGE
<img src="images/large/0010.jpg">
GARBAGE
<img src="images/tn/tn_0010.jpg">
<img src="images/large/0102.jpg">
GARBAGE
<img src="images/tn/tn_0102.jpg">
<img src="images/tn/tn_0215.jpg">
<img src="images/large/0215.jpg">
GARBAGE';


print "Split / Array Method:\n\n";

@Array = split (/large\//, $string);

for (@Array)
 { 
  if (substr($_, 0, 1) eq "0")
   { print substr ($_, 0, index ($_, "jpg") + 3), "\n"; }
 }


print "\n\nDo / Until Method:\n\n";

do
 {
  $position = index ($string, "large/", $position);
  print substr ($string, $position + 6, 8), "\n";
  $position++;
 }
until ($position == rindex ($string, "large/") + 1);


exit;


PRINTED RESULTS:
________________

Split / Array Method:

0010.jpg
0102.jpg
0215.jpg


Do / Until Method:

0010.jpg
0102.jpg
0215.jpg


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

Date: Wed, 21 Nov 2001 03:41:08 GMT
From: Martien Verbruggen <mgjv@tradingpost.com.au>
Subject: Re: need help with a seemingly simple regex
Message-Id: <slrn9vm8ik.isv.mgjv@verbruggen.comdyn.com.au>

On Tue, 20 Nov 2001 18:39:54 -0800,
	Travis Spencer <t.s.spencer@n2.com> wrote:

[reformatted post to fit on a screen]

> Hello,
> 
> I am stuck on a regular expression that seems as though it should be
> pretty easy, but I can't seem to get it.
> 
> I am trying to search for all JPG files used in a certain Web page.
> The img elements looks like this:

You should parse HTML with an HTML parser (HTML::Parser is available
from CPAN). It cannot, generally, be done with regular expressions.
For simple cases, i.e. a subset of HTML, you can get it done, but it
won't be a general solution.

><img src="images/large/0010.jpg">
><img src="images/large/0102.jpg">
><img src="images/large/0215.jpg">
> etc.
> 
> But the problem is that there are many referenced to JPGs that are
> prefixed with the string "tn_" in the same page.  For instance:
> 
><img src="images/tn/tn_0010.jpg">
><img src="images/tn/tn_0102.jpg">
><img src="images/tn/tn_0215.jpg">

Why is this a problem? 

> This is what I have tried so far, but the negation doesn't help at all.
> 
> [^tn_[0-9]+.jpg)][0-9]+.jpg

I take it that you mean that you don't want those?

The following may work for you, but no guarantees are given.  This
assumes a format of your img tags exactly as you gave it here.  and no
alt="-->" or stuff like that.

Remember that I said first that you should use a HTML parser :)

Assuming that the HTML document is available in $html:

my @img = grep { !m#(?:^|/)tn_\w+\.jpg$# } 
          $html =~ m#<img src="(.+?)">#gs;

A possible HTML::Parser solution, with the DATA filehandle opened to
the HTML file:

use strict;
use HTML::Parser;

my $p = HTML::Parser->new(start_h => [\&start, "tagname,attr"]);
$p->parse_file(\*DATA);

my @img;
sub start
{
	my ($tag, $attr) = @_;
	return unless $tag eq "img";
	return if $attr->{src} =~ m#(?:^|/)tn_\w+\.jpg$#;
	push @img, $attr->{src};
}

# now @img contains a list of all the relevant images.

Martien
-- 
                                | 
Martien Verbruggen              | Hi, Dave here, what's the root
Trading Post Australia Pty Ltd  | password?
                                | 


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

Date: Tue, 20 Nov 2001 20:38:35 -0800
From: "Godzilla!" <godzilla@stomp.stomp.tokyo>
Subject: Re: need help with a seemingly simple regex
Message-Id: <3BFB2FCB.9DEE0628@stomp.stomp.tokyo>

Martien Verbruggen wrote:
 
> Travis Spencer wrote:

(snipped)
 
> > I am stuck on a regular expression that seems as though it should be
> > pretty easy, but I can't seem to get it.

> > I am trying to search for all JPG files used in a certain Web page.
> > The img elements looks like this:

> Remember that I said first that you should use a HTML parser :)
 
> A possible HTML::Parser solution, with the DATA filehandle opened to
> the HTML file:
 
> use strict;
> use HTML::Parser;
 
> my $p = HTML::Parser->new(start_h => [\&start, "tagname,attr"]);
> $p->parse_file(\*DATA);

 ....


Godzilla!
--

CONTENTS OF TEST.HTM:
_____________________

<HTML>
GARBAGE
<img src="images/large/0010.jpg">
GARBAGE
<img src="images/tn/tn_0010.jpg">
<img src="images/large/0102.jpg">
GARBAGE
<img src="images/tn/tn_0102.jpg">
<img src="images/tn/tn_0215.jpg">
<img src="images/large/0215.jpg">
GARBAGE
</HTML>


TEST SCRIPT:
____________

#!perl

use strict;
use HTML::Parser;

open (DATA, "test.htm");

my $p = HTML::Parser->new(start_h => [\&start, "tagname,attr"]);
$p->parse_file(\*DATA);

my @img;
sub start
{
        my ($tag, $attr) = @_;
        return unless $tag eq "img";
        return if $attr->{src} =~ m#(?:^|/)tn_\w+\.jpg$#;
        push @img, $attr->{src};
}

close (DATA);

if (@img)
 { print "@img"; }
else
 { print "FUBAR!"; }

exit;


PRINTED RESULTS:
________________

FUBAR!


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

Date: 20 Nov 2001 20:31:48 -0800
From: vazkevin@hotmail.com (Kevin VAZ)
Subject: Overwriting a part of text using a perl script!
Message-Id: <241f7389.0111202031.85cef2d@posting.google.com>

Dear All,

Greetings!

I'am new to perl, but use it for simple scripting. I'am facing a
problem in substituting the date in the header of a file. Was
wondering if we could overwrite only a selected portion of text.
Awating your response.

Regards,
Kevin.

*******************************
    Trusting in GOD Alone.
*******************************


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

Date: Wed, 21 Nov 2001 02:16:35 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: result pages (10 by 10)
Message-Id: <et2mvt8usj2ma2ect3goko20dnhabb2clg@4ax.com>

Jason Gray wrote:

>I'm currently trying to figure out how to display 10 results at a time then
>if there is more, a link will show and you'll be able to view the next 10
>results. Like if a file has 29 lines, I want to be able to view 3 pages. Any
>help would be good.

Try this for starters. Get all search results, or references to them,
into an array. Then manipulate the array so you get the (at most) 10
results you're interested in. Play with various values for $offset,
which is supposed to be an optional parameter, default value 0.

    my @result = (1 .. 29);
    my $offset = 12; # (or 0, or 10, or even 30)
    my $perpage = 10;
    
    my $back = (($offset || 0) > 0);
    if($back) {
           splice @result, 0, $offset;
    }
    my $next = (@result > $perpage);
    if($next) {
         splice @result, $perpage;
    }
    if($back) {  # back button
          print "<<BACK<< (offset = " . (($offset - $perpage > 0)?
            $offset : "") . ")\n" ;
    }
    foreach (@result) {
        print "Result: $_\n";
    }
    if($next) {  # next button
          print ">>NEXT>> (offset = " . ($offset + $perpage) . ")\n" ;
    }


A solution with a hash slice (not splice) is feasable too:

	my @slice = @result[$offset .. $offset+$perpage-1];

but this will include undefined values if you get beyond the end of the
array.

-- 
	Bart.


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

Date: Tue, 20 Nov 2001 20:37:52 -0800
From: "Greg Muth" <gamu829@yahoo.com>
Subject: Re: Template System
Message-Id: <tvmbt2gt1u3k4d@corp.supernews.com>

"Wiliam Stephens" <wil@fbagroup.co.uk> wrote in message
news:39e3e00a.0111201058.5bd9e93d@posting.google.com...
> Yes, thanks. My mind went blank there for a minute!
>
> Cheers

It happens...






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

Date: 21 Nov 2001 03:00:31 GMT
From: gorilla@elaine.furryape.com (Alan Barclay)
Subject: Re: using sendmail from perl
Message-Id: <1006311632.608365@elaine.furryape.com>

In article <JCDK7.119$cs3.74850@news1.news.adelphia.net>,
Zachary Kent <zkent@adelphia.net> wrote:
>"Wiliam Stephens" <wil@fbagroup.co.uk> wrote in message
>news:39e3e00a.0111201540.3c5e4e6@posting.google.com...
>> "Brian Wakem" <no@email.com> wrote in message
>news:<RWxK7.1195$6W6.399766@news2-win.server.ntlworld.com>...
>>
>> > if ($regEmail !~ /^[\w-.]+\@[\w-.]+$/) {
>> > print "You have not entered a valid email address";
>> > ...
>>
>> Surely you'll need a little more complex regex than that to determine
>> a valid email address?
>>
>> Wil
>
>To clarify my needs, I DON'T need to determine if the given email address is
>valid, just that it is properly formed and does not contain invalid
>characters.   Does this regex do that?

No. Try emailing Randal's friends fred+barney@stonehenge.com. Any
char is valid in the localpart of an address, except for the CR
character.

To properly check if an address is valid, then use Abigail's
RFC::RFC822::Address module.


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

Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 6 Apr 01)
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.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 V10 Issue 2168
***************************************


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