[24398] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 6586 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed May 19 21:10:32 2004

Date: Wed, 19 May 2004 18:10:09 -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           Wed, 19 May 2004     Volume: 10 Number: 6586

Today's topics:
    Re: How to find the target of a Unix symlink? <spam@nowhere.com>
    Re: How to find the target of a Unix symlink? <socyl@987jk.com>
    Re: How to find the target of a Unix symlink? <krahnj@acm.org>
    Re: How to find the target of a Unix symlink? <ddunham@redwood.taos.com>
    Re: How to find the target of a Unix symlink? <usenet@morrow.me.uk>
    Re: Meaning of Orthogonality <gmiller@NOTforSPAM.gregmiller.net>
    Re: Meaning of Orthogonality <usenet@morrow.me.uk>
    Re: noob question: Trying to extract part of a string i <krahnj@acm.org>
    Re: Perl vs PHP <usenet@morrow.me.uk>
    Re: problem with references <dwall@fastmail.fm>
    Re: random IP <gmiller@NOTforSPAM.gregmiller.net>
    Re: random IP <usenet@morrow.me.uk>
    Re: Test post from Nortel - pls ignore <matthew.garrish@sympatico.ca>
    Re: Testing whether given file is open? <krahnj@acm.org>
    Re: Was this clever or dumb? <gmiller@NOTforSPAM.gregmiller.net>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Wed, 19 May 2004 17:43:40 -0500
From: Todd <spam@nowhere.com>
Subject: Re: How to find the target of a Unix symlink?
Message-Id: <c8gnur$ind$1@home.itg.ti.com>

kj wrote:

> How does one find the target(s) of a Unix symlink?
> 
> I guess one klugey way would be to pick through the output of
> "/bin/ls -al":
> 
>   sub get_target {
>     my ($link, $seen) = @_;
>     $seen ||= {};
>     return $link if $seen->{$link}; # circularity
>     return $link unless -e $link;
>     my $ls = (`/bin/ls -al $link`)[0];   # ick!
>     return $link unless $ls =~ /\s${link} ->\s+(.*?)\s*$/;
>     $seen->{$link} = 1;
>     get_target($1, $seen); 
>   }
> 
> Is there a more civilized way to do this?
> 
> Thanks!
> 
> kj
> 


perldoc -f readlink

my $target = readlink $link_name;

Todd


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

Date: Wed, 19 May 2004 22:59:40 +0000 (UTC)
From: kj <socyl@987jk.com>
Subject: Re: How to find the target of a Unix symlink?
Message-Id: <c8gosr$18q$1@reader2.panix.com>

In <c8gh1g$re5$1@reader2.panix.com> kj <socyl@987jk.com> writes:

>How does one find the target(s) of a Unix symlink?

>I guess one klugey way would be to pick through the output of
>"/bin/ls -al":

>  sub get_target {
>    my ($link, $seen) = @_;
>    $seen ||= {};
>    return $link if $seen->{$link}; # circularity
>    return $link unless -e $link;
>    my $ls = (`/bin/ls -al $link`)[0];   # ick!
>    return $link unless $ls =~ /\s${link} ->\s+(.*?)\s*$/;
>    $seen->{$link} = 1;
>    get_target($1, $seen); 
>  }

Well, the above is clearly a disaster...

>Is there a more civilized way to do this?

