[25985] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 8204 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Jun 27 00:05:18 2005

Date: Sun, 26 Jun 2005 21:05:06 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Sun, 26 Jun 2005     Volume: 10 Number: 8204

Today's topics:
    Re: I don't know where to ask this quetion... but it's  <tadmc@augustmail.com>
        RegEx Help, Please?  (match after n) <smarta55ATcomcastDOTnet>
    Re: RegEx Help, Please?  (match after n) <noreply@gunnar.cc>
    Re: RegEx Help, Please?  (match after n) <smarta55ATcomcastDOTnet>
    Re: RegEx Help, Please?  (match after n) <1usa@llenroc.ude.invalid>
    Re: RegEx Help, Please?  (match after n) <1usa@llenroc.ude.invalid>
    Re: RegEx Help, Please?  (match after n) <1usa@llenroc.ude.invalid>
    Re: RegEx Help, Please?  (match after n) <smarta55ATcomcastDOTnet>
    Re: RegEx Help, Please?  (match after n) <1usa@llenroc.ude.invalid>
    Re: RegEx Help, Please?  (match after n) <smarta55ATcomcastDOTnet>
    Re: RegEx Help, Please?  (match after n) <noreply@gunnar.cc>
    Re: RegEx Help, Please?  (match after n) <1usa@llenroc.ude.invalid>
    Re: RegEx Help, Please?  (match after n) <noreply@gunnar.cc>
        Simple Structure Question <newsAT@screenlightDOT.com>
    Re: Simple Structure Question <noreply@gunnar.cc>
    Re: Simple Structure Question <newsAT@screenlightDOT.com>
    Re: Simple Structure Question <noreply@gunnar.cc>
    Re: Simple Structure Question <tassilo.von.parseval@rwth-aachen.de>
    Re: Simple Structure Question <1usa@llenroc.ude.invalid>
    Re: Simple Structure Question <sherm@dot-app.org>
    Re: Simple Structure Question <sherm@dot-app.org>
    Re: Simple Structure Question <tadmc@augustmail.com>
    Re: Simple Structure Question <tadmc@augustmail.com>
        UTF-8 to named character entities (Crap)
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Sun, 26 Jun 2005 13:22:02 -0500
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: I don't know where to ask this quetion... but it's got to be something I did....
Message-Id: <slrndbtsia.oji.tadmc@magna.augustmail.com>

VintageWine <> wrote:


> Subject: I don't know where to ask this quetion... but it's got to be something


> instead of
> running, the text of the script shows up in the Window.  This happens
> from any computer so it must be in the settings where I am running the
> Script.


Ask questions about web server configuration in a newsgroup
about web servers, such as:

      comp.infosystems.www.servers.ms-windows


-- 
    Tad McClellan                          SGML consulting
    tadmc@augustmail.com                   Perl programming
    Fort Worth, Texas


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

Date: Sun, 26 Jun 2005 21:49:06 -0400
From: "Smarta55 Chris" <smarta55ATcomcastDOTnet>
Subject: RegEx Help, Please?  (match after n)
Message-Id: <1OudndKerKyOxiLfRVn-qw@comcast.com>

Can someone help me find the last n folders in a path,
or the last n OUs in a fully qualified Netware name... for an app object,
etc?

Example:
\\server\volume\share\folder\folder\folder
I want to grab just the last 2 folders (including or excluding the \s), but
sometimes there
are 3 folders after the share, like in the example, and sometimes there are
more.

Same for an app object in eDirectory
 .appobject.dept.biz.site.county.state.tree
How to I grab just the .site.county.state.tree OUs?
Sometimes there are 5 OUs after the app object, and sometimes more.
I want, I think, to "start at the end of the string, and grab everything
after the 4th dot from the end," but don't have a clue how to code this.

I'm not a perl newbie, but I'm no expert....and I AM a RegEx idiot!

Here's some of what I've tried:
$string = ".appobject.dept.biz.site.county.state.tree";
$string =~ /\..+\..+\..+/$;    # i.e. match a literal dot followed my
anything mult times, followed by another literal dot, followed, etc...
                                        # starting at the end of the string
$string =~ /(\.\W)*/;    # \w does NOT match AlphaNum like it's supposed to,
\W DOES, but it's NOT supposed to.
                                # unless . is an AlphaNum character, but I'm
not sure

