[28113] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 9477 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sat Jul 15 21:05:43 2006

Date: Sat, 15 Jul 2006 18:05:04 -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           Sat, 15 Jul 2006     Volume: 10 Number: 9477

Today's topics:
        Parse data structure Davidcollins001@gmail.com
    Re: Problem with ([\w ]+?) <jurgenex@hotmail.com>
    Re: Problem with ([\w ]+?) <poubelles@gmail.com>
    Re: Problem with ([\w ]+?) <1usa@llenroc.ude.invalid>
    Re: Problem with ([\w ]+?) <tadmc@augustmail.com>
    Re: Problem with ([\w ]+?) <poubelles@gmail.com>
    Re: Requirements for Perl on Windows XP? <WGSGNUAYHTTE@spammotel.com>
    Re: Requirements for Perl on Windows XP? <1usa@llenroc.ude.invalid>
    Re: Requirements for Perl on Windows XP? <sisyphus1@nomail.afraid.org>
    Re: Requirements for Perl on Windows XP? <WGSGNUAYHTTE@spammotel.com>
    Re: Requirements for Perl on Windows XP? <WGSGNUAYHTTE@spammotel.com>
    Re: Requirements for Perl on Windows XP? <WGSGNUAYHTTE@spammotel.com>
    Re: Requirements for Perl on Windows XP? <sisyphus1@nomail.afraid.org>
    Re: Requirements for Perl on Windows XP? <sisyphus1@nomail.afraid.org>
    Re: What is a type error? <jo@durchholz.org>
        Yet another flock question... <socyl@987jk.com.invalid>
    Re: Yet another flock question... <mark.clementsREMOVETHIS@wanadoo.fr>
    Re: Yet another flock question... xhoster@gmail.com
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: 15 Jul 2006 17:03:04 -0700
From: Davidcollins001@gmail.com
Subject: Parse data structure
Message-Id: <1153008184.344970.232180@i42g2000cwa.googlegroups.com>

