[31880] in Perl-Users-Digest
Perl-Users Digest, Issue: 3143 Volume: 11
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sun Sep 26 00:09:31 2010
Date: Sat, 25 Sep 2010 21:09:14 -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 Sat, 25 Sep 2010 Volume: 11 Number: 3143
Today's topics:
How to exclude the lines that start with 0? <clearguy02@yahoo.com>
Re: How to exclude the lines that start with 0? <jurgenex@hotmail.com>
Re: How to exclude the lines that start with 0? <rvtol+usenet@xs4all.nl>
Re: How to initialize a referenced array? <jurgenex@hotmail.com>
Re: how to solve when no root privilege? <marc.girod@gmail.com>
Re: how to solve when no root privilege? <tadmc@seesig.invalid>
Re: how to solve when no root privilege? <ela@yantai.org>
Re: how to solve when no root privilege? <jurgenex@hotmail.com>
Re: how to solve when no root privilege? <ben@morrow.me.uk>
Re: how to solve when no root privilege? <ela@yantai.org>
Re: how to solve when no root privilege? <sherm.pendley@gmail.com>
Re: Long script "just stops" sometime <nospam-abuse@ilyaz.org>
toy list processing problem: collect similar terms <xahlee@gmail.com>
why does this happen? <merrilljensen@q.com>
Re: why does this happen? (Jens Thoms Toerring)
Re: why does this happen? <merrilljensen@q.com>
Re: why does this happen? <rkb@i.frys.com>
Re: why does this happen? <jurgenex@hotmail.com>
Re: why does this happen? <merrilljensen@q.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Sat, 25 Sep 2010 18:50:11 -0700 (PDT)
From: Rider <clearguy02@yahoo.com>
Subject: How to exclude the lines that start with 0?
Message-Id: <316caec9-d78f-4a21-b89b-eb5227ab7b32@c28g2000prj.googlegroups.com>
Hi experts,
It has been a long time I fiddled with perl scripts.
I want to exclude all the lines that start with 0 and print only the
lines starting with non-zeroes.
Here is the script and I am not sure what is wrong here. Can some one
help me in correcting the syntax error here? Or even a short-cut like
one liner?
+++++++++++++++++++++
while(<DATA>)
{
if (^$_ == 0)
{
next;
print;
}
}
__DATA__
0 x.txt
0 y.txt
0 z.txt
101 z.txt
203 a:txt
303 l.txt
------------------------------
Date: Sat, 25 Sep 2010 19:13:08 -0700
From: Jürgen Exner <jurgenex@hotmail.com>
Subject: Re: How to exclude the lines that start with 0?
Message-Id: <goat96thhgqni0pbq5ia2t1n5u4u0qp47o@4ax.com>
Rider <clearguy02@yahoo.com> wrote:
>I want to exclude all the lines that start with 0 and print only the
>lines starting with non-zeroes.
>
>Here is the script and I am not sure what is wrong here. Can some one
>help me in correcting the syntax error here? Or even a short-cut like
>one liner?
>
>+++++++++++++++++++++
>while(<DATA>)
> {
> if (^$_ == 0)
What is
^$_
supposed to do? Even if you meant to write a RE, it still doesn't make
much sense to numerically compare it to 0.
> {
> next;
> print;
> }
>}
while (<>){
print unless /^0/;
}
while (<>){
print unless substr($_, 0, 1) eq '0';
}
I'm sure there are many more possible ways.
jue
------------------------------
Date: Sun, 26 Sep 2010 04:35:21 +0200
From: "Dr.Ruud" <rvtol+usenet@xs4all.nl>
Subject: Re: How to exclude the lines that start with 0?
Message-Id: <4c9eb169$0$41107$e4fe514c@news.xs4all.nl>
On 2010-09-26 03:50, Rider wrote:
> I want to exclude all the lines that start with 0 and print only the
> lines starting with non-zeroes.
perl -ne '/^0/ or print' file
perl -ne '/^0/||print' file
perl -pe 's/^0.*//s' file
--
Ruud
------------------------------
Date: Sat, 25 Sep 2010 14:54:45 -0700
From: Jürgen Exner <jurgenex@hotmail.com>
Subject: Re: How to initialize a referenced array?
Message-Id: <plrs96dm4142fibd14m4cp0jaq4kqql6tf@4ax.com>
[Please do not top-post, that is considered rude]
[Trying to correct]
feltra <feltra@gmail.com> wrote:
>On Sep 25, 9:42 pm, Ben Morrow <b...@morrow.me.uk> wrote:
>> Quoth feltra <fel...@gmail.com>:
>>
>> > Am using arrays with only references in a sub-routine. While I got
>> > the hang of how to access an element of the array using the '->'
>> > operator, I do not know how to intialize this array. I.e. I want to
>> > be able to do something like
>>
>> > @myarr=(); $#myarr = -1;
>>
>> Assuming $aref holds an array reference, that would be
>> @$aref = (); $#$aref = -1;
>
>Basically I am copying one array to another, and within the sub, I
Ok, so just do
@target = @source;
>wouldn't know which one to init (ie. which is the receiving array),
>except thru references...
???
Are you trying to say that in order to pass an array to a sub (instead
of its elements) you have to pass a reference?
>It's possible that there is a better method than copying, but at least
>this solution will solve my problem for now..
Still there is no need to initialize the array.
As simple
@$target = @$source
should do.
jue
------------------------------
Date: Sat, 25 Sep 2010 13:35:30 -0700 (PDT)
From: Marc Girod <marc.girod@gmail.com>
Subject: Re: how to solve when no root privilege?
Message-Id: <63810317-8c26-4124-abf3-596d54da6ad9@i5g2000yqe.googlegroups.com>
On Sep 25, 3:23=A0pm, Sherm Pendley <sherm.pend...@gmail.com> wrote:
> The last issue is easy, and something you can do in your own scripts -
> have a look at 'perldoc lib'.
Or even if one cannot edit the script, on the command line:
perl -Idir foo
Assuming the module is found in directory 'dir', and the script is
'foo'.
I kind of understand that 'foo' has a shebang pointing to a perl,
which
doesn't have dir in its built-in @INC.
Guessing to compensate for lack of information.
Marc
------------------------------
Date: Sat, 25 Sep 2010 21:01:49 -0500
From: Tad McClellan <tadmc@seesig.invalid>
Subject: Re: how to solve when no root privilege?
Message-Id: <slrni9tad9.ibd.tadmc@tadbox.sbcglobal.net>
ela <ela@yantai.org> wrote:
> I'm using a perl that needs to access a module but since the perl is
> accessed from different paths so the module is "invisible".
The path to perl does not change what directories modules
can be found in for that perl.
Are you getting an error message of some sort?
If so, then what does the error message say?
Have you seen the Posting Guidelines that are posted here frequently?
> Since I don't
> have root privilege to place the module to the library path,
You do not need root privilege to add your module's path to
the list of paths that will be searched for modules.
> what can I do
> to solve the problem?
Add your module's path to the list of paths that will be searched for
modules. You can do this with a "use lib" directive (perldoc lib),
or by setting the PERL5LIB environment variable, or by using
the "-I" command line switch (perldoc perlrun) when you invoke perl.
> Either duplicating the perl and module or moving all
> the data files to the perl program path is a bad idea... though it does
> solve the problem...
data files do not go in module directories.
*program* files go in module directories.
--
Rest In Peace:
Jonah McClellan gave his life for his country in a
helicopter crash in Afghanistan on September 21,2010.
Please pray for his wife and three children.
------------------------------
Date: Sun, 26 Sep 2010 10:13:52 -0700
From: "ela" <ela@yantai.org>
Subject: Re: how to solve when no root privilege?
Message-Id: <i7ma8j$uc2$1@ijustice.itsc.cuhk.edu.hk>
"Tad McClellan" <tadmc@seesig.invalid> wrote in message
news:slrni9tad9.ibd.tadmc@tadbox.sbcglobal.net...
> ela <ela@yantai.org> wrote:
>
> Are you getting an error message of some sort?
>
> If so, then what does the error message say?
>
> Add your module's path to the list of paths that will be searched for
> modules. You can do this with a "use lib" directive (perldoc lib),
> or by setting the PERL5LIB environment variable, or by using
> the "-I" command line switch (perldoc perlrun) when you invoke perl.
Thanks Tad McClellan and Marc Girod, in fact after writing something like:
use lib '/myperl/ImportedModule';
the path error goes away. Unfortunately, another error comes out for the
line:
$db = ImportedModule->new( dict => $dictfile);
as:
Unquoted string "ImportedModule" may clash with future reserved word at
/myperl/test.pl line 26.
Can't locate object method "new" via package "ImportedModule" (perhaps you
forgot to load "ImportedModule"?) at /myperl/test.pl line 26.
In fact, in perl, is there any systematic way to troubleshoot? Google
"Unquoted string may clash with future reserved word at" or "Can't locate
object method " just return many irrelevant results. To start with perldoc,
I just don't know what specific topics should go with....
------------------------------
Date: Sat, 25 Sep 2010 19:21:26 -0700
From: Jürgen Exner <jurgenex@hotmail.com>
Subject: Re: how to solve when no root privilege?
Message-Id: <hebt96d4g62t279dlo18l7cq8gcroia1fp@4ax.com>
"ela" <ela@yantai.org> wrote:
>Unquoted string "ImportedModule" may clash with future reserved word at
>/myperl/test.pl line 26.
>
>In fact, in perl, is there any systematic way to troubleshoot? Google
>"Unquoted string may clash with future reserved word at" or "Can't locate
>object method " just return many irrelevant results. To start with perldoc,
>I just don't know what specific topics should go with....
perldoc perldiag
jue
------------------------------
Date: Sun, 26 Sep 2010 03:57:46 +0100
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: how to solve when no root privilege?
Message-Id: <aep2n7-3ma1.ln1@osiris.mauzo.dyndns.org>
Quoth "ela" <ela@yantai.org>:
>
> Unquoted string "ImportedModule" may clash with future reserved word at
> /myperl/test.pl line 26.
If you got that warning you're not using 'strict'. Please stop wasting
everybody's time.
(I also can't see any possible way you could get that warning for a word
that isn't entirely lowercase, but maybe I'm missing something...)
Ben
------------------------------
Date: Sun, 26 Sep 2010 11:11:36 -0700
From: "ela" <ela@yantai.org>
Subject: Re: how to solve when no root privilege?
Message-Id: <i7mdkr$vg6$1@ijustice.itsc.cuhk.edu.hk>
"Jürgen Exner" <jurgenex@hotmail.com> wrote in message
news:hebt96d4g62t279dlo18l7cq8gcroia1fp@4ax.com...
> perldoc perldiag
>
> jue
Thanks for your reference. After examination, I find out the problem comes
from that the library cannot be identified.
although http://perldoc.perl.org/lib.html tells what "use lib" does, it does
not give any examples and so I just don't know whether the directive is done
successfully. So is the following correct?
the module "a.pm" is placed at /pathA/dirA
=========
so in b.pl, I write:
use lib '/pathA/dirA';
a->new (something...);
=========
in a.pm,
package a;
=========
so is the whole thing correct?
------------------------------
Date: Sat, 25 Sep 2010 23:28:58 -0400
From: Sherm Pendley <sherm.pendley@gmail.com>
Subject: Re: how to solve when no root privilege?
Message-Id: <m2aan5chdx.fsf@sherm.shermpendley.com>
"ela" <ela@yantai.org> writes:
> "Jürgen Exner" <jurgenex@hotmail.com> wrote in message
> news:hebt96d4g62t279dlo18l7cq8gcroia1fp@4ax.com...
>> perldoc perldiag
>>
>> jue
>
> Thanks for your reference. After examination, I find out the problem comes
> from that the library cannot be identified.
>
> although http://perldoc.perl.org/lib.html tells what "use lib" does, it does
> not give any examples and so I just don't know whether the directive is done
> successfully. So is the following correct?
>
> the module "a.pm" is placed at /pathA/dirA
> =========
> so in b.pl, I write:
>
> use lib '/pathA/dirA';
>
> a->new (something...);
> =========
> in a.pm,
>
> package a;
> =========
> so is the whole thing correct?
No, it's incomplete. 'use lib' does nothing but add to @INC, the list
of directories in which a module is searched for. You still need to
'use' your module - i.e. 'use a'.
sherm--
--
Sherm Pendley
<http://camelbones.sourceforge.net>
Cocoa Developer
------------------------------
Date: Sat, 25 Sep 2010 20:50:16 +0000 (UTC)
From: Ilya Zakharevich <nospam-abuse@ilyaz.org>
Subject: Re: Long script "just stops" sometime
Message-Id: <slrni9so48.ntq.nospam-abuse@powdermilk.math.berkeley.edu>
On 2010-09-24, Jerry Krinock <jerrykrinock@gmail.com> wrote:
> operation, I find that its CPU and memory usage are hardly noticeable,
> maybe 3% and a few tens of megabytes.
>
> Are there any conditions under which Perl would "just stop"?
With no CPU usage? I would say it reads from STDIN. Did you try to
press Enter or C-d?
> Any suggestions to troubleshoot this would be appreciated.
Have not you heard about debugger? If this happens often, you can
just wait for it to happen in the debugger. If worse comes to worst,
and interactive debugging does not help, you can always start in
NonStop mode with `tracing', and look for the last several thousands
of lines when the `stop' happens.
Hope this helps,
Ilya
------------------------------
Date: Sat, 25 Sep 2010 21:05:13 -0700 (PDT)
From: Xah Lee <xahlee@gmail.com>
Subject: toy list processing problem: collect similar terms
Message-Id: <bbac4565-5e6f-47a5-be8c-76622fb6b908@u31g2000pru.googlegroups.com>
here's a interesting toy list processing problem.
I have a list of lists, where each sublist is labelled by
a number. I need to collect together the contents of all sublists
sharing
the same label. So if I have the list
((0 a b) (1 c d) (2 e f) (3 g h) (1 i j) (2 k l) (4 m n) (2 o p) (4 q
r) (5 s t))
where the first element of each sublist is the label, I need to
produce:
output:
((a b) (c d i j) (e f k l o p) (g h) (m n q r) (s t))
a Mathematica solution is here:
http://xahlee.org/UnixResource_dir/writ/notations_mma.html
R5RS Scheme lisp solution:
http://xahlee.org/UnixResource_dir/writ/Sourav_Mukherjee_sourav.work_gmail.=
scm
by Sourav Mukherjee
also, a Common Lisp solution can be found here:
http://groups.google.com/group/comp.lang.lisp/browse_frm/thread/5d1ded8824b=
c750b?
anyone care to give a solution in Python, Perl, javascript, or other
lang? am guessing the scheme solution can be much improved... perhaps
using some lib but that seems to show scheme is pretty weak if the lib
is non-standard.
Xah =E2=88=91 xahlee.org =E2=98=84
------------------------------
Date: Sat, 25 Sep 2010 17:30:19 -0600
From: Uno <merrilljensen@q.com>
Subject: why does this happen?
Message-Id: <8g7f0bFp1gU1@mid.individual.net>
Hello newsgroups,
How do I not have permission here, when all I did is increment from
perl1 to perl2. Does a file get stripped of its priveleges automatically.
$ ./perl1.pl
Placido P. Octopus
Polypacido P. Octopus
Placido P. Octopus
Polypacido Polyp Octopus
Placido P. Octopus
Placido Polyp Octopus
$ ./perl2.pl
bash: ./perl2.pl: Permission denied
$
This is the source:
$ cat perl2.pl
#!/usr/bin/perl
use strict;
use warnings;
my $string = "Placido P. Octopus\n";
my $regex = "P.";
my $string1 = $string;
print $string1;
$string1 =~ s/$regex/Polyp/;
print $string1;
print "\n";
my $string2 = $string;
print $string2;
$string2 =~ s/$regex/Polyp/g;
print $string2;
print "\n";
my $string3 = $string;
print $string3;
$string3 =~ s/\Q$regex/Polyp/;
print $string3;
print "\n";
# that's the last perl I used
# I build off what I have.
my $filename = "text1.txt"
print $filename
$
Thanks for you comment,
and cheers,
--
Uno
------------------------------
Date: 25 Sep 2010 23:51:23 GMT
From: jt@toerring.de (Jens Thoms Toerring)
Subject: Re: why does this happen?
Message-Id: <8g7g7rFqfnU1@mid.uni-berlin.de>
In comp.lang.perl.misc Uno <merrilljensen@q.com> wrote:
> How do I not have permission here, when all I did is increment from
> perl1 to perl2. Does a file get stripped of its priveleges automatically.
> $ ./perl1.pl
> Placido P. Octopus
> Polypacido P. Octopus
> $ ./perl2.pl
> bash: ./perl2.pl: Permission denied
> $
This is not at all related to Perl (as the leading "bash:"
in the error messages indicates, it's something from the
shell (bash) you're using). You don't have execute permis-
sions for the new file 'perl2.pl', resulting from whatever
you did but do not tell (there's no "increment" from "perl1"
to "perl2"). Do
chmod 755 perl2.pl
or
chmod +x perl2.pl
and things will start to work again.
Jens
--
\ Jens Thoms Toerring ___ jt@toerring.de
\__________________________ http://toerring.de
------------------------------
Date: Sat, 25 Sep 2010 19:25:56 -0600
From: Uno <merrilljensen@q.com>
Subject: Re: why does this happen?
Message-Id: <8g7lp3FpvtU1@mid.individual.net>
Jens Thoms Toerring wrote:
> In comp.lang.perl.misc Uno <merrilljensen@q.com> wrote:
>> Does a file get stripped of its priveleges automatically.
> This is not at all related to Perl (as the leading "bash:"
> in the error messages indicates, it's something from the
> shell (bash) you're using). You don't have execute permis-
> sions for the new file 'perl2.pl', resulting from whatever
> you did but do not tell (there's no "increment" from "perl1"
> to "perl2"). Do
>
> chmod 755 perl2.pl
>
> or
>
> chmod +x perl2.pl
>
> and things will start to work again.
>
> Jens
Na, Jens, why the heck does my OS change permissions when I rename a file?
$ ./perl2.pl
Placido P. Octopus
Polypacido P. Octopus
Placido P. Octopus
Polypacido Polyp Octopus
Placido P. Octopus
Placido Polyp Octopus
text1.txt
$ cat perl2.pl
#!/usr/bin/perl
use strict;
use warnings;
my $string = "Placido P. Octopus\n";
my $regex = "P.";
my $string1 = $string;
print $string1;
$string1 =~ s/$regex/Polyp/;
print $string1;
print "\n";
my $string2 = $string;
print $string2;
$string2 =~ s/$regex/Polyp/g;
print $string2;
print "\n";
my $string3 = $string;
print $string3;
$string3 =~ s/\Q$regex/Polyp/;
print $string3;
print "\n";
# that's the last perl I used
# I build off what I have.
my $filename = "text1.txt";
print "$filename\n";
#end program
$
Tscheuss und gruss,
Jens, aka,
--
Uno
------------------------------
Date: Sat, 25 Sep 2010 19:05:42 -0700 (PDT)
From: Ron Bergin <rkb@i.frys.com>
Subject: Re: why does this happen?
Message-Id: <98294d6b-0594-43ad-8852-020cf4039a6c@y32g2000prc.googlegroups.com>
On Sep 25, 6:25=A0pm, Uno <merrilljen...@q.com> wrote:
> Jens Thoms Toerring wrote:
> > In comp.lang.perl.misc Uno <merrilljen...@q.com> wrote:
> >> Does a file get stripped of its priveleges automatically.
> > This is not at all related to Perl (as the leading "bash:"
> > in the error messages indicates, it's something from the
> > shell (bash) you're using). You don't have execute permis-
> > sions for the new file 'perl2.pl', resulting from whatever
> > you did but do not tell (there's no "increment" from "perl1"
> > to "perl2"). Do
>
> > =A0 chmod 755 perl2.pl
>
> > or
>
> > =A0 chmod +x perl2.pl
>
> > and things will start to work again.
>
> > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 Jens
>
> Na, Jens, why the heck does my OS change permissions when I rename a file=
?
>
Your OS won't do that, but since you didn't show us how you renamed
the file, we can't say what you did wrong.
------------------------------
Date: Sat, 25 Sep 2010 19:16:59 -0700
From: Jürgen Exner <jurgenex@hotmail.com>
Subject: Re: why does this happen?
Message-Id: <b5bt9611ha8gif4jl9imof2bgsha5ms713@4ax.com>
Uno <merrilljensen@q.com> wrote:
>Jens Thoms Toerring wrote:
>> In comp.lang.perl.misc Uno <merrilljensen@q.com> wrote:
>
>>> Does a file get stripped of its priveleges automatically.
>> This is not at all related to Perl (as the leading "bash:"
>> in the error messages indicates, it's something from the
>> shell (bash) you're using). You don't have execute permis-
>> sions for the new file 'perl2.pl', resulting from whatever
>> you did but do not tell (there's no "increment" from "perl1"
>> to "perl2"). Do
>>
>> chmod 755 perl2.pl
>>
>> or
>>
>> chmod +x perl2.pl
>>
>> and things will start to work again.
>>
>> Jens
>
>Na, Jens, why the heck does my OS change permissions when I rename a file?
You may want to ask in NG that deals with whatever OS you are using (you
didn't even say!).
Aside of that Jens was right: that error message is not a Perl error
message, it is clearly issued by your shell.
jue
------------------------------
Date: Sat, 25 Sep 2010 21:33:04 -0600
From: Uno <merrilljensen@q.com>
Subject: Re: why does this happen?
Message-Id: <8g7t7fFtu8U1@mid.individual.net>
Jürgen Exner wrote:
> You may want to ask in NG that deals with whatever OS you are using (you
> didn't even say!).
I x-posted to ubuntu.
>
> Aside of that Jens was right: that error message is not a Perl error
> message, it is clearly issued by your shell.
Nuts, jue, I have every belief that it wasn't perl. Maybe you can help
me with this while the other subthread considers the part that is
germane to perl.
So I rename rm1.f90 to rm2.f90, and I have no problem on the command
line except to iterate the integer that postpends the source file.
Why is perl different?
Gruss,
--
Uno
------------------------------
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:
To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.
Back issues are available via anonymous ftp from
ftp://cil-www.oce.orst.edu/pub/perl/old-digests.
#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 V11 Issue 3143
***************************************