[22556] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 4777 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Mar 28 11:11:38 2003

Date: Fri, 28 Mar 2003 08:10:13 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Fri, 28 Mar 2003     Volume: 10 Number: 4777

Today's topics:
    Re: Perl modules. <phil.latio@f-in-stupid.co.uk>
    Re: Perl modules. (Tad McClellan)
    Re: Perl modules. <phil.latio@f-in-stupid.co.uk>
    Re: Perl modules. (Tad McClellan)
    Re: Perl modules. <flavell@mail.cern.ch>
    Re: Perl modules. <phil.latio@f-in-stupid.co.uk>
    Re: Perl modules. <Graham.T.Wood@oracle.com>
    Re: Perl modules. <phil.latio@f-in-stupid.co.uk>
    Re: Perl modules. (Helgi Briem)
    Re: Perl modules. <usenet@dwall.fastmail.fm>
    Re: Perl modules. <phil.latio@f-in-stupid.co.uk>
    Re: Perl modules. <phil.latio@f-in-stupid.co.uk>
    Re: Perl modules. (Helgi Briem)
    Re: Perl modules. <annoyed@you.now>
    Re: Perl String Manipulation <nobull@mail.com>
    Re: Perl String Manipulation <perl-dvd@darklaser.com>
    Re: regex question <barryk2@SPAM-KILLER.mts.net>
    Re: Sorting keys in a hash runs slower now. <tore@aursand.no>
    Re: Sorting keys in a hash runs slower now. <no@spam.for.me.invalid>
    Re: Win32::FileSecurity removes some existing rights (Bill Yager)
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Fri, 28 Mar 2003 11:44:20 GMT
From: "Phil Latio" <phil.latio@f-in-stupid.co.uk>
Subject: Re: Perl modules.
Message-Id: <oAWga.1337164$6l6.8750604@news.easynews.com>

> 3. include the .pm in the .cgi itself: replace the line "use
> UserTracker;" with the contents of Usertracker.pm.

Please could you show me how with the books example.

Cheers

Phil


#!/usr/bin/perl -wT

#/----------------------------------------------------------------
# UserTracker Module
#
# Inherits from HTML::Parser
#
#

package CGIBook::UserTracker;

push @ISA, "HTML::Parser";

use strict;
use URI;
use HTML::Parser;

1;


#/----------------------------------------------------------------
# Public methods
#

sub new {
    my( $class, $path ) = @_;
    my $id;

    if ( $ENV{PATH_INFO} and
         $ENV{PATH_INFO} =~ s|^/\.([a-z0-9_.-]*)/|/|i ) {
        $id = $1;
    }
    else {
        $id ||= unique_id(  );
    }

    my $self = $class->SUPER::new(  );
    $self->{user_id}    = $id;
    $self->{base_path}  = defined( $path ) ? $path : "";

    return $self;
}

sub base_path {
    my( $self, $path ) = @_;
    $self->{base_path} = $path if defined $path;
    return $self->{base_path};
}

sub user_id {
    my $self = shift;
    return $self->{user_id};
}


#/----------------------------------------------------------------
# Internal (private) subs
#

sub unique_id {
    # Use Apache's mod_unique_id if available
    return $ENV{UNIQUE_ID} if exists $ENV{UNIQUE_ID};

    require Digest::MD5;

    my $md5 = new Digest::MD5;
    my $remote = $ENV{REMOTE_ADDR} . $ENV{REMOTE_PORT};

    # Note this is intended to be unique, and not unguessable
    # It should not be used for generating keys to sensitive data
    my $id = $md5->md5_base64( time, $$, $remote );
    $id =~ tr|+/=|-_.|;  # Make non-word chars URL-friendly
    return $id;
}

sub encode {
    my( $self, $url ) = @_;
    my $uri  = new URI( $url, "http" );
    my $id   = $self->user_id(  );
    my $base = $self->base_path;

    my $path = $uri->path;
    $path =~ s|^$base|$base/.$id| or
        die "Invalid base path configured\n";
    $uri->path( $path );

    return $uri->as_string;
}


