[18102] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 262 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Feb 9 21:10:38 2001

Date: Fri, 9 Feb 2001 18:10:14 -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: <981771013-v10-i262@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Fri, 9 Feb 2001     Volume: 10 Number: 262

Today's topics:
    Re: Radical readdir suggestion <ldo@geek-central.gen.new_zealand>
    Re: Radical readdir suggestion (Martien Verbruggen)
    Re: Radical readdir suggestion (Ilya Zakharevich)
    Re: Radical readdir suggestion <mischief@velma.motion.net>
    Re: Regular Expression Question (David H. Adler)
    Re: Sending email from Perl Script on NT <baumbach@bellatlantic.net>
    Re: Sending email from Perl Script on NT <baumbach@bellatlantic.net>
    Re: shift vs splice in boolean context, why do they act <fecundfec@my-deja.com>
    Re: sorting an array (Martien Verbruggen)
    Re: split a path and keep the slashes? (Craig Berry)
    Re: split a path and keep the slashes? (Abigail)
    Re: Splitting a quote-comma delimitted string (Gwyn Judd)
    Re: splitting a string on the / character <DNess@Home.Com>
    Re: splitting a string on the / character (Mahesh A)
    Re: Using regex to match numbers (not digits)? (Craig Berry)
    Re: XML: "Flattening" XML to dot notation - best module <bart.lateur@skynet.be>
        Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)

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

Date: Sat, 10 Feb 2001 12:30:10 +1300
From: Lawrence DčOliveiro <ldo@geek-central.gen.new_zealand>
Subject: Re: Radical readdir suggestion
Message-Id: <ldo-74B44F.12301010022001@news.wave.co.nz>

In article <slrn984svj.vht.mgjv@martien.heliotrope.home>, 
mgjv@tradingpost.com.au wrote:

>On 7 Feb 2001 15:20:43 GMT,
>	Ilmari Karonen <iltzu@sci.invalid> wrote:
>> In article <slrn9829pp.vht.mgjv@martien.heliotrope.home>, Martien 
>> Verbruggen wrote:
>>>
>>>The file foo is also not part of the content of a directory. The name
>>>foo points to a file on the file systems somewhere. The names . and ..
>>>point to files on the file system somewhere. They are in that respect
>>>not special at all. They get automatically created by a mkdir, and they
>>>always point to directories, but that's pretty much where their
>>>specialness, as far as how they are part of a directory, ends.
>> 
>> Well, except for that fact that they create a loop of hard links.
>
>But a loop of hard links can be created with otherwise named entries as
>well.

No, they cannot--try it.

>It is generally disallowed for regular users to create hard links
>to directories, because they are dangerous when used incorrectly, but
>that doesn't make . and .. really special.

Yes it does, because you cannot create your own entries with the same 
meanings as "." or "..".

>> The problem, as the OP stated, is that Unix filesystems can't make up
>> their minds whether to be trees or arbitrary directed graphs.  On any
>> system which is fully the former, like that in AmigaOS, there are no
>> special entries in a directory, and every file and directory has one
>> and only one link pointing to it.  On a system that is completely the
>> latter, of course, the concept of a parent directory is meaningless.

Actually, the two features (tree versus directed graph, presence/absence 
of special "." and ".." entries) are quite independent. Witness VMS, 
where there are no special directory entries, directory links can form a 
completely general directed graph, with loops permitted, and it is not a 
major calamity as far as the filesystem is concerned to have either 
dangling directory entries pointing at nonexistent objects,  or objects 
with no directory entries at all! (Though naturally all these situations 
can be quite disconcerting to users.)

Regardless of whether you consider the UNIX filesystem to be a tree or a 
directed acyclic graph (loops are not permitted), the fact remains that 
there is a strict hierarchy. That is, given any two filesystem objects, 
you can definitely say that either one lies above the other (and 
"contains" the latter), or the two have a higher-level parent in common 
(which "contains" them both).

