[8210] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 1828 Volume: 8

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sat Feb 7 07:07:28 1998

Date: Sat, 7 Feb 98 04:00:24 -0800
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, 7 Feb 1998     Volume: 8 Number: 1828

Today's topics:
    Re: Accessing WinNT Service Information Remotely from a <mikel@ap.net>
        Anyone built Perl 5.004 on BSDi 3.1? (Russell C. Jackson)
        Bug with >> operator? <chris@muppet.faveve.uni-stuttgart.de>
        Can't locate object method "TIEHASH" (Ned Schumann)
        Compiling Perl 5.004.04 <loo01@ibm.net>
    Re: deleting stuff from an array <ajohnson@gpu.srv.ualberta.ca>
    Re: deleting stuff from an array (Craig Berry)
    Re: Global variable names <ajs@ajs.com>
    Re: Help passing argument to the command line <rjk@coos.dartmouth.edu>
    Re: How do copy files based on pattern on original file <rjk@coos.dartmouth.edu>
    Re: How to use libnet (Jeffrey R. Drumm)
    Re: IO::Socket::INET newbie question <rjk@coos.dartmouth.edu>
    Re: Is Perl 5 year 2000 compliant? (Gary L. Smith)
        Looking for a specific field in a array. <vallery@bvsd.k12.co.us>
    Re: netscape.hst regex <rjk@coos.dartmouth.edu>
    Re: Perl 4 and Associative Arrays? <rjk@coos.dartmouth.edu>
    Re: Perl 4 and Associative Arrays? <rjk@coos.dartmouth.edu>
        Perl and SunOS 5.5.1 <bill@inta.demon.co.uk>
    Re: perl pointer puzzle <ajs@ajs.com>
    Re: problem using variables in s/// operator <ajohnson@gpu.srv.ualberta.ca>
    Re: problem using variables in s/// operator <rjk@coos.dartmouth.edu>
        returning the date <scully@barimens.com>
    Re: searching by file creation/modification date? <ajs@ajs.com>
    Re: Socket Connections <tchrist@mox.perl.com>
    Re: sorting hash by numeric values (Mick Farmer)
    Re: Using flock? <mikel@ap.net>
    Re: Win32::AdminMisc function RenameUser <mikel@ap.net>
        Digest Administrivia (Last modified: 8 Mar 97) (Perl-Users-Digest Admin)

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

Date: Fri, 6 Feb 1998 20:55:05 -0800
From: "Mikel Cook" <mikel@ap.net>
Subject: Re: Accessing WinNT Service Information Remotely from a Web Page
Message-Id: <6bgpc2$a75$1@news.ap.net>


Philip Dore wrote in message <34D86B57.4AAE9176@nortel.com>...
>I am trying to create a script which will from a web page query the
>status of the services running on a remote WinNT system. the script
>works if I use the name of the localhost on which the web server is
>running, but if I use the name of a remote system the script fails and
>returns the error, no such file or directory - HELP.
>

This sounds like a permissions/administration issue to me.  The script will
run under the security ID (SID) of the login ID for your web server.  If you
are using IIS, the installation will usually create an ID of
IUSR_localhost-netbios-name.  That login ID has rights on the local machine,
but would not necessarily be able to go out on the LAN.  To give it such
rights would open up some security risk.  To check this theory, check in the
User Manager under the Policies/User Rights menu item.  Try adding the web
server logon ID explicitly to the list of logins with the "Access this
computer from the network" right.

Mikel Cook
System Administrator
Panttaja Consulting Group, Inc.




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

Date: Sat, 7 Feb 1998 03:32:48 -0800
From: rusty@san.rr.com (Russell C. Jackson)
Subject: Anyone built Perl 5.004 on BSDi 3.1?
Message-Id: <MPG.f45e63794bf28cc98968d@news-server>

I am getting a compile error stating that some of the arguments in a 
function call are incompatible in doio.c.  Does anyone know how to get 
Perl 5.004 to compile on BSDi 3.1?

Please copy me in email if you respond so that I get the response 
immediately.

-- 
Thanks,
Rusty

