[21947] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 4169 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sun Nov 24 14:05:42 2002

Date: Sun, 24 Nov 2002 11:05:10 -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           Sun, 24 Nov 2002     Volume: 10 Number: 4169

Today's topics:
    Re: @INC, use, $LD_LIBRARY_PATH, & modules <goldbb2@earthlink.net>
    Re: a question on regular expression <goldbb2@earthlink.net>
    Re: Can pragma "use locale" affect sort function used i <d.adamkiewicz@i7.com.pl>
    Re: Changing server problem <jurgenex@hotmail.com>
    Re: disambiguating print (was Re: Basic syntax question (Tad McClellan)
    Re: File Processing question (Tad McClellan)
    Re: Find Text in a variable (Tad McClellan)
    Re: hash values ref counted? (Tad McClellan)
    Re: Help with grep + hash value (Trent Hare)
        Perl debugger? (Rob Richardson)
    Re: Perl debugger? <robertbu@hotmail.com>
    Re: Perl/Tk install directories <pa@panix.com>
        Perl/Tk (fafanie)
        removing elements from an array <nick.tipper@bigfoot.com>
        Stack and taking reference to automatic variables (Gupit)
    Re: Stack and taking reference to automatic variables <tassilo.parseval@post.rwth-aachen.de>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Sun, 24 Nov 2002 14:06:51 -0500
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: @INC, use, $LD_LIBRARY_PATH, & modules
Message-Id: <3DE1234B.D0E35714@earthlink.net>

Dave Cross wrote:
[snip]
> use lib /path/to/perl/modules;

This needs quotes:

use lib "/path/to/perl/modules";

-- 
my $n = 2; print +(split //, 'e,4c3H r ktulrnsJ2tPaeh'
 ."\n1oa! er")[map $n = ($n * 24 + 30) % 31, (42) x 26]


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

Date: Sun, 24 Nov 2002 13:53:59 -0500
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: a question on regular expression
Message-Id: <3DE12047.DA2041F5@earthlink.net>

David K. Wall wrote:
> 
> Benjamin Goldberg <goldbb2@earthlink.net> wrote:
> 
> > Kurt Gong wrote:
> >>
> [finding inverted repeats in a DNA sequence]
> 
> [snip program]
> >
> > [untested]
> 
> I think you should have tested it.  Unless I'm mistaken (a frequent
> occurrence), it misses things it should have found.

Some sample data, please?  In particular, show the outputs you expect to
get.

-- 
my $n = 2; print +(split //, 'e,4c3H r ktulrnsJ2tPaeh'
 ."\n1oa! er")[map $n = ($n * 24 + 30) % 31, (42) x 26]


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

Date: Sun, 24 Nov 2002 17:35:07 +0100
From: Darek Adamkiewicz <d.adamkiewicz@i7.com.pl>
Subject: Re: Can pragma "use locale" affect sort function used in module method?
Message-Id: <3DE0FFBB.7090703@i7.com.pl>

Benjamin Goldberg wrote:
> Darek Adamkiewicz wrote:
> 
>>Hello folks,
>>I can't figure out how this could be done - if this could be done
>>- perhaps anybody enlighten me?
> 
> 
> sub themethod {
>#-  my $caller_hints = (caller(1))[8];
      my $caller_hints = (caller(0))[8];#+
>    if( $caller_hints & $locale::hint_bits ) {
>       use locale;
>       @sorted = sort @unsorted;
>    } else {
>       no locale;
>       @sorted = sort @unsorted;
>    }
> }
> 

Modified 'themethod' put in module and invoked from program
works fine.
Thank you.

Regards
Darek




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

Date: Sun, 24 Nov 2002 16:07:40 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: Changing server problem
Message-Id: <gP6E9.18756$hi6.105@nwrddc02.gnilink.net>

Angus wrote:
> I have had the Extropia.com web-store successfully working for a
> couple of years and I have just moved it, unchanged except for the
> obviously needed changes to the setup file, to a new server.
>
> It now refuses to work and I have managed to isolate the problem to a
> few lines in the sub add_to_the_cart. About ten lines down in that sub
> is the following syntax:
>
> chomp $_;
> my @row = split (/\|/, $_);
> my $item_number = pop (@row);
> $highest_item_number = $item_number if ($item_number >
> $highest_item_number);
>
> When I hash out these lines the script will launch, though obviously I
> cannot add to the cart. Without the hashes I get an 'internal server
> error'.