All, that is, except for the "." and ".." entries. If you treat them on 
an equal basis with the other entries, then they violate the hierarchy. 
_But they are the only exceptions to the rule_. Thus, they have to be 
treated specially--the concept of "containment" does not apply to them.

And as far as I know, *all* uses of readdir are with the intention of 
examining the _contents_ of a directory. Thus, it makes sense for 
readdir to skip the "." and ".." entries in a directory, _but only on 
systems where these are not part of the its contents_.

>One of the strengths of the Unix file system is that multiple links can
>point to the same file. Add in symbolic links, and the .. entry is
>almost necessary to get to where you want to be.

VMS is a counterexample, as is MacOS when you include its "alias" 
feature.

>It can be done without
>this structure, as many other file systems prove, but that doesn't mean
>either is better. I much prefer the Unix file system over many others
>I've got a knowledge of.

How is this relevant to the merits of my proposal for readdir?

>> I wanted to check how File::Find deals with this, but apparently it
>> doesn't.  There are other OS specific checks, but "." and ".." are
>> always skipped.  So File::Find is broken on Macs, Amigas, etc.
>
>Then File::Find should be fixed, most likely by someone who actually is
>on a system where . and .. aren't special.

That means changing the Perl code, doesn't it? Which means the Perl code 
itself is no longer cross-platform.


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

Date: Sat, 10 Feb 2001 11:20:22 +1100
From: mgjv@tradingpost.com.au (Martien Verbruggen)
Subject: Re: Radical readdir suggestion
Message-Id: <slrn9892a6.vht.mgjv@martien.heliotrope.home>

On Sat, 10 Feb 2001 12:30:10 +1300,
	Lawrence DčOliveiro <ldo@geek-central.gen.new_zealand> wrote:
> In article <slrn984svj.vht.mgjv@martien.heliotrope.home>, 
> mgjv@tradingpost.com.au wrote:
> 
>>On 7 Feb 2001 15:20:43 GMT,
>>	Ilmari Karonen <iltzu@sci.invalid> wrote:
>>
>>But a loop of hard links can be created with otherwise named entries as
>>well.
> 
> No, they cannot--try it.

Yes they can. Make sure you're root, and on a system that hasn't
implemented extra precautions to prevent it from happening. A standard
Unix file system allows hard links to directories. When that is allowed,
a loop can be set up.

Yes, some systems prohibit it, but the actual file system itself does
not. Don't draw conclusions about what is or isn't allowed based on what
you can do on your OS.

[Snip of very large quote without any additional content added. Please,
cut irrelevant quoted text from your replies.]

Martien
-- 
Martien Verbruggen              | Since light travels faster than
Interactive Media Division      | sound, isn't that why some people
Commercial Dynamics Pty. Ltd.   | appear bright until you hear them
NSW, Australia                  | speak?


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

Date: 10 Feb 2001 01:13:03 GMT
From: ilya@math.ohio-state.edu (Ilya Zakharevich)
Subject: Re: Radical readdir suggestion
Message-Id: <9624iv$9gr$1@charm.magnus.acs.ohio-state.edu>

[A complimentary Cc of this posting was sent to Lawrence DčOliveiro 
<ldo@geek-central.gen.new_zealand>],
who wrote in article <ldo-74B44F.12301010022001@news.wave.co.nz>:
> Regardless of whether you consider the UNIX filesystem to be a tree or a 
> directed acyclic graph (loops are not permitted), the fact remains that 
> there is a strict hierarchy. That is, given any two filesystem objects, 
> you can definitely say that either one lies above the other (and 
> "contains" the latter), or the two have a higher-level parent in common 
> (which "contains" them both).

Given that this is wrong, this explains your desire to maim readdir.
[Think of hard links to directories, and unlinked directories.]

> And as far as I know, *all* uses of readdir are with the intention of 
> examining the _contents_ of a directory.

 ... Another explanation.  ["And as far as I know" does not work in the
real world.  Given a flexible API which does not hide *any* info, the
combined intelligence of the hundreds of thousands of Perl users would
find beautiful ways to use this API - the ways *no single man* is able
to predict.  Especially if this man does not know *standard* ways to
hack FSs.]