=================================================
High Tech Homes - Home Automation Specialists
Russell C. Jackson - Owner
http://home.san.rr.com/jackson - rusty@san.rr.com
=================================================


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

Date: 7 Feb 1998 11:04:27 GMT
From: Christian Recktenwald <chris@muppet.faveve.uni-stuttgart.de>
Subject: Bug with >> operator?
Message-Id: <6bhf3r$jh5$1@infosun2.rus.uni-stuttgart.de>


perl5.004_04:

	perl -e 'print ((2**32-1)>>32,"\n\n");' 

returns 2**32-1 (4294967295) instead of 0

	perl -e 'print (((2**32-1)>>31)>>1,"\n\n");' 

works.

-- 
Christian Recktenwald               | elwood sys adm 
FaVeVe Uni Stuttgart                | 
chris@faveve.uni-stuttgart.de       | ++49 711 685-2004
----------------------------------------------------------------------------
** In personal computers, the CPU is a highly 
** integrated chip called the microprocessor.
**                                        elwood old mainboard users manual.


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

Date: Fri, 06 Feb 1998 19:10:47 -0800
From: ned@olympus.net (Ned Schumann)
Subject: Can't locate object method "TIEHASH"
Message-Id: <ned-0602981910470001@pine.olympus.net>

Just built perl5.004_04 on BSDI 3.1 and the tests ran successfully.

When I execute the following...
(tie %_db, "DB_File", "/h/services/data/usageSummary", O_RDONLY, 0660, $DB_HASH)

I get this error...
Can't locate object method "TIEHASH" via package "DB_File" at
/h/services/modules/userTime.pm line 98, <STDIN> chunk 14.

Would someone please tell me about "TIEHASH" and let me know which
Configure parameter to specify to build it?

Thanks,
Ned


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

Date: Fri, 06 Feb 1998 21:45:26 -0800
From: Joseph Loo <loo01@ibm.net>
Subject: Compiling Perl 5.004.04
Message-Id: <34dbf514.0@news3.ibm.net>

Sorry, if this request has been posted again. I am new to this news 
group and need to get a good version of Perl for a Sun Sparc 2 under 
Solaris 2.5.1.

I got the latest GNU gcc compiler 2.8.0 and tried to compile the perl 
source using dynamic loading. Every time I tried to compile the code, I 
run make test. I keep getting error in the lib/anydbm. The message 
basically said that it could not find a symbol o a bad relocation 
record..

If I compile the code with static load, it seem to work but the install 
of the man pages messu on line 303 in podman. Do you have any 
suggestions where I am going wrong or if this is the correct news group.


Joseph Loo
jloo@acm.org




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

Date: Fri, 06 Feb 1998 23:15:13 -0600
From: Andrew Johnson <ajohnson@gpu.srv.ualberta.ca>
Subject: Re: deleting stuff from an array
Message-Id: <34DBEDE1.6A4F3F5E@gpu.srv.ualberta.ca>

GW Lander wrote:
!
! I have an array with data similar to the following...
! 
! \\MYMACHINE\Processor(0)\% Processor Time
! \\MYMACHINE\Paging File(\??\C:\pagefile.sys)\% Usage Peak
! \\MYMACHINE\Paging File(\??\C:\pagefile.sys)\% Usage
! 
! What I am trying to do is get rid of everything the the left of
! the last "\" and keep just the stuff to the right of the last
! "\".  I would like for the array to look similar to the following
! when this step is done...
! 
! % Processor Time
! % Usage Peak
! % Usage
! 
! Anybody have a suggestion for the simplest way to do this?

here's one way:

@new_data=map{substr($_,rindex($_,'\\')+1)}@data;

hope it helps
regards
andrew


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

Date: 7 Feb 1998 08:22:03 GMT
From: cberry@cinenet.net (Craig Berry)
Subject: Re: deleting stuff from an array
Message-Id: <6bh5jc$6rr$1@marina.cinenet.net>

