[28328] in Perl-Users-Digest
Perl-Users Digest, Issue: 9692 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Sep 6 14:06:01 2006
Date: Wed, 6 Sep 2006 11:05:08 -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, 6 Sep 2006 Volume: 10 Number: 9692
Today's topics:
Re: (Off topic) Cyberwar question <tuser3@gmail.com>
Re: ActiveState Perl configuration - encountering an er frank@rangersnorth.net
Capturing output - how do I avoid the delay? <sukesh@blueyonder.co.uk>
Re: Capturing output - how do I avoid the delay? <aukjan@vanbelkum.no.spam.nl>
Re: Capturing output - how do I avoid the delay? anno4000@radom.zrz.tu-berlin.de
Re: Capturing output - how do I avoid the delay? <bik.mido@tiscalinet.it>
Re: Capturing output - how do I avoid the delay? <mritty@gmail.com>
Re: Capturing output - how do I avoid the delay? <bik.mido@tiscalinet.it>
Did not find leading dereferencer <ro.naldfi.scher@gmail.com>
Re: Did not find leading dereferencer <mritty@gmail.com>
Re: Did not find leading dereferencer <ro.naldfi.scher@gmail.com>
Re: Did not find leading dereferencer <mumia.w.18.spam+nospam.usenet@earthlink.net>
Re: Get Directiry size in windows <mritty@gmail.com>
Re: Mail and Encoding <steve.lavoie@micromedica.com>
Re: Mail and Encoding <hjp-usenet2@hjp.at>
MIME::Parser and Yahoo... <afrinspray@gmail.com>
Pattern Matching and skipping mattjones@hotmail.co.uk
Re: Pattern Matching and skipping <mumia.w.18.spam+nospam.usenet@earthlink.net>
Reg:parsing a file <arvindkannan1@gmail.com>
Re: Reg:parsing a file <klaus03@gmail.com>
Re: Reg:parsing a file <arvindkannan1@gmail.com>
Re: Reg:parsing a file <arvindkannan1@gmail.com>
Re: Regexp slowdown anno4000@radom.zrz.tu-berlin.de
time icrement based loop <deadpickle@gmail.com>
Re: time icrement based loop <tuser3@gmail.com>
Re: time icrement based loop <deadpickle@gmail.com>
Using named constants in cases of a switch <ro.naldfi.scher@gmail.com>
Re: Using named constants in cases of a switch <mritty@gmail.com>
XM::Simple - counting tags <john1949@yahoo.com>
Re: XM::Simple - counting tags <mumia.w.18.spam+nospam.usenet@earthlink.net>
Re: XM::Simple - counting tags <tadmc@augustmail.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 6 Sep 2006 10:38:28 -0700
From: "tuser" <tuser3@gmail.com>
Subject: Re: (Off topic) Cyberwar question
Message-Id: <1157564308.224108.280210@i3g2000cwc.googlegroups.com>
> Michele Dondi wrote:
> > On 4 Sep 2006 14:11:14 -0700, "Skybuck" <skybuck2000@hotmail.com>
> > wrote:
> >
> > [loads ay shite]
> >
> > Oh ma perr wee lassie! Hud ah kent ye wir such a lurvely cunt ah
> > wid've joined yir cyberwar n aw fir sure, likesay. Sae long...
Skybuck wrote:
> We need TRANSLATOR.
use strict;
use warnings;
my $message =
q{Oh ma perr wee lassie! Hud ah kent ye wir such a }.
q{lurvely cunt ah wid've joined yir cyberwar n aw }.
q{fir sure, likesay. Sae long...};
my @translator =
(83, 116, 111, 112, 32, 98, 101, 105, 110, 103, 32, 115,
117, 99, 104, 32, 97, 32, 98, 97, 98, 121, 33, 32, 83,
116, 111, 112, 32, 98, 101, 105, 110, 103, 32, 115, 117,
99, 104, 32, 97, 32, 98, 97, 98, 121, 33, 32, 83, 116, 111,
112, 32, 98, 101, 105, 110, 103, 32, 115, 117, 99, 104, 32,
97, 32, 98, 97, 98, 121, 33, 32, 83, 116, 111, 112, 32, 98,
101, 105, 110, 103, 32, 115, 117, 99, 104, 32, 97, 32, 98, 97,
98, 121, 33, 32, 83, 116, 111, 112, 32, 98, 101, 105, 110,
103, 32, 115, 117, 99, 104, 32, 97, 32, 98, 97, 98, 121, 33,
32, 83, 116, 111, 112, 32, 98, 101, 105, 110, 103, 32, 115,
117, 99, 104, 32, 97, 32, 98, 97, 98, 121, 33);
my $p = 0;
for (@translator) {
substr($message, $p, 1) = chr $_;
$p++;
}
print "translated message: $message\n";
------------------------------
Date: 6 Sep 2006 09:16:01 -0700
From: frank@rangersnorth.net
Subject: Re: ActiveState Perl configuration - encountering an error
Message-Id: <1157559361.303209.113330@m79g2000cwm.googlegroups.com>
Thank you all. The solution was the HTTP_PROXY environment variable
and, as it turns, determining the correct value for that (a purely
internal matter). I appreciate everyone's insight.
------------------------------
Date: 6 Sep 2006 02:28:11 -0700
From: "compuman" <sukesh@blueyonder.co.uk>
Subject: Capturing output - how do I avoid the delay?
Message-Id: <1157534891.849757.22980@e3g2000cwe.googlegroups.com>
Hi
How do avoid the delay when capturing output from a shell command in
Perl?
For example, consider the following example using a find command in a
home directory:
foreach (`find /home/user -type f -print`)
{
print "$_";
}
If I had run the find command on the command line I would see the
output would appear immediately. However putting it into a perl script
like this causes a delay.
I'm guessing that this is because the command is executed first and
then each line is processed by the foreach loop.
However, I want to see the output immediately, just as if I had run
this on the command line.
Any ideas how to achieve this?
------------------------------
Date: Wed, 06 Sep 2006 11:46:59 +0200
From: Aukjan van Belkum <aukjan@vanbelkum.no.spam.nl>
Subject: Re: Capturing output - how do I avoid the delay?
Message-Id: <47de8$44fe9914$c2abfc64$1775@news2.tudelft.nl>
compuman wrote:
> Hi
>
> How do avoid the delay when capturing output from a shell command in
> Perl?
>
> For example, consider the following example using a find command in a
> home directory:
>
> foreach (`find /home/user -type f -print`)
> {
> print "$_";
> }
>
>
> I'm guessing that this is because the command is executed first and
> then each line is processed by the foreach loop.
>
That is correct..
> However, I want to see the output immediately, just as if I had run
> this on the command line.
>
you can achieve this by doing an open:
my $ch;
open($ch,'-|',"find /home/user -type f -print") or die $!;
while(<$ch>){
print;
}
You can read more in: perldoc -f open
Aukjan
------------------------------
Date: 6 Sep 2006 09:54:44 GMT
From: anno4000@radom.zrz.tu-berlin.de
Subject: Re: Capturing output - how do I avoid the delay?
Message-Id: <4m7k74F4u06sU1@news.dfncis.de>
compuman <sukesh@blueyonder.co.uk> wrote in comp.lang.perl.misc:
> Hi
>
> How do avoid the delay when capturing output from a shell command in
> Perl?
>
> For example, consider the following example using a find command in a
> home directory:
>
> foreach (`find /home/user -type f -print`)
> {
> print "$_";
> }
>
> If I had run the find command on the command line I would see the
> output would appear immediately. However putting it into a perl script
> like this causes a delay.
>
> I'm guessing that this is because the command is executed first and
> then each line is processed by the foreach loop.
How else would it work? The backtick operator returns the output
of the command, so it has to wait for the command to finish before
it can return control to the caller. No other way.
> However, I want to see the output immediately, just as if I had run
> this on the command line.
Use File::Find (or one of its derivatives) instead of the external
find.
Use the external find, but open a pipe to the process instead of
using backticks (see perldoc -f open, look for pipe).
Anno
------------------------------
Date: 6 Sep 2006 12:11:55 +0200
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: Capturing output - how do I avoid the delay?
Message-Id: <jc7tf291flev1un7c8m03hmjocplpjh8ug@4ax.com>
On 6 Sep 2006 02:28:11 -0700, "compuman" <sukesh@blueyonder.co.uk>
wrote:
>foreach (`find /home/user -type f -print`)
If you really have to, then
open my $fh, '-|', 'find /home/user -type f -print' or die "$!\n";
while ($fh) { # ...
>{
> print "$_";
>}
print $_;
print;
perldoc -q quoting
perldoc perlvar
>I'm guessing that this is because the command is executed first and
>then each line is processed by the foreach loop.
Indeed.
>However, I want to see the output immediately, just as if I had run
>this on the command line.
See above!
>Any ideas how to achieve this?
Also, feel free to investigate File::Find and relatives...
Michele
--
{$_=pack'B8'x25,unpack'A8'x32,$a^=sub{pop^pop}->(map substr
(($a||=join'',map--$|x$_,(unpack'w',unpack'u','G^<R<Y]*YB='
.'KYU;*EVH[.FHF2W+#"\Z*5TI/ER<Z`S(G.DZZ9OX0Z')=~/./g)x2,$_,
256),7,249);s/[^\w,]/ /g;$ \=/^J/?$/:"\r";print,redo}#JAPH,
------------------------------
Date: 6 Sep 2006 06:27:19 -0700
From: "Paul Lalli" <mritty@gmail.com>
Subject: Re: Capturing output - how do I avoid the delay?
Message-Id: <1157549239.001011.222970@d34g2000cwd.googlegroups.com>
Michele Dondi wrote:
> On 6 Sep 2006 02:28:11 -0700, "compuman" <sukesh@blueyonder.co.uk>
> wrote:
>
> >foreach (`find /home/user -type f -print`)
>
> If you really have to, then
>
> open my $fh, '-|', 'find /home/user -type f -print' or die "$!\n";
> while ($fh) { # ...
I know Michele knows this, but just for the sake of anyone reading this
a year from now...
that should be:
while (<$fh>) { #...
Paul Lalli
------------------------------
Date: 6 Sep 2006 16:25:13 +0200
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: Capturing output - how do I avoid the delay?
Message-Id: <nfmtf2loqrre9e9q9fho81la4vpkn7qck0@4ax.com>
On 6 Sep 2006 06:27:19 -0700, "Paul Lalli" <mritty@gmail.com> wrote:
>> open my $fh, '-|', 'find /home/user -type f -print' or die "$!\n";
>> while ($fh) { # ...
>
>I know Michele knows this, but just for the sake of anyone reading this
>a year from now...
>
>that should be:
>
>while (<$fh>) { #...
Oops, and if we want to learn a lesson from this... always remember
that it's better to paste code rather than retype it. Of course I was
*sure* I wouldn't have got *that* wrong! Sigh...
Michele
--
{$_=pack'B8'x25,unpack'A8'x32,$a^=sub{pop^pop}->(map substr
(($a||=join'',map--$|x$_,(unpack'w',unpack'u','G^<R<Y]*YB='
.'KYU;*EVH[.FHF2W+#"\Z*5TI/ER<Z`S(G.DZZ9OX0Z')=~/./g)x2,$_,
256),7,249);s/[^\w,]/ /g;$ \=/^J/?$/:"\r";print,redo}#JAPH,
------------------------------
Date: 6 Sep 2006 07:38:33 -0700
From: "Ronny" <ro.naldfi.scher@gmail.com>
Subject: Did not find leading dereferencer
Message-Id: <1157553512.915765.166250@i3g2000cwc.googlegroups.com>
I get a weird error message saying
"Did not find leading dereferencer, detected at
offset 6728syntax error at ... near "mk_remote_filename"
The expression in question is this:
join(' ', 'rcp', map(mk_remote_filename, @_))
where mk_remote_filename is a sub defined earlier, prototyped
as
sub mk_remote_filename($)
Maybe Perl doesn't like the isolated occurence of the bareword
mk_remote_filename here (it doesn't look very perlish to me),
but when I check the perldoc for the function map, it mentions
a very similar construct. From the perldocs:
"@chars = map(chr, @nums);
translates a list of numbers to the corresponding characters."
What am I doing wrong? Of course I could also write
(map { mk_remote_filenam $_ } @_)
but I wonder why it doesn't work the way I wrote it.
Ronald
------------------------------
Date: 6 Sep 2006 07:53:17 -0700
From: "Paul Lalli" <mritty@gmail.com>
Subject: Re: Did not find leading dereferencer
Message-Id: <1157554396.965481.207380@p79g2000cwp.googlegroups.com>
Ronny wrote:
> I get a weird error message saying
>
> "Did not find leading dereferencer, detected at
> offset 6728syntax error at ... near "mk_remote_filename"
Odd, I can't find that entry anwhere in my `perldoc perldiag` (This is
perl, v5.8.4 built for sun4-solaris). What Perl version and OS are you
using?
> The expression in question is this:
>
> join(' ', 'rcp', map(mk_remote_filename, @_))
>
> where mk_remote_filename is a sub defined earlier, prototyped
> as
>
> sub mk_remote_filename($)
>
> Maybe Perl doesn't like the isolated occurence of the bareword
> mk_remote_filename here (it doesn't look very perlish to me),
> but when I check the perldoc for the function map, it mentions
> a very similar construct. From the perldocs:
>
> "@chars = map(chr, @nums);
Similar, but not at all identical. chr is a built-in function that
specifically uses the value of $_ if no other value is passed to it.
Your user-written subroutine has no such magic.
> translates a list of numbers to the corresponding characters."
>
> What am I doing wrong? Of course I could also write
> (map { mk_remote_filenam $_ } @_)
> but I wonder why it doesn't work the way I wrote it.
Get rid of the prototype. You shouldn't be using them anyway. Then
try putting something like this in your subroutine:
my $arg = @_ ? shift : $_;
and do to $arg whatever you were doing to $_[0] in the original.
I still have no idea what that error message you're talking about
means, so the above is all guesswork. If it doesn't help, please post
a SHORT but COMPLETE script that demonstrates your error.
Paul Lalli
------------------------------
Date: 6 Sep 2006 08:01:34 -0700
From: "Ronny" <ro.naldfi.scher@gmail.com>
Subject: Re: Did not find leading dereferencer
Message-Id: <1157554894.199321.308630@m79g2000cwm.googlegroups.com>
Paul Lalli schrieb:
> Ronny wrote:
> > "Did not find leading dereferencer, detected at
> > offset 6728syntax error at ... near "mk_remote_filename"
>
> Odd, I can't find that entry anwhere in my `perldoc perldiag` (This is
> perl, v5.8.4 built for sun4-solaris). What Perl version and OS are you
> using?
5.8.3 for Linux
> > join(' ', 'rcp', map(mk_remote_filename, @_))
> >
> > where mk_remote_filename is a sub defined earlier, prototyped
> > as
> >
> > sub mk_remote_filename($)
> Get rid of the prototype. You shouldn't be using them anyway. Then
> try putting something like this in your subroutine:
>
> my $arg = @_ ? shift : $_;
>
> and do to $arg whatever you were doing to $_[0] in the original.
I did and, and now it works! Thank you very much for your help.
Ronald
------------------------------
Date: Wed, 06 Sep 2006 15:31:42 GMT
From: "Mumia W." <mumia.w.18.spam+nospam.usenet@earthlink.net>
Subject: Re: Did not find leading dereferencer
Message-Id: <yRBLg.3943$v%4.2484@newsread1.news.pas.earthlink.net>
On 09/06/2006 09:38 AM, Ronny wrote:
> I get a weird error message saying
>
> "Did not find leading dereferencer, detected at
> offset 6728syntax error at ... near "mk_remote_filename"
>
> The expression in question is this:
>
> join(' ', 'rcp', map(mk_remote_filename, @_))
>
> where mk_remote_filename is a sub defined earlier, prototyped
> as
>
> sub mk_remote_filename($)
>
Maybe part of the problem is that you prototype the sub as
requiring a scalar parameter, but you don't give it any
parameters in the call.
> Maybe Perl doesn't like the isolated occurence of the bareword
> mk_remote_filename here (it doesn't look very perlish to me),
> but when I check the perldoc for the function map, it mentions
> a very similar construct. From the perldocs:
>
> "@chars = map(chr, @nums);
> translates a list of numbers to the corresponding characters."
>
Yes, but chr can function without any parameters.
> What am I doing wrong? Of course I could also write
> (map { mk_remote_filenam $_ } @_)
> but I wonder why it doesn't work the way I wrote it.
>
> Ronald
>
Try this: map mk_remote_filename($_), @_
Or you could define mk_remote_filename to not have a prototype
and use your old code.
------------------------------
Date: 6 Sep 2006 03:56:29 -0700
From: "Paul Lalli" <mritty@gmail.com>
Subject: Re: Get Directiry size in windows
Message-Id: <1157540189.025047.124990@m79g2000cwm.googlegroups.com>
Dark wrote:
> $dirsize = `dir \"C:/Program Files/\" | findstr \"File(s)\"`;
>
> I have escaped the other double quotes \" above.
Yes, you have. Why have you?
Paul Lalli
------------------------------
Date: Wed, 06 Sep 2006 12:48:59 -0400
From: steve <steve.lavoie@micromedica.com>
Subject: Re: Mail and Encoding
Message-Id: <f1DLg.33325$ED.5208@read2.cgocable.net>
Thanks you! It is the solution. I tested it this morning and it is all
right!
Steve Lavoie
Network administrator
Micromedica
A. Sinan Unur wrote:
> steve <steve.lavoie@micromedica.com> wrote in news:zmkLg.30408$ED.23735
> @read2.cgocable.net:
>
>
>>I am trying to parse every email I am getting in a spam@domain.com. I
>>can pull the email using Net::POP3. I am parsing each email using a
>>Mail::Internet object. The problem I am getting is that in certain
>>case, like Outlook forward message where the signature is in HTML some
>>special characters are encode like =20 . Most message are in french so
>>I have some special character like é è and so on.
>>
>>I have tried Encode:: module but I dont know from which table to what
>>I should convert.
>>
>>Anyone got some ideas?
>
>
> I am always confused about these things but I think you are looking at
> messages in quoted printable format:
>
> http://search.cpan.org/~gaas/MIME-Base64-3.07/QuotedPrint.pm
>
> http://en.wikipedia.org/wiki/Quoted-printable
>
>
>>Sorry for my bad english.. I am french native.
>
>
> Not to worry and no need to apologize. There are people from all over
> the world in this group.
>
> Sinan
>
------------------------------
Date: Wed, 6 Sep 2006 19:50:58 +0200
From: "Peter J. Holzer" <hjp-usenet2@hjp.at>
Subject: Re: Mail and Encoding
Message-Id: <slrnefu2k6.qb5.hjp-usenet2@yoyo.hjp.at>
On 2006-09-05 19:34, steve <steve.lavoie@micromedica.com> wrote:
> I am trying to parse every email I am getting in a spam@domain.com. I
> can pull the email using Net::POP3. I am parsing each email using a
> Mail::Internet object.
For parsing MIME mails (most are these days) you should use MIME::Parser.
hp
--
_ | Peter J. Holzer | > Wieso sollte man etwas erfinden was nicht
|_|_) | Sysadmin WSR | > ist?
| | | hjp@hjp.at | Was sonst wäre der Sinn des Erfindens?
__/ | http://www.hjp.at/ | -- P. Einstein u. V. Gringmuth in desd
------------------------------
Date: 6 Sep 2006 10:22:29 -0700
From: "afrinspray" <afrinspray@gmail.com>
Subject: MIME::Parser and Yahoo...
Message-Id: <1157563349.617638.34390@d34g2000cwd.googlegroups.com>
I'm using a perl script to parse emails, and I'm having trouble with
this Yahoo MIME code. Can you guys think of any reason why
MIME::Parser keeps cutting out everything before the quoted part
(Someemail@example.com wrote:)? What is the :39820 in the boundary?
Could it have something to do with the encoding?
<snip>
--0-501421522-1157090632=:39820
Content-Type: text/html; charset=iso-8859-1
Content-Transfer-Encoding: quoted-printable
Dam that Phantom... just when I thought he went to Honduras!<br> <br>
(=
Note Dam is spelled so as to be politically
correct...)<br><br><b><i>Some=
email@example.com</i></b> wrote:<blockquote class=3D"replbq"
</snip>
Everything works fine except when the emails come in from this guy.
Thanks,
Mike
------------------------------
Date: 6 Sep 2006 07:24:07 -0700
From: mattjones@hotmail.co.uk
Subject: Pattern Matching and skipping
Message-Id: <1157552647.180310.203450@h48g2000cwc.googlegroups.com>
Hi,
I've got a small problem....im searching for words in a sentence (from
a log file) then pulling the sentence and putting it in a database. My
problem is that if the word and thus the sentence is no in the log file
- it is missing the log file out altogether and now recording them in
the database.
Is there a way of telling the program to look for these words - and if
they are not there - just skip that pattern (leave the field blank) and
move to the next pattern?
<SNIP>
while (<LOG>) {
if (/FASTSEARCH|conflicting/) {
my @lines = split /\n/; {
foreach my $fast (@lines) {
while (<LOG>) {
if (/elapsed/) {
my @lines = split /\n/; {
foreach my $elapsed2 (@lines) {
So, the script looks for FASTSEARCH and conflicting......if these are
not present i'd like the script to leave the field blank and move to
the next pattern (elapsed).
At the moment my script works but a few of the log files don't contain
FASTSEARCH or conflicting and so are not getting read into the database
(presumably because i am just doing loop after loop and if it doesn't
pick up either of these words it breaks the chain!)
Thanks
Matt (PERL Newbie!)
------------------------------
Date: Wed, 06 Sep 2006 15:31:43 GMT
From: "Mumia W." <mumia.w.18.spam+nospam.usenet@earthlink.net>
Subject: Re: Pattern Matching and skipping
Message-Id: <zRBLg.3944$v%4.75@newsread1.news.pas.earthlink.net>
On 09/06/2006 09:24 AM, mattjones@hotmail.co.uk wrote:
> Hi,
>
> I've got a small problem....im searching for words in a sentence (from
> a log file) then pulling the sentence and putting it in a database. My
> problem is that if the word and thus the sentence is no in the log file
> - it is missing the log file out altogether and now recording them in
> the database.
> Is there a way of telling the program to look for these words - and if
> they are not there - just skip that pattern (leave the field blank) and
> move to the next pattern?
>
> <SNIP>
>
> while (<LOG>) {
> if (/FASTSEARCH|conflicting/) {
> my @lines = split /\n/; {
> foreach my $fast (@lines) {
>
> while (<LOG>) {
> if (/elapsed/) {
> my @lines = split /\n/; {
> foreach my $elapsed2 (@lines) {
>
> So, the script looks for FASTSEARCH and conflicting......if these are
> not present i'd like the script to leave the field blank and move to
> the next pattern (elapsed).
> At the moment my script works but a few of the log files don't contain
> FASTSEARCH or conflicting and so are not getting read into the database
> (presumably because i am just doing loop after loop and if it doesn't
> pick up either of these words it breaks the chain!)
>
> Thanks
>
> Matt (PERL Newbie!)
>
Use the 'else' section of the if statement to tell perl what
to do when FASTSEARCH and conflicting are not there.
if (condition) {
... code ...
} else {
... code ...
}
------------------------------
Date: 6 Sep 2006 09:42:08 -0700
From: "sivga" <arvindkannan1@gmail.com>
Subject: Reg:parsing a file
Message-Id: <1157560928.305506.255770@m79g2000cwm.googlegroups.com>
hello experts,
Iam new to perl .Can you pls suggest how to do this this is wat iam
trying to do i have a text file with following lines
exact 5
seasad 3
switch text 1.2
new data 20
cd data 10
phase 30
extra 40
same 200
different 500
wat i need do is i neeed to read the file and if the file has (matches)
switch text i need to write switch text to a new file say k2 and the
next four lines new data ,cd data,extra and phase to k2 .other wise no
need to write to the file k2. ,I cannot form the string say new data cd
data and write to a file coz the numbers at the end will differ .How do
i do it ?
while (<AG>) {
if ($_ =~ /exact +([0-9]+)/ ) {
print k1 " $_";
} elsif ( $_ =~ /switch text /) {
print k2 "$_";
} elsif ($_ =~ /same/) {
print k1 "$_";
}
Thanks for the help
------------------------------
Date: 6 Sep 2006 10:08:49 -0700
From: "Klaus" <klaus03@gmail.com>
Subject: Re: Reg:parsing a file
Message-Id: <1157562528.965249.98650@i3g2000cwc.googlegroups.com>
sivga wrote:
> hello experts,
>
> Iam new to perl .Can you pls suggest how to do this this is wat iam
> trying to do i have a text file
[snip]
> wat i need do is i neeed to read the file
[snip]
> i need to write switch text to a new file say k2
[snip]
It is recommended that you begin your perl program with the following
two lines:
use strict;
use warnings;
Secondly, you need to open all your input-file and output-files.
Have a look at "perldoc perlopen" on how to open files.
Personally, I would say:
open my $AG, '<', 'ag.txt' or die "Error <ag.txt ($!)";
open my $k1, '>', 'k1.txt' or die "Error >k1.txt ($!)";
open my $k2, '>', 'k2.txt' or die "Error >k2.txt ($!)";
> while (<AG>) {
while (<$AG>) {
> print k1 " $_";
print {$k1} ' ', $_;
> print k2 "$_";
print {$k2} $_;
> print k1 "$_";
print {$k1} $_;
------------------------------
Date: 6 Sep 2006 10:17:01 -0700
From: "sivga" <arvindkannan1@gmail.com>
Subject: Re: Reg:parsing a file
Message-Id: <1157563020.986030.111750@p79g2000cwp.googlegroups.com>
Klaus wrote:
> sivga wrote:
> > hello experts,
> >
> > Iam new to perl .Can you pls suggest how to do this this is wat iam
> > trying to do i have a text file
>
> [snip]
>
> > wat i need do is i neeed to read the file
>
> [snip]
>
> > i need to write switch text to a new file say k2
>
> [snip]
>
> It is recommended that you begin your perl program with the following
> two lines:
>
> use strict;
> use warnings;
>
> Secondly, you need to open all your input-file and output-files.
> Have a look at "perldoc perlopen" on how to open files.
>
> Personally, I would say:
>
> open my $AG, '<', 'ag.txt' or die "Error <ag.txt ($!)";
> open my $k1, '>', 'k1.txt' or die "Error >k1.txt ($!)";
> open my $k2, '>', 'k2.txt' or die "Error >k2.txt ($!)";
>
> > while (<AG>) {
> while (<$AG>) {
>
> > print k1 " $_";
> print {$k1} ' ', $_;
>
> > print k2 "$_";
> print {$k2} $_;
>
> > print k1 "$_";
> print {$k1} $_;
klaus i have already done all those ..i have pasted jus the snippet of
the code . The problem is there a way to specify like if the condition
matches then get next four lines .how do i specify this
thanks for the help
------------------------------
Date: 6 Sep 2006 10:52:07 -0700
From: "sivga" <arvindkannan1@gmail.com>
Subject: Re: Reg:parsing a file
Message-Id: <1157565127.772837.37360@i3g2000cwc.googlegroups.com>
sivga wrote:
> Klaus wrote:
> > sivga wrote:
> > > hello experts,
> > >
> > > Iam new to perl .Can you pls suggest how to do this this is wat iam
> > > trying to do i have a text file
> >
> > [snip]
> >
> > > wat i need do is i neeed to read the file
> >
> > [snip]
> >
> > > i need to write switch text to a new file say k2
> >
> > [snip]
> >
> > It is recommended that you begin your perl program with the following
> > two lines:
> >
> > use strict;
> > use warnings;
> >
> > Secondly, you need to open all your input-file and output-files.
> > Have a look at "perldoc perlopen" on how to open files.
> >
> > Personally, I would say:
> >
> > open my $AG, '<', 'ag.txt' or die "Error <ag.txt ($!)";
> > open my $k1, '>', 'k1.txt' or die "Error >k1.txt ($!)";
> > open my $k2, '>', 'k2.txt' or die "Error >k2.txt ($!)";
> >
> > > while (<AG>) {
> > while (<$AG>) {
> >
> > > print k1 " $_";
> > print {$k1} ' ', $_;
> >
> > > print k2 "$_";
> > print {$k2} $_;
> >
> > > print k1 "$_";
> > print {$k1} $_;
>
> klaus i have already done all those ..i have pasted jus the snippet of
> the code . The problem is there a way to specify like if the condition
> matches then get next four lines .how do i specify this
>
> thanks for the help
wat i need do is if th eline matches then i need to get the next four
lines an place it in a array ..how do i do it in perl ?
------------------------------
Date: 6 Sep 2006 10:57:56 GMT
From: anno4000@radom.zrz.tu-berlin.de
Subject: Re: Regexp slowdown
Message-Id: <4m7ntkF4vhecU1@news.dfncis.de>
<chris.ritchie@gmail.com> wrote in comp.lang.perl.misc:
[...]
> I'm sorry I can't post my code, but I can't take it out of context
> enough to make it nonproprietary.
So you've been wasting everybody's time right from the beginning.
> But I've only asked for help with
> ways the intepreter works and interfaces with the OS, which is what I
> need.
"My car slows down after a mile of driving. No, I can't show you my
car. I'm just asking how the gear box works and how it interfaces
with the motor, which is what I need."
> If I can't spot fundamental errors in my regexs, then I have
> bigger problems.
You do.
Anno
------------------------------
Date: 6 Sep 2006 09:30:25 -0700
From: "deadpickle" <deadpickle@gmail.com>
Subject: time icrement based loop
Message-Id: <1157560225.909190.310670@h48g2000cwc.googlegroups.com>
I need to create a loop that will run a command every 5 seconds. I
know I can probably do this with a series of while, for and if
statements but I just cant wrap my head around it. Is there an easier
way? If not, how is it suggested that I do this?
The command I need to run is
$fh->client_automated("x.x.x.x","port","get","some_file");
It is part of a client script that uses the Net::FileShare module. If
the program is run within a while loop it eventually has an error that
closes the port and stops connection. This is bad because I need a
constant connection in order to keep the data flowing between the
computers. Any help would be very appriciated.
------------------------------
Date: 6 Sep 2006 09:42:54 -0700
From: "tuser" <tuser3@gmail.com>
Subject: Re: time icrement based loop
Message-Id: <1157560974.270475.302660@e3g2000cwe.googlegroups.com>
deadpickle wrote:
> I need to create a loop that will run a command every 5 seconds. I
> know I can probably do this with a series of while, for and if
> statements but I just cant wrap my head around it. Is there an easier
> way?
easier than a series of while, for and if ?
Well, I don't know if that's really easier, but it's certainly short.
Here is a perl program to run a command every 5 seconds without a
series of while, for and if statements:
perl -e '{ print qq{run command\n}; sleep 5; redo }'
------------------------------
Date: 6 Sep 2006 09:51:54 -0700
From: "deadpickle" <deadpickle@gmail.com>
Subject: Re: time icrement based loop
Message-Id: <1157561514.813432.311260@m79g2000cwm.googlegroups.com>
tuser wrote:
> deadpickle wrote:
> > I need to create a loop that will run a command every 5 seconds. I
> > know I can probably do this with a series of while, for and if
> > statements but I just cant wrap my head around it. Is there an easier
> > way?
>
> easier than a series of while, for and if ?
>
> Well, I don't know if that's really easier, but it's certainly short.
> Here is a perl program to run a command every 5 seconds without a
> series of while, for and if statements:
>
> perl -e '{ print qq{run command\n}; sleep 5; redo }'
Thank you very much. Ill run it and see what happens.
------------------------------
Date: 6 Sep 2006 05:07:57 -0700
From: "Ronny" <ro.naldfi.scher@gmail.com>
Subject: Using named constants in cases of a switch
Message-Id: <1157544477.632291.69340@d34g2000cwd.googlegroups.com>
Assuming the following (the code should be compatible to Perl 5.8.3 AND
Perl 6):
use Switch 'perl6';
use constant { FOO => 1, BAR => 2, BAZ => 3 };
my $var = BAR;
...
Now I would like to write a "switch" expression, where one of the cases
shoulb
be executed if $var is either BAR or BAZ:
given($var) {
when(FOO) { handle_foo() }
when(??? what do I put here ???) { handle_ba() }
else { warn "Illegal value: $var\n"; }
}
So the question is, how do I express "either BAR or BAZ" in the second
"when"?
I found one solution to this, but I don't like it: Since the argument
of when is allowed
to be a regexp, I could use
when(/^(@{[BAR]}|@{[BAZ]}$/) { handle_ba() }
but this is slightly ugly IMO. Has someone a better solution for this?
Note that I look for a solution using given...when. I'm aware that one
could skin this
cat in completely different way too, but that's not the point here.
Ronald
------------------------------
Date: 6 Sep 2006 06:15:58 -0700
From: "Paul Lalli" <mritty@gmail.com>
Subject: Re: Using named constants in cases of a switch
Message-Id: <1157548558.094092.325450@m73g2000cwd.googlegroups.com>
Ronny wrote:
> Assuming the following (the code should be compatible to Perl 5.8.3 AND
> Perl 6):
>
> use Switch 'perl6';
> use constant { FOO => 1, BAR => 2, BAZ => 3 };
> my $var = BAR;
> ...
>
> Now I would like to write a "switch" expression, where one of the cases
> shoulb
> be executed if $var is either BAR or BAZ:
>
> given($var) {
> when(FOO) { handle_foo() }
> when(??? what do I put here ???) { handle_ba() }
> else { warn "Illegal value: $var\n"; }
> }
>
> So the question is, how do I express "either BAR or BAZ" in the second
> "when"?
This doesn't actually have anything to do with constants, near as I can
tell. The situation is the same whenever you want your 'when'
statement to be "if the given variable is any of these..."
when ( [BAR, BAZ] ) { handle_ba() }
Note that I think there's an error in the Switch.pm documentation, as
the list of possible matches does not cover a given scalar with a when
array-ref. The examples in the documentation do cover this scenario,
however...
Paul Lalli
------------------------------
Date: Wed, 6 Sep 2006 11:26:15 +0100
From: "John" <john1949@yahoo.com>
Subject: XM::Simple - counting tags
Message-Id: <9KudnauTerDWP2PZRVnyig@eclipse.net.uk>
Hi
After parsing with XML::Simple the variable $xml contains:
<city>
<firm>
<employee>Fred</employee>
<employee>Bill</employee>
<employee>Bob</employee>
</firm>
</city>
I need to know how many employees? I can easily extract each
employeee but I only need the count. Is there an easier way?
Regards
John
------------------------------
Date: Wed, 06 Sep 2006 11:44:13 GMT
From: "Mumia W." <mumia.w.18.spam+nospam.usenet@earthlink.net>
Subject: Re: XM::Simple - counting tags
Message-Id: <hwyLg.15781$Qf.10786@newsread2.news.pas.earthlink.net>
On 09/06/2006 05:26 AM, John wrote:
> Hi
>
> After parsing with XML::Simple the variable $xml contains:
>
> <city>
> <firm>
> <employee>Fred</employee>
> <employee>Bill</employee>
> <employee>Bob</employee>
> </firm>
> </city>
>
> I need to know how many employees? I can easily extract each
> employeee but I only need the count. Is there an easier way?
>
> Regards
> John
>
>
>
>
You can probably use the 'ForceArray => 1' option when parsing
the file then count the number of elements in the array.
------------------------------
Date: Wed, 6 Sep 2006 07:27:30 -0500
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: XM::Simple - counting tags
Message-Id: <slrneftfli.6ea.tadmc@magna.augustmail.com>
John <john1949@yahoo.com> wrote:
> I need to know how many employees?
That is a different question from the one in your Subject header.
There are 6 employee "tags".
There are 3 employee "elements".
See the XML FAQ:
http://xml.silmaril.ie/authors/makeup/
> I can easily extract each
> employeee but I only need the count. Is there an easier way?
-----------------------------------------
#!/usr/bin/perl
use warnings;
use strict;
use XML::Simple;
my $xml = '<city>
<firm>
<employee>Fred</employee>
<employee>Bill</employee>
<employee>Bob</employee>
</firm>
</city>
';
my $ref = XMLin( $xml );
my $count = @{ $ref->{firm}{employee} }; # See "Use Rule 1" in perlreftut.pod
print "there are $count employee elements\n";
-----------------------------------------
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
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 9692
***************************************