#/----------------------------------------------------------------
# Subs to implement HTML::Parser callbacks
#

sub start {
    my( $self, $tag, $attr, $attrseq, $origtext ) = @_;
    my $new_text = $origtext;

    my %relevant_pairs = (
        frameset    => "src",
        a           => "href",
        area        => "href",
        form        => "action",
# Uncomment these lines if you want to track images too
#        img         => "src",
#        body        => "background",
    );

    while ( my( $rel_tag, $rel_attr ) = each %relevant_pairs ) {
        if ( $tag eq $rel_tag and $attr->{$rel_attr} ) {
            $attr->{$rel_attr} = $self->encode( $attr->{$rel_attr} );
            my @attribs = map { "$_=\"$attr->{$_}\"" } @$attrseq;
            $new_text = "<$tag @attribs>";
        }
    }

    # Meta refresh tags have a different format, handled separately
    if ( $tag eq "meta" and $attr->{"http-equiv"} eq "refresh" ) {
        my( $delay, $url ) = split ";URL=", $attr->{content}, 2;
        $attr->{content} = "$delay;URL=" . $self->encode( $url );
        my @attribs = map { "$_=\"$attr->{$_}\"" } @$attrseq;
        $new_text = "<$tag @attribs>";
    }

    print $new_text;
}

sub declaration {
    my( $self, $decl ) = @_;
    print $decl;
}

sub text {
    my( $self, $text ) = @_;
    print $text;
}

sub end {
    my( $self, $tag ) = @_;
    print "</$tag>";
}

sub comment {
    my( $self, $comment ) = @_;
    print "<!--$comment-->";
}


#!/usr/bin/perl -wT

use strict;
use CGIBook::UserTracker;

local *FILE;
my $track = new CGIBook::UserTracker;
$track->base_path( "/store" );

my $requested_doc = $ENV{PATH_TRANSLATED};
unless ( -e $requested_doc ) {
    print "Location: /errors/not_found.html\n\n";
}

open FILE, $requested_doc or die "Failed to open $requested_doc: $!";

my $doc = do {
    local $/ = undef;
    <FILE>;
};

close FILE;

# This assumes we're only tracking HTML files:
print "Content-type: text/html\n\n";
$track->parse( $doc );




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

Date: Fri, 28 Mar 2003 06:12:12 -0600
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Perl modules.
Message-Id: <slrnb88f0s.2sa.tadmc@magna.augustmail.com>

Josef Möllers <josef.moellers@fujitsu-siemens.com> wrote:
> Phil Latio wrote:


[ snip CGI program uses a module ]


>> Where do you put the UserTracker.pm?
> 
> In any directory included in the @INC array.


> TMTOWTDI:
> 1. install the .pm in the same directory as the .cgi and append "." to
> @INC, if it's not already there.


AND chdir() to the directory where the program is located.

It is not where the program is that matters for relative paths,
it is the current working directory that matters.


> 2. request installation of the .pm in whatever directory the web hoster
> provides for this purpose.
> 3. include the .pm in the .cgi itself: replace the line "use
> UserTracker;" with the contents of Usertracker.pm.


4. install the .pm in any old directory that you have write access
   for, and the "use lib" it, as in:

   perldoc -q module

      "How do I keep my own module/library directory?"


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


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

Date: Fri, 28 Mar 2003 12:51:28 GMT
From: "Phil Latio" <phil.latio@f-in-stupid.co.uk>
Subject: Re: Perl modules.
Message-Id: <kzXga.6812392$6N5.918360@post-03.news.easynews.com>

Many thanks for the reply.

> 4. install the .pm in any old directory that you have write access

Can I just transfer the below to any directory as above, call the file
UserTracker.pm and expect query_track.cgi to find it?

>    for, and the "use lib" it, as in:

Could you explain what you mean. What is lib?

Cheers

Phil

#!/usr/bin/perl -wT

#/----------------------------------------------------------------
# UserTracker Module
#
# Inherits from HTML::Parser
#
#

package CGIBook::UserTracker;

push @ISA, "HTML::Parser";

use strict;
use URI;
use HTML::Parser;