Andrew Johnson (ajohnson@gpu.srv.ualberta.ca) wrote:
: GW Lander wrote:
: !
: ! I have an array with data similar to the following...
: ! 
: ! \\MYMACHINE\Processor(0)\% Processor Time
: ! \\MYMACHINE\Paging File(\??\C:\pagefile.sys)\% Usage Peak
: ! \\MYMACHINE\Paging File(\??\C:\pagefile.sys)\% Usage
: ! 
: ! What I am trying to do is get rid of everything the the left of
: ! the last "\" and keep just the stuff to the right of the last
: ! "\".  I would like for the array to look similar to the following
: ! when this step is done...
: ! 
: ! % Processor Time
: ! % Usage Peak
: ! % Usage
: ! 
: ! Anybody have a suggestion for the simplest way to do this?
: 
: here's one way:
: 
: @new_data=map{substr($_,rindex($_,'\\')+1)}@data;

Or, if you really mean to change the array elements 'in place'...

  foreach (@data) {
    s!.*\\!!;
  }

The greediness of * will suck up everything before the last \.

---------------------------------------------------------------------
   |   Craig Berry - cberry@cinenet.net
 --*--    Home Page: http://www.cinenet.net/users/cberry/home.html
   |      Member of The HTML Writers Guild: http://www.hwg.org/   
       "Every man and every woman is a star."


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

Date: 07 Feb 1998 03:14:00 -0500
From: Aaron Sherman <ajs@ajs.com>
Subject: Re: Global variable names
Message-Id: <m3ra5fkf1z.fsf@lorien.ajs.com>

Kaare Rasmussen <kar@webline.dk> writes:

> > You may want to try returning a reference to whatever you variable you
> > create inside the function or module. For a subroutine, here is an
> > example:
> 
> Thabks for the reply. But tell me, does it return the name of the
> variable too? And how do I return more variables than one?

You don't need (or particularly want) the name. e.g.:

	sub gimme_ref {
		my $variable = shift;
		return \$variable;
	}

Here, you don't much care that my subroutine called the variable
$variable. In fact, since it was a lexically scoped variable, knowing
that it was called $variable will do you not one bit of good, because
that name is now gone (the thing referenced by the return value
literally has no name).

Yes, you can return a list any time you want in perl, and that list
can contain any types of scalar values including references. For
instance, here's a subroutine that returns a list of references to a
hash, array and scalar:

	sub refs3 {
		my @array = qw(one two three);
		my %hash = ( one => 1, two => 2, three => 3 );
		my $scalar = 'one';
		return(\@array, \%hash, \$scalar);
	}



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

Date: Sat, 07 Feb 1998 00:48:23 -0500
From: Chipmunk <rjk@coos.dartmouth.edu>
To: Scott DiNitto <sdinitto@kronos.com>
Subject: Re: Help passing argument to the command line
Message-Id: <34DBF5A8.1451E3F2@coos.dartmouth.edu>

[posted and mailed]

Scott DiNitto wrote:
> 
> I am writing a script that will allow a user to shut down and restart
> a database automaticly via a perl script. However, in order to do
> that, the user has to su to another user. I do not want to add the
> users who need to shut down the databases to the dba group because
> then they can do other dba admin stuff I don't want them to touch!!
> 
> [...ponderings about passing a password to su...]
> 
> I need to know if what I am trying is possible... basicly to have perl
> automaticly interact with a commands STDIN prompts. Any help is
> appreciated!

Yes, by opening a pipe to the command.

But it's not what you want to do in this case.  What you want to do is
make a setuid script that will run as the more privileged user.

Read the perlsec manpage to find out about taint checking (done automatically
in setuid scripts).
Make the privileged user the owner of the script:   chown user script.pl
Set the setuid bit of the script:                   chmod u+s script.pl

Now, when someone runs your script, it will have the privileges of the owner,
instead of the person executing it.

Hope that helps!

Chipmunk


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

Date: Sat, 07 Feb 1998 01:34:10 -0500
From: Chipmunk <rjk@coos.dartmouth.edu>
To: ckcheng@tribune.com
Subject: Re: How do copy files based on pattern on original file namnes
Message-Id: <34DC0066.1E203297@coos.dartmouth.edu>

