[24492] in Perl-Users-Digest
Perl-Users Digest, Issue: 6672 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Jun 9 18:05:49 2004
Date: Wed, 9 Jun 2004 15:05:07 -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, 9 Jun 2004 Volume: 10 Number: 6672
Today's topics:
Re: Beginner needs help with script :) <usenet@morrow.me.uk>
change de current working directory of my session... david_cantin@hotmail.com
change de current working directory of my session... david_cantin@hotmail.com
change de current working directory of my session... david_cantin@hotmail.com
Re: change de current working directory of my session.. (Anno Siegel)
Re: change de current working directory of my session.. <bxb7668@somewhere.nocom>
Re: change de current working directory of my session.. <jurgenex@hotmail.com>
Re: Contructing a dir. tree (JR)
Re: Contructing a dir. tree <ittyspam@yahoo.com>
Counting elements in a hash russell.brooks@perdue.com
Re: Counting elements in a hash <ittyspam@yahoo.com>
Re: Counting elements in a hash <dwall@fastmail.fm>
Re: Counting elements in a hash <thepoet_nospam@arcor.de>
Re: Exit status from 'die' <usenet@morrow.me.uk>
Re: Help me with threads issue ! <usenet@morrow.me.uk>
Re: killing my children <usenet@morrow.me.uk>
Re: match aaa but not 123aaa <usenet@morrow.me.uk>
Matching a word or Pattern in perl (Raj Sathgunam)
Re: Matching a word or Pattern in perl <MyFirstnameHere.News1@gustra.org>
Re: No-install Perl Interpretor <usenet@morrow.me.uk>
Re: No-install Perl Interpretor <bik.mido@tiscalinet.it>
Re: Print a section of a text file. (Anno Siegel)
Re: Print a section of a text file. (Anno Siegel)
Re: search engine <jgibson@mail.arc.nasa.gov>
Re: sub returning nothing <usenet@morrow.me.uk>
Re: sub returning nothing <MyFirstnameHere.News1@gustra.org>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Wed, 9 Jun 2004 18:54:30 +0000 (UTC)
From: Ben Morrow <usenet@morrow.me.uk>
Subject: Re: Beginner needs help with script :)
Message-Id: <ca7md4$e3l$5@wisteria.csv.warwick.ac.uk>
Quoth nobull@mail.com:
>
> In English (and especially American English, IIRC) the phrase "I beg
> your pardon" has two distinct meanings depending on tone of voice. In
> one tone it means "I'm sorry, what have I done wrong?". In another it
> is roughly equivalent to "screw you!".
The distiction is just as present in British English.
Ben
--
Razors pain you / Rivers are damp
Acids stain you / And drugs cause cramp. [Dorothy Parker]
Guns aren't lawful / Nooses give
Gas smells awful / You might as well live. ben@morrow.me.uk
------------------------------
Date: 9 Jun 2004 13:12:04 -0700
From: david_cantin@hotmail.com
Subject: change de current working directory of my session...
Message-Id: <ca7quk$ot4@odbk17.prod.google.com>
Hi,
Is it possible to run a perl script that change my current "session"
working dir? Something like a script that a thing like thar :
$pwd
/home/foo
$./perl_script
$pwd
/usr/local/bin
it's dificult because a new process is started when we run a perl
script, so if the perl script change the cwd, the change will die with
the script...
Ps, My os is AIX 4.3 and 5.2
David
------------------------------
Date: 9 Jun 2004 13:17:37 -0700
From: david_cantin@hotmail.com
Subject: change de current working directory of my session...
Message-Id: <ca7r91$l9q@odah37.prod.google.com>
Hi,
Is it possible to run a perl script that change my current "session"
working dir? Something like a script that a thing like thar :
$pwd
/home/foo
$./perl_script
$pwd
/usr/local/bin
it's dificult because a new process is started when we run a perl
script, so if the perl script change the cwd, the change will die with
the script...
Ps, My os is AIX 4.3 and 5.2
David
------------------------------
Date: 9 Jun 2004 13:18:29 -0700
From: david_cantin@hotmail.com
Subject: change de current working directory of my session...
Message-Id: <ca7ral$pjp@odbk17.prod.google.com>
Hi,
Is it possible to run a perl script that change my current "session"
working dir? Something like a script that a thing like thar :
$pwd
/home/foo
$./perl_script
$pwd
/usr/local/bin
it's dificult because a new process is started when we run a perl
script, so if the perl script change the cwd, the change will die with
the script...
Ps, My os is AIX 4.3 and 5.2
David
------------------------------
Date: 9 Jun 2004 20:52:01 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: change de current working directory of my session...
Message-Id: <ca7t9h$rg$2@mamenchi.zrz.TU-Berlin.DE>
<david_cantin@hotmail.com> wrote in comp.lang.perl.misc:
> Hi,
>
> Is it possible to run a perl script that change my current "session"
> working dir? Something like a script that a thing like thar :
>
> $pwd
> /home/foo
> $./perl_script
> $pwd
> /usr/local/bin
No.
> it's dificult because a new process is started when we run a perl
> script, so if the perl script change the cwd, the change will die with
> the script...
Exactly.
In most shells this should work:
eval cd `perl -le 'print "/tmp"'`
but that's not the Perl program changing the directory for you, but
it's Perl telling the shell where to change the directory to. It's
also off topic.
Anno
------------------------------
Date: Wed, 9 Jun 2004 21:17:17 GMT
From: "bxb7668" <bxb7668@somewhere.nocom>
Subject: Re: change de current working directory of my session...
Message-Id: <Hz28Gr.CwJ@news.boeing.com>
<david_cantin@hotmail.com> wrote in message
news:ca7quk$ot4@odbk17.prod.google.com...
> Hi,
>
> Is it possible to run a perl script that change my current "session"
> working dir? Something like a script that a thing like thar :
>
> $pwd
> /home/foo
> $./perl_script
> $pwd
> /usr/local/bin
>
> it's dificult because a new process is started when we run a perl
> script, so if the perl script change the cwd, the change will die
with
> the script...
>
> Ps, My os is AIX 4.3 and 5.2
>
>
> David
Running the script with a "dot space" before it causes it to run in
the current shell. In other words:
. ./perl_script
(That's: dot space dot slash ... Those dots are hard to see on the
screen)
------------------------------
Date: Wed, 09 Jun 2004 21:50:54 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: change de current working directory of my session...
Message-Id: <2DLxc.1877$H65.1140@nwrddc02.gnilink.net>
bxb7668 wrote:
> Running the script with a "dot space" before it causes it to run in
> the current shell. In other words:
>
> . ./perl_script
>
> (That's: dot space dot slash ... Those dots are hard to see on the
> screen)
Sure, the dot is short for the shell "source" command.
The only question is: how would a shell interpret a Perl script?
jue
------------------------------
Date: 9 Jun 2004 12:31:15 -0700
From: jrolandumuc@yahoo.com (JR)
Subject: Re: Contructing a dir. tree
Message-Id: <b386d54b.0406091131.6f9286a8@posting.google.com>
Prab_kar@hotmail.com (Prabh) wrote in message news:<e7774537.0406081707.4ffd52ea@posting.google.com>...
> Hello all,
> I'm given a path to an element,"foo/bar1/bar2/XYZ.txt" and I'm trying
> to print the following format from my input:
>
> ======================================================
> Parent Folder: foo
> {
> Some text here about "foo"
> Child Folder: bar1
> {
> Some text here about "bar1"
> Child Folder: bar2
> {
> Some text here about "bar2"
> }
> }
> }
>
> File element: Some text about "XYZ.txt"
> ======================================================
>
> I'm trying to do this as:
>
> #!/usr/local/bin/perl
>
> use strict ;
> use warnings ;
>
> my $input = 'foo/bar1/bar2/XYZ.txt' ;
> my @arr = split(/\//,$input) ; # Get all folders.
> my $finalIndex = $#arr ; # The final index of @arr.
> my $count = 0 ;
> my @out ; # Array stores the o/p format.
>
> foreach my $line ( @arr )
> {
> # count == 0, parent folder.
> if ( $count == 0 )
> {
> print "Parent Folder: $line \n { \n Some text here \n
> } \n" ;
> push(@out,"Parent Folder: $line \n { \n Some text here
> \n }") ;
>
> } elsif ( $count == $finalIndex ) # The file element, XYZ.txt
> {
> print "File element: $line\n" ;
> push(@out,"File element: $line") ;
> } else # All sub-directories here.
> {
> print "Sub-Folder: $line. Insert under $arr[$count -
> 1]\n" ;
> push(@out,"Sub-Folder: $line. Insert under $arr[$count
> - 1]") ;
> }
>
> $count++ ;
>
> }
>
> print "======================================\n" ;
> map { print "$_\n" ; } @out ;
>
> ===========================================================
> It outputs,
>
> Parent Folder: foo
> {
> Some text here
> }
> Sub-Folder: bar1. Insert under foo
> Sub-Folder: bar2. Insert under bar1
> File element: XYZ.txt
>
> How do I insert the info about the sub-folder inside each other in a
> nested way and all of such info under the parent folder section?
>
> Could anyone tell me how I go about doing it?
>
> I tried looking up at splice, but it requires I give an offset to
> insert some elements inside my @out array.
>
> Thanks for your time,
> Prabh
I'm not 100% sure I understand what you want, but try:
#!/usr/local/bin/perl
use strict;
my $directory = 'foo/bar1/bar2/bar3/XYZ.txt';
my @arr = split /\//, $directory;
my @out = ();
my $info = undef;
my $count = 0;
$info = qq|Parent Folder: $_\n{\n Some text here about "$arr[0]"\n|;
$info .= qq| Child Folder: bar1\n|;
$info .= qq| {\n|;
my $indent = 6;
for my $i (1..$#arr-1) {
$info .= " " x $indent . qq|Some text here about "$arr[$i]"\n|;
$info .= " " x $indent . qq|Child folder: $arr[$i+1]\n|;
$info .= " " x $indent . qq|{\n|;
$indent += 3;
$count++;
}
$info .= " " x ($indent -= 3) . qq|}\n| for (0..$count+1);
$info .= qq|\nFile element: Some text about "$arr[$#arr]"\n|;
$info .= "=" x 39, "\n";
print $info;
Good luck
------------------------------
Date: Wed, 9 Jun 2004 15:44:07 -0400
From: Paul Lalli <ittyspam@yahoo.com>
Subject: Re: Contructing a dir. tree
Message-Id: <20040609153546.J8971@dishwasher.cs.rpi.edu>
On Wed, 9 Jun 2004, JR wrote:
> I'm not 100% sure I understand what you want, but try:
>
> #!/usr/local/bin/perl
> use strict;
use warnings;
> my $directory = 'foo/bar1/bar2/bar3/XYZ.txt';
> my @arr = split /\//, $directory;
> my @out = ();
Why are you declaring a variable you never use?
> my $info = undef;
That's a completely worthless initialization.
my $info;
does the same thing.
> my $count = 0;
That's an almost-completely worthless initialization
my $count;
will have the same effect sine all you're ever doing to count is
incrementing it. (An undef value increments to 1 without so much as a
warning).
> $info = qq|Parent Folder: $_\n{\n Some text here about "$arr[0]"\n|;
> $info .= qq| Child Folder: bar1\n|;
> $info .= qq| {\n|;
>
> my $indent = 6;
> for my $i (1..$#arr-1) {
> $info .= " " x $indent . qq|Some text here about "$arr[$i]"\n|;
> $info .= " " x $indent . qq|Child folder: $arr[$i+1]\n|;
> $info .= " " x $indent . qq|{\n|;
> $indent += 3;
> $count++;
> }
> $info .= " " x ($indent -= 3) . qq|}\n| for (0..$count+1);
>
> $info .= qq|\nFile element: Some text about "$arr[$#arr]"\n|;
> $info .= "=" x 39, "\n";
> print $info;
I'm not at all clear as to why you're building up this (potentially huge)
scalar to be printed only once at the end. Why are you not just printing
each line of text as it comes? Can you explain what benefit is to be
gained by storing all this text in memory before printing?
Paul Lalli
------------------------------
Date: 9 Jun 2004 12:35:36 -0700
From: russell.brooks@perdue.com
Subject: Counting elements in a hash
Message-Id: <43f48366.0406091135.27e5aa03@posting.google.com>
Hi,
I've created a hash of an array. There are a varying number of
elements in the arrays. I need to count the number of elements, and
although I have read through the documentation, I have been unable to
find a clean way of doing this.
For example,
$table{28}[0] = 541;
$table{36}[0] = 1024;
$table{36}[1] = 2048;
$table{36}[2] = 4096;
$table{36}[3] = 8192;
$table{51}[0] = 77;
What I'm trying to obtain is a count of values for each array in the
hash. For example, the above example has 4 values associated with
array 36.
scalar keys %table gives 3, which isn't what I need.
scalar keys $tables{28} is illegal since the arguments for keys must
be a hash, not a hash element.
Is iterating through the hash the best option?
Thanks,
Russ
------------------------------
Date: Wed, 9 Jun 2004 15:48:31 -0400
From: Paul Lalli <ittyspam@yahoo.com>
Subject: Re: Counting elements in a hash
Message-Id: <20040609154553.G8971@dishwasher.cs.rpi.edu>
On Wed, 9 Jun 2004 russell.brooks@perdue.com wrote:
> Hi,
> I've created a hash of an array. There are a varying number of
> elements in the arrays. I need to count the number of elements, and
> although I have read through the documentation, I have been unable to
> find a clean way of doing this.
> For example,
>
> $table{28}[0] = 541;
> $table{36}[0] = 1024;
> $table{36}[1] = 2048;
> $table{36}[2] = 4096;
> $table{36}[3] = 8192;
> $table{51}[0] = 77;
>
> What I'm trying to obtain is a count of values for each array in the
> hash. For example, the above example has 4 values associated with
> array 36.
>
> scalar keys %table gives 3, which isn't what I need.
> scalar keys $tables{28} is illegal since the arguments for keys must
> be a hash, not a hash element.
>
> Is iterating through the hash the best option?
You've made this more complicated than it is. $table{36} is an array
reference. You want to find the number of elements in the array
referenced by $table{36}, correct?
$size = @{$table{36}};
The @{ } syntax dereferences the given array reference. The assignment to
a scalar evaluates the resulting array in a scalar context, which results
in the size of that array.
Paul Lalli
------------------------------
Date: Wed, 09 Jun 2004 19:54:05 -0000
From: "David K. Wall" <dwall@fastmail.fm>
Subject: Re: Counting elements in a hash
Message-Id: <Xns9503A1C0CA314dkwwashere@216.168.3.30>
<russell.brooks@perdue.com> wrote:
> Hi,
> I've created a hash of an array. There are a varying number of
> elements in the arrays. I need to count the number of elements,
> and although I have read through the documentation, I have been
> unable to find a clean way of doing this.
> For example,
>
> $table{28}[0] = 541;
> $table{36}[0] = 1024;
> $table{36}[1] = 2048;
> $table{36}[2] = 4096;
> $table{36}[3] = 8192;
> $table{51}[0] = 77;
>
> What I'm trying to obtain is a count of values for each array in
> the hash. For example, the above example has 4 values associated
> with array 36.
>
> scalar keys %table gives 3, which isn't what I need.
> scalar keys $tables{28} is illegal since the arguments for keys
> must be a hash, not a hash element.
>
> Is iterating through the hash the best option?
You want the size of an *array*, right? The way to do that is to put
the array in scalar context, but $table{28} is a reference to an
array. So dereference it and then put it in scalar context.
my $size = @{$table{36}};
or you can be more specific, in case the normal context is list
context:
print scalar @{$table{36}};
(without using scalar() this would just print the elements of
@{$table{36}} )
------------------------------
Date: Wed, 9 Jun 2004 21:55:50 +0200
From: "Christian Winter" <thepoet_nospam@arcor.de>
Subject: Re: Counting elements in a hash
Message-Id: <40c76bae$0$22988$9b4e6d93@newsread2.arcor-online.net>
<russell.brooks@perdue.com> wrote:
> Hi,
> I've created a hash of an array. There are a varying number of
> elements in the arrays. I need to count the number of elements, and
> although I have read through the documentation, I have been unable to
> find a clean way of doing this.
You won't get around inspecting each hash element.
Either in a for() loop:
my $count;
$count += scalar @{$table{$_}} for(keys %table);
or if you need the count for each hash element,
with a map block like:
my %count = map {
$_ => scalar @{$table{$_}}
} keys %table;
-Christian
------------------------------
Date: Wed, 9 Jun 2004 19:01:51 +0000 (UTC)
From: Ben Morrow <usenet@morrow.me.uk>
Subject: Re: Exit status from 'die'
Message-Id: <ca7mqv$e3l$7@wisteria.csv.warwick.ac.uk>
Quoth Bernard Cosell <bernie@rev.net>:
> I'm trying to use a __DIE__ handler to manage the 'departure' of my
> program and I've noticed a bit of an oddity I'm not sure about to try
> to get the exit status to be correct.
>
> Given this scrap of code:
>
> sub Report
> { print $_[0];
> exit $! ;
What made you think $! contains the exit status? Try $?.
Ben
--
And if you wanna make sense / Whatcha looking at me for? (Fiona Apple)
* ben@morrow.me.uk *
------------------------------
Date: Wed, 9 Jun 2004 19:08:42 +0000 (UTC)
From: Ben Morrow <usenet@morrow.me.uk>
Subject: Re: Help me with threads issue !
Message-Id: <ca7n7q$e3l$8@wisteria.csv.warwick.ac.uk>
Quoth cji_work@yahoo.com (Charlie):
> I need some help from you about the thread issue I have.
> What I want to do is to simulate multi users to access one web server.
> I want to simulate as many as 200 users to assess that web server to
> check the performance from both the web server and the backend DB.
>
> The ways that I emploment it are: 1). to have the apache(version
> 1.3.31) installed on the Linux platform. 2) I am using the perl
> 5.8.4, along with some perl modules, such as Mechanize, threads to
> create the test scripts. And I put the test scripts under the dir of
> (Apache)/cgi-bin/.
Under linux (or any other platform which implements fork decently) there
is no point in using ithreads unless you need the functionality of
threads::shared (and even then, you can use forks.pm from CPAN to
simulate it). Forking will be both faster and safer.
Ben
--
Musica Dei donum optimi, trahit homines, trahit deos. |
Musica truces molit animos, tristesque mentes erigit. | ben@morrow.me.uk
Musica vel ipsas arbores et horridas movet feras. |
------------------------------
Date: Wed, 9 Jun 2004 18:42:39 +0000 (UTC)
From: Ben Morrow <usenet@morrow.me.uk>
Subject: Re: killing my children
Message-Id: <ca7lmu$e3l$3@wisteria.csv.warwick.ac.uk>
Quoth spacehopper_man@yahoo.com (Oliver):
> ok - thanks very much - I still have problems getting my children to
> exit - all works ok if I use POSIX::_exit :(
>
> problem - children not going away when they've finished their work.
>
> solution: fork as per normal - then keep track like this:
>
> sub is_alive {
> my $pid = shift;
> my $status = waitpid $pid, WNOHANG;
>
> return ($status == -1) ? 0 : 1;
This is wrong: waitpid with WNOHANG returns 0 if the child isn't dead.
return $status != -1 && $status;
> }
>
> and use SIG{CHLD} = 'IGNORE'
> it works!... nearly...
>
> it only works if the child exits like this:
>
> POSIX::_exit(0); # force exit now
>
> ..this is the crux of my problem.
> if I use normal perl 'exit' then the children hang around - and my
> parent process has also stopped exiting too.
>
> I guess what's happening is that some DESTROY or END method is hanging
> - and _exit skips these.
Note that children will *also* call any END blocks they've inherited
from the parent: if one of these is not expecting to be run in the
child, it may be hanging because some needed resource is no longer
available.
You can avoid this be recording the pid in tha parent and checking in
the END block that that is still your pid.
> or whether
> POSIX:_exit is likely to cause me problems ??
If your children contain any objects (created or inherited) that need
cleanup, then that cleanup won't occur. You will need to look at the
code to see whether that will be a problem (I would suggest that if the
children are inheriting complex objects they don;t need, you refactor
the code so that these are not created until after you fork...).
Ben
--
Like all men in Babylon I have been a proconsul; like all, a slave ... During
one lunar year, I have been declared invisible; I shrieked and was not heard,
I stole my bread and was not decapitated.
~ ben@morrow.me.uk ~ Jorge Luis Borges, 'The Babylon Lottery'
------------------------------
Date: Wed, 9 Jun 2004 18:56:19 +0000 (UTC)
From: Ben Morrow <usenet@morrow.me.uk>
Subject: Re: match aaa but not 123aaa
Message-Id: <ca7mgj$e3l$6@wisteria.csv.warwick.ac.uk>
Quoth Ken Sington <ken_sington@nospam_abcdefg.com>:
> Jay Tilton wrote:
>
> > Ken Sington <ken_sington@nospam_abcdefg.com> wrote:
> >
> ......
>
> >
> > /(?<!123)YaaaY/
> >
> > : my one liner didn't work
> > : $x =~ s/(!\123)(Y)(a{3})(Y)/$1$2$3$4/g;
> > : the ! doesn't seem to negate it.
> >
> > What did you read in perlre that made you believe it would?
>
> isn't ! suppose to negate??
Not in regexen.
> I thought I saw it used in regex somewhere, but I can't find it again.
> Has anyone seen such a thing?
No.
> Or am I having one of my many delusions?
Apparently.
Ben
--
don't get my sympathy hanging out the 15th floor. you've changed the locks 3
times, he still comes reeling though the door, and soon he'll get to you, teach
you how to get to purest hell. you do it to yourself and that's what really
hurts is you do it to yourself just you, you and noone else ** ben@morrow.me.uk
------------------------------
Date: 9 Jun 2004 14:09:46 -0700
From: tcsraj@yahoo.com (Raj Sathgunam)
Subject: Matching a word or Pattern in perl
Message-Id: <f81a1f8a.0406091309.5287940f@posting.google.com>
Hi ,
I have to match either one of the below output from a log file.
Match "No Activity" OR XYZ:10 ABC:30 MNO:10 PQR:5 .
I could get pattern for second one. How can i combine the patterns to
match either one of them. Id this valid
/No Activity/||/.+\sXYZ:(\d+)+\s+ABC:(\d+)+\s+MNO:(\d+)+\s+PQR:(\d+)/
Thanks
------------------------------
Date: Wed, 09 Jun 2004 23:34:43 +0200
From: Gunnar Strand <MyFirstnameHere.News1@gustra.org>
Subject: Re: Matching a word or Pattern in perl
Message-Id: <ca7vpg$ev4$1@hudsucker.umdac.umu.se>
Hi Raj,
Raj Sathgunam wrote:
> Hi ,
>
> I have to match either one of the below output from a log file.
> Match "No Activity" OR XYZ:10 ABC:30 MNO:10 PQR:5 .
> I could get pattern for second one. How can i combine the patterns to
> match either one of them. Id this valid
> /No Activity/||/.+\sXYZ:(\d+)+\s+ABC:(\d+)+\s+MNO:(\d+)+\s+PQR:(\d+)/
I'm no expert on re, but yes, it would be valid to have that expression,
but only if the string is in $_. Otherwise each pattern match would
need the variable as well:
$line =~ /No Activity/ || $line =~
/.+\sXYZ:(\d+)+\s+ABC:(\d+)+\s+MNO:(\d+)+\s+PQR:(\d+)/
You will find that the pluses after your number matches are superfluous:
(\d+)+ can be written (\d+)
If your log file contains many "No Activity" lines, then you will
probably find it to run faster if you use ordinary string comparison
for the no activity lines, eg.:
'No Activity' eq $_
or, if you haven't used 'chop' or 'chomp' on the string:
'No Activity\n' eq $_
(I am assuming the 'No Activity' is the only text on the line.)
Kind Regards,
/Gunnar
------------------------------
Date: Wed, 9 Jun 2004 18:46:25 +0000 (UTC)
From: Ben Morrow <usenet@morrow.me.uk>
Subject: Re: No-install Perl Interpretor
Message-Id: <ca7lu1$e3l$4@wisteria.csv.warwick.ac.uk>
Quoth Michele Dondi <bik.mido@tiscalinet.it>:
> On Mon, 07 Jun 2004 13:45:42 +0200, Micla <mick.lan@laposte.net>
> wrote:
>
> >Would anybody know a Perl version usable without any prior installation?
> >
> >One of the goals foreseen for it would be to have some "personal"
> >scripts on a USB memory key, immediately usable on any computer that I
> >have the opportunity to go on.
> >
> >But there are also other reasons to try to use Perl scripts without
> >installing Perl previously.
>
> IMHO it's unreasonable to think that you won't need at least some of
> the core modules. Now one possibility I have been thinking of for
> other reasons and with which I would like to make some experiments
> anyway is to spot the possibility[1] to put code in @INC to move
> *most*[2] of perl lib into, say, a zip archive. Of course this would
> be yet another instance of "trading time for space"...
>
> [1] That I recently mentioned in another thread, BTW!
> [2] It's obvious that a bunch of modules should remain available in a
> physical directory to make the thing work...
This is exactly what PAR does. It packs a perl, a script and a whole lot
of modules up into one executable that is able to find and use those
modules.
Ben
--
Razors pain you / Rivers are damp
Acids stain you / And drugs cause cramp. [Dorothy Parker]
Guns aren't lawful / Nooses give
Gas smells awful / You might as well live. ben@morrow.me.uk
------------------------------
Date: Wed, 09 Jun 2004 21:56:32 +0200
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: No-install Perl Interpretor
Message-Id: <d1aec0plkeecil7c4bsdp23vrcabacs4rn@4ax.com>
On Wed, 9 Jun 2004 14:29:03 +0000 (UTC), rdwillia@hgmp.mrc.ac.uk
(Richard Williams) wrote:
>>the core modules. Now one possibility I have been thinking of for
>>other reasons and with which I would like to make some experiments
>>anyway is to spot the possibility[1] to put code in @INC to move
>>*most*[2] of perl lib into, say, a zip archive. Of course this would
[snip]
>Tinyperl for Windows rather cleverly manages to use dozens of modules, yet
>the complete distribution is just 3 files (executable, 'PerlLib' as a
>.dll, and a zipfile of modules), plus docs. The .dll contains the
>Compress::Zlib XS module, which handles unpacking any other required
>modules from the zipfile into a temporary directory on the fly. The
>unpacked modules are deleted after use.
So probably it does *exactly* what I had in mind, except that I
wouldn't unpack to a temp dir at all...
Michele
--
you'll see that it shouldn't be so. AND, the writting as usuall is
fantastic incompetent. To illustrate, i quote:
- Xah Lee trolling on clpmisc,
"perl bug File::Basename and Perl's nature"
------------------------------
Date: 9 Jun 2004 20:17:44 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Print a section of a text file.
Message-Id: <ca7r98$54$1@mamenchi.zrz.TU-Berlin.DE>
Prabh <Prab_kar@hotmail.com> wrote in comp.lang.perl.misc:
> Paul Lalli <ittyspam@yahoo.com> wrote in message
> news:<20040607194210.N8971@dishwasher.cs.rpi.edu>...
> > On Mon, 7 Jun 2004, Prabh wrote:
[nested "{}"]
> > > Files Section:
> > > {
> > > File1:
> > > {
> > > Description1
> > > Size1
> > > Date1
> > > }
> > >
> > > File2:
> > > {
> > > Description2
> > > Size2
> > > Date2
> > > }
> > > }
[...]
> Heres a long shot, but anyone have an idea what algorithm the VI
> editor uses to match the { with the corresponding }. It does it so
> well, if the algorithm is simple enough, maybe I could replicate it
> :).
Well, this is really a job for Text::Balanced -- I think that has been
mentioned elsewhere.
For an ad-hoc solution, assume the whole file is read into $_ (if it's
too large for that, things get more complicated). The following prints
exactly the contents of the nested "{}" with no concern for line structure.
It may lose more line-feeds than is aesthetically pleasing.
my $bal = 0;
my $from;
while ( /([{}])/g ) {
$from = pos() - 1 if $bal == 0; # $bal will go up or we die
# ( $bal += 2*( $1 eq '{') - 1) >= 0 or die "unbalanced '}'"; # hi uri :)
$bal ++ if $1 eq '{';
$bal -- if $1 eq '}';
die "unbalanced '}'" if $bal < 0;
print substr( $_, $from, pos() - $from) if $bal == 0;
}
Anno
------------------------------
Date: 9 Jun 2004 20:42:14 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Print a section of a text file.
Message-Id: <ca7sn6$rg$1@mamenchi.zrz.TU-Berlin.DE>
Prabh <Prab_kar@hotmail.com> wrote in comp.lang.perl.misc:
[problem snipped on the assumption that everyone still around knows it]
> Hello all,
> I'm posting from Google, time-delay and all.
> I was able to print the Files section this way:
>
> =============================================================
>
> #!/usr/local/bin/perl
>
> use strict ;
> use warnings ;
>
> my $open_brace = 0 ; # Count the open braces
> my $close_brace = 0 ; # Count the close braces
> my $in_FilesSection = 0 ; # This will tell if I should start
> printing.
>
> open(FDL,"file.txt") or die "Can't open file.txt: $!\n" ;
> while(<FDL>)
> {
> chomp ;
No need to chomp, you only add the "\n" back on.
> $in_FilesSection = 1 if ( /^Files section/i ) ;
> if ( $in_FilesSection )
> {
> $open_brace++ if ( /\}/ ) ;
> $close_brace++ if ( /\{/ ) ;
There's no need to escape the {}.
> print "$_\n" ;
> last if ( ( $open_brace == $close_brace ) && (
> $open_brace and $close_brace != 0 ) ) ;
> }
>
> }
> close(FDL) ;
>
> ==================================================================
>
>
> Inside the Files section, I increment the open or close brace count
> and keep printing "$_" till the count of open brace is equal to close
> brace and they're non-zero.
You need only a single count. Increment on '{', decrement on '}'.
It's 0 outside {}, > 0 inside and negative on error.
> This did print the entire Files section and not just till the first }.
> I'd appreciate if someone could give some feedback on my solution.
Your solution assumes that all '{' and '}' are on a line by themselves.
It fails if a line is allowed to contain complete or partial blocks.
I have shown a solution that doesn't care about line feeds elsewhere
in this thread. For convenience I'll repeat the short version of the
code below.
Anno
my ( $bal, $from) = 0;
while ( /([{}])/g ) {
$from = pos() - 1 if $bal == 0;
$bal += 2*( $1 eq '{') - 1; # increment or decrement
print substr( $_, $from, pos() - $from) if $bal == 0;
}
------------------------------
Date: Wed, 09 Jun 2004 12:15:56 -0700
From: Jim Gibson <jgibson@mail.arc.nasa.gov>
Subject: Re: search engine
Message-Id: <090620041215567377%jgibson@mail.arc.nasa.gov>
In article <f65ac990.0406090331.78d70f8@posting.google.com>, Nitin
Thakur <nitinthakur@hotmail.com> wrote:
> Hi,
>
> I have written a script, which lists text files from a directory on a
> web page on our intranet site. I want to add search functionality to
> this page so that users can grep a regular expression and it lists
> those files. Is there any simple cgi/perl script available or can
> somebody give me some pointers as to how to make one.
>
> A speedy response would be appreciated.
I am typing as fast as I can. Unfortunately, I do not have time to test
my suggestions, so you are on your own.
>
> Cheers
>
> Nitin
>
> Here is the code for the listing the files
> =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
> #!/usr/bin/perl -w
> #Set Dir path.
> $dir = "/reports/";
> use CGI qw/:all/;
> $query = new CGI;
> @months=qw(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec);
> chdir $dir;
Get a file name pattern from a form on the web page:
my $pattern = $query->param('pattern');
Use this pattern to accept or reject files in the readdir loop, below:
>
> #Open dir and start listing and take time.
> opendir (DIR, "$dir") || die "Can not Reports: $!";
> foreach (readdir DIR) {
> ($dev, $ino, $mode, $nlink, $uid, $gid, $rdev, $size, $atime,
> $mtime, $ctime) = stat $_;
> next if !$dev;
> next if /^\./;
next unless /$pattern/; # skip files not matching pattern
> $dates{$_} = $mtime;
> $rdev = " ";
> $gid = " ";
> $ino = " ";
> $size = " ";
> $uid = " ";
> $mode = " ";
> $atime = " ";
> $ctime = " ";
> $nlink = " ";
> }
> closedir DIR || die "Can not close Dir: $!";
[ rest of program snipped ]
------------------------------
Date: Wed, 9 Jun 2004 18:33:30 +0000 (UTC)
From: Ben Morrow <usenet@morrow.me.uk>
Subject: Re: sub returning nothing
Message-Id: <ca7l5q$e3l$2@wisteria.csv.warwick.ac.uk>
Quoth Gunnar Strand <MyFirstnameHere.News1@gustra.org>:
> Brian McCauley wrote:
> > Gunnar Strand <MyFirstnameHere.News1@gustra.org> writes:
<snippage:
sub isok {
print $_[0] ? 'OK' : 'NOK';
print "\n";
}
sub void {
return;
}
now isok(void, 1) prints 'OK' not 'NOK'
>
> >>IMHO, it would have been nice if perl could have issued some kind
> >>of warning, since relying on 'nothing' as a return value seems...
> >>well, not-so-common.
> >
> >
> > I'm affraid that calling functions in a list context is common in
> > perl.
>
> Agreed. But it is going to make it more difficult to write test
> cases for methods erroneously
It is not erroneous. It is often necessary: if you wish a function to
return false in list context, it must return the empty list.
> using return; (or empty) instead of
> a valid value, as some tests will have to create the needed
> context (or at least when using Test::Unit::TestCase.)
I'm not quite understanding your usage of isok... AFAICS, isok takes one
argument, and you are calling it with two; so I wouldn't be surprised
when it doesn't do what you expect.
isok void;
correctly prints 'NOK';
isok 1 == void;
correctly prints 'NOK' as well.
I will assume you're not being stupid :), and that in fact your isok
function is more like:
sub isok {
print +( $_[0] ? 'ok' : 'not ok' ), " # $_[1]\n";
}
and your problem is that
isok void, 'testing void function';
prints 'ok' not 'not ok'. The answer here is that isok should have been
prototyped with ($$): in that case, the first arg would be evaluated in
scalar context, and would have been 'undef' not '()', and it would have
worked correctly.
If for some reason you don't wish to use prototypes then you must do the
work of adding scalar() where necessary yourself.
Ben
--
If you put all the prophets, | You'd have so much more reason
Mystics and saints | Than ever was born
In one room together, | Out of all of the conflicts of time.
ben@morrow.me.uk The Levellers, 'Believers'
------------------------------
Date: Wed, 09 Jun 2004 23:01:01 +0200
From: Gunnar Strand <MyFirstnameHere.News1@gustra.org>
Subject: Re: sub returning nothing
Message-Id: <ca7tqf$e8o$1@hudsucker.umdac.umu.se>
Ben Morrow wrote:
> Quoth Gunnar Strand <MyFirstnameHere.News1@gustra.org>:
>
>>Brian McCauley wrote:
>>
>>>Gunnar Strand <MyFirstnameHere.News1@gustra.org> writes:
>
[snip]
>>>I'm affraid that calling functions in a list context is common in
>>>perl.
>>
>>Agreed. But it is going to make it more difficult to write test
>>cases for methods erroneously
>
>
> It is not erroneous. It is often necessary: if you wish a function to
> return false in list context, it must return the empty list.
Of course, but in this case I was writing a test case for a sub
which was expected to return a scalar, so here it was in fact
erroneous. I just didn't expect the result I got.
>>using return; (or empty) instead of
>>a valid value, as some tests will have to create the needed
>>context (or at least when using Test::Unit::TestCase.)
>
>
> I'm not quite understanding your usage of isok... AFAICS, isok takes one
> argument, and you are calling it with two; so I wouldn't be surprised
> when it doesn't do what you expect.
> isok void;
>
> correctly prints 'NOK';
>
> isok 1 == void;
>
> correctly prints 'NOK' as well.
>
> I will assume you're not being stupid :), and that in fact your isok
> function is more like:
>
> sub isok {
> print +( $_[0] ? 'ok' : 'not ok' ), " # $_[1]\n";
> }
>
Good point, I should have used the second argument of isok in my
example for clarity. Thanks for your confidence, but sometimes I
wonder :-)
> and your problem is that
>
> isok void, 'testing void function';
>
> prints 'ok' not 'not ok'. The answer here is that isok should have been
> prototyped with ($$): in that case, the first arg would be evaluated in
> scalar context, and would have been 'undef' not '()', and it would have
> worked correctly.
Unfortunately what you are suggesting will not work since I am using
Test::Unit::TestCase::assert() (as isok), which can accept either one
or more arguments, so it has no chance of telling which way it was
called.
> If for some reason you don't wish to use prototypes then you must do the
> work of adding scalar() where necessary yourself.
Yes, I used the assert( myvoid() || '', "Function failed" ) trick I saw
in the thread Brian posted about this issue. It is just that a day
will come when I forget to add the scalar context and think my sub is
working hard, while it is actually in a coma at the hospital because I
didn't give it a brain.
Regards,
/Gunnar
------------------------------
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.
NOTE: due to the current flood of worm email banging on ruby, the smtp
server on ruby has been shut off until further notice.
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 6672
***************************************