And I can't remember the 4,612 other patterns I've tried, or the
accompanying 4,612 hairs I've
yanked from my scalp in the process.  :-(

Thank you,
Chris




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

Date: Mon, 27 Jun 2005 04:13:16 +0200
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: RegEx Help, Please?  (match after n)
Message-Id: <3i95luFkcq6bU1@individual.net>

Smarta55 Chris wrote:
> Can someone help me find the last n folders in a path,
> or the last n OUs in a fully qualified Netware name... for an app object,
> etc?
> 
> Example:
> \\server\volume\share\folder\folder\folder
> I want to grab just the last 2 folders (including or excluding the \s), but
> sometimes there
> are 3 folders after the share, like in the example, and sometimes there are
> more.
> 
> Same for an app object in eDirectory
> .appobject.dept.biz.site.county.state.tree
> How to I grab just the .site.county.state.tree OUs?
> Sometimes there are 5 OUs after the app object, and sometimes more.
> I want, I think, to "start at the end of the string, and grab everything
> after the 4th dot from the end," but don't have a clue how to code this.
> 
> I'm not a perl newbie, but I'm no expert....and I AM a RegEx idiot!

Then don't overuse them. How about this for your first example:

     my @folders = ( split /\\/, $path )[-2..-1];

Leaving the second example as an exercise for you. ;-)

-- 
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl


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

Date: Sun, 26 Jun 2005 22:34:46 -0400
From: "Smarta55 Chris" <smarta55ATcomcastDOTnet>
Subject: Re: RegEx Help, Please?  (match after n)
Message-Id: <wredneddtMlU-CLfRVn-sQ@comcast.com>

Thank you.  I used:
    my @ous = (split /\.,/,$string)[-2..-1];  and got back 'folder folder'.
changing
-2 to -3 brought back 'folder folder folder'
I've used split before, but I don't understand the [-2..-1] part.
I ruled out using split because I'll never know how long the string
will be, or how many OUs will follow the object in its FQN.
Also, it's not returning what I need....obviously my thought/need wasn't
translated well to my text..

When I match against  ".appobject.dept.biz.site.county.state.tree", and
need to return the last 4 OUs, what I need back is ".site.county.state.tree"
The leading dot before
site isn't important (but is preferred), but the 3 dots between site,
county, state, and tree are needed.
I plan to append a new object, and additional OU(s), before what's returned.

Thank you for your help,
Chris


"Gunnar Hjalmarsson" <noreply@gunnar.cc> wrote in message
news:3i95luFkcq6bU1@individual.net...
>
> Then don't overuse them. How about this for your first example:
>
>      my @folders = ( split /\\/, $path )[-2..-1];
>
> Leaving the second example as an exercise for you. ;-)
>
> -- 
> Gunnar Hjalmarsson
> Email: http://www.gunnar.cc/cgi-bin/contact.pl




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

Date: Mon, 27 Jun 2005 02:38:55 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: RegEx Help, Please?  (match after n)
Message-Id: <Xns9681E664C2F08asu1cornelledu@127.0.0.1>

"Smarta55 Chris" <smarta55ATcomcastDOTnet> wrote in
news:1OudndKerKyOxiLfRVn-qw@comcast.com: 

> Can someone help me find the last n folders in a path,
> or the last n OUs 

You are missing an 'I' there ... Seriously, though, I don't know what 
you are referring to.

> Example:
> \\server\volume\share\folder\folder\folder
> I want to grab just the last 2 folders (including or excluding the
> \s), but sometimes there are 3 folders after the share, like in the
> example, and sometimes there are more.

OK.

> Same for an app object in eDirectory
> .appobject.dept.biz.site.county.state.tree
> How to I grab just the .site.county.state.tree OUs?
> Sometimes there are 5 OUs after the app object, and sometimes more.
> I want, I think, to "start at the end of the string, and grab
> everything after the 4th dot from the end," but don't have a clue how
> to code this. 

perldoc perlfunc
perldoc -f reverse
perldoc -f split

In addition,

perldoc -f rindex
perldoc -f substr

might also be of interest, in case you want to write a different 
algorithm.

> I'm not a perl newbie, but I'm no expert....and I AM a RegEx idiot!

Probably not, but you need to look at this calmly. 

