[13001] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 411 Volume: 9

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sat Aug 7 01:07:25 1999

Date: Fri, 6 Aug 1999 22:05: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           Fri, 6 Aug 1999     Volume: 9 Number: 411

Today's topics:
    Re: a time to kill <llornkcor@llornkcor.com>
    Re: a time to kill <uri@sysarch.com>
    Re: Breakingdown an array? (David Efflandt)
    Re: Breakingdown an array? <rootbeer@redcat.com>
        Can I Pass Object refs as parameters to a new object? <motox@mail.relia.net>
        Changed specific text in fetched page. <shale1@uswest.net>
    Re: embedded perl and malloc. <dan@tuatha.sidhe.org>
    Re: FAQ doesn't work in this case! <shale1@uswest.net>
        file size makky@my-deja.com
    Re: file size <jbc@shell2.la.best.com>
    Re: file size <rootbeer@redcat.com>
    Re: Finding duplicate elements in an array? <kelly@pcocd2.intel.com>
    Re: How to uninstall Perl on Unix ? <hal_mounce@amdahl.com>
    Re: Is there any books on DBI? <uri@sysarch.com>
        Is this an appropreate use of -i switch? (Bill Moseley)
    Re: modem dialingL HOWTO. <llornkcor@llornkcor.com>
    Re: modem dialingL HOWTO. <davidj@zipworld.net>
    Re: New to Perl - Question About RegExpr <cw@dwc.ch>
        Problem with standard IO::Socket::INET module <hughd@screwspam.com>
    Re: ps -ef |grep ""kill script? (Jerome O'Neil)
    Re: ps -ef |grep ""kill script? <rootbeer@redcat.com>
        Renaming a hash key ? <cw@dwc.ch>
    Re: Renaming a hash key ? <rootbeer@redcat.com>
    Re: reverse of localtime? (Larry Rosler)
        TFTP server in Perl <twitten@home.com>
    Re: TFTP server in Perl <rootbeer@redcat.com>
    Re: variable taking regexp as value (Earl Hood)
    Re: variable taking regexp as value (Larry Rosler)
        Digest Administrivia (Last modified: 1 Jul 99) (Perl-Users-Digest Admin)

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

Date: 06 Aug 1999 20:37:00 -0600
From: llornkcor <llornkcor@llornkcor.com>
Subject: Re: a time to kill
Message-Id: <r9lg71v7.fsf@wind.localdomain>


and what's even MORE funny, I have been learning perl for about 3 weeks now,
and find myself on Tom's killfile... 
;o)
do smileys also get one put on Tom's killfile, I wonder?

llornkcor <llornkcor@llornkcor.com> writes:

>oh, this was a good laugh... thanks.
>



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

Date: 07 Aug 1999 00:21:34 -0400
From: Uri Guttman <uri@sysarch.com>
Subject: Re: a time to kill
Message-Id: <x71zdggr01.fsf@home.sysarch.com>

>>>>> "A" == Abigail  <abigail@delanet.com> writes:

  A> [comp.lang.perl.*]
  A> Score:: 2000
  A>   From: elaine ashton
  A>   From: Greg Bacon
  A>   From: Larry Rosler
  A>   From: Uri Guttman

hey, i made abigail's list but not tom's :-()

i wonder if i am who larry referred to when he noticed his name on tom's
list and someone else was missing?

uri

-- 
Uri Guttman  -----------------  SYStems ARCHitecture and Software Engineering
uri@sysarch.com  ---------------------------  Perl, Internet, UNIX Consulting
Have Perl, Will Travel  -----------------------------  http://www.sysarch.com
The Best Search Engine on the Net -------------  http://www.northernlight.com
"F**king Windows 98", said the general in South Park before shooting Bill.


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

Date: 7 Aug 1999 03:59:48 GMT
From: efflandt@xnet.com (David Efflandt)
Subject: Re: Breakingdown an array?
Message-Id: <slrn7qnc1b.hh.efflandt@efflandt.xnet.com>