[posted and mailed]

ckcheng@tribune.com wrote:
> 
> I have about 7000 files in a directory and I need to copy them to
> different locations based on the pattern on the original file names.
> All file name start with 00 and end with 008, for example, 00ABCDEFGH008,
> 00ABCDEFG-008, 00AB------008.
> 
> So, what I need to do is if the file name is 00ABCDEFGH008, I'll copy
> it to ABC/ABCDEFGH.

A general way to do it:

~> cat rnm
#!/usr/local/bin/perl

# Usage: rename perlexpr [files]

($op = shift) || die "Usage: $0 perlexpr [filename]\n";
if (!@ARGV) {
    @ARGV = <STDIN>;
    chop(@ARGV);
}
for (@ARGV) {
    $was = $_;
    eval $op;
    die $@ if $@;
    rename($was,$_) unless $was eq $_;
}

~> rnm 's,00((.{3}).*)008,$2/$1,' 00*008

$op should result in $_ containing the new filename.

This probably won't work with subdirectories that don't
exist yet.

Be careful: this script makes it easy to mess up your files,
by renaming them all to the same name, for example.

Chipmunk


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

Date: Sat, 07 Feb 1998 05:18:37 GMT
From: drummj@mail.mmc.org (Jeffrey R. Drumm)
Subject: Re: How to use libnet
Message-Id: <34dbee01.1336757806@news.mmc.org>

On Fri, 06 Feb 1998 10:35:14 -0800, Vic Hargrave <hargrave@concentric.net>
wrote:

>I'm getting started with using Perl for network programming.  I have been
>using the Socket library for doing the basics.  Now I would like to use the
>libnet for FTP and other high level protocols. I have two questions in this
>regard:
>
>1. How do you include libnet in your program to use its facilites?
>   In other words what do you put in the "use" statment, e.g.
>   "use Socket", to get libnet loaded?
>
>2. Is libnet supported within the Perl for Win32 environment?
>
>If anyone could help me with this I would greatly appreciate it.
>Thanks in advance...

To answer your second question (others have answered your first), many of the
libnet modules seem to work fine with Gurusamy Sarathy's port of 5.004.02 (I
only say 'many' because I haven't tried them all). I have used Net::FTP and
Net::SMTP without problems, but only after I upgraded to libnet 1.0605.

Hope this helps . . .


-- 
                               Jeffrey R. Drumm, Systems Integration Specialist
                       Maine Medical Center - Medical Information Systems Group
                                                            drummj@mail.mmc.org
"Broken? Hell no! Uniquely implemented!" - me


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

Date: Sat, 07 Feb 1998 00:25:07 -0500
From: Chipmunk <rjk@coos.dartmouth.edu>
To: "Shawn M. Kelly" <kellysm@ix.netcom.com>
Subject: Re: IO::Socket::INET newbie question
Message-Id: <34DBF034.4444D37F@coos.dartmouth.edu>

[posted and mailed]

Shawn M. Kelly wrote:
> 
>     Thank you very much for the assist. I didn't understand the $pop->
> references but I managed to use the autoflush successfully in my ugly
> code. I could not find references to autoflush or the $pop-> (methods?)
> notation in the Camel or Gecko book? Would this be documented in some
> other book or only in the online doc somewhere?

You can find autoflush on page 442 of the Camel book, 2nd ed.
autoflush is listed not in the index, which may be why you
couldn't find it in the text.

The -> method invoking syntax is discussed on pages 295-297.
It's indexed under methods: invocation, although if you don't
know to look under methods you wouldn't find that either.

Hope that helps!

Chipmunk


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

Date: Sat, 07 Feb 1998 05:08:34 GMT
From: gls@infinet.com (Gary L. Smith)
Subject: Re: Is Perl 5 year 2000 compliant?
Message-Id: <m%RC.180$kh1.8449686@news2>

Tiberius (Abraxas@hell.com) wrote:

: Well, exactly what *isn't* in the documentation? Of course it's in the
: documentation. Virtually everything is. If only questions that had no
: answers in the docs were posted in the newsgroups, there'd be like,
: what, 2 questions a day?