1;


#/----------------------------------------------------------------
# Public methods
#

sub new {
    my( $class, $path ) = @_;
    my $id;

    if ( $ENV{PATH_INFO} and
         $ENV{PATH_INFO} =~ s|^/\.([a-z0-9_.-]*)/|/|i ) {
        $id = $1;
    }
    else {
        $id ||= unique_id(  );
    }

    my $self = $class->SUPER::new(  );
    $self->{user_id}    = $id;
    $self->{base_path}  = defined( $path ) ? $path : "";

    return $self;
}

sub base_path {
    my( $self, $path ) = @_;
    $self->{base_path} = $path if defined $path;
    return $self->{base_path};
}

sub user_id {
    my $self = shift;
    return $self->{user_id};
}


#/----------------------------------------------------------------
# Internal (private) subs
#

sub unique_id {
    # Use Apache's mod_unique_id if available
    return $ENV{UNIQUE_ID} if exists $ENV{UNIQUE_ID};

    require Digest::MD5;

    my $md5 = new Digest::MD5;
    my $remote = $ENV{REMOTE_ADDR} . $ENV{REMOTE_PORT};

    # Note this is intended to be unique, and not unguessable
    # It should not be used for generating keys to sensitive data
    my $id = $md5->md5_base64( time, $$, $remote );
    $id =~ tr|+/=|-_.|;  # Make non-word chars URL-friendly
    return $id;
}

sub encode {
    my( $self, $url ) = @_;
    my $uri  = new URI( $url, "http" );
    my $id   = $self->user_id(  );
    my $base = $self->base_path;

    my $path = $uri->path;
    $path =~ s|^$base|$base/.$id| or
        die "Invalid base path configured\n";
    $uri->path( $path );

    return $uri->as_string;
}


#/----------------------------------------------------------------
# Subs to implement HTML::Parser callbacks
#

sub start {
    my( $self, $tag, $attr, $attrseq, $origtext ) = @_;
    my $new_text = $origtext;

    my %relevant_pairs = (
        frameset    => "src",
        a           => "href",
        area        => "href",
        form        => "action",
# Uncomment these lines if you want to track images too
#        img         => "src",
#        body        => "background",
    );

    while ( my( $rel_tag, $rel_attr ) = each %relevant_pairs ) {
        if ( $tag eq $rel_tag and $attr->{$rel_attr} ) {
            $attr->{$rel_attr} = $self->encode( $attr->{$rel_attr} );
            my @attribs = map { "$_=\"$attr->{$_}\"" } @$attrseq;
            $new_text = "<$tag @attribs>";
        }
    }

    # Meta refresh tags have a different format, handled separately
    if ( $tag eq "meta" and $attr->{"http-equiv"} eq "refresh" ) {
        my( $delay, $url ) = split ";URL=", $attr->{content}, 2;
        $attr->{content} = "$delay;URL=" . $self->encode( $url );
        my @attribs = map { "$_=\"$attr->{$_}\"" } @$attrseq;
        $new_text = "<$tag @attribs>";
    }

    print $new_text;
}

sub declaration {
    my( $self, $decl ) = @_;
    print $decl;
}

sub text {
    my( $self, $text ) = @_;
    print $text;
}

sub end {
    my( $self, $tag ) = @_;
    print "</$tag>";
}

sub comment {
    my( $self, $comment ) = @_;
    print "<!--$comment-->";
}




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

Date: Fri, 28 Mar 2003 07:57:00 -0600
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Perl modules.
Message-Id: <slrnb88l5c.368.tadmc@magna.augustmail.com>


[ Please DO NOT top-post, it can get you killfiled ]


Phil Latio <phil.latio@f-in-stupid.co.uk> wrote:
> Many thanks for the reply.
> 
>> 4. install the .pm in any old directory that you have write access
> 
> Can I just transfer the below to any directory as above, call the file
> UserTracker.pm and expect query_track.cgi to find it?


No...


>>    for, and the "use lib" it, as in:


 ...you'd need to do the above to allow perl to find it.


> Could you explain what you mean. 


Did you read the Frequently Asked Question's answer?

