[29292] in Perl-Users-Digest
Perl-Users Digest, Issue: 536 Volume: 11
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Jun 19 18:10:13 2007
Date: Tue, 19 Jun 2007 15:09:06 -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 Tue, 19 Jun 2007 Volume: 11 Number: 536
Today's topics:
Re: Generic Syntax highlighting module <brian.raven@osbsl.co.uk>
Re: help with getting pid!! <dummy@example.com>
Re: help with getting pid!! <jurgenex@hotmail.com>
Re: help with getting pid!! xhoster@gmail.com
Re: How to test weather something is a func,method or v <ch.l.ngre@online.de>
Re: lightweight access to large data structures? <nospam-abuse@ilyaz.org>
Re: lightweight access to large data structures? xhoster@gmail.com
Re: lightweight access to large data structures? <nospam-abuse@ilyaz.org>
Re: paragraph mode <grahn+nntp@snipabacken.dyndns.org>
Re: perl and php <eflorac@imaginet.fr>
Re: question about sorting syntax <corn29@excite.com>
Re: question about sorting syntax <uri@stemsystems.com>
Re: RegEx Solution Needed <purlgurl@purlgurl.net>
Re: RegEx Solution Needed <dummy@example.com>
Re: The Modernization of Emacs <iamfractal@hotmail.com>
Re: The Modernization of Emacs <lew@lewscanon.nospam>
Re: Which Perl 5 OO extension can be seen as "standard" <ch.l.ngre@online.de>
writing to file fails <vahid.moghaddasi@gmail.com>
Re: writing to file fails <vahid.moghaddasi@gmail.com>
Re: writing to file fails <mritty@gmail.com>
Re: writing to file fails <glex_no-spam@qwest-spam-no.invalid>
Re: writing to file fails <vahid.moghaddasi@gmail.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Tue, 19 Jun 2007 22:18:10 +0100
From: Brian Raven <brian.raven@osbsl.co.uk>
Subject: Re: Generic Syntax highlighting module
Message-Id: <zm2v8wz1.fsf@osbsl.co.uk>
Stephen O'D <stephen.odonnell@gmail.com> writes:
> On Jun 18, 5:39 am, "Asim Suter" <asu...@cisco.com> wrote:
>> For an editor have you tried gvim yet ?
>>
>> Asim Suter
>>
>> "Stephen O'D" <stephen.odonn...@gmail.com> wrote in message
>>
>> news:1182087183.374807.65020@m36g2000hse.googlegroups.com...
>>
>> > Guys,
>>
>> > I am looking for a module that can syntax highlight lots of different
>> > types of source code so I can display it in a browser.
>>
>> > I have tried installing Syntax::Highlight::Universal, which is based
>> > on the Colorer library, but it fails to compile for me and the module
>> > doesn't seem to be maintained any more.
>>
>> > Any suggestions of a good module to use that supports many different
>> > languages?
>>
>> > thanks,
>>
>> > Stephen.
>
> I am more of an emacs fan to be honest :) I don't want to create
> myself an editor, I want to be able to display syntax highlighted code
> in a browser, and support many languages ...
http://www.gnu.org/software/src-highlite/
HTH
--
Brian Raven
------------------------------
Date: Tue, 19 Jun 2007 18:38:08 GMT
From: "John W. Krahn" <dummy@example.com>
Subject: Re: help with getting pid!!
Message-Id: <koVdi.38604$vT6.104@edtnps90>
seema wrote:
> Hi all,
>
> I am new to perl programming, I have return a perl script to get the
> pid of all my_app currently running on HP-UX box,
>
> #!/usr/bin/perl
>
> @process_array= `ps -ef | grep my_app | grep -v grep | awk '{print
> $2}'`;
>
> foreach $index (@process_array)
> {
> print $index, "\n";
> }
>
> It doesnt give the pid of my_app am I doing some thing wrong here??
> Thanks in advance,
#!/usr/bin/perl
use warnings;
use strict;
my @process_array = `ps -C my_app` =~ /^\s*(\d+)/gm;
print map "$_\n", @process_array;
John
--
Perl isn't a toolbox, but a small machine shop where you
can special-order certain sorts of tools at low cost and
in short order. -- Larry Wall
------------------------------
Date: Tue, 19 Jun 2007 18:50:27 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: help with getting pid!!
Message-Id: <TzVdi.3162$Sm5.2576@trndny04>
seema wrote:
> I am new to perl programming, I have return a perl script to get the
> pid of all my_app currently running on HP-UX box,
>
> #!/usr/bin/perl
> @process_array= `ps -ef | grep my_app | grep -v grep | awk '{print
> $2}'`;
> foreach $index (@process_array)
> {
> print $index, "\n";
> }
>
> It doesnt give the pid of my_app am I doing some thing wrong here??
Well, your _Perl_ code doesn't do much but printing the content of the array
@process_array and that looks ok to me.
Maybe you can check what that awful external command does and what it prints
to STDOUT?
BTW: why do you use Perl at all if all you do is printing the output of a
shell command?
jue
------------------------------
Date: 19 Jun 2007 19:32:29 GMT
From: xhoster@gmail.com
Subject: Re: help with getting pid!!
Message-Id: <20070619153231.915$cn@newsreader.com>
seema <seema_coma@yahoo.co.in> wrote:
> Hi all,
>
> I am new to perl programming, I have return a perl script to get the
> pid of all my_app currently running on HP-UX box,
>
> #!/usr/bin/perl
>
> @process_array= `ps -ef | grep my_app | grep -v grep | awk '{print
> $2}'`;
If you had turned on warnings, then Perl would have told you
(approximately) what the problem is. Perl is interpolating its own $2, so
what awk sees is not literally $2, but rather the value that was held in
Perl's variable named $2.
Xho
--
-------------------- http://NewsReader.Com/ --------------------
Usenet Newsgroup Service $9.95/Month 30GB
------------------------------
Date: Tue, 19 Jun 2007 22:50:42 +0200
From: Ch Lamprecht <ch.l.ngre@online.de>
Subject: Re: How to test weather something is a func,method or var
Message-Id: <f59fj1$212$3@online.de>
muede wrote:
> But I guess there is no such straight way for telling if
> something is a
> Foo->method or
> Foo::func,
>
> because it is just a matter of how the programmer of the module wanted
> these to be used. To perl they are just CODE or subs. All that the
> operator '->' does is adding the module name to the argument list.
No, it will search for the appropriate method in Foo's inheritance tree (instead
of just calling Foo::method). That makes quite a difference...
Christoph
--
ch.l.ngre-nospam-@online.de
------------------------------
Date: Tue, 19 Jun 2007 18:40:03 +0000 (UTC)
From: Ilya Zakharevich <nospam-abuse@ilyaz.org>
Subject: Re: lightweight access to large data structures?
Message-Id: <f597u3$223m$1@agate.berkeley.edu>
[A complimentary Cc of this posting was sent to
<xhoster@gmail.com>], who wrote in article <20070618183757.507$9o@newsreader.com>:
> usenet@DavidFilmer.com wrote:
> > On Jun 18, 2:20 pm, ivo...@gmail.com wrote:
> > > I have a 300MB .csv data file...
> > > it gobbled up about 4GB of RAM
> >
> > There's no reason why 300 MB of input data should consume 4 GB when
> > imported into a Perl data structure.
>
> Sure there is. Perl has all kinds of memory overhead. Heck, I'm surprised
> it doesn't take more, given that in his example, each chunk of data is only
> a few bytes.
Correct.
> For each chunk, you have to have a full scalar struct
> (about 20 bytes), plus you need the string storage (starts at about 12
> bytes, even if the string is only one character long).
Wrong. With Perl's malloc(), the minimal allocated buffer is 4bytes.
With system's malloc() - is, obviously, system-dependent.
> Then he has many, many hash structures, each with high overhead.
Correct.
Hope this helps,
Ilya
------------------------------
Date: 19 Jun 2007 19:24:45 GMT
From: xhoster@gmail.com
Subject: Re: lightweight access to large data structures?
Message-Id: <20070619152447.613$lv@newsreader.com>
Ilya Zakharevich <nospam-abuse@ilyaz.org> wrote:
> [A complimentary Cc of this posting was sent to
>
> <xhoster@gmail.com>], who wrote in article
> <20070618183757.507$9o@newsreader.com>:
> > usenet@DavidFilmer.com wrote:
> > > On Jun 18, 2:20 pm, ivo...@gmail.com wrote:
> > > > I have a 300MB .csv data file...
> > > > it gobbled up about 4GB of RAM
> > >
> > > There's no reason why 300 MB of input data should consume 4 GB when
> > > imported into a Perl data structure.
> >
> > Sure there is. Perl has all kinds of memory overhead. Heck, I'm
> > surprised it doesn't take more, given that in his example, each chunk
> > of data is only a few bytes.
>
> Correct.
>
> > For each chunk, you have to have a full scalar struct
> > (about 20 bytes), plus you need the string storage (starts at about 12
> > bytes, even if the string is only one character long).
>
> Wrong. With Perl's malloc(), the minimal allocated buffer is 4bytes.
That may be the minimal amount of space that Perl is capable of allocating,
but that does mean it is not the minimal amount of space that Perl actually
does allocate in any given circumstance. Indeed, under my 64 bit version
of perl it seems that the minimum space allocated for string storage for a
small string is 24 bytes, not the 12 bytes it was last time I checked on a
32 bit system.
#!/usr/bin/perl
use strict;
use warnings;
my @x;
push @x, '' foreach 0..1_000_000;
print "start\t", +(`ps -p $$ -o rss `)[1];
foreach my $size (1..1000) {
$_ .= 'x' foreach (@x) ;
print "$size\t", +(`ps -p $$ -o rss `)[1];
}
__END__
Notice below how no meaningful additional space is needed until the strings
reach 24 bytes long.
$ perl scalar_size2.pl
start 82432
1 82436
2 82436
3 82436
4 82436
5 82436
6 82436
7 82436
8 82436
9 82436
10 82436
11 82436
12 82436
13 82436
14 82436
15 82436
16 82436
17 82436
18 82436
19 82436
20 82436
21 82436
22 82436
23 82436
24 98280
25 98280
26 98280
27 98280
28 98280
29 98280
30 98280
31 98280
32 98280
33 98280
34 98280
35 98280
36 98280
37 98280
38 98280
39 98280
40 113988
41 113988
42 113988
43 113988
44 113988
45 113988
Xho
--
-------------------- http://NewsReader.Com/ --------------------
Usenet Newsgroup Service $9.95/Month 30GB
------------------------------
Date: Tue, 19 Jun 2007 22:05:23 +0000 (UTC)
From: Ilya Zakharevich <nospam-abuse@ilyaz.org>
Subject: Re: lightweight access to large data structures?
Message-Id: <f59jv3$25l2$1@agate.berkeley.edu>
[A complimentary Cc of this posting was sent to
<xhoster@gmail.com>], who wrote in article <20070619152447.613$lv@newsreader.com>:
> > > For each chunk, you have to have a full scalar struct
> > > (about 20 bytes), plus you need the string storage (starts at about 12
> > > bytes, even if the string is only one character long).
> > Wrong. With Perl's malloc(), the minimal allocated buffer is 4bytes.
> That may be the minimal amount of space that Perl is capable of allocating,
> but that does mean it is not the minimal amount of space that Perl actually
> does allocate in any given circumstance.
This does not even parse.
> Indeed, under my 64 bit version
> of perl it seems that the minimum space allocated for string storage for a
> small string is 24 bytes, not the 12 bytes it was last time I checked on a
As I explain, there is no "indeed". Unless you specify that your
usemymalloc=y.
Hope this helps,
Ilya
------------------------------
Date: 19 Jun 2007 20:42:21 GMT
From: Jorgen Grahn <grahn+nntp@snipabacken.dyndns.org>
Subject: Re: paragraph mode
Message-Id: <slrnf7gftm.52s.grahn+nntp@frailea.sa.invalid>
On Mon, 18 Jun 2007 17:32:40 -0500, Tad McClellan <tadmc@seesig.invalid> wrote:
> Larry <larry.grant.dc@gmail.com> wrote:
>> Is there any exact definition of "paragraph mode", i.e.
...
>> However, I am quite sure I have seen "0a 20 0a" treated as a
>> "paragraph boundary" under Linux (can't test it so easily right now).
>
> I doubt it.
Yes; "Linux" most likely have no particular opinion about paragraphs.
On the other hand, emacs' backward-paragraph function /does/ treat a
line with a blankspace as a paragraph separator. I didn't expect it
to, but it did.
/Jorgen
--
// Jorgen Grahn <grahn@ Ph'nglui mglw'nafh Cthulhu
\X/ snipabacken.dyndns.org> R'lyeh wgah'nagl fhtagn!
------------------------------
Date: Tue, 19 Jun 2007 21:32:41 +0200
From: Emmanuel Florac <eflorac@imaginet.fr>
Subject: Re: perl and php
Message-Id: <pan.2007.06.19.19.32.41.641418@imaginet.fr>
Le Mon, 18 Jun 2007 19:08:59 -0700, skywriter14 a écrit :
>
> Please tell me why there are tons of web sites made with PHP as compared
> to Perl or any other language, if PHP is worse than Perl and Ruby. How
> does it survive? Not only the rookies program with PHP, isn't it?
Probably because a tremendous number of rookies started with php and go on
using it when they become more proficient. You know the best tool isn't
the more common, actually most common tools ( Windows, Java, PHP ) usually
suck more :) "100 billions flies eat shit, why shouldn't we?"
--
Je suis riche des biens dont je sais me passer.
Louis-Jean-Baptiste Etienne Vigée.
------------------------------
Date: Tue, 19 Jun 2007 11:39:15 -0700
From: Adam Sandler <corn29@excite.com>
Subject: Re: question about sorting syntax
Message-Id: <1182278355.955946.196540@n60g2000hse.googlegroups.com>
On Jun 15, 1:47 pm, Paul Lalli <mri...@gmail.com> wrote:
> I would be very curious to see where this code originated.
I found the same exact code snippet on a handful of sites... including
sites by authors who also post here. Here is the URL of the page
which I bookmarked:
http://www.perlmonks.org/?node=145659
Thanks to everyone for their responses
------------------------------
Date: Tue, 19 Jun 2007 19:04:57 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: question about sorting syntax
Message-Id: <x7hcp37okm.fsf@mail.sysarch.com>
>>>>> "AS" == Adam Sandler <corn29@excite.com> writes:
AS> On Jun 15, 1:47 pm, Paul Lalli <mri...@gmail.com> wrote:
>> I would be very curious to see where this code originated.
AS> I found the same exact code snippet on a handful of sites... including
AS> sites by authors who also post here. Here is the URL of the page
AS> which I bookmarked:
AS> http://www.perlmonks.org/?node=145659
AS> Thanks to everyone for their responses
and check out Sort::Maker on cpan which can do this sort for you very
easily and it can be among the fastest ways to sort in perl. you might
also learn a lot from the docs on the various sorting styles including
the ST and GRT.
uri
--
Uri Guttman ------ uri@stemsystems.com -------- http://www.stemsystems.com
--Perl Consulting, Stem Development, Systems Architecture, Design and Coding-
Search or Offer Perl Jobs ---------------------------- http://jobs.perl.org
------------------------------
Date: Tue, 19 Jun 2007 11:27:48 -0700
From: Purl Gurl <purlgurl@purlgurl.net>
Subject: Re: RegEx Solution Needed
Message-Id: <GeSdnUpvF8q1veXbnZ2dnUVZ_jmdnZ2d@giganews.com>
Matt White wrote:
> I am in need of an effective regular expression that will capture
> multiple values on the same line, not knowing in advance how many
> matching values there are. Basically it needs to match strings of 3
> digits within a string that contains anything (all on the same line).
> abc123def456ghi789jkl
> I want to end up with a list that looks like:
> [123,456,789]
Your article is gibberish. Your "contains anything" includes a number
or strings of numbers or oddball characters or megabytes of binary data,
or literally anything which includes a week old pizza and a kitchen sink.
My presumption is, based on your gibberish, you have a string which contains
multiple sets of three numbers delimited by alphabet characters, a to z, only.
Work towards writing articles which are clear, concise and coherent rather
than writing gibberish. I find gibberish writers to be annoying.
#!perl
$string = "abc123def456ghi789jkl";
$string =~ tr/a-z//d;
1 while $string =~ s/(\d{3})(\d{3})/$1,$2/;
@List = split (/,/, $string);
print "@List";
PRINTED RESULTS:
123 456 789
--
Purl Gurl
--
"Then again what can you expect from a fat-assed, champagne swilling,
half-breed just off the Rez?"
- Joe Kline
------------------------------
Date: Tue, 19 Jun 2007 18:42:28 GMT
From: "John W. Krahn" <dummy@example.com>
Subject: Re: RegEx Solution Needed
Message-Id: <osVdi.8$xk5.2@edtnps82>
Matt White wrote:
> Hello,
>
> I am in need of an effective regular expression that will capture
> multiple values on the same line, not knowing in advance how many
> matching values there are. Basically it needs to match strings of 3
> digits within a string that contains anything (all on the same line).
> I am pretty familiar with regular expressions but I've never tried
> anything like this before.
>
> So what I have is a line like:
> abc123def456ghi789jkl
>
> I want to end up with a list that looks like:
> [123,456,789]
$ perl -le'
$_ = q/abc123def456ghi789jkl/;
print for /(?<=\D)\d{1,3}(?=\D)/g;
'
123
456
789
$ perl -le'
$_ = q/abc123def456ghi789jkl/;
print for grep 3 == length, /\d+/g;
'
123
456
789
John
--
Perl isn't a toolbox, but a small machine shop where you
can special-order certain sorts of tools at low cost and
in short order. -- Larry Wall
------------------------------
Date: Tue, 19 Jun 2007 12:21:15 -0700
From: Ed <iamfractal@hotmail.com>
Subject: Re: The Modernization of Emacs
Message-Id: <1182280875.861486.324370@w5g2000hsg.googlegroups.com>
On 19 Juni, 07:14, Harry George
>
> I've used emacs since the 1980's.
...
> --
> Harry George
> PLM Engineering Architecture
I've asked this question on an emacs forum and got no response, so I
presume the answer is no, but I see, Harry, that you're a veteran, so
maybe you've seen things few others have.
Have you ever seen an, "Extract method," function for emacs? Whereby
you highlight some lines of code, press a key, and the code is whisked
into its own method, with the appropriate method invocation left in
its place. If you could post a link, that'd be just champion.
.ed
--
www.EdmundKirwan.com - Home of The Fractal Class Composition
------------------------------
Date: Tue, 19 Jun 2007 16:20:36 -0400
From: Lew <lew@lewscanon.nospam>
Subject: Re: The Modernization of Emacs
Message-Id: <DuadnZPj1PsJp-XbnZ2dnUVZ_q2pnZ2d@comcast.com>
Ed wrote:
> On 19 Juni, 07:14, Harry George
>> I've used emacs since the 1980's.
> ...
>> --
>> Harry George
>> PLM Engineering Architecture
>
> I've asked this question on an emacs forum and got no response, so I
> presume the answer is no, but I see, Harry, that you're a veteran, so
> maybe you've seen things few others have.
>
> Have you ever seen an, "Extract method," function for emacs? Whereby
> you highlight some lines of code, press a key, and the code is whisked
> into its own method, with the appropriate method invocation left in
> its place. If you could post a link, that'd be just champion.
I googled about a bit and came up with
<http://bicyclerepair.sourceforge.net/>
linked from
<http://en.wikipedia.org/wiki/Refactoring>
I also looked at emacs's own "Info" pages and found this tidbit:
> `M-x c-beginning-of-defun'
> `M-x c-end-of-defun'
> Move point to the beginning or end of the current function or
> top-level definition. These are found by searching for the least
> enclosing braces. (By contrast, `beginning-of-defun' and
> `end-of-defun' search for braces in column zero.) If you are
> editing code where the opening brace of a function isn't placed in
> column zero, you may wish to bind `C-M-a' and `C-M-e' to these
> commands. *Note Moving by Defuns::.
>
> `M-a'
> Move point to the beginning of the innermost C statement
> (`c-beginning-of-statement'). If point is already at the beginning
> of a statement, move to the beginning of the preceding statement.
> With prefix argument N, move back N - 1 statements.
>
> In comments or in strings which span more than one line, this
> command moves by sentences instead of statements.
>
> `M-e'
> Move point to the end of the innermost C statement or sentence;
> like `M-a' except that it moves in the other direction
> (`c-end-of-statement').
You could, and I believe others have, create a macro to encapsulate these
actions with setting the mark and copying the region.
Here is a very promising-looking one that I found for C(**) and Java:
<http://xref-tech.com/speller/main.html>
GWMF.
--
Lew
------------------------------
Date: Tue, 19 Jun 2007 22:40:44 +0200
From: Ch Lamprecht <ch.l.ngre@online.de>
Subject: Re: Which Perl 5 OO extension can be seen as "standard" (defacto, quasi)?
Message-Id: <f59f0b$212$2@online.de>
Ilias Lazaridis wrote:
> I dislike the verbosity:
>
> has 'x' => (is => 'rw', isa => 'Int');
> has 'y' => (is => 'rw', isa => 'Int');
You don't need the type constraint here:
has 'x' => (is=>'rw');
has 'y' => (is=>'rw');
If that's still too verbose for you you could wrap &has and make (is=>'rw') default.
>
> sub clear {
> my $self = shift;
> $self->x(0);
> $self->y(0);
> }
>
--
use Tk;use Tk::GraphItems;$c=tkinit->Canvas->pack;push@i,Tk::GraphItems->
TextBox(text=>$_,canvas=>$c,x=>$x+=70,y=>100)for(Just=>another=>Perl=>Hacker);
Tk::GraphItems->Connector(source=>$i[$_],target=>$i[$_+1])for(0..2);
$c->repeat(30,sub{$_->move(0,4*cos($d+=3.16))for(@i)});MainLoop
------------------------------
Date: Tue, 19 Jun 2007 14:14:53 -0700
From: Vahid <vahid.moghaddasi@gmail.com>
Subject: writing to file fails
Message-Id: <1182287693.826236.262880@u2g2000hsc.googlegroups.com>
Hi all;
I am trying to read two files and write the result into the third file
but keep getting "..undefined value as a symbol.." error. Can someone
please tell me what am I doing wrong? Thank you.
#!/usr/bin/perl -w
#
#
#use strict; # if uncomment this, I get many errors.
use warnings;
$ENV{'PATH'} = "/usr/sbin:/sbin:/bin:/usr/bin:/usr/local/bin:";
my $SHADOW = etc_shadow;
my $secSHADOW = sec_passwd;
$|=1;
#
#
#
open (SHADOWfh, "<$SHADOW") || die "Can not open the file: $SHADOW\n";
open (secSHADOWfh, ">$secSHADOW") || die "Can not open the file:
$secSHADOW\n";
my @lines = <SHADOWfh> ;
foreach my $line (@lines) {
my ($username,$pass,$lastchange) = split /:/, $line;
my $sec_lastupdate = ($lastchange*86400);
printf ("%s:\n\tpassword = %s\n\tlastupdate = %d\n\tflags = \n
\n",$username,$pass,$sec_lastupdate); # OK here
printf $secSHADOWfh "%s:\n\tpassword = %s\n\tlastupdate = %d\n
\tflags = \n\n",$username,$pass,$sec_lastupdate; # NOT OK here.
}
close $SHADOWfh;
close $secSHADOWfh;
------------------------------
Date: Tue, 19 Jun 2007 14:21:48 -0700
From: Vahid <vahid.moghaddasi@gmail.com>
Subject: Re: writing to file fails
Message-Id: <1182288108.341846.192330@o61g2000hsh.googlegroups.com>
On Jun 19, 5:14 pm, Vahid <vahid.moghadd...@gmail.com> wrote:
> Hi all;
> I am trying to read two files and write the result into the third file
>
Sorry, actually just reformatting UNIX's /etc/shadow file to
user:
password =
lastupdate =
flags =
and then writing it to another file. I get the following error after
running the script:
Can't use an undefined value as a symbol reference at /tmp/
mksec_passwd.pl line 22, <SHADOWfh> line 860.
Line 860 is the last line in the shadow file.
Thanks again.
------------------------------
Date: Tue, 19 Jun 2007 14:21:55 -0700
From: Paul Lalli <mritty@gmail.com>
Subject: Re: writing to file fails
Message-Id: <1182288115.660942.91820@n2g2000hse.googlegroups.com>
On Jun 19, 5:14 pm, Vahid <vahid.moghadd...@gmail.com> wrote:
> I am trying to read two files and write the result into the third file
> but keep getting "..undefined value as a symbol.." error. Can someone
> please tell me what am I doing wrong?
Yes. You're ignoring Perl telling you about your errors, and instead
asking us to tell you about them instead. Very inefficient of you.
> #!/usr/bin/perl -w
> #
> #
> #use strict; # if uncomment this, I get many errors.
No kidding. That's because you made many errors. You should be
FIXING the errors it tells you about, not plugging your fingers in
your ears and screaming LA LA LA I CAN'T HEAR YOU!!!
> use warnings;
> $ENV{'PATH'} = "/usr/sbin:/sbin:/bin:/usr/bin:/usr/local/bin:";
> my $SHADOW = etc_shadow;
> my $secSHADOW = sec_passwd;
Here's your first two errors. You're assigning barewords to these
variables. Perl doesn't know what they are, so it *guesses* that
they're strings, because there's no subroutines with those names in
scope. use strict will prevent this guessing and tell you to fix this
problem. Strings in perl are delimited by quotes:
my $SHADOW = 'etc_shadow';
my $secSHADOW = 'sec_passwd';
> $|=1;
> #
> #
> #
>
> open (SHADOWfh, "<$SHADOW") || die "Can not open the file: $SHADOW\n";
> open (secSHADOWfh, ">$secSHADOW") || die "Can not open the file:
> $secSHADOW\n";
>
> my @lines = <SHADOWfh> ;
> foreach my $line (@lines) {
You're reading the entire array into an array at once, and then
processing the array one element at a time. Very wasteful and
inefficient. Instead, read one line and process that line before you
read another:
while (my $line = <SHADOWfh>);
> my ($username,$pass,$lastchange) = split /:/, $line;
> my $sec_lastupdate = ($lastchange*86400);
> printf ("%s:\n\tpassword = %s\n\tlastupdate = %d\n\tflags = \n
> \n",$username,$pass,$sec_lastupdate); # OK here
> printf $secSHADOWfh "%s:\n\tpassword = %s\n\tlastupdate = %d\n
> \tflags = \n\n",$username,$pass,$sec_lastupdate; # NOT OK here.}
Of course it's not. $secSHADOWfh is a variable that doesn't
previously exist. It's not a filehandle. The filehandle is
secSHADOWfh. `use strict;` would have told you aobut this error. But
you decided you didn't want to hear Perl tell you about these errors,
and instead asked Usenet what you did wrong instead.
> close $SHADOWfh;
> close $secSHADOWfh;
Once again, Perl will tell you there's no such variables with these
names if you let it.
Paul Lalli
------------------------------
Date: Tue, 19 Jun 2007 16:28:00 -0500
From: "J. Gleixner" <glex_no-spam@qwest-spam-no.invalid>
Subject: Re: writing to file fails
Message-Id: <46784a60$0$10302$815e3792@news.qwest.net>
Vahid wrote:
> Hi all;
> I am trying to read two files and write the result into the third file
> but keep getting "..undefined value as a symbol.." error. Can someone
> please tell me what am I doing wrong? Thank you.
>
> #!/usr/bin/perl -w
> #
> #
> #use strict; # if uncomment this, I get many errors.
Good. Then uncomment and fix the errors.
> use warnings;
> $ENV{'PATH'} = "/usr/sbin:/sbin:/bin:/usr/bin:/usr/local/bin:";
> my $SHADOW = etc_shadow;
> my $secSHADOW = sec_passwd;
my $SHADOW = 'etc_shadow';
my $secSHADOW = 'sec_passwd';
> $|=1;
> #
> #
> #
>
> open (SHADOWfh, "<$SHADOW") || die "Can not open the file: $SHADOW\n";
> open (secSHADOWfh, ">$secSHADOW") || die "Can not open the file:
> $secSHADOW\n";
Print the reason why open failed, which will be stored in $!.
perldoc -f open
>
> my @lines = <SHADOWfh> ;
> foreach my $line (@lines) {
Replace those with:
while( my $line = <SHADOWfh> )
> my ($username,$pass,$lastchange) = split /:/, $line;
> my $sec_lastupdate = ($lastchange*86400);
my $sec_lastupdate = $lastchange * 86400;
> printf ("%s:\n\tpassword = %s\n\tlastupdate = %d\n\tflags = \n
> \n",$username,$pass,$sec_lastupdate); # OK here
> printf $secSHADOWfh "%s:\n\tpassword = %s\n\tlastupdate = %d\n
> \tflags = \n\n",$username,$pass,$sec_lastupdate; # NOT OK here.
Using the version of open, you're using above, that would be:
printf secSHADOWfh
perldoc -f open
> }
> close $SHADOWfh;
> close $secSHADOWfh;
>
------------------------------
Date: Tue, 19 Jun 2007 14:39:10 -0700
From: Vahid <vahid.moghaddasi@gmail.com>
Subject: Re: writing to file fails
Message-Id: <1182289150.666707.126410@n2g2000hse.googlegroups.com>
On Jun 19, 5:21 pm, Paul Lalli <mri...@gmail.com> wrote:
>
> Once again, Perl will tell you there's no such variables with these
> names if you let it.
>
The error was not descriptive enough for me so I did not know what to
do with it, your explanation was.
I modified my code to the following and everything is fine now.
Thanks.
#!/usr/bin/perl -w
#
use strict;
use warnings;
$ENV{'PATH'} = "/usr/sbin:/sbin:/bin:/usr/bin:/usr/local/bin:";
my $SHADOW = 'etc_shadow';
my $secSHADOW = 'sec_passwd';
$|=1;
#
open (SHADOWfh, "<$SHADOW") || die "Can not open the file: $SHADOW\n";
open (secSHADOWfh, ">$secSHADOW") || die "Can not open the file:
$secSHADOW\n";
while (my $line = <SHADOWfh>)
{
my ($username,$pass,$lastchange) = split /:/, $line;
my $sec_lastupdate = ($lastchange*86400);
printf ("%s:\n\tpassword = %s\n\tlastupdate = %d\n\tflags = \n
\n",$username,$pass,$sec_lastupdate);
printf secSHADOWfh "%s:\n\tpassword = %s\n\tlastupdate = %d\n
\tflags = \n\n",$username,$pass,$sec_lastupdate;
}
close SHADOWfh;
close secSHADOWfh;
Thanks again.
------------------------------
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 V11 Issue 536
**************************************