[22886] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 5107 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Jun 11 14:11:02 2003

Date: Wed, 11 Jun 2003 11:10:12 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Wed, 11 Jun 2003     Volume: 10 Number: 5107

Today's topics:
        perl+apache - how to execute a default command into a c <wiz@near.it>
    Re: perl+apache - how to execute a default command into <nobull@mail.com>
        perl/xml research project topic recommendation (Ari)
    Re: perl/xml research project topic recommendation (Tad McClellan)
        Some Perl guts questions about Magic <im_not_giving_it_here@i_hate_spam.com>
        Sorting question (Math55)
    Re: Sorting question <jurgenex@hotmail.com>
    Re: Sorting question <nobull@mail.com>
    Re: stripping leading zeros thru multiple fields <mbudash@sonic.net>
    Re: using Dumper to save hash and retrieving it. <abc@nowhere.com>
    Re: virtual x server for Tk <chip@NO-Spam-afcoms.com>
    Re: Why is the system call not working? (Tad McClellan)
    Re: Why is the system call not working? (John D)
    Re: Why is the system call not working? <zentara@highstream.net>
    Re: Win32::ListView  sample please?? (Kenjis Kaan)
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Wed, 11 Jun 2003 17:01:40 +0200
From: Wiz <wiz@near.it>
Subject: perl+apache - how to execute a default command into a cgi script?
Message-Id: <bc7gec$ertfc$1@ID-70527.news.dfncis.de>

Hi there,
I need to execute into all cgi on a web server a default command.
So, when the browser get a cgi, perl must execute a command, then pass throu
the complete cgi.
How I can do it?
Thanks to all


Marco


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

Date: 11 Jun 2003 18:43:42 +0100
From: Brian McCauley <nobull@mail.com>
Subject: Re: perl+apache - how to execute a default command into a cgi script?
Message-Id: <u94r2wy0fl.fsf@wcl-l.bham.ac.uk>

Wiz <wiz@near.it> writes:

> I need to execute into all cgi on a web server a default command.
> So, when the browser get a cgi, perl must execute a command, then pass throu
> the complete cgi.
> How I can do it?

Put the command in a module.

Configure Apache to set a PERL5OPT enviroment variable with a -M
switch to load the module.

Note: This will only apply to CGI scripts written in Perl.

If you want to get the command executed for other CGI scripts then you
need to look into mod_perl.

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


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

Date: 11 Jun 2003 09:11:02 -0700
From: schakhmat@yahoo.com (Ari)
Subject: perl/xml research project topic recommendation
Message-Id: <a9f0b74d.0306110811.4625da94@posting.google.com>

Dear Perl People,

My college Perl class has been assigned a group research project with
the goal of helping to keep students abreast of new developments in
Perl programming theory and implementation. My group's topic is going
to need to involve Perl and XML, and we have to somehow narrow our
focus from this broad scope. I see that there's a lot of good stuff at
xml.com/pub/q/perlxml, but without knowing Perl or XML yet it's hard
for us to judge in advance what topics may turn out to be too simple
or too involved. Could someone please suggest a Perl/XML topic you
think is appropriate for 5 students beginning to learn those
languages?

Thank you! -- ari


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

Date: Wed, 11 Jun 2003 12:49:55 -0500
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: perl/xml research project topic recommendation
Message-Id: <slrnbeequ3.3er.tadmc@magna.augustmail.com>

Ari <schakhmat@yahoo.com> wrote:

> Could someone please suggest a Perl/XML topic you
> think is appropriate for 5 students beginning to learn those
> languages?


You might also want to ask on the mailing list for Perl and XML:

   http://lists.perl.org/showlist.cgi?name=perl-xml


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


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

Date: Wed, 11 Jun 2003 12:36:16 +0100
From: Asfand Yar Qazi <im_not_giving_it_here@i_hate_spam.com>
Subject: Some Perl guts questions about Magic
Message-Id: <bc743g$451$1@newsg2.svr.pol.co.uk>

Hello,

I HAEV SUM QEUSTONS (*ahem*)

I create a Perl variable in C using newSViv and attach some pointer 
addresses to its magic.  It is not the responsibility of Perl to 
construct/destruct the objects pointed to by the C pointers.