Nothing obvious wrong with those lines. Seems to be valid Perl.
Does you script work from the command line? It is MUCH easier to debug
without the CGI overhead.

jue




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

Date: Sun, 24 Nov 2002 10:51:52 -0600
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: disambiguating print (was Re: Basic syntax question on using arrays   returned from function)
Message-Id: <slrnau20t8.i0c.tadmc@magna.augustmail.com>

Dave Tweed <dtweed@acm.org> wrote:
> Tad McClellan wrote:
>> Dave Tweed <dtweed@acm.org> wrote:

>> > I still find it confusing that this doesn't work as I expect if the first
>> > argument is a function call that the parser doesn't know about yet. In
>> > other words, given
>> >
>> >    perl -we "print (foo ('x')); sub foo {'Hi'}"
>> >
>> > the parser still thinks that foo is meant to be a filehandle,


>> This new issue is about filehandles not being first class data types.
> 
> Yes, and this in turn brought about the special comma-less, whitespace-
> required syntax used for filehandles in print(f) argument lists, which
> I have always felt was a particularly egregious wart.


I am a member of the choir on that issue.  :-)


>> So in your case above, I would _still_ not resort to unary plus


still still.  ;-)


>> In that case, if Perl wants a filehandle, I'd just give it a filehandle:
>>    print STDOUT (foo ('x'));

> Not a general solution, as I might have select()ed a different default
> filehandle.


> But I guess
> it's the best way to document my intent.


I think the best solution in that case would be to declare 
the function first:

   sub foo;
   ...

   print foo ('x');
   ...

   sub foo {
     # foo()'s definition
   }


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


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

Date: Sun, 24 Nov 2002 08:07:04 -0600
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: File Processing question
Message-Id: <slrnau1n88.gt4.tadmc@magna.augustmail.com>

Pularis <pularis@go.com> wrote:
> How can I extract a particular word while I am reading a file and then
> replace that word with something else ?. I have a plain text file and
> I am making an html file out of it and when I see some particular
> words I need to insert hmtl liks.
                  ^^^^^^

   perldoc -q insert

      "How do I change one line in a file/delete a line in a
       file/insert a line in the middle of a file/append to the
       beginning of a file?"


> Any help will be much appreciated.


Any checking of the Perl FAQ before posting to the Perl
newsgroup will be much appreciated.


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


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

Date: Sun, 24 Nov 2002 08:25:12 -0600
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Find Text in a variable
Message-Id: <slrnau1oa8.gt4.tadmc@magna.augustmail.com>

Blnukem <blnukem@hotmail.com> wrote:

> Ok that 


What "that"?

Please learn to quote your followups correctly.


> seem's to match to the first ip address of 192.168.1.1 I need to
> find the second ip address of 254.52.585.547 in the string shouldnt this
> seek to the end of the stirng and find the last ip address of 254.52.585.547


No.

Why do you think it should find the last one?


> my $content = "(mac address: 00-20-52-d7-76-d6) ip address:192.168.1.1subnet
> mask:255.255.252.0
> dhcpserver:disabled wan:(mac address: 00-24-65-d1-78-b7)
> ipaddress:254.52.585.547 subnet mask:255.255.252.0 ";
  ^^^
  ^^^

That will NEVER match the pattern you are using.

Please do not attempt to retype code, use copy/paste, else
you'll just get comments about your typos instead of about
your real problem.

I pointed this out to you over a year ago. Why are you still
attempting to retype stuff?


> my ($ip) = $content =~  /ip address:([0-9.]+)/;


There is no m//g option, so this will find the first match
and then stop attempting matches.


> print( defined($ip) ? ($ip, "\n") : "No match\n" );


   my(@ips) = $content =~  /ip address:([0-9.]+)/g;
   print $ips[1];    # print the second one found
   print $ips[-1];   # print the last one found


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


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

Date: Sun, 24 Nov 2002 11:03:11 -0600
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: hash values ref counted?
Message-Id: <slrnau21if.i0c.tadmc@magna.augustmail.com>

Paul Wood <paul@torporific.org> wrote:

> Hi, I've found myself writing something along the lines of...
> 
> %hash = (
>   'space1.key1' => 1,
>   'space1.key2' => 2,
>   'space2.key1' => 3,
> );