Have you ever used a Microsoft product?  A good deal of what's worth 
knowing is not in any documentation, and when it is there, you often 
can't find it.   Responding to a question with "look in the documentation 
under strange-term-you'd-never-come-up-with-on-your-own" can be 
trememdously helpful.

--
 
Gary L. Smith                    gls@infinet.com
Columbus, Ohio                 Gary_Smith@oclc.org


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

Date: Fri, 6 Feb 1998 15:41:05 -0700
From: Jason Vallery <vallery@bvsd.k12.co.us>
Subject: Looking for a specific field in a array.
Message-Id: <Pine.GSO.3.96.980206153646.26482A-100000@bvsd.k12.co.us>

I have gather form data into an array for later posting. My problem is
trying to gather the first field in the array, it is a hidden value
containg the number of the question.
What I am trying to do is redirect a user based upon how they abswer a
question. The user will fill out a form question by question, the script
directs the user to the appropriate question and saves thier information
in a file. I also would like to know if if would be possible to name a
file after someones ip address, or maybe the last 2 digits or something.
Sorry if I sound new to perl, becuase I am.
Thanks in advance, any help would be appreciated.


  _____________________________________________ 
 / __________  	 Jason Ray Vallery		\
| |       ___)_                                 |
| |       _____) vallery@bvsd.k12.co.us         |            
| |      ______) guide4@bvsd.k12.co.us          |            
| |    _______)  vallery@usa.net                |            
| \_______)      vallery_j@gems.colorado.edu    |
 \_____________________________________________/



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

Date: Sat, 07 Feb 1998 01:10:46 -0500
From: Chipmunk <rjk@coos.dartmouth.edu>
Subject: Re: netscape.hst regex
Message-Id: <34DBFAE9.8F60C903@coos.dartmouth.edu>

[posted but not mailed - munged addresses are annoying]

Cam Bevis wrote:
> 
> Its a 4 byte hex string (the date, captured to $1), followed by
> "http://",
> followed by the URL(captured to $2). I think I have a byte
> ordering/hex->decimal->date conversion problem too,
> but I'm not tackling that right now(any pointers would be welcomed,
> though).
> 
> Here's (what seems to be) a record looks like:
> 
> >;d4http://www.databaseamerica.com/image/dba_anim.gif
> 
> ...and here's the code I'm trying to use?
> 
> open HISTORY, "netscape.hst";

Always check the return value of open!

open HISTORY, "netscape.hst" or die "Unable to open netscape.hst: $!\n";

> my $Data = <HISTORY>; # whole file as a single string

Whole file?  Not unless you've previously set $/ to undef.