> Here's some of what I've tried:
> $string = ".appobject.dept.biz.site.county.state.tree";
> $string =~ /\..+\..+\..+/$;    # i.e. match a literal dot followed my
> anything mult times, followed by another literal dot, followed, etc...
>                                         # starting at the end of the
>                               string 
> $string =~ /(\.\W)*/;    # \w does NOT match AlphaNum like it's
> supposed to, \W DOES, but it's NOT supposed to.
>                                 # unless . is an AlphaNum character,
>                               but I'm 
> not sure

This looks like Def Poetry to me.
 
> And I can't remember the 4,612 other patterns I've tried, or the
> accompanying 4,612 hairs I've yanked from my scalp in the process.
>  :-(

Here are two examples to get you started:

First:

#!/usr/bin/perl

use strict;
use warnings;

sub last_n_components {
    my ($s, $d, $n) = @_;
    join($d, reverse((reverse split /\Q$d\E/, $s) [0 .. $n - 1]))
}

print +last_n_components(
    q{.appobject.dept.biz.site.county.state.tree},
    '.', 2
)."\n";

print +last_n_components(
    q{\\\\server\volume\share\folder\folder\folder},
    '\\', 2
)."\n";

__END__

Now, if you are going to deal with paths, your life will be much easier 
if you do it portably from the start:

#!/usr/bin/perl

use strict;
use warnings;

use File::Spec::Functions qw'catdir splitdir';

sub last_n_path_components {
    my ($s, $n) = @_;
    catdir reverse((reverse splitdir $s)[0 .. $n - 1]);
}

print +last_n_path_components(
    q{\\\\server\volume\share\folder\folder\folder}, 2)."\n";

__END__


-- 
A. Sinan Unur <1usa@llenroc.ude.invalid>
(reverse each component and remove .invalid for email address)

comp.lang.perl.misc guidelines on the WWW:
http://mail.augustmail.com/~tadmc/clpmisc/clpmisc_guidelines.html


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

Date: Mon, 27 Jun 2005 02:49:09 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: RegEx Help, Please?  (match after n)
Message-Id: <Xns9681E820B1D5Basu1cornelledu@127.0.0.1>

"Smarta55 Chris" <smarta55ATcomcastDOTnet> wrote in
news:wredneddtMlU-CLfRVn-sQ@comcast.com: 

[ Top-posting fixed. Please do not do that. ]

> "Gunnar Hjalmarsson" <noreply@gunnar.cc> wrote in message
> news:3i95luFkcq6bU1@individual.net...
>>
>> Then don't overuse them. How about this for your first example:
>>
>>      my @folders = ( split /\\/, $path )[-2..-1];
>>
>> Leaving the second example as an exercise for you. ;-)

>     my @ous = (split /\.,/,$string)[-2..-1];  and got back 'folder
>     folder'. 
> changing
> -2 to -3 brought back 'folder folder folder'

You mentioned something about not being a newbie. You do need to read 
the first few chapters of 'Learning Perl'.

@ous is an array. You can join the elements of that array to get what 
ever you want.

> I've used split before, but I don't understand the [-2..-1] part.

That is an array slice. It selects all the elements from the second to 
last to the last one from the array returned by split. It is infinitely 
more efficient than the double reverse I used.

> I ruled out using split because I'll never know how long the string
> will be, or how many OUs will follow the object in its FQN.

WTF? Is this an acronym contest?

Anyway, by indexing from the end of the array, you do not need to know 
how many components in total there are, because, as you said, you are 
only interested in the last n.

> Also, it's not returning what I need ...

Yes it is. You just do not know Perl very well.

> When I match against  ".appobject.dept.biz.site.county.state.tree",
> and need to return the last 4 OUs, what I need back is
> ".site.county.state.tree" The leading dot before
> site isn't important (but is preferred), but the 3 dots between site,
> county, state, and tree are needed.

Then join the elements of the returned array using a dot.

That is what 

perldoc -f join 

is for.

Sinan
-- 
A. Sinan Unur <1usa@llenroc.ude.invalid>
(reverse each component and remove .invalid for email address)

comp.lang.perl.misc guidelines on the WWW:
http://mail.augustmail.com/~tadmc/clpmisc/clpmisc_guidelines.html


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

Date: Mon, 27 Jun 2005 02:54:45 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: RegEx Help, Please?  (match after n)
Message-Id: <Xns9681E913BE3EEasu1cornelledu@127.0.0.1>