If so, then quote the part that you are not following, and we'll
try and explain it to you.


> What is lib?


   perldoc lib



[snip TOFU]

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


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

Date: Fri, 28 Mar 2003 14:20:07 +0100
From: "Alan J. Flavell" <flavell@mail.cern.ch>
Subject: Re: Perl modules.
Message-Id: <Pine.LNX.4.53.0303281413310.6559@lxplus085.cern.ch>

On Fri, Mar 28, Phil Latio inscribed on the eternal scroll:

> >    for, and the "use lib" it, as in:

[you snipped the instructions which had been provided for your
edification]

> Could you explain what you mean.

   perldoc -q module

      "How do I keep my own module/library directory?"

Could you explain which part of the instructions you didn't
understand?  We'd find it hard to understand how someone had got so
far with Perl programming without the ability to consult its
accompanying documentation.  Here's another view of the same
information:

<
http://www.perldoc.com/perl5.8.0/pod/perlfaq8.html#How-do-I-keep-my-own-module-library-directory-
>


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

Date: Fri, 28 Mar 2003 14:14:20 GMT
From: "Phil Latio" <phil.latio@f-in-stupid.co.uk>
Subject: Re: Perl modules.
Message-Id: <0NYga.6816382$6N5.919068@post-03.news.easynews.com>

"Tad McClellan" <tadmc@augustmail.com> wrote in message
news:slrnb88l5c.368.tadmc@magna.augustmail.com...
> Did you read the Frequently Asked Question's answer?

Thanks for the reply again.

I types "perldoc -q module" into Google and found http://www.perldoc.com/
which looks just what I am looking for.

Cheers

Phil








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

Date: Fri, 28 Mar 2003 14:17:37 +0000
From: Graham Wood <Graham.T.Wood@oracle.com>
Subject: Re: Perl modules.
Message-Id: <3E845981.57571DA1@oracle.com>

This is a multi-part message in MIME format.
--------------F84E92E89A096E1F6AC08DEB
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 7bit

Phil Latio wrote:

> >    for, and the "use lib" it, as in:
>
> Could you explain what you mean. What is lib?

use lib "/path/to/modules";

will add /path/to/modules to the @INC array.  That is, it tell perl to
look in the specified path for any modules as well as in the default
locations.

You can then put modulename.pm into /path/to/modules and...

use modulename;

will find it.

Graham

--------------F84E92E89A096E1F6AC08DEB
Content-Type: text/x-vcard; charset=UTF-8;
 name="Graham.T.Wood.vcf"
Content-Transfer-Encoding: 7bit
Content-Description: Card for Graham Wood
Content-Disposition: attachment;
 filename="Graham.T.Wood.vcf"

begin:vcard 
n:;Graham
x-mozilla-html:FALSE
adr:;;;;;;
version:2.1
email;internet:Graham.Wood@oracle.com
fn:Graham Wood
end:vcard

--------------F84E92E89A096E1F6AC08DEB--



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

Date: Fri, 28 Mar 2003 14:39:42 GMT
From: "Phil Latio" <phil.latio@f-in-stupid.co.uk>
Subject: Re: Perl modules.
Message-Id: <O8Zga.6817711$6N5.919308@post-03.news.easynews.com>


"Alan J. Flavell" <flavell@mail.cern.ch> wrote in message
news:Pine.LNX.4.53.0303281413310.6559@lxplus085.cern.ch...
> On Fri, Mar 28, Phil Latio inscribed on the eternal scroll:
>
> > >    for, and the "use lib" it, as in:
>
> [you snipped the instructions which had been provided for your
> edification]
>
> > Could you explain what you mean.
>
>    perldoc -q module
>
>       "How do I keep my own module/library directory?"
>
> Could you explain which part of the instructions you didn't
> understand?  We'd find it hard to understand how someone had got so
> far with Perl programming without the ability to consult its
> accompanying documentation.  Here's another view of the same
> information:
>
> <
>
http://www.perldoc.com/perl5.8.0/pod/perlfaq8.html#How-do-I-keep-my-own-modu
le-library-directory-