On Thu, 29 Jul 1999 13:16:03 +0100, Fred Mc Mahon <fred@alpstreet.net> wrote:
>hello, - if you can get through this it would be much appreciated.
>
>        I'm using a form to appened data to a pipe delimited database.
>First a user does a keyword search and gets a return on their query,
>Which might be say 6 matches.
>        They then can choose to add these to their database. The problem
>is 
>I only want them to add 1 item at a time.
>        Im using an array variable in the script to add all the data to
>the
>database it looks like this:
>
>foreach $field (@details_row)
> {
> $details_row .= "$field\|";
> }
>
>$details_row .= "$name\|$address\|$phone\n";
>print BOOK "$details_row";
>close (BOOK);
>
>        Is there a way to say if there is 2 $details_row, then return
>page and 

$#foo is the index of the last item in array @foo, and since the index of
the first item is zero:

# somewhere before above routine:
if ($#details_row) {
    print "sorry only one entry can be made at a time\n";
}


>
>        Any help would be greatly apprecitiated.
>
>        fred.


-- 
David Efflandt   efflandt@xnet.com   http://www.xnet.com/~efflandt/
http://www.de-srv.com/   http://cgi-help.virtualave.net/


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

Date: Fri, 6 Aug 1999 21:39:25 -0700
From: Tom Phoenix <rootbeer@redcat.com>
Subject: Re: Breakingdown an array?
Message-Id: <Pine.GSO.4.10.9908062136130.9452-100000@user2.teleport.com>

On 7 Aug 1999, David Efflandt wrote:

> if ($#details_row) {
>     print "sorry only one entry can be made at a time\n";
> }

Of course, that conditional is true whenever the number of elements is not
one. Since zero elements would be a different number than one element,
this code may not be doing what you want. To make your intent clearer to
your maintenance programmer, you could use one of these forms.

    if (@details_row > 1) { ... }

    if (@details_row != 1) { ... }

Cheers!

-- 
Tom Phoenix       Perl Training and Hacking       Esperanto
Randal Schwartz Case:     http://www.rahul.net/jeffrey/ovs/



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

Date: Fri, 6 Aug 1999 23:00:42 -0600
From: "Madness" <motox@mail.relia.net>
Subject: Can I Pass Object refs as parameters to a new object?
Message-Id: <37abbb8c.0@news.relia.net>

Just wondering if I have a modules Customer.pm, Persistent.pm, Signup.pm,
and I have 3 object references to these modules cust, persist, and signup.
I want to keep session with the Customer object while possibly using a
signup, persist, or other object.  Can I pass in cust as a reference to
persist or signup for instance and use it in there the same way as I use it
in my script while maintaining session information?

puny example
-----------------------------------------------
somefile.pl

$cust = new Customer;
$persist = new Persistent;
$signup = new Signup;


$persist->restore($cust);
print $cust->name;
print $cust->address;
$signup->signupUser($cust);

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

Is there a better method??

Goal
------------
I currently have a program written in perl which has many methods that I
would like to break out into modules.  Thats my goal.

Thanks

Nic






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

Date: Fri, 6 Aug 1999 10:45:50 -0600
From: "InLandPAC Publishing Services" <shale1@uswest.net>
Subject: Changed specific text in fetched page.
Message-Id: <O6Pq3.1529$5z4.127849@news.uswest.net>

I currently fetch a page to display a "clone" through a popup window.

What I would like to do is change the color of and bold every time $keyword
appears in the page. (not in the tags, but between them - i.e., the text
that the viewer sees via the browser).

I am currently using LWP to fetch the page.

If you need sample code of how I am fetching the page, I will do so.

Chad.




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

Date: Sat, 07 Aug 1999 04:23:35 GMT
From: <dan@tuatha.sidhe.org>
Subject: Re: embedded perl and malloc.
Message-Id: <bxOq3.269$Ic.576@news.rdc1.ct.home.com>