> while( $Data =~m|(.{4})http://(.*)|igs)

Let's say you *had* read the whole file into a single string,
and the file looked like this:
a2#dhttp://url1.com/
6&hAhttp://url2.com/

That regex would put "a2#d" in $1, and, because of the /s and .*,
"url1.com\n6&hAhttp://url2.com/\n" in $2.

Try this instead:

while ($Data =~ m|^(.{4})http://(.*)$|igm) {

The /m allows ^ and $ to match at embedded newlines.

Assuming the records are separated by newlines.  Are they?

>    { $mytime= $1; $url= $2;  $mytime=pack("H*", unpack("V*",
> $mytime));$mytime=gmtime $mytime;print "$mytime $url \n"; }

What lovely formatting.

Hope that helps!

Chipmunk


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

Date: Sat, 07 Feb 1998 00:36:43 -0500
From: Chipmunk <rjk@coos.dartmouth.edu>
Subject: Re: Perl 4 and Associative Arrays?
Message-Id: <34DBF2EC.45BD24BB@coos.dartmouth.edu>

[posted but not mailed - munged addresses are annoying]

Don wrote:
> 
> I have been using associative arrays with Perl 5 with success.
> Recently I passed on one of my scripts to a friend who's ISP is using
> Perl 4 and the script seems to have died at the creation of the
> associative array.
> The code looks something like this;
> 
> if (exists($urls{$url_from}))
>    {
>         $urls{$url_from}++;
>    }
>   else
>    {
>         $urls{$url_from} = 1;
>    }
> 
> And generates an error at "exists(".

If you tried calling exists() on the exists function in Perl4,
you'd find out that it doesn't exist.

To put it another way, the exists() function is new in Perl5.

> I tried this also with a
> statement like;
> 
> if ($urls{url_from})
>  {
>         $urls{$url_from}++;
>    }
>   else
>    {
>         $urls{$url_from} = 1;
>    }
> 
> And it still dies at "$urls{".

That works for me with Perl4.  What error message do you get when it dies?
(BTW, you left off the $ on url_from in the first line.  What does your
actual code look like?)

Make sure the previous line ends with a semicolon.

> Is this a problem with my code or with Perl 4?

Both.

> Is there a way around it?

Fix your code.  Tell your friend to get a better ISP.
(Where better is defined as one that has installed Perl5.)

BTW, you don't actually need to check if the key exists or the value is true.
Just do $urls{$url_from}++;  The first time, it will increment 0, giving you
a value of 1, just as you'd expect.

Chipmunk


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

Date: Sat, 07 Feb 1998 00:35:57 -0500
From: Chipmunk <rjk@coos.dartmouth.edu>
To: defike@ilstu.edu..spam.not
Subject: Re: Perl 4 and Associative Arrays?
Message-Id: <34DBF2BE.5CADB8D6@coos.dartmouth.edu>

[posted and mailed]

Don wrote:
> 
> I have been using associative arrays with Perl 5 with success.
> Recently I passed on one of my scripts to a friend who's ISP is using
> Perl 4 and the script seems to have died at the creation of the
> associative array.
> The code looks something like this;
> 
> if (exists($urls{$url_from}))
>    {
>         $urls{$url_from}++;
>    }
>   else
>    {
>         $urls{$url_from} = 1;
>    }
> 
> And generates an error at "exists(".

If you tried calling exists() on the exists function in Perl4,
you'd find out that it doesn't exist.

To put it another way, the exists() function is new in Perl5.

> I tried this also with a
> statement like;
> 
> if ($urls{url_from})
>  {
>         $urls{$url_from}++;
>    }
>   else
>    {
>         $urls{$url_from} = 1;
>    }
> 
> And it still dies at "$urls{".

That works for me with Perl4.  What error message do you get when it dies?
(BTW, you left off the $ on url_from in the first line.  What does your
actual code look like?)

Make sure the previous line ends with a semicolon.

> Is this a problem with my code or with Perl 4?

Both.

> Is there a way around it?

Fix your code.  Tell your friend to get a better ISP.
(Where better is defined as one that has installed Perl5.)

BTW, you don't actually need to check if the key exists or the value is true.
Just do $urls{$url_from}++;  The first time, it will increment 0, giving you
a value of 1, just as you'd expect.

Chipmunk


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

Date: Sat, 07 Feb 1998 11:48:29 GMT
From: "Bill Spencer" <bill@inta.demon.co.uk>
Subject: Perl and SunOS 5.5.1
Message-Id: <01bd33be$15960d00$503f989e@inta.demon.co.uk>

Hi all,
I am new to this group, but have been using perl for 6-months.
I seem to have a problem with signals using Perl 5.00 on
SunOs 5.5.1.
When running with the -w switch i get a warning :-

No such signal SIGQUIT, SIGINT, SIGHUP etc.
These are obviously correct signals. The signal handler
does not therefore get called.

Anyone have any idea's, Help would be much appreciated.

Yours
Bill


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

Date: 07 Feb 1998 02:39:12 -0500
From: Aaron Sherman <ajs@ajs.com>
Subject: Re: perl pointer puzzle
Message-Id: <m3u3abkgny.fsf@lorien.ajs.com>

aml@world.std.com (Andrew M. Langmead) writes:

> Dan Boorstein <dboorstein@shopcfn.com> writes:
> 
> The example could be rewritten without symbolic references as follows.
> 
> 
>  $temp{var} = \$variable; # use hard reference
>  $variable = "output_1";
>  $reference = \${$temp{var}};
>  # which is a convoluted way of saying "$reference = $temp{var}"
>  print "$$reference\n";


Be careful, here. This is just asking for someone to come along and
re-write as:

	$temp{var} = \$variable;
	my $variable = "output_1";

and get a rude surprise. Of course, if they're using strict, there's
no problem. It just won't work.

The bottom line, though, is that the original poster did not
understand what a pointer vs. reference vs. symbolic reference
was. The answer to his woes likely lies in reading perlref and
perldsc.


			-AJS


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

Date: Fri, 06 Feb 1998 23:24:53 -0600
From: Andrew Johnson <ajohnson@gpu.srv.ualberta.ca>
Subject: Re: problem using variables in s/// operator
Message-Id: <34DBF025.2C18FA11@gpu.srv.ualberta.ca>

DIAL|MB|VTC-Dave Meyer wrote:
!
! I'm having trouble getting the s/// operator do to exactly what I
! want when I use variables as arguments.  Here's an example:
! 
! my $str1="hello there";
! $str1 =~ s/(.)e/e$1/g;
! print "$str1\n"; # prints 'ehllo teher', which is correct
! 
! my $str2="hello there";
! my $sexp=q{(.)e};
! my $rexp=q{e$1};
! $str2 =~ s/$sexp/$rexp/g;
! print "$str2\n"; # prints e$1llo te$1e$1, which is not what I wanted
! 
! How do I get the $1 in $rexp in the second snippet to be treated the
! same way as the $1 in the s/// operator in the first snippet?  I've
! tried various combinations of evals and the e modifier, but without
! any luck.

depending on what you're ultimately trying to do, there's
probably other ways to get it done with out such
things...however, one way you can get your above example to work
is by the use of extra double quotes and double /ee :

my $str2="hello there";
my $sexp=q{(.)e};
my $rexp=q{"e$1"};
$str2 =~ s/$sexp/$rexp/gee;
print "$str2\n";

hope it helps
regards
andrew


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

Date: Sat, 07 Feb 1998 01:53:39 -0500
From: Chipmunk <rjk@coos.dartmouth.edu>
To: meyer@virtc.com
Subject: Re: problem using variables in s/// operator
Message-Id: <34DC04F9.C6187386@coos.dartmouth.edu>

[posted and mailed]

DIAL|MB|VTC-Dave Meyer wrote:
> 
> my $str1="hello there";
> $str1 =~ s/(.)e/e$1/g;
> print "$str1\n"; # prints 'ehllo teher', which is correct
> 
> my $str2="hello there";
> my $sexp=q{(.)e};
> my $rexp=q{e$1};
> $str2 =~ s/$sexp/$rexp/g;
> print "$str2\n"; # prints e$1llo te$1e$1, which is not what I wanted
> 
> How do I get the $1 in $rexp in the second snippet to be treated the
> same way as the $1 in the s/// operator in the first snippet?  I've
> tried various combinations of evals and the e modifier, but without
> any luck.

You need to evaluate it once to interpolate $rexp, and then evaluate it
again to interpolate $1.

s/$sexp/qq(qq($rexp))/gee;

my $str2="hello there";
my $sexp=q{(.)e};
my $rexp=q{e$1};
$str2 =~ s/$sexp/qq(qq($rexp))/gee;
print "$str2\n"; # prints 'ehllo teher'

Chipmunk


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

Date: Sat, 7 Feb 1998 00:47:46 -0500
From: "Scully" <scully@barimens.com>
Subject: returning the date
Message-Id: <6bgsv0$71v$1@news.cc.ucf.edu>

I have been searching through perl books looking for an example use of the
localtime function similar to what I need, but I haven't been able to find
one.

Can anybody tell me what perl code I'd need to include in my script to print
the date to an open file in the format mm/dd/yy ?

M Scully




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

Date: 07 Feb 1998 02:56:54 -0500
From: Aaron Sherman <ajs@ajs.com>
Subject: Re: searching by file creation/modification date?
Message-Id: <m3sopvkfuh.fsf@lorien.ajs.com>

mwang@alhena.ibk.ml.com (Michael Wang) writes:

> Martien Verbruggen <mgjv@comdyn.com.au> wrote:

> Question:
> How do we modify ctime? touch does not do this.
> What other operations that alter ctime?

This is getting a little off-topic, but here's the Linux info from
stat(2):

       Traditionally,  st_ctime  is changed by writing or by set-
       ting inode information (i.e., owner,  group,  link  count,
       mode, etc.).

Under my copy of Linux (2.0.33) and a Solaris 2.5 system that I have
access to, touch DOES update the ctime.

			-AJS


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

Date: 7 Feb 1998 02:23:24 GMT
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: Socket Connections
Message-Id: <6bggis$doa$1@csnews.cs.colorado.edu>

 [courtesy cc of this posting sent to cited author via email]

In comp.lang.perl.misc, 
    efflandt@xnet.com (David Efflandt) writes:
:Dots have special meaning in double quoted strings.  Either use single
:quotes or escape the dots. Examples:
:
:$ipaddress = '207.165.90.100';
:$ipaddress = "207\.165\.90\.100";

Um, no; you're thinking of regular expressions, not DQ-strings.

--tom
-- 
	Tom Christiansen	tchrist@jhereg.perl.com

    I dunno, I dream in Perl sometimes...
                    --Larry Wall in  <8538@jpl-devvax.JPL.NASA.GOV>


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

Date: Sat, 7 Feb 1998 10:44:43 GMT
From: mick@picus.dcs.bbk.ac.uk (Mick Farmer)
Subject: Re: sorting hash by numeric values
Message-Id: <Eo08IJ.AHq@mail2.ccs.bbk.ac.uk>

Dear Bob,

You could try something like this.

	@out = ();
	while (($keyword, $count) = each(%keywords)) {
		push @out, printf "%6d%s", $count, $keyword;
	}
	@ordered = sort @out;
	print @ordered;

Regards,

Mick


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

Date: Fri, 6 Feb 1998 21:32:17 -0800
From: "Mikel Cook" <mikel@ap.net>
Subject: Re: Using flock?
Message-Id: <6bgrho$ga0$1@news.ap.net>

>Question 1)
>Does flock work on NT systems or is it a unix command?


I see flock used in the guest book example in "Learning Perl on Win32
Systems" which leads me to believe that it works on NT.

Mr. Pope answered the other questions more knowledgeably than I can.

>Question 3)
>I understand #2, and #8.  Can someone explain what the other two are used
>for?