I found readlink, but my gripe with it is that it doesn't follow
links beyond the first hop.  (I.e. if "first" points to "second",
and "second" points to "third", readlink "first" returns "second"
not "third.)  stat, on the other hand, does a nice job of finding
the ultimate target of a sequence of links, but one ends up with
a device and an inode, not a filename for the target.

Is there a way to get the filename (or filenames) associated with
a dev+inode combination?

Thanks in advance,

kj

-- 
NOTE: In my address everything before the period is backwards.


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

Date: Wed, 19 May 2004 23:44:56 GMT
From: "John W. Krahn" <krahnj@acm.org>
Subject: Re: How to find the target of a Unix symlink?
Message-Id: <40ABF16D.3793E96C@acm.org>

kj wrote:
> 
> How does one find the target(s) of a Unix symlink?

perldoc -f readlink


John
-- 
use Perl;
program
fulfillment


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

Date: Wed, 19 May 2004 23:53:30 GMT
From: Darren Dunham <ddunham@redwood.taos.com>
Subject: Re: How to find the target of a Unix symlink?
Message-Id: <_rSqc.69332$Y73.25923@newssvr25.news.prodigy.com>

kj <socyl@987jk.com> wrote:
> I found readlink, but my gripe with it is that it doesn't follow
> links beyond the first hop.  (I.e. if "first" points to "second",
> and "second" points to "third", readlink "first" returns "second"
> not "third.)  stat, on the other hand, does a nice job of finding
> the ultimate target of a sequence of links, but one ends up with
> a device and an inode, not a filename for the target.

> Is there a way to get the filename (or filenames) associated with
> a dev+inode combination?

No, not easily.  The System rarely (never?) needs to do this, so there
is no index for it.

You would have to 'find' on the filesystem (ususally expensive), trying
to match the inode, and must realize that there may be more than one
filename for it.

-- 
Darren Dunham                                           ddunham@taos.com
Senior Technical Consultant         TAOS            http://www.taos.com/
Got some Dr Pepper?                           San Francisco, CA bay area
         < This line left intentionally blank to confuse you. >


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

Date: Thu, 20 May 2004 00:41:39 +0000 (UTC)
From: Ben Morrow <usenet@morrow.me.uk>
Subject: Re: How to find the target of a Unix symlink?
Message-Id: <c8gus3$hf8$3@wisteria.csv.warwick.ac.uk>


Quoth kj <socyl@987jk.com>:
> In <c8gh1g$re5$1@reader2.panix.com> kj <socyl@987jk.com> writes:
> 
> >How does one find the target(s) of a Unix symlink?
> 
> I found readlink, but my gripe with it is that it doesn't follow
> links beyond the first hop.  (I.e. if "first" points to "second",
> and "second" points to "third", readlink "first" returns "second"
> not "third.)  

This is the only way to get all the information. A simple way to follow
all links:

sub readalllinks {
    my $file = shift;
    while (-l $file) {
        $file = readlink $file;
    }
}
    
> stat, on the other hand, does a nice job of finding
> the ultimate target of a sequence of links, but one ends up with
> a device and an inode, not a filename for the target.
> 
> Is there a way to get the filename (or filenames) associated with
> a dev+inode combination?

No, except in special cases.

Ben

-- 
Like all men in Babylon I have been a proconsul; like all, a slave ... During
one lunar year, I have been declared invisible; I shrieked and was not heard,
I stole my bread and was not decapitated.
~ ben@morrow.me.uk ~                   Jorge Luis Borges, 'The Babylon Lottery'


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

Date: Wed, 19 May 2004 23:46:43 GMT
From: Greg Miller <gmiller@NOTforSPAM.gregmiller.net>
Subject: Re: Meaning of Orthogonality
Message-Id: <5opna01ei3f4gs6rddlrukavosltao4qjv@4ax.com>

On Wed, 19 May 2004 08:43:13 -0000, Edward Wijaya
<ewijaya@singnet.com.sg> wrote:

>Perl is said to be an "orthogonal" programming language.
>What does it mean?

	Means it has more than 8 sides. ;)  Seriously, loosely
speaking it means all features in the language are created equally.
E.G.  In perl you can return an integer from a function, but you can't
return an array from a function (a pointer to an array doesn't count).
So Perl is not orthogonal (like everyone else said).  In an completely
orthogonal language, you should be able to have an array of functions.
Not that it's useful, but that's what it would have to do.
	But, in general, when people refer to whether or not a
language is orthogonal, they're referring to whether or not all of the
language's data types can be used like any other.  E.G. operator
overloading, returning an object from a function, arrays of arrays of
structs of objects.
	I'm not sure how this word came to be associated with
programming languages.  The mathematical definition says two things
are orthogonal if they are at 90 degrees to each other.  If you try to
adapt that to programming language structures, you'd think an
orthogonal language is one that treats everything differently than
everything else.  But in the programming languages context, it means
to treat everything the same.
	Now that I've said that, I've noticed the mathematical
definition of orthogonal, and the programming language definition are
orthogonal to each other!  Maybe it was a joke someone made that got
out of hand.

	Oh, and here's a programming language which follows the
mathematical definition of orthogonal:
http://www.muppetlabs.com/~breadbox/orth/
	I'm assuming (hoping) that really is a joke.


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

Date: Thu, 20 May 2004 00:36:24 +0000 (UTC)
From: Ben Morrow <usenet@morrow.me.uk>
Subject: Re: Meaning of Orthogonality
Message-Id: <c8gui7$hf8$2@wisteria.csv.warwick.ac.uk>


Quoth Greg Miller <gmiller@NOTforSPAM.gregmiller.net>:
> 	Means it has more than 8 sides. ;)  Seriously, loosely
> speaking it means all features in the language are created equally.
> E.G.  In perl you can return an integer from a function, but you can't
> return an array from a function (a pointer to an array doesn't count).
> So Perl is not orthogonal (like everyone else said).  In an completely
> orthogonal language, you should be able to have an array of functions.
> Not that it's useful, but that's what it would have to do.
> 	I'm not sure how this word came to be associated with
> programming languages.  The mathematical definition says two things
> are orthogonal if they are at 90 degrees to each other.  If you try to
> adapt that to programming language structures, you'd think an
> orthogonal language is one that treats everything differently than
> everything else.  But in the programming languages context, it means
> to treat everything the same.
> 	Now that I've said that, I've noticed the mathematical
> definition of orthogonal, and the programming language definition are
> orthogonal to each other!  Maybe it was a joke someone made that got
> out of hand.

No, it does make sense. It means, to take you example, that the
definition of 'function return value' is orthogonal to the definition of
'data types': any function can return any data type. Think vectors: two
vectors are orthogonal iff any combination gives another unique vector.

Ben

-- 
For the last month, a large number of PSNs in the Arpa[Inter-]net have been
reporting symptoms of congestion ... These reports have been accompanied by an
increasing number of user complaints ... As of June,... the Arpanet contained
47 nodes and 63 links. [ftp://rtfm.mit.edu/pub/arpaprob.txt] * ben@morrow.me.uk


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

Date: Wed, 19 May 2004 23:22:01 GMT
From: "John W. Krahn" <krahnj@acm.org>
Subject: Re: noob question: Trying to extract part of a string in a variableto  another variable
Message-Id: <40ABEC0D.866A8352@acm.org>

Paul Lalli wrote:
> 
> On Wed, 19 May 2004, cayenne wrote:
> 
> > Richard Morse <remorse@partners.org> wrote in message news:<remorse-79A20D.12400626042004@plato.harvard.edu>...
> > >
> > >    my ($user_id) = ($mail_address =~ m/([\w.-+=]+)@/);
> >
> > Just quickly, can you explain the extensive use of parens here? I
> > understand the () in the regular expression, to keep those parts the
> > match...but, what is the function of the () around $user_id and the
> > entire part after the = sign?
> 
> The parens around $user_id force the binding operation of =~ to be
> evaluated in list context.  This is done because a pattern match in list
> context returns a list of all of the captured matches (ie, the things that
> go into $1, $2, etc).  This is a shorthand way of writing the two
> statements:
> 
> $mail_address =~ m/([\w.-+=]+)@/
> my $user_id = $1;

They are not the same at all.  If the match fails the first will set
$user_id to undef but your version will set $user_id to the contents of
a previously successful match's capturing parentheses or ''.




John
-- 
use Perl;
program
fulfillment


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

Date: Thu, 20 May 2004 00:45:58 +0000 (UTC)
From: Ben Morrow <usenet@morrow.me.uk>
Subject: Re: Perl vs PHP
Message-Id: <c8gv46$hf8$4@wisteria.csv.warwick.ac.uk>


Quoth "porter970" <porter970@lycos.com>:
> Is there a reason to use Perl rather than PHP?

Yes: it's Perl :).

> I've got stuff that uses both ... so much of the syntax, etc. is similar. 

*boggle* Beyond a basic similarity to C, and to shell, is it?

> Is one more secure ... or faster ... ?

Perl with taint mode may help you more to write secure programs than PHP.
If you have access to mod_php (or ISAPI php) but not mod_perl then PHP
will be faster. And vice-versa, obviously, but the former seems to be
not uncommon among web hosting providers.

My own personal opinion is that PHP is more like perl4 than perl5, and
is not really suited to writing complex programs. Others, I know,
disagree with me here...

Ben

-- 
It will be seen that the Erwhonians are a meek and long-suffering people,
easily led by the nose, and quick to offer up common sense at the shrine of
logic, when a philosopher convinces them that their institutions are not based 
on the strictest morality.  [Samuel Butler, paraphrased]       ben@morrow.me.uk


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

Date: Thu, 20 May 2004 00:29:56 -0000
From: "David K. Wall" <dwall@fastmail.fm>
Subject: Re: problem with references
Message-Id: <Xns94EED0880F870dkwwashere@216.168.3.30>

jacek <bornslippy.SPAM.IS.NOT.OK@o2.pl> wrote:

> I'm new to perl (only yesterday I wrote my first .pl script)
> and I have a problem with references

Now is a good time to learn some good habits, like declaring all your 
variables before you use them, disabling certain unsafe constructs, 
and having perl warn you about possible errors.  You can do this by 
putting

    use strict;
    use warnings;

at the beginning of your program.

> ....
> $var = 22;
> $ptr = \$var;
> $$ptr = 23;
> print "$var\n"; #gives 23 ok
> print "$ptr\n"; ################
> 
> $thread = new Thread \&ThreadProcedure, $ptr;

This method of creating a new object is discouraged, at least by Damian 
Conway in his "Object Oriented Perl" book.  I would write it as 

    my $thread = Thread->new( \&ThreadProcedure, $ptr );

to avoid the complications he mentions.

> $thread->join;
> print "$var\n"; #gives 23 which is not ok, I thought it'd be 24
> .......
> sub ThreadProcedure
> {
>     $v = @_[0];

Better written as 

    $v = $_[0];

If you had had warnings enabled, perl would have told you about this.


>     print "$$v\n"; #gives 23 ok
>     print "$v\n";   ###############
>     $$v = 24;

For a normal subroutine this would work as expected, but this takes 
place in a different thread. I've never had a need for threads and have 
never used them -- but some quick tests show that 

    $$ptr = $thread->join;

above will produce the *results* you want, even if it's not quite the way 
you wanted to do it.


>}
> 
> 2 lines with ############## give different memory address, so it's
> no doubt that changing value of $var in ThreadProcedure is not
> seen in main thread. what should I do to work it properly?

I don't know. Your problem is not with references, but with threads. 

Regarding the use of the Threads module and your stated newness to Perl, 
there's a particularly relevant sentence in the docs for Thread.pm:

    For new code the use of the Thread module is discouraged and 
    the direct use of the threads and threads::shared modules is 
    encouraged instead.



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

Date: Wed, 19 May 2004 22:47:10 GMT
From: Greg Miller <gmiller@NOTforSPAM.gregmiller.net>
Subject: Re: random IP
Message-Id: <7hona0p429nkvr2ji0ja40a93e6uouijjo@4ax.com>

On Tue, 18 May 2004 19:20:06 +0000 (UTC), Ben Morrow
<usenet@morrow.me.uk> wrote:

>Include the pid, $$, and sleep for at least a second.

	If all of the processes sleep for 1 second, then this has no
effect on the randomness.  You could sleep for a random period of
time, but if you've got several processes starting every second, then
you're still guaranteed to have duplicates as long as your time
resolution is only one second.  And with only 32 bits to work with,
you're going to have dups quite often anyway.


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

Date: Thu, 20 May 2004 00:47:53 +0000 (UTC)
From: Ben Morrow <usenet@morrow.me.uk>
Subject: Re: random IP
Message-Id: <c8gv7p$hf8$5@wisteria.csv.warwick.ac.uk>


Quoth Greg Miller <gmiller@NOTforSPAM.gregmiller.net>:
> On Tue, 18 May 2004 19:20:06 +0000 (UTC), Ben Morrow
> <usenet@morrow.me.uk> wrote:
> 
> >Include the pid, $$, and sleep for at least a second.
> 
> 	If all of the processes sleep for 1 second, then this has no
> effect on the randomness.

Randomness, no; uniqueness, yes. If you sleep for a second then (time,
pid) is unique during that second.

Ben

-- 
   Although few may originate a policy, we are all able to judge it.
                                             - Pericles of Athens, c.430 B.C.
  ben@morrow.me.uk


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

Date: Wed, 19 May 2004 20:38:05 -0400
From: "Matt Garrish" <matthew.garrish@sympatico.ca>
Subject: Re: Test post from Nortel - pls ignore
Message-Id: <K5Tqc.29989$qJ5.774306@news20.bellglobal.com>


"Chris" <chrisvz@nortelnetworks.com> wrote in message
news:c8gfe4$7p5$1@zcars0v6.ca.nortel.com...
> Testing outbound posts, please ignore.
>
> News Admin @ Nortel
>

You should test your balance sheets while you're at it...

Matt




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

Date: Wed, 19 May 2004 22:30:04 GMT
From: "John W. Krahn" <krahnj@acm.org>
Subject: Re: Testing whether given file is open?
Message-Id: <40ABDFE0.1FFEF870@acm.org>

Richard Morse wrote:
> 
> One other option is to have the upload client send the size of the file
> first, and then send the file.  When the uploaded file is the same as
> the sent size, it's been entirely transferred.

There is no guarantee that the size of the file on the server will be
the same as the size of the file on the client.


John
-- 
use Perl;
program
fulfillment


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

Date: Wed, 19 May 2004 23:57:46 GMT
From: Greg Miller <gmiller@NOTforSPAM.gregmiller.net>
Subject: Re: Was this clever or dumb?
Message-Id: <1msna0pl7dvi37d9g8bhebrlq9kfpl4kdb@4ax.com>

On 19 May 2004 11:51:24 -0700, tigerhillside@netscape.net (Tiger
Hillside) wrote:

>That would have worked, but at the printing end I would have had to
>pull the fields apart and get that right. Then I had what I thought
>was a good idea. I did the following concatination: $timevalue . " on
>" . $datevalue", sorted the keys, and just printed out the has value
>and the key.

	I do that all of the time.  So I'm guessing it's dumb ;)  I
think it's the best way to do it for a small dataset.  But if you're
going to be looking at thousands or millions of records, you're better
off doing an "order by" in your SQL on the date/time then loop through
all of the records and output the date/time and count anytime the
date/time on the current record isn't the same as it was on the last
record.


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

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


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