> Thus, it makes sense for 
> readdir to skip the "." and ".." entries in a directory, _but only on 
> systems where these are not part of the its contents_.

Sometimes: yes, of course, it would be useful.  But only as an option.

Ilya


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

Date: Sat, 10 Feb 2001 01:51:44 -0000
From: Chris Stith <mischief@velma.motion.net>
Subject: Re: Radical readdir suggestion
Message-Id: <t897lgmla7rb9f@corp.supernews.com>

Ilya Zakharevich <ilya@math.ohio-state.edu> wrote:
> [A complimentary Cc of this posting was sent to Lawrence D?Oliveiro 
> <ldo@geek-central.gen.new_zealand>],
> who wrote in article <ldo-74B44F.12301010022001@news.wave.co.nz>:
>> Regardless of whether you consider the UNIX filesystem to be a tree or a 
>> directed acyclic graph (loops are not permitted), the fact remains that 
>> there is a strict hierarchy. That is, given any two filesystem objects, 
>> you can definitely say that either one lies above the other (and 
>> "contains" the latter), or the two have a higher-level parent in common 
>> (which "contains" them both).

> Given that this is wrong, this explains your desire to maim readdir.
> [Think of hard links to directories, and unlinked directories.]

I link to directories all the time, BTW. On my old 486 laptop, for
example, I have /usr/bin/local linked to /usr/bin to save space. I have
/etc/httpd/conf (where some Linux distros put Apache configs and
expect to find them later) to /usr/local/apache/conf.

>> And as far as I know, *all* uses of readdir are with the intention of 
>> examining the _contents_ of a directory.

One of the ways I've seen to tell what the current directory happens to
be involves reading the directory contents, seeing if '..' is part of
them, getting the inode of '.',  doing opendir() and readdir() on the
parent, then testing to see which of the contents of the parent directory
has the same inode as '.'. Combine paths of parents until either
'..' and '.' are both the root directory (or your chrooted environment,
which for any reasonable purpose is the same) or you can't change to
'..'. This might not be the best way to do this, but it's portable
across Unix and DOS/Windows and doesn't shell out to anything.

>> Thus, it makes sense for 
>> readdir to skip the "." and ".." entries in a directory, _but only on 
>> systems where these are not part of the its contents_.

> Sometimes: yes, of course, it would be useful.  But only as an option.

As Ilmari and I had mentioned (and I thought agreed upon) earlier,
a variable to set or another function (similar to binmode()'s use on
Windows) to toggle the behavior of readdir would best suit the needs of
both sides. I don't want to lose my dot entires any more than some of
the people here want to see them.

Chris

-- 
Christopher E. Stith

Even in the worst of times, there is always someone who's
never had it better. Even in the best of times, there is
always someone who's never had it worse.



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

Date: 9 Feb 2001 23:37:38 GMT
From: dha@panix2.panix.com (David H. Adler)
Subject: Re: Regular Expression Question
Message-Id: <slrn988vq2.e77.dha@panix2.panix.com>

On 9 Feb 2001 21:10:26 GMT, Eli the Bearded <elijah@workspot.net> wrote:
>In comp.lang.perl.misc, David H. Adler <dha@panix6.panix.com> wrote:
>> On 8 Feb 2001 23:16:34 GMT, Damian James <damian@qimr.edu.au> wrote:
>> >Note that the OP wanted to test the length of the _match_, not the line.
>> >DHA's solution in this thread did this.
>> Nevertheless, I yield to ETB for the solution in the painful
>> category. :-)
>
>s/ETB/EtB/, please.

Aw, jeez... *another* style guide to deal with???

:-)

dha

-- 
David H. Adler - <dha@panix.com> - http://www.panix.com/~dha/
You get the idea that if Apple won a 90% market share, bought out
Microsoft, and hired Bill Gates to mop the bathrooms, Business Week
would write: "Apple has all but ignored the possibility of alien
invasion..."	- David Pogue


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