I have seen the other type locks used by SQL Server for locking data.  My
guess is that you should avoid using them on NT for now.






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

Date: Fri, 6 Feb 1998 21:28:52 -0800
From: "Mikel Cook" <mikel@ap.net>
Subject: Re: Win32::AdminMisc function RenameUser
Message-Id: <6bgrbc$fnm$1@news.ap.net>

>Win32::AdminMisc::RenameUser($srv, $uid, $newuid);
>
Maybe if you prepend the uid and newuid with the netbios name of the target
machine Windows NT will get the picture.  The default is to have the domain
name prepended to the login name.  That seems to be the way NT thinks about
login names.  They should be separated by a back slash:

machine\user

I know I use this when I need the "Connect As" box when mapping a drive and
my login is not from a system that is a member of the domain that has the
share.






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

Date: 8 Mar 97 21:33:47 GMT (Last modified)
From: Perl-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 8 Mar 97)
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.misc (and this Digest), send your
article to perl-users@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.

The Meta-FAQ, an article containing information about the FAQ, is
available by requesting "send perl-users meta-faq". The real FAQ, as it
appeared last in the newsgroup, can be retrieved with the request "send
perl-users FAQ". Due to their sizes, neither the Meta-FAQ nor the FAQ
are included in the digest.

The "mini-FAQ", which is an updated version of the Meta-FAQ, is
available by requesting "send perl-users mini-faq". It appears twice
weekly in the group, but is not distributed in the digest.

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 V8 Issue 1828
**************************************

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