"A. Sinan Unur" <1usa@llenroc.ude.invalid> wrote in 
news:Xns9681E664C2F08asu1cornelledu@127.0.0.1:


> sub last_n_components {
>     my ($s, $d, $n) = @_;
>     join($d, reverse((reverse split /\Q$d\E/, $s) [0 .. $n - 1]))
> }

Ahem ... This is what happens if you try to watch TV and post at the 
same time.

Sorry about that.

This should be better:

#!/usr/bin/perl

use strict;
use warnings;

use File::Spec::Functions qw'catdir splitdir';

sub last_n_components {
    my ($s, $d, $n) = @_;
    join $d, (split /\Q$d\E/, $s)[-$n .. -1];
}

sub last_n_path_components {
    my ($s, $n) = @_;
    catdir( (splitdir $s)[-$n .. - 1] );
}

print +last_n_components(
    q{.appobject.dept.biz.site.county.state.tree},
    '.', 2
)."\n";

print +last_n_path_components(
    q{\\\\server\volume\share\folder\folder\folder}, 2)."\n";

__END__



-- 
A. Sinan Unur <1usa@llenroc.ude.invalid>
(reverse each component and remove .invalid for email address)

comp.lang.perl.misc guidelines on the WWW:
http://mail.augustmail.com/~tadmc/clpmisc/clpmisc_guidelines.html


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

Date: Sun, 26 Jun 2005 22:57:28 -0400
From: "Smarta55 Chris" <smarta55ATcomcastDOTnet>
Subject: Re: RegEx Help, Please?  (match after n)
Message-Id: <JdydneHp0fKE9iLfRVn-oA@comcast.com>