Thanks for the link.

I should clarify that until 20 minutes, I had not heard of
http://www.perldoc.com and it had strangely evaded me on my searches using
Google. Therefore the phrase "perldoc -q module" didn't make any sense
because I didn't understand in what context it had to be used. I also don't
currently have shell access.

Cheers

Phil






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

Date: Fri, 28 Mar 2003 14:43:50 GMT
From: helgi@decode.is (Helgi Briem)
Subject: Re: Perl modules.
Message-Id: <3e845dd5.4243864314@news.cis.dfn.de>

On Fri, 28 Mar 2003 14:14:20 GMT, "Phil Latio"
<phil.latio@f-in-stupid.co.uk> wrote:

>"Tad McClellan" <tadmc@augustmail.com> wrote in message
>news:slrnb88l5c.368.tadmc@magna.augustmail.com...
>> Did you read the Frequently Asked Question's answer?
>
>Thanks for the reply again.
>
>I types "perldoc -q module" into Google and found 
>http://www.perldoc.com/ which looks just what I am looking for.

Not bad, but it really is much closer to hand.

If you have installed Perl on your computer, it comes
equipped with a full set of excellent, user-friendly
documentation, possibly the best in existence for
any programming language.  

This documentation is mirrored by www.perldoc.com, but 
may not match your local installation precisely, so using
the local copy is best (and fastest).

Open up a command line on your desktop computer
(even Macs have one these days).

Give the command perldoc -q module there.

On a Windows machine, this looks something like:
c:\>perldoc -q module

What it means is "use the perldoc program to
search for the query word module in the 
Frequently Asked Questions section of your
perl documentation.

If you have installed the Activestate.com distribution
of Perl, you will also have a HTML version of the
documentation, which you may or may not prefer.

If so, you can open C:/Perl/HTML/index.html in a web 
browser.
-- 
Regards, Helgi Briem
helgi DOT briem AT decode DOT is


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

Date: Fri, 28 Mar 2003 14:54:24 -0000
From: "David K. Wall" <usenet@dwall.fastmail.fm>
Subject: Re: Perl modules.
Message-Id: <Xns934C64C67C53Edkwwashere@216.168.3.30>

Phil Latio <phil.latio@f-in-stupid.co.uk> wrote:

> I should clarify that until 20 minutes, I had not heard of
> http://www.perldoc.com and it had strangely evaded me on my searches
> using Google. Therefore the phrase "perldoc -q module" didn't make
> any sense because I didn't understand in what context it had to be
> used. I also don't currently have shell access.

Sure you do.  Since you're using Outlook, you're (probably) on Windows, 
which has a DOS (command) prompt.  You can grab a copy of Perl from 
activestate.com if you haven't already, and then you can play with Perl 
and read the extensive documentation that comes with it to your heart's 
content.  Once you get Perl installed, typing 'perldoc perldoc' at a 
command prompt (without the quotes) will get you started.  Or as Helgi 
Briem said, you might prefer the HTML docs that Activestate Perl installs.

-- 
David K. Wall - usenet@dwall.fastmail.fm
WWJD? JWRTFM.


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

Date: Fri, 28 Mar 2003 14:54:34 GMT
From: "Phil Latio" <phil.latio@f-in-stupid.co.uk>
Subject: Re: Perl modules.
Message-Id: <KmZga.3491422$TJ.484790@post-02.news.easynews.com>


"Helgi Briem" <helgi@decode.is> wrote in message
news:3e845dd5.4243864314@news.cis.dfn.de...
> On Fri, 28 Mar 2003 14:14:20 GMT, "Phil Latio"
> <phil.latio@f-in-stupid.co.uk> wrote:
>
> >"Tad McClellan" <tadmc@augustmail.com> wrote in message
> >news:slrnb88l5c.368.tadmc@magna.augustmail.com...
> >> Did you read the Frequently Asked Question's answer?
> >
> >Thanks for the reply again.
> >
> >I types "perldoc -q module" into Google and found
> >http://www.perldoc.com/ which looks just what I am looking for.
>
> Not bad, but it really is much closer to hand.
>
> If you have installed Perl on your computer, it comes
> equipped with a full set of excellent, user-friendly
> documentation, possibly the best in existence for
> any programming language.