Date: Fri, 09 Feb 2001 23:01:36 GMT
From: Jason Baumbach <baumbach@bellatlantic.net>
Subject: Re: Sending email from Perl Script on NT
Message-Id: <3A8476AD.721DDCE5@bellatlantic.net>

This would be perfect for my needs yet I can not get it to work.  :-(

I am running Windows 2000 Advanced Server.
Active Perl 5.6.0

Any Ideas????

Franziskus Scharpff wrote:

> I do not know the LWP and HTTP Package, so I can not help you directly.
>
> What I can offer is a possibility that works under NT:
>
>       use Net::SMTP;
>
>     $smtp = Net::SMTP->new('mailhost');         # your Smtp - Server
> $smtp->mail($ENV{USER});                    # I write the name of the Sender
> here                                                 # because some Mailer
> do not accept a Mail without a complete name.
>     $smtp->to('postmaster');                    # Display Name of Recipient
>     $smtp->data();
>     $smtp->datasend("To: postmaster\n");        # Mailadress
>     $smtp->datasend("\nSubject: xy \n");        # You NEED the leading \n
> $smtp->datasend("\n");
>     $smtp->datasend("A simple test message\n");
>
>     $smtp->dataend();    $smtp->quit;
> This works for me.Hope it helps you.
> Franziskus
>
> <jgunnip@my-deja.com> wrote in message news:96130h$2fq$1@nnrp1.deja.com...
> >
> >
> > Hi,
> >
> > Does anyone know why the following code to send email works perfectly
> > on Linux but not on Windows NT?  It doesn't complain (i.e. die()) when
> > I use it on NT.  I just never receive the email.
> >
> > Thanks,
> > Jon
> >
> > email('foo@bar.com', 'bar@foo.com', 'Hello', 'Just saying Hi!');
> >
> > sub email {
> >   use LWP::UserAgent;
> >   use HTTP::Request;
> >
> >   my $to       = shift;
> >   my $from     = shift;
> >   my $subject  = shift;
> >   my $message  = shift or die 'Usage email($to, $from, $sub, $msg)';
> >
> >   # mail message
> >   my $ua = LWP::UserAgent->new or die "$!";
> >   my $req = HTTP::Request->new(POST => "mailto:$to") or die "$!";
> >   $req->header(Subject => "$subject", From => $from);
> >   $req->content($message);
> >
> >   $ua->request($req) or die "Error sending mail";
> > }
> >
> >
> >
> > Sent via Deja.com
> > http://www.deja.com/




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

Date: Fri, 09 Feb 2001 23:00:01 GMT
From: Jason Baumbach <baumbach@bellatlantic.net>
Subject: Re: Sending email from Perl Script on NT
Message-Id: <3A84764F.270350A7@bellatlantic.net>

This would be perfect for my needs yet I can not get it to work.  :-(

I am running Windows 2000 Advanced Server.
Active Perl 5.6.0

Any Ideas????

Franziskus Scharpff wrote:

> I do not know the LWP and HTTP Package, so I can not help you directly.
>
> What I can offer is a possibility that works under NT:
>
>       use Net::SMTP;
>
>     $smtp = Net::SMTP->new('mailhost');         # your Smtp - Server
> $smtp->mail($ENV{USER});                    # I write the name of the Sender
> here                                                 # because some Mailer
> do not accept a Mail without a complete name.
>     $smtp->to('postmaster');                    # Display Name of Recipient
>     $smtp->data();
>     $smtp->datasend("To: postmaster\n");        # Mailadress
>     $smtp->datasend("\nSubject: xy \n");        # You NEED the leading \n
> $smtp->datasend("\n");
>     $smtp->datasend("A simple test message\n");
>
>     $smtp->dataend();    $smtp->quit;
> This works for me.Hope it helps you.
> Franziskus
>
> <jgunnip@my-deja.com> wrote in message news:96130h$2fq$1@nnrp1.deja.com...
> >
> >
> > Hi,
> >
> > Does anyone know why the following code to send email works perfectly
> > on Linux but not on Windows NT?  It doesn't complain (i.e. die()) when
> > I use it on NT.  I just never receive the email.
> >
> > Thanks,
> > Jon
> >
> > email('foo@bar.com', 'bar@foo.com', 'Hello', 'Just saying Hi!');
> >
> > sub email {
> >   use LWP::UserAgent;
> >   use HTTP::Request;
> >
> >   my $to       = shift;
> >   my $from     = shift;
> >   my $subject  = shift;
> >   my $message  = shift or die 'Usage email($to, $from, $sub, $msg)';
> >
> >   # mail message
> >   my $ua = LWP::UserAgent->new or die "$!";
> >   my $req = HTTP::Request->new(POST => "mailto:$to") or die "$!";
> >   $req->header(Subject => "$subject", From => $from);
> >   $req->content($message);
> >
> >   $ua->request($req) or die "Error sending mail";
> > }
> >
> >
> >
> > Sent via Deja.com
> > http://www.deja.com/




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

Date: Fri, 09 Feb 2001 23:06:05 GMT
From: Yary Hluchan <fecundfec@my-deja.com>
Subject: Re: shift vs splice in boolean context, why do they act differently
Message-Id: <961t4o$rp6$1@nnrp1.deja.com>

Thanks for the explanation.  I was confused because
"perldoc -f splice" says the following are equivalent-
 shift(@a)           splice(@a,0,1)

but in fact neither of shift nor pop are exact equivalents
to any form of splice, because splice returns lists while
shift & pop return scalars when called in list context.

The example I gave was contrived, here's the code that inspired it

while (($k, $v) = ($s->{sorthash}?
                     map {$_,$$val{$_}} splice @srt,0,1 :
                     each %$val)) {

that is, I am either iterating over a hash with each, or I'm using a
pre-sorted keylist one item at a time.  Using shift there causes an
infinite loop.

Sure would be nice if shift returned an empty list
when being called in a list context on an empty list.


Sent via Deja.com
http://www.deja.com/


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

Date: Sat, 10 Feb 2001 11:25:53 +1100
From: mgjv@tradingpost.com.au (Martien Verbruggen)
Subject: Re: sorting an array
Message-Id: <slrn9892kh.vht.mgjv@martien.heliotrope.home>

On 09 Feb 2001 12:24:43 +0000,
	J.C.Posey <jcp@myrtle.ukc.ac.uk> wrote:
> abigail@foad.org (Abigail) writes:
>> 
>> Really? What did you try and what was the error you got?
> 
> I tried print sort @daily_totals;
> 
> Then it would give me "syntax error at line XX, near print".

That almost certainly means you have an error before the line with the
print statement. Investigate the lines before there. Perl tells you at
which line it first notices that something is wrong. This isn't always
the line where the error has occurred. Did you properly use a semicolon
to separate the statements?

Martien
-- 
Martien Verbruggen              | 
Interactive Media Division      | Think of the average person. Half of
Commercial Dynamics Pty. Ltd.   | the people out there are dumber.
NSW, Australia                  | 


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

Date: Fri, 09 Feb 2001 23:57:25 -0000
From: cberry@cinenet.net (Craig Berry)
Subject: Re: split a path and keep the slashes?
Message-Id: <t890v5sgamqkb6@corp.supernews.com>

tebrusca@my-deja.com wrote:
: Given a path: "//A/B/" or "/A/B" or "/A//B//" etc
: Return a list: "/A", "/B"
: 
: That is, ignore multiple slashes and give items with leading slash

  my @list = map { "/$_" } grep { $_ } split m!/!, $string;

That grep in the middle is to get rid of a trailing null string that will
occur if there are trailing slashes in $string.

-- 
   |   Craig Berry - http://www.cinenet.net/~cberry/
 --*--  "When the going gets weird, the weird turn pro."
   |               - Hunter S. Thompson


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

Date: 10 Feb 2001 00:29:18 GMT
From: abigail@foad.org (Abigail)
Subject: Re: split a path and keep the slashes?
Message-Id: <slrn9892qt.doc.abigail@tsathoggua.rlyeh.net>

Craig Berry (cberry@cinenet.net) wrote on MMDCCXIX September MCMXCIII in
<URL:news:t890v5sgamqkb6@corp.supernews.com>:
$$ tebrusca@my-deja.com wrote:
$$ : Given a path: "//A/B/" or "/A/B" or "/A//B//" etc
$$ : Return a list: "/A", "/B"
$$ : 
$$ : That is, ignore multiple slashes and give items with leading slash
$$ 
$$   my @list = map { "/$_" } grep { $_ } split m!/!, $string;
$$ 
$$ That grep in the middle is to get rid of a trailing null string that will
$$ occur if there are trailing slashes in $string.


By default, split ignores trailing empty fields. However, multiple
/'s cause empty fields, because you don't use m!/+!. However, grepping
on $_ isn't good, as that checks for true/falseness of $_, and 0 is
false. But you shouldn't get rid of 0's.



Abigail
-- 
map{${+chr}=chr}map{$_=>$_^ord$"}$=+$]..3*$=/2;        
print "$J$u$s$t $a$n$o$t$h$e$r $P$e$r$l $H$a$c$k$e$r\n";


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

Date: Sat, 10 Feb 2001 00:51:04 GMT
From: tjla@guvfybir.qlaqaf.bet (Gwyn Judd)
Subject: Re: Splitting a quote-comma delimitted string
Message-Id: <slrn98943n.7o0.tjla@thislove.dyndns.org>

I was shocked! How could Eric <eric.kort@vai.org>
say such a terrible thing:
>How can I split the following without splitting on the comma inside quotes:

This is in the FAQ:

perldoc -q 'How can I split a [character] delimited string except when
inside [character]?'

-- 
Gwyn Judd (print `echo 'tjla@guvfybir.qlaqaf.bet' | rot13`)

"We look for things."
"So I've heard."

        -- Reginod and Geordi in ST:TNG "Samaritan Snare"


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

Date: Fri, 09 Feb 2001 23:06:15 GMT
From: David Ness <DNess@Home.Com>
Subject: Re: splitting a string on the / character
Message-Id: <3A8477F4.738AAC89@Home.Com>

Mahesh A wrote:
> 
> Now, I am not refering to any specific contributer, but I don't get
> all this. People can spend hours discussing a map, a fish or may be an
> elephant or a sea gherkin which has nothing to do with perl (Ooops..
> map does !!), but not a minute or a half to give a simple answer for
> present and reference to a manpage for later.
> 
> If this is what knowledgeable people are.. I'd rather stay away...
> 
> -

IMO you miss the point. Random conversation is random conversation and
`perl people' are no more or less likely to engage in it than are others.
With regard to perl, however, this NG answers a _huge_ number of questions
and people who do this work (I am not one of them, BTW) have learned a lot
over the years about how to make the use of their time effective. As a result 
they generally try to `teach you how to fish' and thus solve future problems as 
well, rather than to just `throw you a fish' and only solve the immediate
problem.

Help obtained here isn't always phrased in pleasant ways, but it generally is 
very effective, and I, for one, wouldn't want to tell the `regulars' here how to 
help unless I had spent a lot of time trying to help others first...


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

Date: Fri, 09 Feb 2001 23:16:38 GMT
From: maheshasolkar@yahoo.com (Mahesh A)
Subject: Re: splitting a string on the / character
Message-Id: <3a8479ab.279829012@news>

On Fri, 09 Feb 2001 23:06:15 GMT, David Ness <DNess@Home.Com> wrote:

>Mahesh A wrote:
>> 
>> Now, I am not refering to any specific contributer, but I don't get
>> all this. People can spend hours discussing a map, a fish or may be
an
>> elephant or a sea gherkin which has nothing to do with perl
(Ooops..
>> map does !!), but not a minute or a half to give a simple answer
for
>> present and reference to a manpage for later.
>> 
>> If this is what knowledgeable people are.. I'd rather stay away...
>> 
>> -
>

In my opinion, IMO is "In my opinion" ??? But I couldn't get NG ??

>IMO you miss the point. Random conversation is random conversation
and
>`perl people' are no more or less likely to engage in it than are
others.
>With regard to perl, however, this NG answers a _huge_ number of
questions
>and people who do this work (I am not one of them, BTW) have learned
a lot
>over the years about how to make the use of their time effective. As
a result 
>they generally try to `teach you how to fish' and thus solve future
problems as 
>well, rather than to just `throw you a fish' and only solve the
immediate
>problem.
>
>Help obtained here isn't always phrased in pleasant ways, but it
generally is 
>very effective, and I, for one, wouldn't want to tell the `regulars'
here how to 
>help unless I had spent a lot of time trying to help others first...

I just hope that you are right !!



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

Date: Fri, 09 Feb 2001 23:07:22 -0000
From: cberry@cinenet.net (Craig Berry)
Subject: Re: Using regex to match numbers (not digits)?
Message-Id: <t88u1a6upvq7e6@corp.supernews.com>

nukes666@my-deja.com wrote:
: I need to search a file which has, let's say, 2000 numbers in it
: between 1 & 2000, each on it's own line. I want to only print numbers
: 700 through 900 and 1200 through 1500.

Regexes are pretty cool, but they're not the right tool for every problem.
Much as in the case of verifying IP address validity, currently under
discussion on another thread, your problem is better addressed through
simple numeric comparisons.

: I need something which would do something that in my "mind" might look
: like this:
: 
: while (<FILE>) {
:       print if /[700-900][1200-1500]/;
:       }
: 
: Apparently, though, this returns any lines based on digit matches, and
: not numbers.

You misunderstand how regexes (and character classes inside them) work.
Your pattern looks for one of the characters (7 0 0 1 2 3 4 5 6 7 8 9 0
0), followed by one of the characters (1 2 0 0 1 5 0 0).  And yes, those
can in fact be compressed to the sets (0 1 2 3 4 5 6 7 8 9) and (0 1 2 5)
respectively.

: Could someone suggest the appropriate regex to return
: ranges of numbers?

  while (<FILE>) {
    print if ($_ >=  700 && $_ <=  900) ||
             ($_ >= 1200 && $_ <= 1500)
  }

-- 
   |   Craig Berry - http://www.cinenet.net/~cberry/
 --*--  "When the going gets weird, the weird turn pro."
   |               - Hunter S. Thompson


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

Date: Sat, 10 Feb 2001 01:40:15 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: XML: "Flattening" XML to dot notation - best module?
Message-Id: <id698tsakcm68sqmk17vs295upqobav75i@4ax.com>

Matt Kruse wrote:

>I want to "flatten" XML into dot notation. For example:
>
><foo>
>    <bar>X</bar>
>    <bar2>Y</bar2>
></foo>
>
>Becomes:
>
>foo.bar = X
>foo.bar2 = Y
>
>Assuming the XML will be very simple (no attributes, all text values, etc)
>then what would be the easiest way to accomplish this?

You can use XML::Parser. The "context" method of XML::Parser::Expat
pretty much does what you want.

This doesn't quite work:

#! perl -w
use XML::Parser;
$p = new XML::Parser(Handlers => {Char  => \&char});
$p->parse(<<'#EOT#');
<foo>
    <bar>X</bar>
    <bar2>Y</bar2>
</foo>
#EOT#

sub char {
    local $" = ".";
    print "@{[$_[0]->context]} = '$_[1]'\n";
}
__END__

but mainly because XML::Parser doesn't ignore whitespace. So you must
weed them out.

Careful: text can be split over multiple calls to the Char handler. So,
you ought to append the text to a string, and not print it out straight
away.

-- 
	Bart.


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

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 V10 Issue 262
**************************************


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