abhidon@hotmail.com wrote:
> Hi,

>    We have perl embedded in our application. It is for Solaris 2.x and
> HP UX 10.20. While building perl and perl libraries, we configure the
> build, NOT to use perl's malloc(). This means, perl should use the
> system malloc(). This is the library, our application is linked against.

>     We put in some trace statements in perl's malloc (pp_sys.c), and
> they showed up. This indicates, that perl IS using it's own malloc,
> inspite the fact, we configured it not to!

Then something went wrong with the configuration. Did you clear everything
out and start fresh?

>      The application is multi-threaded, and the stack trace in the does
> not neccessarily give us the exact stack we want. The  problem occurs
> inconsistently and we do not have access to the debugger, when it
> actually happens.

If you're calling non-threaded perl from a threaded app, you need to be
very, *very* sure that you never have two threads in the interpreter at
once. In fact, you need to make sure that one interpreter has cleanly
exited back to your program before you head into it with another thread.

if you're calling threaded perl from a threaded app, you still need to
make sure that you lock all your variables properly before accessing them.
You'll need to do the lock from perl rather than C, as there's no way to
do it from C at the moment. Also make sure you use the latest version of
perl.

Even when built with threads, perl's not 100% bulletproof. It is possible,
almost easy, to whack things. That should hopefully get improved for 5.6,
but for now... be real careful.

					Dan


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

Date: Fri, 6 Aug 1999 09:15:42 -0600
From: "InLandPAC Publishing Services" <shale1@uswest.net>
Subject: Re: FAQ doesn't work in this case!
Message-Id: <hONq3.1194$5z4.113535@news.uswest.net>

I get results like this:

[TABLE NOT DISPLAYED][TABLE NOT DISPLAYED][FORM NOT DISPLAYED][TABLE NOT
DISPLAYED][TABLE NOT DISPLAYED]see us in action!  Create the ultimate
android.[FORM NOT DISPLAYED]


brian d foy <brian@pm.org> wrote in message
news:brian-ya02408000R0608991849530001@news.panix.com...
> In article <7of4sp$fmp$1@nnrp1.deja.com>, inlandpac@my-deja.com posted:
>
>
> > Isn't HTML::Parse or HTML::Parser supposed to do this?
> >
> > The documentation shows great uses, but it still does not display the
> > text between the HTML tags correctly (if at all) and sometimes even
> > shows attributes within tags (where these tags are complex).
>
> HTML::Parser is fine.  you must be doing something not correct.
> however, you have yet to show a reasonable snippet that demonstrates
> the behaviour you get.  we don't need to see all of the code - just
> the smallest example that illustrates the problem.
>
> --
> brian d foy
> CGI Meta FAQ <URL:http://www.smithrenaud.com/public/CGI_MetaFAQ.html>
> Perl Monger Hats! <URL:http://www.pm.org/clothing.shtml>




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

Date: Sat, 07 Aug 1999 01:55:40 GMT
From: makky@my-deja.com
Subject: file size
Message-Id: <7og3mp$65n$1@nnrp1.deja.com>

hi, does someone know if there is a best way to find the file size in
perl?  thanks.

-mak


Sent via Deja.com http://www.deja.com/
Share what you know. Learn what you don't.


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

Date: 07 Aug 1999 03:36:31 GMT
From: John Callender <jbc@shell2.la.best.com>
Subject: Re: file size
Message-Id: <37aba9bf$0$204@nntp1.ba.best.com>

makky@my-deja.com wrote:
> hi, does someone know if there is a best way to find the file size in
> perl?  thanks.

You want the file test operator -s, which you could use something like
this:

$size = -s $filename;

It is one of a whole slew of really handy file test operators, like -f
(which tests whether or not the file is a plain file), -T (file is a
text file), and -d (file is a directory). Having heard them referred to
frequently as "the file test operators," a newcomer might expect to
find them documented in the perlop man page. That would be too easy,
though; instead, they're described at the very beginning of the
alphabetical function listings in the perlfunc man page. Hence, you
could read about them by entering:

man perlfunc

or 

perldoc perlfunc

and paging down a ways.

-- 
John Callender
jbc@west.net
http://www.west.net/~jbc/


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

Date: Fri, 6 Aug 1999 21:09:49 -0700
From: Tom Phoenix <rootbeer@redcat.com>
Subject: Re: file size
Message-Id: <Pine.GSO.4.10.9908062108390.9452-100000@user2.teleport.com>

On Sat, 7 Aug 1999 makky@my-deja.com wrote:

> hi, does someone know if there is a best way to find the file size in
> perl?  thanks.

Define "best". What's best for me may not be best for you, and there's no
point in any of us wasting our time until you can say just what you want.
 
You may need to choose among fastest, most memory efficient, easiest to
program, fewest lines of code, most robust, most portable, easiest to
debug, easiest to maintain, most like your other favorite programming
languages, or perhaps you mean some other criterion. (Of course, one
solution may fall into more than one of these categories.)

But look for the filetest (-X) operators in perlfunc. Cheers! 

-- 
Tom Phoenix       Perl Training and Hacking       Esperanto
Randal Schwartz Case:     http://www.rahul.net/jeffrey/ovs/



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

Date: 06 Aug 1999 20:54:37 -0700
From: Michael Kelly - FVC PCD VET ~ <kelly@pcocd2.intel.com>
Subject: Re: Finding duplicate elements in an array?
Message-Id: <us2oggkmeiq.fsf@fht2007.fm.intel.com>

pfash1@aol.com (Pfash1) writes:

> 
> I have been struggling with a Perl issue that you might have some insight on:
> How do I check an array of undetermined size to see if there are duplicate
> elements contained in it? In other words:
> 
> @arrayone = ('one', 'two', three', 'one')

	Paul,

	Checkout the perl man pages on data structures, and look at
'hash of hash' aka 'HoH'.  Its in your man pages 'man perldsc'.
Assign the elements of the array to keys in a hash, the duplicates
will over write the origionals.

	foreach $cell (@arrayone){$hash{$cell} = 0};
	@arrayone = (keys %hash);

The list will be in an unknown order, unless you

	@arrayone = (sort keys %hash);

But the sort can be expensive machine wise.


	Mike.


-- 
Not speaking for Intel
Michael Kelly (the one in Folsom)
1900 Prarie City Road	desk (916) 356-2822
Folsom, CA. 95630	Page (916) 360-5847


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

Date: Fri, 06 Aug 1999 19:05:04 -0700
From: Hal Mounce <hal_mounce@amdahl.com>
To: mizote <philippe.sockeel@cdn.fr>
Subject: Re: How to uninstall Perl on Unix ?
Message-Id: <37AB9450.2826AB66@amdahl.com>

mizote wrote:
> 
> Well, I just want to completely uninstall Perl on HP-UX10.20 before
> reinstalling it with different options.

HP ships perl4 and ksh88.  This, of course, sucks.

I left my perl4 intact in /usr/contrib/bin/perl in case there were any
perl4 dependencies in Q4.  I put perl in under /opt/perl5 and fiddled
with /etc/PATH and /etc/MANPATH.

I've screwed up my perl installation any number of times now, and have
no problems whacking things off at /opt/perl5 to effect a cleanup.

What SD-UX doesn't know won't hurt him.

Hal


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

Date: 07 Aug 1999 00:32:40 -0400
From: Uri Guttman <uri@sysarch.com>
Subject: Re: Is there any books on DBI?
Message-Id: <x7yafofbx3.fsf@home.sysarch.com>

>>>>> "LR" == Larry Rosler <lr@hpl.hp.com> writes:

  LR> In article <37AAA79C.C6E48946@kawo2.rwth-aachen.de> on Fri, 06 Aug 1999 
  LR> 11:15:08 +0200, Alex Farber <alex@kawo2.rwth-aachen.de> says...
  >> "John C." wrote:
  >> > Hi, I am new to perl and am wondering if there are any books on DBI or
  >> > information available on the web.
  >> > I would like to use the mSQL DBD.
  >> 
  >> a book "MySQL & mSQL" http://www.oreilly.com/catalog/msql/
  >> has just been published by O'Reilly

  LR> But is not yet available.  Amazon is selling it at 40% off or so, but 
  LR> doesn't have any.

  LR> I printed the online chapter at 
  LR> <URL:http://www.oreilly.com/catalog/msql/chapter/ch10-beta.html> and was 
  LR> unimpressed, because the examples have far too much HTML and CGI stuff 
  LR> (and boring at that) and not enough DBI stuff.  I hope the rest of the 
  LR> book corrects the focus.

i saw a real copy at work but i didn't browse it much. so it is real
even if amazon doesn't have it. try fatbrain or bookpool.

uri

-- 
Uri Guttman  -----------------  SYStems ARCHitecture and Software Engineering
uri@sysarch.com  ---------------------------  Perl, Internet, UNIX Consulting
Have Perl, Will Travel  -----------------------------  http://www.sysarch.com
The Best Search Engine on the Net -------------  http://www.northernlight.com
"F**king Windows 98", said the general in South Park before shooting Bill.


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

Date: Fri, 6 Aug 1999 21:07:09 -0700
From: moseley@best.com (Bill Moseley)
Subject: Is this an appropreate use of -i switch?
Message-Id: <MPG.121550bd787f87c698968c@nntp1.ba.best.com>

I'm doing text substitution on a bunch of files and I got lazy
and decided to let perl's magic -I do some work for me.

As it's magic (at least in my mind), I'm wondering if there's
any pitfalls to watch out for using this method.  For example, would
I be better off doing the reading/writing/renaming myself to catch
open/write/close errors (to prevent a partially updated file), 
or does the -I magic do that for me?  That is, with -I do the files
only get renamed at the end if all goes well?

My sample code:

I use File::Find to recurse a directory tree, then I search the file
for a pattern, and if I find it I let perl's -I do the work of
editing the file in place and creating a backup of the old file.

Anything I need to worry about using this method?


Would pre-compiling the search pattern with /o be a good idea, even if
they are constants?



#! perl -w -I.old

use strict;


use File::Find;

find(\&wanted, '.');


sub wanted {

    # look at all text files except .old files
    
    if ( -T && !/\.old$/ ) {

        open( IN, $_ ) or die "Bummer on file $_:$!";

        while ( my $line = <IN> ) {

            if ( $line =~ /this/I ) {

                close( IN ) or die "Failed close of $_: $!";

                print STDERR "Processing: $_\n";

                # save file's times
                my ($atime, $mtime) = (stat)[8,9];
                
                # use perl's -I magic
                
                @ARGV = ($_);
        
                while (my $line = <>) {
                    $line =~ s/this/that/I;
                    print $line;
                }

                # set new file's timestamp to previous setting
                utime $atime, $mtime, ($_);
                
                last;
            }
        }
            
    }
}




-- 
Bill Moseley mailto:moseley@best.com
pls note the one line sig, not counting this one.


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

Date: 06 Aug 1999 20:39:13 -0600
From: llornkcor <llornkcor@llornkcor.com>
Subject: Re: modem dialingL HOWTO.
Message-Id: <oggk71ri.fsf@wind.localdomain>

I think there is a ActiveState perl module called Win32::RasAdmin, that might
help. Not much documentation for it, tho. And it only works on NT

>How would I do this on Win32?

-- 
 - "Peace cannot be kept by force. It can only be achieved by
    understanding."
 - "Whoever undertakes to set himself up as judge in the
 field of truth and knowledge is shipwrecked by the
 laughter of the Gods."        -A. Einstein



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

Date: Sat, 7 Aug 1999 13:18:56 +1000
From: "David James" <davidj@zipworld.net>
Subject: Re: modem dialingL HOWTO.
Message-Id: <7og8ad$mts$1@the-fly.zip.com.au>


Greg Teets <teetsg@fuse.net> wrote in message
news:37ab898d.178274577@nntp.fuse.net...
> >
> >Assumption:  You want to run your Perl app on linux.
> >
> >Simplest way:
> >
> >open(MODEM,">/dev/modem") || die"Can't open modem: $!";
> >print MODEM "ATDT5551212\r";  # Hayes command language common to
> >                              # most modems
> >close MODEM;
> >
> >Hope this helps.
> How would I do this on Win32?

I would guess you'd open COMn: (where n is the number of the com port)
instead of /dev/modem. I don't have the hardware to test this though so I'm
not sure.

Hope this helps,

David





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

Date: Fri, 06 Aug 1999 19:18:40 +0200
From: Christoph Wernli <cw@dwc.ch>
To: Derek Battams <dbattams@canada.com>
Subject: Re: New to Perl - Question About RegExpr
Message-Id: <37AB18F0.6BE8C067@dwc.ch>

[posted and mailed]

Derek Battams wrote:
> 
> $Config{'required'} =~ s/(\s+|\n)?,(\s+|\n)?/,/g;
> 
> I realize that this is a regular expression, but here are my questions...
> 
> (1) Exactly what does the "=~" operator do?  I've been reading the limited
> information that I have found on the Internet, but this has not come up.

It binds the regex to the variable => the regex operates on the variable.

> (2) Are there any other similar operators like "=~"?  If so, what do they
> do?

!~ 	=> 	negates the outcome

perldoc perlop will tell you more.

> (3) Where is the best place to learn about regular expressions (how to write
> them, etc.)?

Jeffrey Friedels "Mastering Regular Expressions".

-w


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

Date: Sat, 07 Aug 1999 02:22:30 GMT
From: "He whom the perl gods have cursed" <hughd@screwspam.com>
Subject: Problem with standard IO::Socket::INET module
Message-Id: <37ab9866.001@screwspam.com>


The following mind-numbingly simple script fails to compile:

#!c:\perl\bin\perl.exe
use strict;
use IO::Socket::INET;

my $sock = IO::Socket::INET->new(PeerAddr => 'some.nntp.server',
                                                        PeerPort => 'nntp(119)',
                                                        Proto    => 'tcp');

Can't locate IO/Socket/INET.pm in @INC (@INC contains: C:\PERL\lib C:\PERL\site\lib .) at dummy.pl line 3.
BEGIN failed--compilation aborted at dummy.pl line 3.

The problem is that C:\Perl\lib\IO\Socket.pm defines IO::Socket::INET as well as
IO::Socket. I tried creating a subdirectory called Socket and putting the code for
IO::Socket::INET in it in a filed called INET.pm, but then perl complains that it can't
find the method register_domain (which should be inherited from IO::Socket.)

In desperation I put the IO::Socket::INET code in a new module called IO::INET,
stored it in a new file C:\perl\lib\IO\INET.pm, and renamed all occurences of
IO::Socket::INET to IO::INET in the source code in both my script and the modules -
with the same result, ie. perl can't find the methods that are supposed to be inherited
from IO::Socket.

Will someone please take pity on me and show me how to propitiate the perl gods?
I'm running Activestate Perl 5.09 on Windows 98. Please don't tell me I have to upgrade
to the latest-n-greatest bleeding edge version, or dwnload some bloatware from CPAN,
or flame me for not running Linux - I just want to do something very simple, in fact
trivial, and I can't understand why perl won't let me do it!


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

Date: 7 Aug 1999 01:53:33 GMT
From: jeromeo@atrieva.com (Jerome O'Neil)
To: "Dutch McElvy" <dutch@mindspring.com>
Subject: Re: ps -ef |grep ""kill script?
Message-Id: <7og3it$t46$2@brokaw.wa.com>

[Posted and mailed]

In article <7ofmak$dn6$1@nntp3.atl.mindspring.net>,
	"Dutch McElvy" <dutch@mindspring.com> writes:
> What would be the syntax for pulling the PIDs out of ps -ef and killing
> them?

kill -9 `ps -ef | grep foo | awk -e '{print $2}'`

Works for me. Your signals may vary.

-- 
Jerome O'Neil, Operations and Information Services
Atrieva Corporation, 600 University St., Ste. 911, Seattle, WA 98101
jeromeo@atrieva.com - Voice:206/749-2947 
The Atrieva Service: Safe and Easy Online Backup  http://www.i-filezone.com


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

Date: Fri, 6 Aug 1999 21:06:43 -0700
From: Tom Phoenix <rootbeer@redcat.com>
Subject: Re: ps -ef |grep ""kill script?
Message-Id: <Pine.GSO.4.10.9908062100490.9452-100000@user2.teleport.com>

On 7 Aug 1999, Jerome O'Neil wrote:

> kill -9 `ps -ef | grep foo | awk -e '{print $2}'`

Using signal 9 as your first choice? Well, I can't say it doesn't work.
It's surely no less effective than using a tablespoon of strychnine to
cure snoring.

Cheers!

-- 
Tom Phoenix       Perl Training and Hacking       Esperanto
Randal Schwartz Case:     http://www.rahul.net/jeffrey/ovs/



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

Date: Fri, 06 Aug 1999 19:46:29 +0200
From: Christoph Wernli <cw@dwc.ch>
Subject: Renaming a hash key ?
Message-Id: <37AB1F75.4D217CC4@dwc.ch>

Is there a possibility other than

$hash{new_key} = $hash{old_key};
delete $hash{old_key};

to rename a key ?

TIA,

-w


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

Date: Fri, 6 Aug 1999 21:35:08 -0700
From: Tom Phoenix <rootbeer@redcat.com>
Subject: Re: Renaming a hash key ?
Message-Id: <Pine.GSO.4.10.9908062132580.9452-100000@user2.teleport.com>

On Fri, 6 Aug 1999, Christoph Wernli wrote:

> Is there a possibility other than
> 
> $hash{new_key} = $hash{old_key};
> delete $hash{old_key};
> 
> to rename a key ?

There's no method that's amazingly great. But generally there's a better
way to solve a programming problem than to rename hash keys, if you can
find it. Good luck with it!

-- 
Tom Phoenix       Perl Training and Hacking       Esperanto
Randal Schwartz Case:     http://www.rahul.net/jeffrey/ovs/



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

Date: Fri, 6 Aug 1999 20:42:02 -0700
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: reverse of localtime?
Message-Id: <MPG.12154ad0b951a0b989df7@nntp.hpl.hp.com>

In article <7og0t2$4hq$1@nnrp1.deja.com> on Sat, 07 Aug 1999 01:07:51 
GMT, Makarand Kulkarni <makarand_kulkarni@my-deja.com> says...
> [In article <19990806211626.17158.qmail@nym.alias.net>,
>   Kin Cho <kin@symmetrycomm.com> wrote:
> > I'm seeking a function when given the output string of localtime
                                      ^^^^^^^^^^^^^^^^^
> > (in scalar context), returns the output of time().. {rest snipped.}
     ^^^^^^^^^^^^^^^^^

> timelocal() of Time::Local() will help you.
> --
> use Time::Local ;
> print time () . "\n" ;
>  ($sec,$min,$hour,$mday,$mon,$year) = localtime ();

Ahem...

> $time = timelocal($sec,$min,$hour,$mday,$mon,$year);
> print $time . "\n" ;

-- 
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com


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

Date: Sat, 07 Aug 1999 03:18:08 GMT
From: "Todd Witten" <twitten@home.com>
Subject: TFTP server in Perl
Message-Id: <QzNq3.3235$vu2.1049@news.rdc1.tx.home.com>

Anyone know where I could get a TFTP server writtten in perl?

--
Todd Witten
Data Engineer
Cox Fibernet
twitten@home.com




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

Date: Fri, 6 Aug 1999 21:10:46 -0700
From: Tom Phoenix <rootbeer@redcat.com>
Subject: Re: TFTP server in Perl
Message-Id: <Pine.GSO.4.10.9908062110310.9452-100000@user2.teleport.com>

On Sat, 7 Aug 1999, Todd Witten wrote:

> Anyone know where I could get a TFTP server writtten in perl?

If you're wishing merely to _find_ (as opposed to write) programs,
this newsgroup may not be the best resource for you. There are many
freeware and shareware archives which you can find by searching Yahoo
or a similar service. Hope this helps!

-- 
Tom Phoenix       Perl Training and Hacking       Esperanto
Randal Schwartz Case:     http://www.rahul.net/jeffrey/ovs/



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

Date: 7 Aug 1999 01:58:55 GMT
From: ehood@medusa.acs.uci.edu (Earl Hood)
Subject: Re: variable taking regexp as value
Message-Id: <7og3sv$fke@news.service.uci.edu>

In article <7ofqok$evf$1@nntp9.atl.mindspring.net>,
Julio <juliok@mindspring.com> wrote:

>myprog '(.)(.)'   '\2\1'
>
>The code would contain something like
>$x = $ARGV[0]; etc.,
>......
>$line  =~ s/$x/$y/;
>
>and the effect would be the same as if I had said 
>
>$line =~ s/(.)(.)/\2\1/;
>
>What happens is that $line ends up containing \2\1, as
>experts must have guessed by now. 

As you have noted, $1 and $2 is the proper way to refer to
back references.

The problem you are having is that $y only gets expanded once
so $1$2 will be treated literally.  I.e.  Perl does not recursively
expand (this could cause and infinite loop in many cases).

Try using eval.  For example:

    eval qq{ \$line =~ s/\$x/$y/; };

Here, $y will get expanded before the statement gets evaluated.

Note, you may need to check $y for certain characters (like '/') which
would make eval return an error, unless you are assuming that the
user will properly escape characters (the same applies to $x).

	--ewh
-- 
             Earl Hood              | University of California: Irvine
      ehood@medusa.acs.uci.edu      |      Electronic Loiterer
http://www.oac.uci.edu/indiv/ehood/ | Dabbler of SGML/WWW/Perl/MIME


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

Date: Fri, 6 Aug 1999 20:56:32 -0700
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: variable taking regexp as value
Message-Id: <MPG.12154e38a6dcda68989df8@nntp.hpl.hp.com>

[Posted and a courtesy copy sent.]

In article <7ofqok$evf$1@nntp9.atl.mindspring.net> on Fri, 06 Aug 1999 
23:16:44 GMT, Julio <juliok@mindspring.com> says...
> I've been trying to do a substitution using variable that take regexp
> values,  for example I want to write a program such that I can invoke
> it as
> 
> myprog '(.)(.)'   '\2\1'
> 
> The code would contain something like
> $x = $ARGV[0]; etc.,
> ......
> $line  =~ s/$x/$y/;
> 
> and the effect would be the same as if I had said 
> 
> $line =~ s/(.)(.)/\2\1/;
> 
> What happens is that $line ends up containing \2\1, as
> experts must have guessed by now. 
> 
> I have tried:
> 
> a) sayig $2$1 instead

That is better.  The \1 and \2 should be used within the regex only.

> b) Using different types of quotes

Those are the right kind of quotes.

> x) Using ${$x}

$x is not a reference.

> c) using eval

That is how I did it.


#!/usr/local/bin/perl -w
use strict;

sub myprog {
    eval "s/$_[0]/$_[1]/";
    $@ and die $@;
}

$_ = "foobar\n";

myprog '(.)(.)', '$2$1';

print;
__END__

Output:
ofobar

-- 
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com


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

Date: 1 Jul 99 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 1 Jul 99)
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 V9 Issue 411
*************************************


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