Thank you....for teaching me that I am, afterall, a perl newbie.
I'm more confused than before.  I'll check the perldocs you
mention, then assign this script to someone else at work.  :-(

There's no simple, single-line $ao =~ /some pattern or other/; that'll work?
I just want to append an app object's name to a biz name, then to the last 4
OUs of the match, and create
it in eDirectory with a 3rd party utility.  :-(

Thanks for your help!
Chris

"A. Sinan Unur" <1usa@llenroc.ude.invalid> wrote in message
news:Xns9681E664C2F08asu1cornelledu@127.0.0.1...
> "Smarta55 Chris" <smarta55ATcomcastDOTnet> wrote in
> news:1OudndKerKyOxiLfRVn-qw@comcast.com:
>
> > Can someone help me find the last n folders in a path,
> > or the last n OUs
>
> You are missing an 'I' there ... Seriously, though, I don't know what
> you are referring to.
>
> > Example:
> > \\server\volume\share\folder\folder\folder
> > I want to grab just the last 2 folders (including or excluding the
> > \s), but sometimes there are 3 folders after the share, like in the
> > example, and sometimes there are more.
>
> OK.
>
> > Same for an app object in eDirectory
> > .appobject.dept.biz.site.county.state.tree
> > How to I grab just the .site.county.state.tree OUs?
> > Sometimes there are 5 OUs after the app object, and sometimes more.
> > I want, I think, to "start at the end of the string, and grab
> > everything after the 4th dot from the end," but don't have a clue how
> > to code this.
>
> perldoc perlfunc
> perldoc -f reverse
> perldoc -f split
>
> In addition,
>
> perldoc -f rindex
> perldoc -f substr
>
> might also be of interest, in case you want to write a different
> algorithm.
>
> > I'm not a perl newbie, but I'm no expert....and I AM a RegEx idiot!
>
> Probably not, but you need to look at this calmly.
>
> > Here's some of what I've tried:
> > $string = ".appobject.dept.biz.site.county.state.tree";
> > $string =~ /\..+\..+\..+/$;    # i.e. match a literal dot followed my
> > anything mult times, followed by another literal dot, followed, etc...
> >                                         # starting at the end of the
> >                               string
> > $string =~ /(\.\W)*/;    # \w does NOT match AlphaNum like it's
> > supposed to, \W DOES, but it's NOT supposed to.
> >                                 # unless . is an AlphaNum character,
> >                               but I'm
> > not sure
>
> This looks like Def Poetry to me.
>
> > And I can't remember the 4,612 other patterns I've tried, or the
> > accompanying 4,612 hairs I've yanked from my scalp in the process.
> >  :-(
>
> Here are two examples to get you started:
>
> First:
>
> #!/usr/bin/perl
>
> use strict;
> use warnings;
>
> sub last_n_components {
>     my ($s, $d, $n) = @_;
>     join($d, reverse((reverse split /\Q$d\E/, $s) [0 .. $n - 1]))
> }
>
> print +last_n_components(
>     q{.appobject.dept.biz.site.county.state.tree},
>     '.', 2
> )."\n";
>
> print +last_n_components(
>     q{\\\\server\volume\share\folder\folder\folder},
>     '\\', 2
> )."\n";
>
> __END__
>
> Now, if you are going to deal with paths, your life will be much easier
> if you do it portably from the start:
>
> #!/usr/bin/perl
>
> use strict;
> use warnings;
>
> use File::Spec::Functions qw'catdir splitdir';
>
> sub last_n_path_components {
>     my ($s, $n) = @_;
>     catdir reverse((reverse splitdir $s)[0 .. $n - 1]);
> }
>
> print +last_n_path_components(
>     q{\\\\server\volume\share\folder\folder\folder}, 2)."\n";
>
> __END__
>
>
> -- 
> A. Sinan Unur <1usa@llenroc.ude.invalid>
> (reverse each component and remove .invalid for email address)
>
> comp.lang.perl.misc guidelines on the WWW:
> http://mail.augustmail.com/~tadmc/clpmisc/clpmisc_guidelines.html




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

Date: Mon, 27 Jun 2005 03:06:23 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: RegEx Help, Please?  (match after n)
Message-Id: <Xns9681EB0CCD868asu1cornelledu@127.0.0.1>

"Smarta55 Chris" <smarta55ATcomcastDOTnet> wrote in
news:JdydneHp0fKE9iLfRVn-oA@comcast.com: 

> Thank you....

You are welcome. However, please note that top-posting and full-quoting 
are generally not useful in facilitating a productive exchange.

Please do read the posting guidelines for this group. They contain 
valuable information on how you can help yourself, and help others help 
you.

> for teaching me that I am, afterall, a perl newbie.

>> "Smarta55 Chris" <smarta55ATcomcastDOTnet> wrote in
>> news:1OudndKerKyOxiLfRVn-qw@comcast.com:
>>
>> > I'm not a perl newbie, 

> I'm more confused than before.  I'll check the perldocs you
> mention, then assign this script to someone else at work.  :-(

Well, to be honest, my double reverse was very convoluted, and I have 
onlyself (no, actually, HBO) to blame.
 
> There's no simple, single-line $ao =~ /some pattern or other/;

There is no reason to bring out the big guns for this kind of thing. 
Besides, I would probably mess that up even worse than I messed up with 
the double reverse.

Sinan
-- 
A. Sinan Unur <1usa@llenroc.ude.invalid>
(reverse each component and remove .invalid for email address)

comp.lang.perl.misc guidelines on the WWW:
http://mail.augustmail.com/~tadmc/clpmisc/clpmisc_guidelines.html


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

Date: Sun, 26 Jun 2005 23:19:16 -0400
From: "Smarta55 Chris" <smarta55ATcomcastDOTnet>
Subject: Re: RegEx Help, Please?  (match after n)
Message-Id: <VZOdnbv3lJar7SLfRVn-vw@comcast.com>


> You are welcome. However, please note that top-posting and full-quoting
> are generally not useful in facilitating a productive exchange.
>
> Please do read the posting guidelines for this group. They contain
> valuable information on how you can help yourself, and help others help
> you.

Now I'm a newsgroups newbie, too!  :-)

Thanks




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

Date: Mon, 27 Jun 2005 05:21:53 +0200
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: RegEx Help, Please?  (match after n)
Message-Id: <3i99mkFkev2gU1@individual.net>

Smarta55 Chris wrote:
> Thank you.  I used:
>     my @ous = (split /\.,/,$string)[-2..-1];  and got back 'folder folder'.
--------------------------^
??

> changing
> -2 to -3 brought back 'folder folder folder'
> I've used split before, but I don't understand the [-2..-1] part.

split() returns a list, and the above picks a slice of the list.

-1 represents the last, and -2 represents the second last element of a 
list, so -2..-1 are 'all' (two) elements between the second last and the 
last. See "perldoc perldata".

Sinan made use of the reverse() function instead in his solutions.

> I ruled out using split because I'll never know how long the string
> will be, or how many OUs will follow the object in its FQN.
> Also, it's not returning what I need....obviously my thought/need wasn't
> translated well to my text..
> 
> When I match against  ".appobject.dept.biz.site.county.state.tree", and
> need to return the last 4 OUs, what I need back is ".site.county.state.tree"
> The leading dot before
> site isn't important (but is preferred), but the 3 dots between site,
> county, state, and tree are needed.

Well, you could use join(). Or maybe just:

     my $n = 4;
     print $& if $string =~ /(?:\.[^.]+){$n}$/;

-- 
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl


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

Date: Mon, 27 Jun 2005 03:24:08 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: RegEx Help, Please?  (match after n)
Message-Id: <Xns9681EE0ECA07Casu1cornelledu@127.0.0.1>

"Smarta55 Chris" <smarta55ATcomcastDOTnet> wrote in
news:VZOdnbv3lJar7SLfRVn-vw@comcast.com: 

>> You are welcome. However, please note that top-posting and
>> full-quoting are generally not useful in facilitating a productive
>> exchange. 
>>
>> Please do read the posting guidelines for this group. They contain
>> valuable information on how you can help yourself, and help others
>> help you.
> 
> Now I'm a newsgroups newbie, too!  :-)

Well, we all started somewhere :)

Now, the next thing to take care of is to make sure you properly
attribute the quoted portions, so that people can keep track of who said
what. 

I see you are using Outlook Express on Windows: May I recommend XNews as
a proper newsreader? 

<URL:http://xnews.3dnews.net/>

Sinan

-- 
A. Sinan Unur <1usa@llenroc.ude.invalid>
(reverse each component and remove .invalid for email address)

comp.lang.perl.misc guidelines on the WWW:
http://mail.augustmail.com/~tadmc/clpmisc/clpmisc_guidelines.html


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

Date: Mon, 27 Jun 2005 05:35:35 +0200
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: RegEx Help, Please?  (match after n)
Message-Id: <3i9agaFk9avaU1@individual.net>

A. Sinan Unur wrote:
> "Smarta55 Chris" wrote:
>> I've used split before, but I don't understand the [-2..-1] part.
> 
> That is an array slice. It selects all the elements from the second to 
> last to the last one from the array returned by split.

     s/array/list/g;

-- 
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl


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

Date: Sun, 26 Jun 2005 19:23:58 GMT
From: one man army <newsAT@screenlightDOT.com>
Subject: Simple Structure Question
Message-Id: <newsAT-F07B6F.12225526062005@newssvr13-ext.news.prodigy.com>

(I am new to this Language, Perl)

I have a small script running. Can someone explain this line?

  while ( $token = $p->get_tag("a")) {
      $url = $token->[1]{href} || "-";
       ...

$token is now a struct, with a first element that has a string, but 
{href} refers to a pattern that may occur, which returns a true or false?

Can someone write a 2 line synonym that is not so terse?

thanks in advance


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

Date: Sun, 26 Jun 2005 21:47:22 +0200
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: Simple Structure Question
Message-Id: <3i8f2cFkbp3bU1@individual.net>

one man army wrote:
> Can someone explain this line?
> 
>   while ( $token = $p->get_tag("a")) {
>       $url = $token->[1]{href} || "-";
>        ...
> 
> $token is now a struct, with a first element that has a string, but 
> {href} refers to a pattern that may occur, which returns a true or false?
> 
> Can someone write a 2 line synonym that is not so terse?

Even if not a synonym, these are two (command) lines:

     perldoc perlref
     perldoc perldsc

In other words, you seem to have some reading to do. ( $token->[1]{href} 
tells us that $token is a reference to an "array of hashes". )

-- 
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl


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

Date: Sun, 26 Jun 2005 20:02:27 GMT
From: one man army <newsAT@screenlightDOT.com>
Subject: Re: Simple Structure Question
Message-Id: <newsAT-94497E.13012426062005@newssvr13-ext.news.prodigy.com>

ok, I added this...

  while ( $token = $p->get_tag("a")) {
      print( "$token->[1]  AND $token->[2]\n");

and I got 

    HASH(0x8dbd2c)  AND ARRAY(0x8dbc84)

So now I am really confused. I don't even know how to look up the 
structure of $token, and am confused by this syntax of apparently 
extracting a hash entry with a key == "href".

Q. What file defines the structure of the return arg from get_tag()? 
Parser.pm doesn't seem to have it at all...

Q. ok, so $token->[1] is a HASH. The ref I am looking at says 

  if ( exists $token("href") ) 
   { $url = "href"; } 
  else 
   { $url = "-"; }
 
  this is the synonym?

  light shed is appreciated..


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

Date: Sun, 26 Jun 2005 22:25:23 +0200
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: Simple Structure Question
Message-Id: <3i8h9nFjpfaqU1@individual.net>

one man army wrote:
> I don't even know how to look up the structure of $token,

     use Data::Dumper;
     print Dumper $token;

> and am confused by this syntax of apparently 
> extracting a hash entry with a key == "href".

That's where the reading come in, I guess. (See my reply to your first 
message.)

-- 
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl


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

Date: Sun, 26 Jun 2005 22:33:50 +0200
From: "Tassilo v. Parseval" <tassilo.von.parseval@rwth-aachen.de>
Subject: Re: Simple Structure Question
Message-Id: <slrndbu49e.3ao.tassilo.von.parseval@localhost.localdomain>

Also sprach one man army:

> ok, I added this...
>
>   while ( $token = $p->get_tag("a")) {
>       print( "$token->[1]  AND $token->[2]\n");
>
> and I got 
>
>     HASH(0x8dbd2c)  AND ARRAY(0x8dbc84)
>
> So now I am really confused. I don't even know how to look up the 
> structure of $token, and am confused by this syntax of apparently 
> extracting a hash entry with a key == "href".

In addition to the documentation Gunnar pointed you to alreay, you can
also use Data::Dumper to peek inside a data-structure:

    use Data::Dumper;

    ...
    print Dumper $token;

This is useful for getting a feeling for nested data-structures and in
particular for the one you have to deal with.

> Q. What file defines the structure of the return arg from get_tag()? 
> Parser.pm doesn't seem to have it at all...

It's either PullParser.pm or TokeParser.pm. However, I doubt that
looking inside these modules will provide you with that much input (for
now).

> Q. ok, so $token->[1] is a HASH. The ref I am looking at says 

Actually it's a hash reference.

>   if ( exists $token("href") ) 
>    { $url = "href"; } 
>   else 
>    { $url = "-"; }
>  
>   this is the synonym?

I don't understand that questions. References don't usually say
anything.

Tassilo
-- 
use bigint;
$n=71423350343770280161397026330337371139054411854220053437565440;
$m=-8,;;$_=$n&(0xff)<<$m,,$_>>=$m,,print+chr,,while(($m+=8)<=200);


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

Date: Sun, 26 Jun 2005 20:52:35 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: Simple Structure Question
Message-Id: <Xns9681ABABFEC26asu1cornelledu@127.0.0.1>

one man army <newsAT@screenlightDOT.com> wrote in news:newsAT-
94497E.13012426062005@newssvr13-ext.news.prodigy.com:

> ok, I added this...

I am not sure what you added 'this' to ...

>   while ( $token = $p->get_tag("a")) {
>       print( "$token->[1]  AND $token->[2]\n");
> 
> and I got 
> 
>     HASH(0x8dbd2c)  AND ARRAY(0x8dbc84)
> 
> So now I am really confused. I don't even know how to look up the 
> structure of $token, and am confused by this syntax of apparently 
> extracting a hash entry with a key == "href".

use Data::Dumper;

print Dumper $token;

> Q. What file defines the structure of the return arg from get_tag()? 
> Parser.pm doesn't seem to have it at all...

Well, you have the source code for the whole program in front of you, 
there should be an appropriate use statement somewhere from which you 
can glean this. On the other hand,

<URL:http://www.google.com/search?q=perl+html+parser+get_tag>

It is not so hard, is it?

> Q. ok, so $token->[1] is a HASH. 

It is a reference to a hash.

> The ref I am looking at says 
> 
>   if ( exists $token("href") ) 

That, on the other hand, is a syntax error.

>    { $url = "href"; } 
>   else 
>    { $url = "-"; }
>  
>   this is the synonym?

I don't know what you mean.

Sinan

-- 
A. Sinan Unur <1usa@llenroc.ude.invalid>
(reverse each component and remove .invalid for email address)

comp.lang.perl.misc guidelines on the WWW:
http://mail.augustmail.com/~tadmc/clpmisc/clpmisc_guidelines.html


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

Date: Sun, 26 Jun 2005 18:28:23 -0400
From: Sherm Pendley <sherm@dot-app.org>
Subject: Re: Simple Structure Question
Message-Id: <87wtogwy60.fsf@dot-app.org>

one man army <newsAT@screenlightDOT.com> writes:

> ok, I added this...
>
>   while ( $token = $p->get_tag("a")) {
>       print( "$token->[1]  AND $token->[2]\n");
>
> and I got 
>
>     HASH(0x8dbd2c)  AND ARRAY(0x8dbc84)
>
> So now I am really confused. I don't even know how to look up the 
> structure of $token

Data::Dumper is your friend.

use Data::Dumper; # at the top of your script

# ... later ...

print Dumper($token);

sherm--


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

Date: Sun, 26 Jun 2005 18:53:13 -0400
From: Sherm Pendley <sherm@dot-app.org>
Subject: Re: Simple Structure Question
Message-Id: <87hdfkwx0m.fsf@dot-app.org>

Sherm Pendley <sherm@dot-app.org> writes:

> Data::Dumper is your friend.

Note to self - read replies *before* posting. That didn't really need to be
said a *fourth* time. :-(

sherm--


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

Date: Sun, 26 Jun 2005 20:13:24 -0500
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: Simple Structure Question
Message-Id: <slrndbuklk.p95.tadmc@magna.augustmail.com>

Sherm Pendley <sherm@dot-app.org> wrote:
> Sherm Pendley <sherm@dot-app.org> writes:
> 
>> Data::Dumper is your friend.
> 
> Note to self - read replies *before* posting. That didn't really need to be
> said a *fourth* time. :-(


That's the sort of thing that can happen when the OP asks a FAQ.  :-(


   perldoc -q struct

       How do I print out or copy a recursive data structure?

       The Data::Dumper module on CPAN (or the 5.005 release of Perl)
       is great for printing out data structures. 


-- 
    Tad McClellan                          SGML consulting
    tadmc@augustmail.com                   Perl programming
    Fort Worth, Texas


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

Date: Sun, 26 Jun 2005 20:16:02 -0500
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: Simple Structure Question
Message-Id: <slrndbukqi.p95.tadmc@magna.augustmail.com>

one man army <newsAT@screenlightDOT.com> wrote:

> (I am new to this Language, Perl)


(you should still check the Perl FAQ before posting)


>   while ( $token = $p->get_tag("a")) {
>       $url = $token->[1]{href} || "-";
>        ...
> 
> $token is now a struct, 


   perldoc -q struct

     How can I make the Perl equivalent of a C structure/C++ class/hash or
     array of hashes or arrays?


Then try,

   perldoc perlreftut
   perldoc perlref
   perldoc perllol
   perldoc perldsc

-- 
    Tad McClellan                          SGML consulting
    tadmc@augustmail.com                   Perl programming
    Fort Worth, Texas


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

Date: Sun, 26 Jun 2005 22:05:33 +0000 (UTC)
From: crappi@hetnet-dot-nl.no-spam.invalid (Crap)
Subject: UTF-8 to named character entities
Message-Id: <d9n8rb$815$1@domitilla.aioe.org>

Hi all,

I need a conversion from UTF-8 to named character entities (ë ->
&euml;) and after using the file for publishing purposes I need
to convert it back to UTF-8. I tried this with HTML:Entities but i
get very strange results. I know very little about Perl and its
available modules. I just got perl to work on my Mac. Below is a
piece of my XML-file and the converted result. Can anybody please
give me an advise on how to proceed.
Thanks,
Chris

-- XML --
<a>(…). De andere soort is die welke de contacten en transacties
tussen patiënten reguleert.’<vn>
<al>
<a>EN 1130b31-1131a.</a>
</al>
</vn>

-- after conversion --
<a>(&acirc;€&brvbar;). De andere soort is
die welke de contacten en transacties tussen
pati&Atilde;&laquo;nten
reguleert.&acirc;€™<vn>
<al>
<a>EN 1130b31-1131a.</a>
</al>
</vn>



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

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.  

NOTE: due to the current flood of worm email banging on ruby, the smtp
server on ruby has been shut off until further notice. 

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


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