If I do a '$i = $j', how does this affect any Magic attached to $j? 
Does the magic get duplicated, or just the pointers to the magic?

What happens to the Magic when $j goes out of scope and is garbage 
collected?

Perl code calls a C function.  The C code creates the variable, attaches 
magic to it, and returns it (e.g. '$j = get_drawable("monkey.png")'). 
The perl code passes this magic variable to several C functions that 
extract the pointer information from the variable and use that pointer 
information in wacky ways.  Then the perl code scope ends.  Will the 
system be in a 'clean' state now?  I.e. no memory leaks?

Thanks very much.

-- 
http://www.it-is-truth.org/



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

Date: 11 Jun 2003 04:57:46 -0700
From: magelord@t-online.de (Math55)
Subject: Sorting question
Message-Id: <a2b8188a.0306110357.44258e36@posting.google.com>

hello, i wrote this programm. i am using the "du" to get something like this:


123 /tmp/cache


i am turning this around:


/tmp/cache 123


how can i sort the array NOT by numbers? THANKS :-)



#!/usr/bin/perl -w

use strict;
use warnings;
use Tk;
use Tk::Label;
use Tk::HList;
use Tk::Tree;
use FileHandle;

my $mw    = MainWindow->new();
my $label = $mw->Label( -width => 15 );
my $hlist = $mw->ScrlTree(
    -separator        => '/',
    -selectmode       => 'extended',
    -scrollbars       => 'osoe',
    -height           => '20',
    -width            => '30',
    -selectforeground => 'yellow',
    -browsecmd        => sub {

        my $file = shift;
        $label->configure( -text => $file );
    }
);



`du -m -a /tmp > /tmp/all 2>/dev/null`;
`find ./ -type d >> all`;
`sort /tmp/all > /tmp/sorted`;

my @path;

open SD,'</tmp/sorted' or die "Couldn't open: $!\n";
while (<SD>) {
	chomp;
	
	@path=((' ',(split)[1,0]));
		
	#$hlist->add($path[1],
    #				-text=>$path[1],
    # 			   -image=>$hlist->Getimage('folder'));
    #$hlist->setmode(@path => "open");	
}close SD; 




print "NACH DER ZUWEISUNG";

$hlist->pack;
$label->pack;
$mw->Button( -command => sub { exit }, -text => 'exit' )->pack;

MainLoop;



i need to dispay this in a hlist....

THANKS FOR YOUR HELP...:)


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

Date: Wed, 11 Jun 2003 16:53:21 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: Sorting question
Message-Id: <58JFa.78$_J.60@nwrddc03.gnilink.net>

Math55 wrote:
> hello, i wrote this programm. i am using the "du" to get something
> like this:
>
> how can i sort the array NOT by numbers? THANKS :-)

Well, then by what _do_ you want to sort it?
The alphabetical sequence of the fourth letter in the second subdirectory
unless the moon is made of green cheese, in which case ....; oh, just forget
it

[...]
> `du -m -a /tmp > /tmp/all 2>/dev/null`;
> `find ./ -type d >> all`;
> `sort /tmp/all > /tmp/sorted`;
[...]

Why are you using backticks when you are throwing away the returned results
anyway?
And why are you using an external program sort including all the overhead of
forking a new process and exec'ing instead of using Perl's build in function
sort()?
And if you want to find files or directories, then why aren't you using
File::find?
And why are you creating a temporary file /tmp/sorted when later you are
reading this file into the program line by line?

But to get back to your original question: If you want to learn about sort
then I suggest you read up on sort() in The Fine Manual (perldoc -f sort) as
well as in the FAQ (perldoc -q sort). There are many examples for how to
create and use your own custom comparison function.

jue




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

Date: 11 Jun 2003 18:10:50 +0100
From: Brian McCauley <nobull@mail.com>
Subject: Re: Sorting question
Message-Id: <u9ptlky1yd.fsf@wcl-l.bham.ac.uk>

magelord@t-online.de (Math55) writes:

> hello, i wrote this programm.

And you admit to it?

> i am using the "du" to get something like this:
> 
> 
> 123 /tmp/cache
> 
> 
> i am turning this around:
> 
> 
> /tmp/cache 123
> 
> 
> how can i sort the array NOT by numbers? THANKS :-)