You should chastize yourself whenever you catch yourself writing
something along those lines.  :-)


   You should always prefer lexical (my) over dynamic (local)
   variables, except when you can't.

Your's does not appear to be one of the "when you can't" cases.

Do you have "use strict" turned on?


> {
>   local %hash = map { $_ =~ /^space1\.(.+)/ ? ($1, $hash{$_}) : () }
> keys %hash;
>   print $hash{'key1'}, "\n"; # prints 1
> }
> 
> Now, does locally changing the name of the keys make an extra copy of
> the value? 


Yes.


When you have multi-part keys like that, it is usually an indication
that you have not chosen the best data structure.

A Hash of Hashes (HoH) would be easier to work with:

   my %hash = (
      space1 => { key1 => 1,
                  key2 => 2,
                },
      space2 => { key1 => 3, }
   );

Then you would no longer need a copy.


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


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

Date: 24 Nov 2002 10:40:12 -0800
From: trent@autoimages.com (Trent Hare)
Subject: Re: Help with grep + hash value
Message-Id: <bc421eed.0211241040.4618b097@posting.google.com>

Thanks for your help Jay, but I probably wasn't very clear in my
original post.

I'm trying get the grep to be more "lenient" in it's tossing out
photos...
I have photos that are named "12345C.jpg" that belong to car "12345C",
(which has been temporarily appended ".jpg" for the array matching
purposes) and I also have photos named "12345_2.jpg" "12345_3.jpg"
etc., that I don't want placed into the @orphanpics.

So, when the hash value = "12345C.jpg" how do I get it to allow
12345C_2.jpg as well using this type of array matching?

push @orphanpics, grep {not exists $h{$_}} @pictures;


Thanks,
Trent


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

Date: 24 Nov 2002 09:09:52 -0800
From: therobs@n2net.net (Rob Richardson)
Subject: Perl debugger?
Message-Id: <f79bc007.0211240909.21296104@posting.google.com>

Greetings!

I am entering the Perl world from the worlds of Visual C++ and Visual
Basic.  In both of those worlds, I have at my disposal a powerful
debugger that allows me to set breakpoints in code, to execute my code
one step at a time, to enter or skip over subroutines, and to watch
variables as they change.  Most imporantly, the debugger can execute
code in exactly the same environment in which the production version
will run.  Presumably, other Perl programmers also have experience
with these or other IDEs with similar capabilities.  So, since Perl is
largely used for Web programming, I would presume that there exist
IDEs for Perl that can act as web servers, accepting connections from
browsers, generating web pages and responding to events from those
pages by running the requested Perl scripts, stopping at breakpoints,
displaying variable values, and all the rest of it.  If that is indeed
the case, what do people recommend that I try to persuade the
non-profit organization I'm volunteering to do web programming for to
spend money on?

I've seen tantalizing hints in posts on this group, but I don't know
where to start.

Thanks!

Rob


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

Date: Sun, 24 Nov 2002 18:23:43 GMT
From: "robertbu" <robertbu@hotmail.com>
Subject: Re: Perl debugger?
Message-Id: <PO8E9.16960$mL2.14567@nwrddc01.gnilink.net>


"Rob Richardson" <therobs@n2net.net> wrote in message
news:f79bc007.0211240909.21296104@posting.google.com...
> Greetings!

> I am entering the Perl world from the worlds of Visual C++ and Visual
> Basic.  In both of those worlds, I have at my disposal a powerful
> debugger that allows me to set breakpoints in code, to execute my code
> one step at a time, to enter or skip over subroutines, and to watch
> variables as they change.  Most imporantly, the debugger can execute
> code in exactly the same environment in which the production version
> will run.

I cannot make recommendations, but I can point you at a place to state.

ActiveState (www.activestate) has VisualStudio .NET plug-ins.  They also
have an IDE (Komodo) which was reviewed on www.perl.com.  While it likely
doesn't meet your criteria, there is a free graphical debugger at
http://world.std.com/~aep/ptkdb/.  And there is always the -d switch.   Most
CGI apps are debugged at the command line before being uploaded to the
server.

== Rob ==





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

Date: Sun, 24 Nov 2002 18:53:54 +0000 (UTC)
From: Pierre Asselin <pa@panix.com>
Subject: Re: Perl/Tk install directories
Message-Id: <arr77v$is4$1@reader1.panix.com>

In <1751b2b5.0211221453.4866c072@posting.google.com> manutd_kit@yahoo.com (kit) writes:

>http://www.perl.com/pub/a/2001/03/gui.html
>I learnt how to install perl/tk in here.

It installs fine from the command line, it's just that the destination
libdir seems strange.  I doubt that installing from teh CPAN shell
will change that.  I guess I'll check with the author.


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

Date: 24 Nov 2002 08:10:26 -0800
From: fafanie99@yahoo.fr (fafanie)
Subject: Perl/Tk
Message-Id: <31b33246.0211240810.198cb405@posting.google.com>

Hi,

I want to build a graphical interface in Perl/Tk.
Via this interface, I want to run a script perl from a button.
For the moment, this script run via a console MS-Dos or a xterm unix.

How to do?
The command system("perl test.pl") or system("start perl test.pl") fails.

Thus, my script writes some messages in STDOUT (console,xterm).
How can I see theses outputs in my interface?

Thanks, 
fafanie


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

Date: Sun, 24 Nov 2002 19:02:07 -0000
From: "Nick Tipper" <nick.tipper@bigfoot.com>
Subject: removing elements from an array
Message-Id: <3de121fd_1@mk-nntp-2.news.uk.tiscali.com>

Hi can anybody please tell me how i can remove an element from an array thus

foreach (@arr) {
    if (some condition) {
         # remove $_ from @arr
     }
}

i know i could

for  $i  (0 .. $#arr) {
    if(some condition) {
        splice @arr, $i, 1;
    }
}

but i really want to use the 'foreach' method because i am trying to use
this in a recursive fashion and i keep getting unitialised variable problems
with 'for'

TIA



--
Nick Tipper
nick.tipper@bigfoot.com




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

Date: 24 Nov 2002 09:59:34 -0800
From: gupit@yahoo.com (Gupit)
Subject: Stack and taking reference to automatic variables
Message-Id: <1ea0ec40.0211240959.21d8f694@posting.google.com>

I am confused about how perl allows taking reference to automatic
variables i.e. variables declared using my.

sub foo { 
  my @l = qw(a b c d);
  my @a = (1, 2, 3, 4);
  return \@a;
}

From my understanding both @l and @a are allocated on the stack. When
foo returns, @l should get automatically deallocated. Since we return
a reference to @a, it should linger around. But does that mean perl
makes a copy of the variable on the heap and deallocates the stack
version?

Or is there no concept of allocating automatic variables on stack in
perl? All variables are by default allocated on heap!

Thanks
Gupit


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

Date: 24 Nov 2002 18:51:06 GMT
From: "Tassilo v. Parseval" <tassilo.parseval@post.rwth-aachen.de>
Subject: Re: Stack and taking reference to automatic variables
Message-Id: <arr72q$28r$1@nets3.rz.RWTH-Aachen.DE>

Also sprach Gupit:

> I am confused about how perl allows taking reference to automatic
> variables i.e. variables declared using my.
> 
> sub foo { 
>   my @l = qw(a b c d);
>   my @a = (1, 2, 3, 4);
>   return \@a;
> }
> 
> From my understanding both @l and @a are allocated on the stack. When
> foo returns, @l should get automatically deallocated. Since we return
> a reference to @a, it should linger around. But does that mean perl
> makes a copy of the variable on the heap and deallocates the stack
> version?

No. Each Perl variable internally has an integer field holding the
number of references to this variable. If you say:

    my $var;

a new SV is created with a reference count of 1. In your sub it looks
like:

    sub foo {
        my @a = (1, 2, 3, 4); # ref-count: 1
        return \@a;           # ref-count: 2
    } # leaving scope -> ref-count: 1

Since ref-count is 1, @a is internally still stored and not yet destroyed.

> Or is there no concept of allocating automatic variables on stack in
> perl? All variables are by default allocated on heap!

Automatic variables is a concept that I know from C. Perl is not like C.
There's a couple of hundred lines in C involved when you just declare a
variable. Deallocation (or rather destroying) of variables happens with
the help of the reference count.

Tassilo
-- 
$_=q!",}])(tsuJ[{@"tnirp}3..0}_$;//::niam/s~=)]3[))_$-3(rellac(=_$({
pam{rekcahbus;})(rekcah{lrePbus;})(lreP{rehtonabus;})(rehtona{tsuJbus!;
$_=reverse;s/sub/(reverse"bus").chr(32)/xge;tr~\n~~d;eval;


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

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


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