I am looking to parse data into a complex structure of hashes and
arrays. I have been reading the data structures cookbook on the CPAN
website
(http://search.cpan.org/~nwclark/perl-5.8.7/pod/perldsc.pod#MORE_ELABORATE_RECORDS).
At the bottom they say that it is sometimes easier to have the file as
the data structure that would be used to create the structure in perl.

I was wondering how to do this? I have been playing around trying to
learn how to use complex structures, but I can't figure out how to get
perl to parse code into a hash? I did initially think of placing the
data structure in a file and setting the hash equal to it, but that
doesn't work. am I thinking too simplistic?

This is my data structure that I am playing around with in a separate
file:

may  => [
         [2,'train',20.00, 'expensive'],
         [6,'train',15],
	  [19,'car',18,'best way']
	     ],
june => [
	 [5,'car',2.00],
	 [9,'train',1],
	 [19,'cat',18,'best way']
	    ],
july => [
     	 [14,'plane',100],
	 [23,'boat',20]
	    ],


And this is the code I have to read and print it out:


## read above from file into hash
open(DATA, "<$file");
my %HoLoL=<DATA>;
close(DATA);


## print each element separately
foreach my $date ( keys %HoLoL )
{
    print "$date";
    for(my $i=0; $i<($#{@{$HoLoL{$date}}}+1); $i++)
    {
	for(my $j=0; $j<($#{ $HoLoL{$date} [$i] }+1); $j++)
	{
	    print "\t ${ $HoLoL{$date} [$i]}[$j] ";
	}
	print "\n";
    }
}
print "\n";


(I know I can print it out easier and probably quicker with one less
loop at least, I just wanted to know how to get to each element.)

Thanks in advance



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

Date: Sat, 15 Jul 2006 22:41:52 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: Problem with ([\w ]+?)
Message-Id: <Qaeug.4053$Ss2.3130@trnddc01>

forwax wrote:
> Hi there,
>
> I'm trying to use "([\w ]+?)" to get some city name and is team name
> out in some kind of condition but seems not to work with 3 city/team
> that I got. The code that I use is at the bottom of the post.
>
> Here some that work:
> - "Edmonton Oilers"
> - "Detroit Red Wings"
> - "Montreal Canadiens"
>
> But it doesn't work with does 3:
> - "St.Louis Blues"
> - "Wilkes-Barre/Scranton Penguins"
> - "Omaha Ak-Sar-Ben Knights"
>
> Should "([\w ]+?)" be enough to work or I'm missing something ?

Neither . nor - or / are word characters. It appears you expect \w to match 
them nevertheless.

> 1.
> elsif ($_ =~ /<tr><td class="STHSSchedule_GameNumber">\d+<\/td><td
> class="STHSSchedule_ProLink"><a href="$prefix-(\d+).html">([\w ]+?)
> \((\d+)\) vs ([\w ]+?) \((\d+)\)<\/a>(.*)<\/td><td
> class="STHSSchedule_FarmLink">/i) { }
>
> 2.
> elsif ($_ =~ /<a href="$prefix-Farm-(\d+).html">([\w ]+?) \((\d+)\) vs
> ([\w ]+?) \((\d+)\)(<\/a>)(.*)<\/td><\/tr>/i) { }

Urg! This is excellent code if you are trying win the Perl obfuscation 
contest.
However if you are interested in readable, maintainable, robust, and correct 
code you may want to check out one of the HMTL parser modules.

jue 




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

Date: 15 Jul 2006 15:43:04 -0700
From: "forwax" <poubelles@gmail.com>
Subject: Re: Problem with ([\w ]+?)
Message-Id: <1153003384.915410.11760@h48g2000cwc.googlegroups.com>

I'll go straight to it... I'm a newb, a newb that work in IT but is
just a technician and it's been a while since I writin some code and my
best language was structural C (yeah I know, I'm a dinosaur in that
field).

I've read the link you've givin me and did a search on google to see if
I could get something more of a beginner aproch to parse a HTML file. I
want to learn but I have to be honest, I was trying to keep it simple
so I could comprehend what I was doing.

The solution you have givin me seems the best, to extract the text for
the HTML and put it in the file I want. It's just great. But do you
know an other web site that would be more to my level (beginner that
is) ?


A. Sinan Unur wrote:
> "forwax" <poubelles@gmail.com> wrote in news:1152999768.027653.88390
> @m79g2000cwm.googlegroups.com:
>
> > I'm trying to use "([\w ]+?)"
>
> ...
>
> > But it doesn't work with does 3:
> > - "St.Louis Blues"
> > - "Wilkes-Barre/Scranton Penguins"
> > - "Omaha Ak-Sar-Ben Knights"
> >
> > Should "([\w ]+?)" be enough to work or I'm missing something ?
>
> perldoc perlre
>
>   In addition, Perl defines the following:
>
>       \w  Match a "word" character (alphanumeric plus "_")
>
> > 1.
> > elsif ($_ =~ /<tr><td class="STHSSchedule_GameNumber">\d+<\/td><td
> > class="STHSSchedule_ProLink"><a href="$prefix-(\d+).html">([\w ]+?)
> > \((\d+)\) vs ([\w ]+?) \((\d+)\)<\/a>(.*)<\/td><td
> > class="STHSSchedule_FarmLink">/i) { }
> >
> > 2.
> > elsif ($_ =~ /<a href="$prefix-Farm-(\d+).html">([\w ]+?) \((\d+)\) vs
> > ([\w ]+?) \((\d+)\)(<\/a>)(.*)<\/td><\/tr>/i) { }
>
> This is impossible to read and very error prone. You would do yourself a
> service by properly parsing HTML:
>
> perldoc -q html
>
> http://search.cpan.org/~gaas/HTML-Parser-3.55/
>
> Sinan
>
> --
> A. Sinan Unur <1usa@llenroc.ude.invalid>
> (remove .invalid and reverse each component for email address)
>
> comp.lang.perl.misc guidelines on the WWW:
> http://augustmail.com/~tadmc/clpmisc/clpmisc_guidelines.html



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

Date: Sat, 15 Jul 2006 22:53:10 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: Problem with ([\w ]+?)
Message-Id: <Xns9801C03702DFEasu1cornelledu@127.0.0.1>

"forwax" <poubelles@gmail.com> wrote in news:1153003384.915410.11760
@h48g2000cwc.googlegroups.com:

[ Please do not top-post.
  Please do not quote sigs.
  Please do read the posting guidelines for this group.
  Please do at least browse through the FAQ list.
  TOFU snipped.
]

> I'll go straight to it... I'm a newb, a newb 

perldoc -q book
perldoc -q learn

You have to learn to walk before you can run.

> I've read the link you've givin me and did a search on google to see

[ I am assuming you are referring to 
  http://search.cpan.org/~gaas/HTML-Parser-3.55/
]

 ...

> The solution you have givin me seems the best, to extract the text for
> the HTML and put it in the file I want.

I proposed no such thing. You can use the HTML::Parser 
(HTML::TokeParser, part of the same package, is easier IMHO) to extract 
information based on table cell class without being tripped by commented 
out sections, odd formatting variations etc.


> But do you know an other web site that would be more to my level 
> (beginner that is) ?

There is a lot of documentation installed alongside Perl on your 
computer.

perldoc perltoc

To get an overall sense of it all, you'll probably need a good book.

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

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



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

Date: Sat, 15 Jul 2006 18:22:08 -0500
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: Problem with ([\w ]+?)
Message-Id: <slrnebiu50.9pk.tadmc@magna.augustmail.com>

forwax <poubelles@gmail.com> wrote:

> I've read the link you've givin me 


Please also see the Posting Guidelines link that was in his .sig


> and did a search on google to see if


The place to search is http://search.cpan.org, maybe you can find
a module that does most of the heavy lifting for you, such as
HTML::TableExtract, since your data looks to be in an HTML table.


> I could get something more of a beginner aproch to parse a HTML file. I
> want to learn but I have to be honest, I was trying to keep it simple
> so I could comprehend what I was doing.


I would have posted an example using that module if I didn't have to
reverse-engineer what your data looks like (hint).

You can probably get something working by copying some of the code
given in the module's docs, and adding a bit to it.

   perldoc HTML::TableExtract



[ snip TOFU ]

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


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

Date: 15 Jul 2006 16:49:58 -0700
From: "forwax" <poubelles@gmail.com>
Subject: Re: Problem with ([\w ]+?)
Message-Id: <1153007398.007605.73770@s13g2000cwa.googlegroups.com>

Tad, you are right, I'm trying to extract text from HTML tables so I'll
look in extractTable like you said.

As for the snipet you have asked. These is the 5 types of line I want
some extraction, all the other is of none importance.

1.
<tr><td colspan="3" class="STHSSchedule_GameDay"><b>Day 1</b></td></tr>

2.
<tr><td class="STHSSchedule_GameNumber">1</td><td
class="STHSSchedule_ProLink"><a href="AHSQ2006-1.html">New York Rangers
(1) vs Pittsburgh Penguins (2)</a> </td><td
class="STHSSchedule_FarmLink">

3.
<a href="AHSQ2006-Farm-1.html">Hartford Wolfpack (3) vs
Wilkes-Barre/Scranton Penguins (7)</a></td></tr>

4.
<tr><td class="STHSSchedule_GameNumber">55</td><td
class="STHSSchedule_ProLink">Carolina Hurricanes vs Atlanta
Thrashers</td><td>Lowell Lock Monsters

5.
 vs Chicago Wolves </td></tr>

with all these 5 HTML lines I need the text of the cell a well as the
"a href" if there's one.

I hope this post is ok because I just starting out to readthe "posting
guidelines"

And as for running before walking, I did get some perl book from the
library but I do so little perl programming that I always forget the
intermidiate and advance stuff. So I would considere my self like a
walking baby at best LOL.



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

Date: 15 Jul 2006 15:34:11 -0700
From: "Teffy" <WGSGNUAYHTTE@spammotel.com>
Subject: Re: Requirements for Perl on Windows XP?
Message-Id: <1153002851.800541.191030@75g2000cwc.googlegroups.com>

A. Sinan Unur wrote:
> "Teffy" <WGSGNUAYHTTE@spammotel.com> wrote in
> > http://groups.google.com/group/microsoft.public.windowsxp.general/bro...
>
> This URL does not lead anywhere.
> 
> Sinan


Sorry, it leads here: http://tinyurl.com/zwb8x

Teffy



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

Date: Sat, 15 Jul 2006 22:45:46 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: Requirements for Perl on Windows XP?
Message-Id: <Xns9801BEF5E208Dasu1cornelledu@127.0.0.1>

"Teffy" <WGSGNUAYHTTE@spammotel.com> wrote in
news:1153002851.800541.191030@75g2000cwc.googlegroups.com: 

> A. Sinan Unur wrote:
>> "Teffy" <WGSGNUAYHTTE@spammotel.com> wrote in
>> > 
http://groups.google.com/group/microsoft.public.windowsxp.general/br
>> > o... 
>>
>> This URL does not lead anywhere.

 ...

> Sorry, it leads here: http://tinyurl.com/zwb8x

Honestly, at this point, who cares where it leads? I have already told 
you twice how to solve your problem.

Man: Hello. I would like to leave my house but I can't get to the roof.
Stranger: What's wrong with the door?

Please use PPM and solve your problem.

Sinan

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

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



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

Date: Sun, 16 Jul 2006 09:39:41 +1000
From: "Sisyphus" <sisyphus1@nomail.afraid.org>
Subject: Re: Requirements for Perl on Windows XP?
Message-Id: <44b97da7$0$1206$afc38c87@news.optusnet.com.au>


"Teffy" <WGSGNUAYHTTE@spammotel.com> wrote in message

> HTML::LinkExtor
> (http://search.cpan.org/dist/HTML-Parser/lib/HTML/LinkExtor.pm) and
> SOAP::Lite   (http://search.cpan.org/dist/SOAP-Lite/) are required by
> UTIL.
>

You already have both of those modules in your ActiveState perl build 817.
If "UTIL" is not working, it must be for some other reason.

Cheers,
Rob




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

Date: 15 Jul 2006 17:01:16 -0700
From: "Teffy" <WGSGNUAYHTTE@spammotel.com>
Subject: Re: Requirements for Perl on Windows XP?
Message-Id: <1153008076.605295.280650@75g2000cwc.googlegroups.com>

A. Sinan Unur wrote:
>
> Please use PPM and solve your problem.
>

>From the ppm command prompt I typed:
ppm> search linkextor
and it listed two similar modules (HDML-LinkExtor and
HTML-SimpleLinkExtor), but not the one I need, HTML-LinkExtor.

I also tried:
ppm> search soap-lite
and found similarly named modules, but not exact.

I found two pages at the ActiveState site (http://tinyurl.com/emyq6 and
http://tinyurl.com/j2v6b) that say there is currently no pre-built PPM
package for either HTML::LinkExtor or SOAP::Lite.  Bummer.

Teffy



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

Date: 15 Jul 2006 17:18:07 -0700
From: "Teffy" <WGSGNUAYHTTE@spammotel.com>
Subject: Re: Requirements for Perl on Windows XP?
Message-Id: <1153009087.694566.232990@35g2000cwc.googlegroups.com>

Sisyphus wrote:
> "Teffy" <WGSGNUAYHTTE@spammotel.com> wrote in message
>
> > HTML::LinkExtor
> > (http://search.cpan.org/dist/HTML-Parser/lib/HTML/LinkExtor.pm) and
> > SOAP::Lite   (http://search.cpan.org/dist/SOAP-Lite/) are required by
> > UTIL.
> >
>
> You already have both of those modules in your ActiveState perl build 817.
> If "UTIL" is not working, it must be for some other reason.
>
> Cheers,
> Rob

After doing the things described here: http://tinyurl.com/zwb8x, I
still get the error message:

---------------------------
perl.exe - Unable To Locate Component
---------------------------
This application has failed to start
because MSVCR80.dll was not found. Re-installing
 the application may fix this problem.
---------------------------

Thanks,
Teffy



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

Date: 15 Jul 2006 17:32:17 -0700
From: "Teffy" <WGSGNUAYHTTE@spammotel.com>
Subject: Re: Requirements for Perl on Windows XP?
Message-Id: <1153009937.412497.259750@b28g2000cwb.googlegroups.com>

Teffy wrote:
> Sisyphus wrote:
> > "Teffy" <WGSGNUAYHTTE@spammotel.com> wrote in message
> >
> > > HTML::LinkExtor
> > > (http://search.cpan.org/dist/HTML-Parser/lib/HTML/LinkExtor.pm) and
> > > SOAP::Lite   (http://search.cpan.org/dist/SOAP-Lite/) are required by
> > > UTIL.
> > >
> >
> > You already have both of those modules in your ActiveState perl build 817.
> > If "UTIL" is not working, it must be for some other reason.
> >
> > Cheers,
> > Rob

I believe HTML::LinkExtor is part of HTML::Parser.  I see HTML::Parser
and Soap::Lite listed as part of the core ActiveState perl build 817
here:  http://ppm.activestate.com/BuildStatus/5.8.html

Does this mean my first mistake was to assume that I needed to install
the extra modules, and somehow screw it up with nmake, and everything
went downhill from there?  Maybe I should revert to a version of my
Windows XP system from before all this?

Thank you,
Teffy



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

Date: Sun, 16 Jul 2006 10:49:58 +1000
From: "Sisyphus" <sisyphus1@nomail.afraid.org>
Subject: Re: Requirements for Perl on Windows XP?
Message-Id: <44b98e1c$0$22362$afc38c87@news.optusnet.com.au>


"Teffy" <WGSGNUAYHTTE@spammotel.com> wrote in message
news:1153009937.412497.259750@b28g2000cwb.googlegroups.com...
> Teffy wrote:
> > Sisyphus wrote:
> > > "Teffy" <WGSGNUAYHTTE@spammotel.com> wrote in message
> > >
> > > > HTML::LinkExtor
> > > > (http://search.cpan.org/dist/HTML-Parser/lib/HTML/LinkExtor.pm) and
> > > > SOAP::Lite   (http://search.cpan.org/dist/SOAP-Lite/) are required
by
> > > > UTIL.
> > > >
> > >
> > > You already have both of those modules in your ActiveState perl build
817.
> > > If "UTIL" is not working, it must be for some other reason.
> > >
> > > Cheers,
> > > Rob
>
> I believe HTML::LinkExtor is part of HTML::Parser.  I see HTML::Parser
> and Soap::Lite listed as part of the core ActiveState perl build 817
> here:  http://ppm.activestate.com/BuildStatus/5.8.html
>

Yep - like I said, you already have them :-)

> Does this mean my first mistake was to assume that I needed to install
> the extra modules, and somehow screw it up with nmake, and everything
> went downhill from there?  Maybe I should revert to a version of my
> Windows XP system from before all this?
>

Probably just uninstalling ActiveState perl and then reinstalling it is all
that's needed. That should get you back to the HTML::Parser and SOAP::Lite
that come with ActiveState perl.

I find it a little difficult to follow exactly what has gone wrong, though
I've visited the tinyurl link that you supplied. Seems like you might have
managed to build and install something that requires MSVCR80.dll at runtime.
Either you don't have that dll (though I would have expected it to be in one
of the downloads you got from Microsoft) or it's not in one of the "path"
folders.

Cheers,
Rob




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

Date: Sun, 16 Jul 2006 10:51:34 +1000
From: "Sisyphus" <sisyphus1@nomail.afraid.org>
Subject: Re: Requirements for Perl on Windows XP?
Message-Id: <44b98e7d$0$25589$afc38c87@news.optusnet.com.au>


"Teffy" <WGSGNUAYHTTE@spammotel.com> wrote in message
news:1153008076.605295.280650@75g2000cwc.googlegroups.com...
> A. Sinan Unur wrote:
> >
> > Please use PPM and solve your problem.
> >
>
> >From the ppm command prompt I typed:
> ppm> search linkextor
> and it listed two similar modules (HDML-LinkExtor and
> HTML-SimpleLinkExtor), but not the one I need, HTML-LinkExtor.
>
> I also tried:
> ppm> search soap-lite
> and found similarly named modules, but not exact.
>
> I found two pages at the ActiveState site (http://tinyurl.com/emyq6 and
> http://tinyurl.com/j2v6b) that say there is currently no pre-built PPM
> package for either HTML::LinkExtor or SOAP::Lite.  Bummer.
>

Yep - they generally don't provide ppm's for modules that ship as standard
with ActiveState perl.

Cheers,
Rob




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

Date: Sun, 16 Jul 2006 00:37:14 +0200
From: Joachim Durchholz <jo@durchholz.org>
Subject: Re: What is a type error?
Message-Id: <e9bqvr$jt$1@online.de>

Marshall schrieb:
> Joachim Durchholz wrote:
>> As I said elsewhere, the record has an identity even though it isn't
>> explicit in SQL.
> 
> Hmmmm. What can this mean?
> 
> In general, I feel that "records" are not the right conceptual
> level to think about.

They are, when it comes to aliasing of mutable data. I think it's 
justified by the fact that aliased mutable data has a galling tendency 
to break abstraction barriers. (More on this on request.)

> In any event, I am not sure what you mean by non-explicit
> identity.

The identity isn't visible from inside SQL. (Unless there's an OID 
facility available, which *is* an explicit identity.)

 > I would say, records in SQL have value, and their
> identity is exactly their value.

Definitely not. You can have two equal records and update just one of 
them, yielding non-equal records; by my definition (and by intuition), 
this means that the records were equal but not identical.

 > I do not see that they have
> any identity outside of their value. We can uniquely identify
> any particular record via a key, but a table may have more
> than one key, and an update may change the values of one
> key but not another. So it is not possible in general to
> definitely and uniquely assign a mapping from each record
> of a table after an update to each record of the table before
> the update, and if you can't do that, then where
> is the record identity?

Such a mapping is indeed possible. Simply extend the table with a new 
column, number the columns consecutively, and identify the records via 
that column.

But even if you don't do that, there's still identity. It is irrelevant 
whether the programs can directly read the value of the identity field; 
the adverse effects happen because updates are in-place. (If every 
update generated a new record, then we'd indeed have no identity.)

> Okay. At this point, though, the term aliasing has become extremely
> general. I believe "i+1+1" is an alias for "i+2" under this definition.

No, "i+1+1" isn't an alias in itself. It's an expression - to be an 
alias, it would have to be a reference to something.

However, a[i+1+1] is an alias to a[i+2]. Not that this is particularly 
important - 1+1 is replacable by 2 in every context, so this is 
essentially the same as saying "a[i+2] is an alias of a[i+2]", which is 
vacuously true.

There's another aspect here. If two expressions are always aliases to 
the same mutable, that's usually easy to determine; this kind of 
aliasing is usually not much of a problem.
What's more of a problem are those cases where there's occasional 
aliasing. I.e. a[i] and a[j] may or may not be aliases of each other, 
depending on the current value of i and j, and *that* is a problem 
because the number of code paths to be tested doubles. It's even more of 
a problem because testing with random data will usually not uncover the 
case where the aliasing actually happens; you have to go around and 
construct test cases specifically for the code paths that have aliasing. 
Given that references may cross abstraction barriers (actually that's 
often the purpose of constructing a reference in the first place), this 
means you have to look for your test cases at multiple levels of 
software abstraction, and *that* is really, really bad.

> That is so general that I am concerned it has lost its ability to
> identify problems specific to pointers.

If the reference to "pointers" above means "references", then I don't 
know about any pointer problems that cannot be reproduced, in one form 
or the other, in any of the other aliasing mechanisms.

> Again, by generalizing the term this far, I am concerned with a
> loss of precision. If "joe" in the prolog is a references, then
> "reference" is just a term for "data" that is being used in a
> certain way. The conection with a specfic address space
> has been lost in favor of the full domain of the datatype.

Aliasing is indeed a more general idea that goes beyond address spaces.

However, identity and aliasing can be defined in fully abstract terms, 
so I welcome this opportunity to get rid of a too-concrete model.

>> The records still have identities. It's possible to have two WHERE
>> clauses that refer to the same record, and if you update the record
>> using one WHERE clause, the record returned by the other WHERE clause
>> will have changed, too.
> 
> Is this any different from saying that an expression that includes
> a variable will produce a different value if the variable changes?

Yes.
Note that the WHERE clause properly includes array indexing (just set up 
a table that has continuous numeric primary key, and a single other column).

I.e. I'm not talking about how a[i] is an alias of a[i+1] after updating 
i, I'm talking about how a[i] may be an alias of a[j].

> It seems odd to me to suggest that "i+1" has identity.

It doesn't (unless it's passed around as a closure, but that's 
irrelevant to this discussion).
"i" does have identity. "a[i]" does have identity. "a[i+1]" does have 
identity.
Let me say that for purposes of this discussion, if it can be assigned 
to (or otherwise mutated), it has identity. (We *can* assign identity to 
immutable things, but it's equivalent to equality and not interesting 
for this discussion.)

 > I can see
> that i has identity, but I would say that "i+1" has only value.

Agreed.

> But perhaps the ultimate upshoot of this thread is that my use
> of terminology is nonstandard.

It's somewhat restricted, but not really nonstandard.

>> Possibly. There are so many isolation levels that I have to look them up
>> whenever I want to get the terminology 100% correct.
> 
> Hmmm. Is it that there are so many, or that they are simply not
> part of our daily concern?

I guess it's the latter. IIRC there are four or five isolation levels.

 > It seems to me there are more different
> styles of parameter passing than there are isolation levels, but
> I don't usually see (competent) people (such as yourself) getting
> call-by-value confused with call-by-reference.

Indeed.
Though the number of parameter passing mechanisms isn't that large 
anyway. Off the top of my head, I could recite just three (by value, by 
reference, by name aka lazy), the rest are just combinations with other 
concepts (in/out/through, most notably) or a mapping to implementation 
details (by reference vs. "pointer by value" in C++, for example).

Regards,
Jo


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

Date: Sat, 15 Jul 2006 22:43:07 +0000 (UTC)
From: kj <socyl@987jk.com.invalid>
Subject: Yet another flock question...
Message-Id: <e9br1r$b8l$1@reader2.panix.com>



For the following, assume the OS is some Un*x.

Suppose one uses flock like this (lifted with minor modifications
from perlfunc):

                   use Fcntl ':flock'; # import LOCK_* constants

                   sub lock {
                       flock(LOG,LOCK_EX);
                       # and, in case someone appended
                       # while we were waiting...
                       seek(LOG, 0, 2);
                   }

                   sub unlock {
                       flock(LOG,LOCK_UN);
                   }

                   open(LOG, ">>/var/log/my.log"
                           or die "Can't open logfile: $!";



                   # elsewhere... 

                   lock();
                   print LOG $msg,"\n\n";
                   unlock();


 ...but suppose that after the open() but before lock(), some
other process (e.g. a logfile rotator) moves /var/log/my.log to
/var/log/my.log.1, creates a new /var/log/my.log file, and perhaps
a *third* process then writes some new stuff to this new /var/log/my.log.
(Note that this is not an improbable scenario; in a long-running
process, such as a server, ample time can occur between the executions
of the open() and lock() statements for all of this to happen).

In this case, the code above will end up appending $msg to
/var/log/my.log.1 and not to the newly created /var/log/my.log.
Now /var/log/my.log.1 would have entries that are more recent than
the earliest entries in /var/log/my.log, which can lead to problems
or at least confusion.

How could the code above be modified to ensure that not only the
print statement is on an exclusively-locked handle, but also that
the file being written to is indeed the latest instance of
/var/log/my.log?

I can't think of any solution.  The best I can come up (which sucks)
is to always open the handle immediately before requesting the lock
(i.e. no intervening statements between the open() and the lock()).
All the external events between the open() and the lock() described
above can still happen, but at least now the probability of this
is greatly reduced.

There's got to be something better, but I'm drawing a blank.  Any
help would be appreciated.

TIA!

kj
-- 
NOTE: In my address everything before the first period is backwards;
and the last period, and everything after it, should be discarded.


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

Date: Sun, 16 Jul 2006 01:02:49 +0200
From: Mark Clements <mark.clementsREMOVETHIS@wanadoo.fr>
Subject: Re: Yet another flock question...
Message-Id: <44b9740f$0$857$ba4acef3@news.orange.fr>

kj wrote:
> For the following, assume the OS is some Un*x.
> 
> Suppose one uses flock like this (lifted with minor modifications
> from perlfunc):
> 
>                    use Fcntl ':flock'; # import LOCK_* constants
> 
>                    sub lock {
>                        flock(LOG,LOCK_EX);
>                        # and, in case someone appended
>                        # while we were waiting...
>                        seek(LOG, 0, 2);
>                    }
> 
>                    sub unlock {
>                        flock(LOG,LOCK_UN);
>                    }
> 
>                    open(LOG, ">>/var/log/my.log"
>                            or die "Can't open logfile: $!";
> 
> 
> 
>                    # elsewhere... 
> 
>                    lock();
>                    print LOG $msg,"\n\n";
>                    unlock();
> 
> 
> ...but suppose that after the open() but before lock(), some
> other process (e.g. a logfile rotator) moves /var/log/my.log to
> /var/log/my.log.1, creates a new /var/log/my.log file, and perhaps
> a *third* process then writes some new stuff to this new /var/log/my.log.
> (Note that this is not an improbable scenario; in a long-running
> process, such as a server, ample time can occur between the executions
> of the open() and lock() statements for all of this to happen).
> 
> In this case, the code above will end up appending $msg to
> /var/log/my.log.1 and not to the newly created /var/log/my.log.
> Now /var/log/my.log.1 would have entries that are more recent than
> the earliest entries in /var/log/my.log, which can lead to problems
> or at least confusion.
> 
> How could the code above be modified to ensure that not only the
> print statement is on an exclusively-locked handle, but also that
> the file being written to is indeed the latest instance of
> /var/log/my.log?
> 
> I can't think of any solution.  The best I can come up (which sucks)
> is to always open the handle immediately before requesting the lock
> (i.e. no intervening statements between the open() and the lock()).
> All the external events between the open() and the lock() described
> above can still happen, but at least now the probability of this
> is greatly reduced.
> 
> There's got to be something better, but I'm drawing a blank.  Any
> help would be appreciated.
> 

This isn't a direct answer, but if this is a real-world problem rather 
than a learning exercise, how about going through syslog and/or using a 
logging package eg Log::Log4perl?

Mark


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

Date: 15 Jul 2006 23:24:17 GMT
From: xhoster@gmail.com
Subject: Re: Yet another flock question...
Message-Id: <20060715192850.780$yp@newsreader.com>

kj <socyl@987jk.com.invalid> wrote:

 ...
> ...but suppose that after the open() but before lock(), some
> other process (e.g. a logfile rotator) moves /var/log/my.log to
> /var/log/my.log.1, creates a new /var/log/my.log file,

Also suppose this happens after the open and after the lock?  What
would be the difference?

> and perhaps
> a *third* process then writes some new stuff to this new /var/log/my.log.
> (Note that this is not an improbable scenario; in a long-running
> process, such as a server, ample time can occur between the executions
> of the open() and lock() statements for all of this to happen).
>
> In this case, the code above will end up appending $msg to
> /var/log/my.log.1 and not to the newly created /var/log/my.log.
> Now /var/log/my.log.1 would have entries that are more recent than
> the earliest entries in /var/log/my.log, which can lead to problems
> or at least confusion.

Since you know about this possibility, then take steps to avoid those
problems or confusion.  That is the way I'd handle it.

>
> How could the code above be modified to ensure that not only the
> print statement is on an exclusively-locked handle, but also that
> the file being written to is indeed the latest instance of
> /var/log/my.log?
>
> I can't think of any solution.  The best I can come up (which sucks)
> is to always open the handle immediately before requesting the lock
> (i.e. no intervening statements between the open() and the lock()).
> All the external events between the open() and the lock() described
> above can still happen, but at least now the probability of this
> is greatly reduced.

The rotator program could take out an exlcusive lock on the file before
renaming, and hold that lock for (say) 10 minutes after renaming it.
When your logger obtains a lock, it would always check to make sure the
lock was not on a file open for more than 10 minutes.  And when tries to
obtain a lock it initially does so non-blockingly, and if it fails it
reopens the file and tries again.

Or you could not rename files.  Have the rotator copy the data and then
truncate the original, rather than renaming it.

Xho

-- 
-------------------- http://NewsReader.Com/ --------------------
Usenet Newsgroup Service                        $9.95/Month 30GB


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

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


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