Perl's sort, by default, is a string sort.

But you are not using Perl's sort, you are using Unix sort.  

Unix sort, by default, is a string sort too - but this has nothing to
do with Perl.

> `du -m -a /tmp > /tmp/all 2>/dev/null`;
> `find ./ -type d >> all`;
> `sort /tmp/all > /tmp/sorted`;

That is bad, see FAQ as previously directed by Tad.

> my @path;

Always declate all variables as lexically scoped in the smallest
applicable scope.
 
> open SD,'</tmp/sorted' or die "Couldn't open: $!\n";

Fixed name temp file is abhorent.  Don't need one at all anyhow:

 open SD,'du -m -a /tmp > /tmp/all 2>/dev/null | sort |' or die "Couldn't open pipe: $!\n";

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


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

Date: Wed, 11 Jun 2003 16:05:07 GMT
From: Michael Budash <mbudash@sonic.net>
Subject: Re: stripping leading zeros thru multiple fields
Message-Id: <mbudash-8421D6.09050711062003@typhoon.sonic.net>

In article <bc6peb$c1r$1$8300dec7@news.demon.co.uk>,
 Garry Short <g4rry_short@zw4llet.com> wrote:

> Michael Budash wrote:
> 
> > In article <2855726c.0306100923.3d82edc@posting.google.com>,
> >  mfabache@yahoo.com (MF) wrote:
> > 
> >> I've come up with the following (via searches and copying code) to
> >> strip all leading zeros thru a date field, but I cannot figure how to
> >> get to the 2nd field+
> >> 
> >> Expected data: "06/06/2003"
> >> Expected output: "6/6/2003"
> >> Current output: "6/06/2003)" # How can I tweak this?
> >> 
> >> Thanks,
> >> Michael
> >> ----
> >> 
> >> use POSIX qw(strftime) ;
> >> # $now_string = strftime "%m/%d/%Y", localtime;
> >> $now_string = "06/06/2003"; # for testing porposies
> >> print "$now_string\n";
> >> 
> >> $now_string =~ s/0(\d+)/$1/; #strip leading zero off of MONTH, now
> >> need DAY
> >> print "$now_string\n";
> > 
> > start with the g modifier on your substitution regex:
> > 
> > $now_string =~ s/0(\d+)/$1/g; # 'g' for 'global'
> > 
> > oh, but that affects the year, too:
> > 
> > output: 6/6/203
> > 
> > so let's be more specific:
> > 
> > $now_string =~ s{0(\d+(/|$))}{$1}g;
> > 
> > ahhh, there it is:
> > 
> > output: 6/6/2003
> > 
> 
> $now_string =~ /0([0-9]\/)/$1/g;
> 
> will also do it, and is a much simpler regex to follow.

[0-9] is the same as \d. and your regex also breaks on 02/10/02003 
(yielding 2/10/02003) because it specificaly looks for a trailing 
backslash in the number string, and the year has none. the o.p. asked to 
"strip all leading zeros thru a date field", and i took that to include 
the years field as well... however, mine is still broken on some years!

after experimenting a while with lookaheads, etc., i vote for ted z's 
solution:

s/(\d+)/$+0/eg;

-- 
Michael Budash


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

Date: Wed, 11 Jun 2003 14:32:41 GMT
From: ktom <abc@nowhere.com>
Subject: Re: using Dumper to save hash and retrieving it.
Message-Id: <3EE73D89.4000404@nowhere.com>

