[28330] in Perl-Users-Digest
Perl-Users Digest, Issue: 9694 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Sep 6 18:10:17 2006
Date: Wed, 6 Sep 2006 15:10: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: 9694
Today's topics:
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: Reg:parsing a file <1usa@llenroc.ude.invalid>
Re: Reg:parsing a file <tadmc@augustmail.com>
Re: Reg:parsing a file <tadmc@augustmail.com>
Re: time icrement based loop xhoster@gmail.com
Re: Ultimate programmer's reference - Quickref.org laun <hjp-usenet2@hjp.at>
Re: Using named constants in cases of a switch <hjp-usenet2@hjp.at>
Re: Using named constants in cases of a switch <not-for-replies@zombie.org.uk>
Re: XM::Simple - counting tags <hjp-usenet2@hjp.at>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 6 Sep 2006 11:19:51 -0700
From: "Klaus" <klaus03@gmail.com>
Subject: Re: Reg:parsing a file
Message-Id: <1157566791.686496.300750@h48g2000cwc.googlegroups.com>
sivga wrote:
> 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 .
then please post some code that you have already done, not something
else which is different to what you have already done.
> 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 ?
I will give an example to match the string "abc" (but be aware that you
will get "Use of uninitialized value" warnings if, after a successful
match /abc/, there are less than 4 lines in the file left):
use strict;
use warnings;
open my $AG, '<', 'ag.txt' or die "Error <ag.txt ($!)";
my @array;
while (<$AG>) { chomp;
if (/abc/) { do{ my $line = <$AG>; push @array, $line } for (1..4)
}
}
{ local $, = "\n"; print @array, '' }
------------------------------
Date: 6 Sep 2006 11:33:41 -0700
From: "sivga" <arvindkannan1@gmail.com>
Subject: Re: Reg:parsing a file
Message-Id: <1157567621.185947.237550@p79g2000cwp.googlegroups.com>
Klaus wrote:
> sivga wrote:
> > 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 .
>
> then please post some code that you have already done, not something
> else which is different to what you have already done.
>
> > 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 ?
>
> I will give an example to match the string "abc" (but be aware that you
> will get "Use of uninitialized value" warnings if, after a successful
> match /abc/, there are less than 4 lines in the file left):
>
> use strict;
> use warnings;
>
> open my $AG, '<', 'ag.txt' or die "Error <ag.txt ($!)";
>
> my @array;
> while (<$AG>) { chomp;
> if (/abc/) { do{ my $line = <$AG>; push @array, $line } for (1..4)
> }
> }
>
> { local $, = "\n"; print @array, '' }
thanks klaus for the help actually i was trying different ways to
handle this .thanks for the help
------------------------------
Date: 6 Sep 2006 11:45:48 -0700
From: "sivga" <arvindkannan1@gmail.com>
Subject: Re: Reg:parsing a file
Message-Id: <1157568347.998671.305790@p79g2000cwp.googlegroups.com>
sivga wrote:
> Klaus wrote:
> > sivga wrote:
> > > 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 .
> >
> > then please post some code that you have already done, not something
> > else which is different to what you have already done.
> >
> > > 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 ?
> >
> > I will give an example to match the string "abc" (but be aware that you
> > will get "Use of uninitialized value" warnings if, after a successful
> > match /abc/, there are less than 4 lines in the file left):
> >
> > use strict;
> > use warnings;
> >
> > open my $AG, '<', 'ag.txt' or die "Error <ag.txt ($!)";
> >
> > my @array;
> > while (<$AG>) { chomp;
> > if (/abc/) { do{ my $line = <$AG>; push @array, $line } for (1..4)
> > }
> > }
> >
> > { local $, = "\n"; print @array, '' }
>
>
> thanks klaus for the help actually i was trying different ways to
> handle this .thanks for the help
klaus thanks for the help but can help in undersatnding how does the
for loop work here when u said for (1..4) Can you pls help here
.thanks
------------------------------
Date: Wed, 06 Sep 2006 18:47:44 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: Reg:parsing a file
Message-Id: <Xns983696841BA71asu1cornelledu@127.0.0.1>
"sivga" <arvindkannan1@gmail.com> wrote in
news:1157568347.998671.305790@p79g2000cwp.googlegroups.com:
> klaus thanks for the help but can help in undersatnding how does the
> for loop work here when u said for (1..4) Can you pls help here
> .thanks
Why don't you get a book or read the documentation?
perldoc perlsyn
Sinan
--
A. Sinan Unur <1usa@llenroc.ude.invalid>
(remove .invalid and reverse each component for email address)
comp.lang.perl.misc guidelines on the WWW:
http://augustmail.com/~tadmc/clpmisc/clpmisc_guidelines.html
------------------------------
Date: Wed, 6 Sep 2006 15:08:49 -0500
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: Reg:parsing a file
Message-Id: <slrnefuamh.782.tadmc@magna.augustmail.com>
sivga <arvindkannan1@gmail.com> 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 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 "$_";
print k2 scalar(<AG>); # print the next 4 lines
print k2 scalar(<AG>);
print k2 scalar(<AG>);
print k2 scalar(<AG>);
>
>
>
> } elsif ($_ =~ /same/) {
> print k1 "$_";
> }
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Wed, 6 Sep 2006 16:00:31 -0500
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: Reg:parsing a file
Message-Id: <slrnefudnf.abp.tadmc@magna.augustmail.com>
sivga <arvindkannan1@gmail.com> wrote:
[ Please trim quoted text that is not needed to establish the
context for your comments.
]
> how does the
> for loop work here when u said for (1..4)
See the "Foreach Loops" section in:
perldoc perlsyn
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: 06 Sep 2006 19:22:02 GMT
From: xhoster@gmail.com
Subject: Re: time icrement based loop
Message-Id: <20060906152224.110$B7@newsreader.com>
"deadpickle" <deadpickle@gmail.com> 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? If not, how is it suggested that I do this?
5 seconds from when to when? one start to the next start? one finish to
the next start? What will happend if it is 3 seconds or 7 seconds rather
than 5? Have you looked at "perldoc -f sleep"?
> 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.
It isn't clear how or if this relates to your first question.
Xho
--
-------------------- http://NewsReader.Com/ --------------------
Usenet Newsgroup Service $9.95/Month 30GB
------------------------------
Date: Wed, 6 Sep 2006 23:03:25 +0200
From: "Peter J. Holzer" <hjp-usenet2@hjp.at>
Subject: Re: Ultimate programmer's reference - Quickref.org launches
Message-Id: <slrnefudt2.u21.hjp-usenet2@yoyo.hjp.at>
On 2006-09-06 04:39, Jürgen Exner <jurgenex@hotmail.com> wrote:
> Robby Walker wrote:
>> The ultimate purpose of the site is to make a quicker way to access
>> all of this information
>
> How could anything on the WWW be faster than information on your own local
> HD? If you've solved that problem, then you really got something
> interesting.
That's not that difficult to solve: The pure retrieval time is only a
small time it takes a human being to find the wanted information. Thus a
well-designed search interface can easily provide quicker access, even
if it takes (for example) one second instead of 20 milliseconds to
retrieve any particular piece of information.
Not that I'm saying that the spamvertisered website provides such a
well-designed interface (actually, I haven't even looked at it).
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: Wed, 6 Sep 2006 23:11:23 +0200
From: "Peter J. Holzer" <hjp-usenet2@hjp.at>
Subject: Re: Using named constants in cases of a switch
Message-Id: <slrnefuebv.u21.hjp-usenet2@yoyo.hjp.at>
On 2006-09-06 12:07, Ronny <ro.naldfi.scher@gmail.com> wrote:
> Now I would like to write a "switch" expression, where one of the
> cases shoulb be executed if $var is either BAR or BAZ:
[...]
> 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() }
Urgs. What are the @{[]} for? What's wrong with
/^(BAR|BAZ)$/
or even
/^BA[RZ]$/
?
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: Wed, 06 Sep 2006 21:46:53 GMT
From: Brian Greenfield <not-for-replies@zombie.org.uk>
Subject: Re: Using named constants in cases of a switch
Message-Id: <obguf291gnshm0egv4frttao52ufh8bl5u@4ax.com>
On Wed, 6 Sep 2006 23:11:23 +0200, "Peter J. Holzer"
<hjp-usenet2@hjp.at> wrote:
>On 2006-09-06 12:07, Ronny <ro.naldfi.scher@gmail.com> wrote:
>> Now I would like to write a "switch" expression, where one of the
>> cases shoulb be executed if $var is either BAR or BAZ:
>[...]
>> 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() }
>
>Urgs. What are the @{[]} for? What's wrong with
>
> /^(BAR|BAZ)$/
>
>or even
>
> /^BA[RZ]$/
because of
use constant { FOO => 1, BAR => 2, BAZ => 3 };
------------------------------
Date: Wed, 6 Sep 2006 23:09:05 +0200
From: "Peter J. Holzer" <hjp-usenet2@hjp.at>
Subject: Re: XM::Simple - counting tags
Message-Id: <slrnefue7m.u21.hjp-usenet2@yoyo.hjp.at>
On 2006-09-06 10:26, John <john1949@yahoo.com> wrote:
><city>
> <firm>
> <employee>Fred</employee>
> <employee>Bill</employee>
> <employee>Bob</employee>
> </firm>
></city>
That's nice, but if it does it already contained that before parsing,
too. Parsing the above data with XML::Simple results in:
$VAR1 = {
'firm' => {
'employee' => [
'Fred',
'Bill',
'Bob'
]
}
};
> I need to know how many employees?
Isn't that quite obvious from the data structure?
scalar @{ $VAR1->{firm}{employee} }
> I can easily extract each employeee but I only need the count. Is
> there an easier way?
An easier way than what?
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 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 9694
***************************************