Thanks for the reply.

I don't have Perl on this Windows PC, only on my Linux server. Also don't
currently have external shell access as I have blocked all ports apart from
80 on that interface in an attempt to stop pesky hackers.

Cheers

Phil




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

Date: Fri, 28 Mar 2003 15:03:35 GMT
From: "Phil Latio" <phil.latio@f-in-stupid.co.uk>
Subject: Re: Perl modules.
Message-Id: <bvZga.4243913$zx5.639349@news.easynews.com>


"David K. Wall" <usenet@dwall.fastmail.fm> wrote in message
news:Xns934C64C67C53Edkwwashere@216.168.3.30...
> Phil Latio <phil.latio@f-in-stupid.co.uk> wrote:
>
> > I should clarify that until 20 minutes, I had not heard of
> > http://www.perldoc.com and it had strangely evaded me on my searches
> > using Google. Therefore the phrase "perldoc -q module" didn't make
> > any sense because I didn't understand in what context it had to be
> > used. I also don't currently have shell access.
>
> Sure you do.  Since you're using Outlook, you're (probably) on Windows,
> which has a DOS (command) prompt.  You can grab a copy of Perl from
> activestate.com if you haven't already, and then you can play with Perl
> and read the extensive documentation that comes with it to your heart's
> content.  Once you get Perl installed, typing 'perldoc perldoc' at a
> command prompt (without the quotes) will get you started.  Or as Helgi
> Briem said, you might prefer the HTML docs that Activestate Perl installs.
> WWJD? JWRTFM.

It's a matter of company policy that you cannot install software, even if
it's free. As you might have gathered I don't make a living out of
programming in Perl (well not yet at least !!).

Cheers

Phil




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

Date: Fri, 28 Mar 2003 15:06:30 GMT
From: helgi@decode.is (Helgi Briem)
Subject: Re: Perl modules.
Message-Id: <3e846373.4245303032@news.cis.dfn.de>

On Fri, 28 Mar 2003 14:39:42 GMT, "Phil Latio"
<phil.latio@f-in-stupid.co.uk> wrote:

>I should clarify that until 20 minutes, I had not heard of
>http://www.perldoc.com and it had strangely evaded me 
>on my searches using Google. Therefore the phrase 
>"perldoc -q module" didn't make any sense
>because I didn't understand in what context it had to be used. 

Well, it doesn't refer to www.perldoc.com, although
that is one way to access the documentation.

>I also don't currently have shell access.

Then set up Perl (and the bundled documentation) on
your local machine.  Blindfolded, hogtied and naked is no 
way to get through life, son.

-- 
Regards, Helgi Briem
helgi DOT briem AT decode DOT is


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

Date: Fri, 28 Mar 2003 09:13:47 -0600
From: Ivan Marsh <annoyed@you.now>
Subject: Re: Perl modules.
Message-Id: <b61oop$rei$2@grandcanyon.binc.net>

Josef Möllers wrote:

> Phil Latio wrote:
>> 
>> Where do you put the UserTracker.pm?
> 
> In any directory included in the @INC array.

I ran into this the other day when I was having trouble with modules not 
being found by my scripts. It turned out to be a permissions problem.

I'm still wondering though, how do you add a new include directory to @INC 
permanently? From the brief bits I read about it, it looked like it could 
only be changed at compile time. I find that hard to believe.

i.m.


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

Date: 28 Mar 2003 14:16:59 +0000
From: Brian McCauley <nobull@mail.com>
Subject: Re: Perl String Manipulation
Message-Id: <u9wuijtw2s.fsf@wcl-l.bham.ac.uk>

esantosa@student.bond.edu.au writes:

> I have already defined this in Perl
> 
> my $text = "erica";
> my $var = "\$text";
> 
> Now, I want to be able to print $var and process $text interpolate
> string at the same time, therefore the output that I expect from
> 
> print "$var" -> is "erica";
> 
> But currently the output for print "$var" -> is "$text";
> 
> Any suggestion??