Martien Verbruggen wrote:
> On Wed, 11 Jun 2003 00:34:53 GMT,
>         ktom <abc@nowhere.com> wrote:
> 
>>i have created a file using the Data::Dumper command..
>>
>>the command used was
>>print OFILE Data::Dumper->Dump([\%pHash],['*xHash']);
>>
>>it created the file whose first few lines look like.
>>%xHash = (
>>   '25' => {
>>     '1169' => {
>>       'value' => '3.157',
>>       'name' => 'PSSYNC_VOH'
>>     },
>>     '559' => {
>>
>>i am trying to retrieve is using the do (as suggested in the book) and 
>>having troubles.  i have used the forms below and i haven't been able to 
>>access or print (using Dumper) the values that i thought i have brought in.
>>
>>#my $xHash = do $inFile2 || die "can't consume dbFile $inFile2\n";
>>#%postHash = do $inFile2 || die "can't consume dbFile $inFile2\n";
>>do $inFile2 || die "can't consume dbFile $inFile2\n";
> 
> 
> Don't use ||, use or instead, or properly parenthesise the do. In
> this specific case it makes no difference, but there are many other
> expressions and functions where it does make a difference (like open()).
> 
> 
>>print Dumper(%postHash);
>>print Dumper(%{$xHash});
>>print %xHash;
> 
> 
> 
> Have you made sure that the file that do is reading from is closed,
> i.e. you're not reading from a file that has only been half flushed?
> 
> Have you attempted to inspect $! and $@ to see what the error might
> be? It is generally very helpful to investigate what exactly is
> causing the error. You did read the documentation on do in the
> perlfunc manual page, right?
> 
> Is your %xHash lexically scoped (with my)? If so, take into account
> that do EXPR can't work with lexicals. You need to make sure that
> %xHash is a global (declare with our, or for old Perls with use vars).

BINGO!!  the proper use of 'our' solved the problem!

thanks for the other suggestions as well, they are always helpful.

if you (someone) could explain what purpose the square brackets serve in 
the Data::Dumper->Dump([\%pHash],['*xHash'] statement.  I know that it 
works but with my limited experience it doesn't make much sense..

> 
> Test data and code:
> 
> use strict;
> use warnings;
> use Data::Dumper;
> 
> my %pHash = (
>     '25' => {
> 	'1169' => {
> 	'value' => '3.157',
> 	'name' => 'PSSYNC_VOH'
> 	},
>     },
> );
> 
> open OFILE, ">foo.hash" or die $!;
> print OFILE Data::Dumper->Dump([\%pHash],['*xHash']);
> close OFILE;
> 
> our %xHash;
> my $rc = do "foo.hash";
> die "can't consume dbFile foo.hash: ", $! || $@  
>     unless defined $rc;
> print Data::Dumper->Dump([\%xHash]);
> 
> 
> For the next time, please create a small, self-contained, valid Perl
> program that exhibits your problem when you have one (but do not
> wildly post large slabs of code). Something as simple as the above
> would do. At least that tells us what you did and how. There are
> simply too many questions left that you haven't provided information
> for. Code snippets never tell the full story.
> 
> 
> Martien
> 
> PS If your input file can return undef from the last statement, you need
> to change the test condition to include tests for $! and $@
> 




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

Date: Wed, 11 Jun 2003 11:31:41 GMT
From: "Chip" <chip@NO-Spam-afcoms.com>
Subject: Re: virtual x server for Tk
Message-Id: <xqEFa.3515$Jw6.2503132@news1.news.adelphia.net>

Thanks Simon,

That is exactly what I was looking for.

Chip
"Simon Andrews" <simon.andrews@bbsrc.ac.uk> wrote in message
news:3EE6E718.5040001@bbsrc.ac.uk...
>
>
> Chip wrote:
> > "Darren Dunham" <ddunham@redwood.taos.com> wrote in message
> > news:79oFa.2559$_P2.130646217@newssvr21.news.prodigy.com...
> >
> >>It is unclear to me from your post what your intention is.  Do you want
> >>to see TK output on the screen in front of you?
> >
> >
> > Yes Darren, I am telneting ( or using ssh ) into a server from another
> > box and want the display to be on the box I am in front of, not the
server.
> >
> > I'm Using putty to telnet in from a windows box.  I think your on
> > the right track because I have seen referances to redirecting the
> > display but that is where my problem is.
>
> You still don't have enough running at your end to be able to do what
> you want.  In order to see graphics displayed on the remote machine you
> need to have an X server running on your windows box.  We use Exceed to
> do this:
>
> http://www.hummingbird.com/products/nc/exceed/index.html
>
> ..but a free alternative would be to install cygwin
> (http://www.cygwin.com/) which includes an X server (XFree86).
>
> Once you have your X server running locally the easiest thing to do is
> to set up putty to use ssh rather than telnet to connect, and then in
> the ssh options, tick the box which says "Enable X11 forwarding".
>
> Your remote program should then be able to display on your windows box.
>
> Hope this helps
>
> Simon.
>




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

Date: Wed, 11 Jun 2003 06:50:19 -0500
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Why is the system call not working?
Message-Id: <slrnbee5rr.300.tadmc@magna.augustmail.com>

Math55 <magelord@t-online.de> wrote:

> i wrote this system call with backticks:
> 
> `du -m -a ./|awk '{print $2 , $1}' > /tmp/all`;


You are abusing backticks.

Use backticks when you want to capture the external program's STDOUT.

Use system() when you want to merely run the external program.


> it always gives me an parse error 


It gives you an _awk_ parse error.

It gives a _perl_ warning which helps point out what is wrong.

You should always enable warnings when developing Perl code.


> because of the ''.


It is not because of the ''.

It is because of the $1 and $2 being taken as Perl variables when
you want them to be taken as awk variables instead.


> anyone who can help me?


# untested

   system "du -m -a ./|awk '{print \$2 , \$1}' > /tmp/all";
or
   system q(du -m -a ./|awk '{print $2 , $1}' > /tmp/all);
or
   my @tmp_all = `du -m -a ./|awk '{print \$2 , \$1}'`;



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


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

Date: 11 Jun 2003 06:01:07 -0700
From: johndageek@yahoo.com (John D)
Subject: Re: Why is the system call not working?
Message-Id: <c608545f.0306110501.4066842c@posting.google.com>

magelord@t-online.de (Math55) wrote in message news:<a2b8188a.0306110147.31311b9@posting.google.com>...
> hello,
> 
> i wrote this system call with backticks:
> 
> `du -m -a ./|awk '{print $2 , $1}' > /tmp/all`;
> 
> it always gives me an parse error because of the ''. even if i try it like this:
> 
> `du -m -a ./|awk \'{print $2 , $1}\' > /tmp/all`; or
> `du -m -a ./|awk {print $2 , $1} > /tmp/all`;
> 
> it does not work.
> 
> anyone who can help me?
> 
> 
> THANKS!!!!!


Why would you use awk when perl can do it better?
oh well ours is not to question why ....

Try this for fun:
`du -a ./|awk '{print \$2, \$1}' > ./xxxx`;

perl wants to interpret the variables in the string, escape em and the os gets em.

Enjoy
JD


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

Date: Wed, 11 Jun 2003 12:35:09 -0400
From: zentara <zentara@highstream.net>
Subject: Re: Why is the system call not working?
Message-Id: <vgmeevgs3pspptp6gkte1b3h6f1toesf2f@4ax.com>

On 11 Jun 2003 02:47:30 -0700, magelord@t-online.de (Math55) wrote:

>i wrote this system call with backticks:
>
>`du -m -a ./|awk '{print $2 , $1}' > /tmp/all`;
>
>it always gives me an parse error because of the ''. even if i try it like this:

>anyone who can help me?
When I run it, I get an error about the comma between $1 and $2
awk: cmd. line:1: {print ,}
awk: cmd. line:1:        ^ parse error

This runs for me: (but maybe the output isn't what you intended?)

#!/usr/bin/perl
use warnings;

`du -m -a ./|awk '{print $2  $1}' > /tmp/all`;





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

Date: 11 Jun 2003 06:16:42 -0700
From: tivolinewbie@canada.com (Kenjis Kaan)
Subject: Re: Win32::ListView  sample please??
Message-Id: <6a8ba9f8.0306110516.1d46500f@posting.google.com>

Had to upgrade Win32::GUI and its working now ;)

tivolinewbie@canada.com (Kenjis Kaan) wrote in message news:<6a8ba9f8.0306092248.78b6263c@posting.google.com>...
> Hi,  I am trying to create a listview program but no matter what I do
> its is not working.  I wonder if its because of the activestate perl
> (5.6.1) I am using.  I can open up a win32 window but the listview
> just isn't what I wanted.
> 
> I need to use ListView in order to display multiple rows of data
> extracted from a DB2 database.  Trying to make a nice little report of
> data in DB2.
> 
> Can someone give me a working example of ListView?  prefereable one
> that also set the text/backgroun color to non-defaults.  TIA


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

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


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