Perhaps I can interest you in String::Interpolate?

-- 
     \\   ( )
  .  _\\__[oo
 .__/  \\ /\@
 .  l___\\
  # ll  l\\
 ###LL  LL\\


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

Date: Fri, 28 Mar 2003 14:43:41 GMT
From: "David" <perl-dvd@darklaser.com>
Subject: Re: Perl String Manipulation
Message-Id: <xcZga.34$xC2.21283@news-west.eli.net>

<esantosa@student.bond.edu.au> wrote in message
news:894a4768.0303272327.5d874173@posting.google.com...
> I have already defined this in Perl
>
> my $text = "erica";
> my $var = "\$text";
>
> Now, I want to be able to print $var and process $text interpolate
> string at the same time, therefore the output that I expect from
>
> print "$var" -> is "erica";
>
> But currently the output for print "$var" -> is "$text";
>
> Any suggestion??

Yes, if you want to just assign the value to $var, I'm confident you
know how to do that, so I'm assuming you want $var to point to the value
of $text.  Here is how you do that

my $var = \$text; # note no quotes

Then when you would like to reference the value by $var you do this

print $$var;

Which means this:

print ${$var};

Basically what you are saying here is set the pointer or reference of
$text value to $var, then with the {} you are de-referencing that and
pulling the actual value of $text.


Regards,
David
perl -e'print for map chr$_+1,"111100113107044099117099132"=~/(.{3})/g'




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

Date: Fri, 28 Mar 2003 08:19:37 -0600
From: Barry Kimelman <barryk2@SPAM-KILLER.mts.net>
Subject: Re: regex question
Message-Id: <MPG.18ee15f458b6c3b8989773@news.mts.net>

[This followup was posted to comp.lang.perl.misc]

In article <3E837459.2010102@gscmail.gsfc.nasa.gov>, Gary Fu 
(gfu@gscmail.gsfc.nasa.gov) says...
> Hi,
> 
> if $xx = 'ABC 123 a b c', I want $id = 123 and $txt = 'b c';
> if $xx = 'ABC 123 a c c', I want $id = 123 and don't care about $txt
> 
> I cannot figure out how to do this with something like
> 
> ($id, $txt) = $xx =~ /ABC (\d+) (b c)/  # I won't get $id for the 2nd case.
> 
> Thanks.
> 
> Gary

Use the following :

($id, $txt) = $xx =~ /ABC (\d+) a ([bc] c)/;

-- 
---------

Barry Kimelman
Winnipeg, Manitoba, Canada
email : bkimelman@hotmail.com


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

Date: Fri, 28 Mar 2003 14:53:52 +0100
From: "Tore Aursand" <tore@aursand.no>
Subject: Re: Sorting keys in a hash runs slower now.
Message-Id: <pan.2003.03.27.16.46.47.564098@aursand.no>

On Thu, 27 Mar 2003 02:06:38 -0800, C Marshall wrote:
>> One general tip;  Do you have to call 'print' every time?  It's more
>> efficient to gather the output you want in a variable, and then print
>> that variable at the end of your script.

> More good advice - I did that too and it runs faster than it did before.

Did 'print' slow your script down?  I've never done any benchmark on it,
but a long time ago, after that I _heard_ that 'print' was quite "tough",
I re-wrote my scripts to gather the output in a variable and print that
variable when the script was done.

Today, I almost cry when I think about old days. :)


-- 
Tore Aursand


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

Date: Fri, 28 Mar 2003 14:41:24 GMT
From: Nils Petter Vaskinn <no@spam.for.me.invalid>
Subject: Re: Sorting keys in a hash runs slower now.
Message-Id: <pan.2003.03.28.15.36.52.554151.2358@spam.for.me.invalid>

On Fri, 28 Mar 2003 11:29:50 +0100, Anno Siegel wrote:

> Nils Petter Vaskinn  <no@spam.for.me.invalid> wrote in
> comp.lang.perl.misc:
> 
> [...]
> 
>> I'm quite new to perl so this is just a shot in the dark. But in most
>> programming languages I've touched floating point arithmetic is more
>> expensive than integer.
> 
> That would depend both on the processor and the language, or rather the
> specific implementation.
> 
>>                         Is this the case for perl too?
> 
> No.  For one, even integers are stored and processed as floats (unless
> you "use integer").  More importantly, the overhead in calling a Perl
> operator is many times the cost of a numeric operation, never mind
> which, so the difference would be insignificant in any case.
 
Thanks for the answer.

So in perl the smart thing(TM) is to use the number representation that
seems logical, not try to force a representation to be integers.

Though in this case the two representations are equally logical; Is a year
52 weeks or is a week 1/52 years? :)

NP


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

Date: 28 Mar 2003 07:18:11 -0800
From: William.Yager@Arnold.af.mil (Bill Yager)
Subject: Re: Win32::FileSecurity removes some existing rights
Message-Id: <ce6a914c.0303280718.4356cd0c@posting.google.com>

A little more information:

I've discovered that permissions are being reset for existing users,
but they don't receive the GENERIC_ALL and therefore don't appear on
the secutiry tab window of directory properties. They do, however,
appear under the advanced dialog.

A bigger problem is that if the directory has the "Allow inheritable
permissions from parent to propigate to this object" box checked
before the Set() is performed, it is removed - or not retained - by
the Set().

As a result, permissions that had previously existed (via inheritance)
are gone. I need to keep those permissions in place. Does
Win32::FileSecurity support this?

Thanks again,

Bill

William.Yager@Arnold.af.mil (Bill Yager) wrote in message news:<ce6a914c.0303271806.4d60d679@posting.google.com>...
> I have a problem. I'm running a script against several directories,
> checking and setting permissions for several users. My intent is to
> append to the DACL if permissions do not exist for one of these users,
> not replace. If permissions exist for one of my users, but are not the
> perms I want them to be (i.e. read instead of full control), I want to
> change the mask for that user only, leaving other users' perms intact.
> I've been using Win32:FileSecurity for this, but have run into a
> problem.
> 
> The script does something like the following:
> 
> use Win32::FileSecurity qw (Get EnumerateRights MakeMask Set);
> 
> $fullmask = MakeMask( qw ( FULL GENERIC_ALL ) );
> 
> Get($dir, \%hash);
> $hash{$user} = $fullmask;
> Set($dir, \%hash);
> 
> The problem is that where some existing users had permissions, they
> now have none. If another user had had permissions set previously
> using Set(), as might happen when I loop through several users for a
> given directory, the permissions remain as previously set. Only
> permissions that were not set via Set(), presumably through Explorer,
> are lost.
> 
> I used EnumerateRights to see what the difference was among users that
> are losing their rights and users that are keeping them, and it looks
> like the only difference is the "GENERIC_ALL" right. If the mask
> contains "GENERIC_ALL" it is reset properly. If not, all rights are
> lost. Is it possible that Set() is not able to properly set the
> permissions of a directory if the mask does not include GENERIC_ALL
> (or GENERIC_READ/GENERIC_EXECUTE/GENERIC_WRITE)? How is it possible
> that a mask can be read using Get() yet that same mask not be set via
> Set()? Also, how is it possible to set directory rights to "Full
> Control" using Explorer and not receive the GENERIC_ALL right if it is
> so necessary!?
> 
> Does this make any sense? Should I just use Win32::Perms instead?
> 
> Thanks,
> 
> Bill


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

Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 6 Apr 01)
Message-Id: <null>


Administrivia:

The Perl-Users Digest is a retransmission of the USENET newsgroup
comp.lang.perl.misc.  For subscription or unsubscription requests, send
the single line:

	subscribe perl-users
or:
	unsubscribe perl-users

to almanac@ruby.oce.orst.edu.  

To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.

To request back copies (available for a week or so), send your request
to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
where x is the volume number and y is the issue number.

For other requests pertaining to the digest, send mail to
perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
sending perl questions to the -request address, I don't have time to
answer them even if I did know the answer.


------------------------------
End of Perl-Users Digest V10 Issue 4777
***************************************


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